﻿/** Search **/
var timerId = 0;
var oldSearchValue = "";
var isFirstFocus = true;

function CancelAsyncPostBack() 
{
	//prm is inialized in the Quick-search module.
    if (prm.get_isInAsyncPostBack()) 
    {
      prm.abortPostBack();
    }
}

function SearchKeyUp(searchValue, buttonId, searchIconId)
{
	if(searchValue != oldSearchValue)
	{
		if(searchValue.toString().length > 1)
		{
			CancelAsyncPostBack() //Clear any ongoing partial update
			clearInterval(timerId); //Clear any search that is scheduled by the timer
			timerId = setInterval("Search('" + buttonId + "', '" + searchIconId + "')", 400); //Set new search in the timer
		}
		oldSearchValue = searchValue;
	}
}
function Search(buttonId, searchIconId)
{
	clearInterval(timerId);
	var obj = document.getElementById(searchIconId);
	obj.src = "/SpbSydTemplates/Images/searchingIcon" + strTheme + ".gif";
	obj = document.getElementById(buttonId);
	obj.click();
}
function SearchFocus(textBoxId, boolFixFocus)
{
	if (isFirstFocus)
	{
		var textBox = document.getElementById(textBoxId);
		if(textBox.value == "Sök och ordlista")
		{
			textBox.value = "";
		}
		isFirstFocus = false;
		
		if(boolFixFocus)
		{
			textBox.value = textBox.value;
		}
	}
}
function ClearFocus() 
{
	isFirstFocus = true;
}

//IE6 only
function SetIframe() 
{
    //sets iframe size and set class that hides elements that still shows through.
	var iframe = document.getElementById("Ie6iframe");
	var resultDiv = document.getElementById("SearchResult");
	iframe.style.height = resultDiv.offsetHeight+7 + "px";
	iframe.style.width = resultDiv.offsetWidth+7 + "px";
	document.getElementById("RightAreaDiv").className = "IE6Hide";
}
function IE6Visible()
{
    document.getElementById("RightAreaDiv").className = "";
}

/* Black box hovering */
function BBMouseOver(objBoxDiv)
{
	objBoxDiv.style.backgroundImage = "url(/SpbSydTemplates/Images/bgFadeBlack2" + strTheme + ".gif)";
}
function BBMouseOut(objBoxDiv)
{
	objBoxDiv.style.backgroundImage = "url(/SpbSydTemplates/Images/bgFadeBlack" + strTheme + ".gif)";
}

/* Show tab content */
function ShowTab(intTab)
{
	for(i=1; i<=5; i++)
	{
		tab = document.getElementById("Tab" + i);
		if(tab)
		{
			tab.className = "";
		}
		data = document.getElementById("ProductData" + i);
		if(data)
		{
			data.style["display"] = "none";
		}
	}
	tab = document.getElementById("Tab" + intTab);
	tab.className = "selected";
	data = document.getElementById("ProductData" + intTab);
	data.style["display"] = "block";

}

/* Login */
function Login(strDropDownId) {
	var selector = document.getElementById(strDropDownId);
	strURL = selector.options[selector.selectedIndex].value
	if (strURL.indexOf("swedbank.se") == -1 && strURL.indexOf("folksam.se") == -1) {
		document.location.href = strURL;
	}
	else {
	    var intW = 900;
	    var intH = 650;
		var myWin = window.open(strURL, "xloginx", "width="+ intW +",height="+ intH +",left="+ (screen.width-intW)/2 +",top="+ (screen.height-intH-200)/2 +",resizable=1,scrollbars=1,menubar=1,location=1,status=1,toolbar=1");
		if(myWin == null)
		{
		    alert("Det gick inte att öppna fönstret med Internetbanken. Kontrollera ifall du har en \"popup-blockerare\" som hindrar fönstret från att öppnas");
		}
		else
		{
		   myWin.focus();
		}
	}
}

/* General functions */
function SurfTo(strURL)
{
    
    if (strURL.search("http:") == -1)
    {
	    window.location.href = strURL;
	}
	else
	{
	    var name = strURL.replace(/[^a-z0-9]+/g, ""); //fix for IE 
	    var myWin = window.open(strURL, name);
	    myWin.focus();
	}
}

function PopWin(strURL, intWidth, intHeight)
{
    var name = strURL.replace(/[^a-z0-9]+/g, ""); //fix for IE 
    var myWin = window.open(strURL, name, "width="+ intWidth +",height="+ intHeight +",left="+ (screen.width-intWidth)/2 +",top="+ (screen.height-intHeight-200)/2);
    myWin.focus();
}


