function displayiconnewwindow(ImageName,string) 
{
	agent = navigator.userAgent;
	WinTop = 100;  
	WinLeft = 150;
	winFeatures = "toolbar=0,location=0,directories=0,status=0";
	winFeatures += ",menubar=0,scrollbars=0,resizable=yes";
	winFeatures += ",screenX="+WinLeft+",screenY="+WinTop;
	winFeatures += ",left="+WinLeft+",top="+WinTop;
	winFeatures += ",height=320,width=270";
	PopUpWindow=window.open("LargeImage.aspx?filename="+ImageName+"&text="+string,"PopUpWindow",winFeatures);
	PopUpWindow.focus();
}

function makeWin(url, p_Width, p_Height, p_Scroll) {

	agent = navigator.userAgent;
	windowName = "";

	params  = "";
	params += "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=0,";
	params += "menubar=0,";
	if (p_Scroll == "null" || p_Scroll == null)
	{
	params += "scrollbars=1,";
	}
	else
	{
	params += "scrollbars=1,";
	}
	params += "resizable=1,";
	params += "top=0,";
	params += "left=0,";
	if (p_Width == "null" || p_Width == null) 
	{
	params += "width=500,";
	params += "height=600,";
	}
	else {
	params += "width=" + p_Width + ",";
	params += "height=" + p_Height;
	}

	// close the window to vary the window size
	if (typeof(win) == "object" && !win.closed){
    win.close();
	}

	win = window.open(url, windowName , params);

	if (agent.indexOf("Mozilla/2") != -1 && agent.indexOf("Win") == -1) {
	    win = window.open(url, windowName , params);
	}

	if (!win.opener) {
	    win.opener = window;
	}

	// bring the window to the front
	win.focus();	
}

function makeLeadTimeWin(url) 
{
	agent = navigator.userAgent;
	windowName = "Sitelet";

	params  = "";
	params += "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=0,";
	params += "menubar=0,";
	params += "scrollbars=1,";
	params += "resizable=0,";
	params += "width=575,";
	params += "height=400";
	   
	win = window.open(url, windowName , params);

	if (agent.indexOf("Mozilla/2") != -1 && agent.indexOf("Win") == -1) 
	{
		win = window.open(url, windowName , params);
	}	
	if (!win.opener) 
	{
		win.opener = window;
	}
}

function VerifyProductCompareOk()
{
	var iCount;
	iCount = 0;
	for(i=0;i<document.prod.skus.length;i++)
	{
			if (document.prod.skus[i].type == 'hidden')
				{
					iCount++;
				}
			if (document.prod.skus[i].type == 'checkbox')
				{
					if (document.prod.skus[i].checked == true)
					{
						iCount++;
					}
				}
	}
	if (iCount > 1)
	{
		document.forms['prod'].submit();
	}
	else
	{
		alert(GetAlertCompareOkStr());
	}
}

function CountSkus(oThis)
{
	var iCount;
	iCount = 0;
	for(i=0;i<document.prod.skus.length;i++)
	{
			if (document.prod.skus[i].type == 'hidden')
				{
					iCount++;
				}
			if (document.prod.skus[i].type == 'checkbox')
				{
					if (document.prod.skus[i].checked == true)
					{
						iCount++;
					}
				}
	}
	if (iCount > 10)
	{
		if (oThis.type == 'checkbox')
		{
			oThis.checked = false;
		}
		alert(GetAlertCountStr());
	}
}

function VerifyInkSelectOk(formName){
	
	
	var iCount;
	iCount = 0;
	if (document.forms[formName].listcount.value > 0)
	{
		iCount = 1;
	} 
	else 
	{
		for(i=0;i<document.forms[formName].listcount.length;i++)
		{
				if (document.forms[formName].listcount[i].value == 1)
				{
					iCount++;
				}
		}
	}
	
	if (iCount > 0)
	{		
		document.forms[formName].submit();
	}
	else
	{
		alert(GetAlertInkSelectOkStr());
	}
}


function AddSkuCount(oThis, count,max, formName)
{
	oThis.value = parseInt(oThis.value);
	
	if (isNaN(oThis.value))
	{
		oThis.value = 0;
		alert(GetInvalidQuantityStr());
	}
		
	if (oThis.value < 0)
	{
		oThis.value = 0;
		alert(GetInvalidQuantityStr());
	}
		
	if (oThis.value > max)
	{
		alert(GetLessThanTenStr());
		oThis.value = max;
	}
	oThis.value = oThis.value;
	
	if (oThis.value != 0)
	{
		if (document.forms[formName].listcount.value >= 0)
		{
			document.forms[formName].listcount.value = 1;
		}
		else
		{
			document.forms[formName].listcount[count].value = 1;
		}
	}
	else
	{
		if (document.forms[formName].listcount.value >= 0)
		{
			document.forms[formName].listcount.value = 0;
		}
		else
		{
			document.forms[formName].listcount[count].value = 0;
		}
	}
}




function VerifyProductSelectOk(formName)
{
	var iCount;
	iCount = 0;
	if (document.forms[formName].listcount.value > 0)
	{
		iCount = 1;
	} 
	else 
	{
		for(i=0;i<document.forms[formName].listcount.length;i++)
		{
				if (document.forms[formName].listcount[i].value == 1)
				{
					iCount++;
				}
		}
	}

	if (iCount > 0)
	{
		document.forms[formName].submit();
	}
	else
	{
		alert(GetAlertInkSelectOkStr());
	}
}

function GoSort(module)
{
	document.forms['sort'].orderby.value = module;
	document.forms['sort'].submit();
}

function ChangeItemsPerPage(Amount)
{
	document.forms['sort'].items_per_page.value = Amount;
	document.forms['sort'].spagenum.value='1';
	document.forms['sort'].submit();
}

function ChangeImageView(ImageFlag,pageNum)
{
	document.forms['sort'].image_flag.value = ImageFlag;
	document.forms['sort'].spagenum.value= pageNum;
	document.forms['sort'].submit();
}

function ChangeSummaryView(SummaryFlag,pageNum)
{
	document.forms['sort'].show_summary.value = SummaryFlag;
	document.forms['sort'].spagenum.value= pageNum;
	document.forms['sort'].submit();
}

function GoPage(iPage,pageName)
{
	document.forms['prod'].action = pageName;
	document.forms['prod'].spagenum.value= iPage;
	document.forms['prod'].submit();
}

function GoProdDetail(sku,url)
{
	document.forms['prod'].action = url;
	document.forms['prod'].sku.value= sku;
	document.forms['prod'].submit();
}

function SelectTab(obj)
{
	obj.style.cursor = "hand";

	var tab = obj.childNodes.item(0).childNodes.item(0).childNodes.item(0);
	for (i = 0; i < tab.childNodes.length; i++)
	{
		var tabPart = tab.childNodes.item(i);
		//alert(tabPart.id);
		switch (i)
		{
			case 0:
				tabPart.childNodes.item(0).src = "../images/Highlighted-Tab-Left.gif"
				break;
			case 1:
				tabPart.style.backgroundImage = "url(../images/Highlighted-Tab-Background.gif)";
				break;
			case 2:
				tabPart.childNodes.item(0).src = "../images/Highlighted-Tab-Right.gif"
				break;
		}
	}
}

function DeselectTab(obj)
{
	var tab = obj.childNodes.item(0).childNodes.item(0).childNodes.item(0);
	for (i = 0; i < tab.childNodes.length; i++)
	{
		var tabPart = tab.childNodes.item(i);
		//alert(tabPart.id);
		switch (i)
		{
			case 0:
				tabPart.childNodes.item(0).src = "../images/Inactive-Tab-Left.gif"
				break;
			case 1:
				tabPart.style.backgroundImage = "url(../images/Inactive-Tab-Background.gif)";
				break;
			case 2:
				tabPart.childNodes.item(0).src = "../images/Inactive-Tab-Right.gif"
				break;
		}
	}
}

function NavigateTo(url)
{
	window.location.href = url;
}

function ValidateConnectionString(obj) 
{ 
	var idNum = obj.name.split("_")[1]; 
	var connectionString = document.all("txtConnectionString_" + idNum).value; 
	var encodedConnectionString = encodeURI(connectionString); 

	window.showModalDialog("ValidateConnectionStrings.aspx?type=single&dsn=" + encodedConnectionString, "", "scroll:no;status:no;resizable:no;help:no;dialogHeight:230px;dialogWidth:550px;"); 
} 

function ValidateAllConnectionStrings(count) 
{ 
	var connectionStrings = "";
	for (i = 0; i < count; i++)
	{
		connectionStrings += document.all("txtConnectionString_" + i).value; 
		if (i < count - 1)
		{
			connectionStrings += "|";
		}
	}
	var encodedConnectionStrings = encodeURI(connectionStrings); 

	window.showModalDialog("ValidateConnectionStrings.aspx?type=multiple&dsn=" + encodedConnectionStrings, "", "status:no;resizable:no;help:no;dialogHeight:400px;dialogWidth:550px;"); 
} 

function PrinterSwitchCountry(countryInfo)
{
	arrCountryInfo = countryInfo.split("|");
	
	if (arrCountryInfo[1] != "")
	{
		var expDays = arrCountryInfo[2];
		window.location.href = "PrinterSegRedirect.aspx?redirect=" + encodeURI(arrCountryInfo[1]) + "&expDays=" + expDays + "&country=" + arrCountryInfo[0];
	}
	else
	{
		document.forms['PrinterSeg'].countrycode.value = arrCountryInfo[0];
		document.forms['PrinterSeg'].c.value = arrCountryInfo[0];
		document.forms['PrinterSeg'].customerid.value = "";
		document.forms['PrinterSeg'].changedcountry.value = "true";
		document.forms['PrinterSeg'].submit();
	}
}

function RemoveParameterFromUrl(url, paramToRemove)
{

	paramToRemove = '&' + paramToRemove;
	var paramsWithout = '';
	 //assumes ? exists in segment URL 
	
	if (url.indexOf(paramToRemove) > 0)
	{
		
		var locationOfParam = url.indexOf(paramToRemove);
		var paramsBefore = url.substring(locationOfParam, 0);
		var endOfString = url.substring(locationOfParam + 3, url.length);
		var paramsAfter = '';
		
		if (endOfString.indexOf('&') > 0)
		{
			paramsAfter = endOfString.substring(endOfString.indexOf('&'), endOfString.length);
		}
		
		paramsWithout = paramsBefore + paramsAfter;
	
	}
	
	return paramsWithout;
	
}

function PrinterSwitchSegment(SegmentInfo, cookied)
{
	var url = window.location.href;
	var len = url.length;
	var allParams = '&' + url.substring( url.indexOf('?') + 1, len); 
	allParams = RemoveParameterFromUrl(allParams,'s=');
	allParams = RemoveParameterFromUrl(allParams,'l=');
	allParams = RemoveParameterFromUrl(allParams,'c=');
	
	if (SegmentInfo != "")
	{
		arrSegmentInfo = SegmentInfo.split("|");
		var segmentRedirectUrl = arrSegmentInfo[3]; 
		var finalRedirect = encodeURI(segmentRedirectUrl + allParams);
		
		
		if (segmentRedirectUrl != "")
		{
			window.location.href = finalRedirect;
		}
		document.forms['PrinterSeg'].application.value = arrSegmentInfo[1];
		document.forms['PrinterSeg'].customerid.value = arrSegmentInfo[2];

		if (arrSegmentInfo[2] == "")
		{
			window.open("PrinterSegPopup.aspx?id=" + arrSegmentInfo[0],"SubSegWin","height=500,width=300,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
		}
	}
	else
	{
		document.forms['PrinterSeg'].application.value = "";
		document.forms['PrinterSeg'].customerid.value = "";
	}
}

function RedirectToPaperSelector(categoryId, dcc)
{
	var c = document.forms['PrinterSeg'].countrycode.value;
	var l = document.forms['PrinterSeg'].l.value;
	var cs = document.forms['PrinterSeg'].customerid.value;
	var host = "";
	var url = "";
	if (cs != "")
	{
		if (c != "us" && c != "ca")
		{
			host = document.forms['PrinterSeg'].emeadomain.value;
		}
		else
		{
			host = document.forms['PrinterSeg'].usdomain.value;
		}
		if (host != null && host != "")
		{
			url = "http://" + host + "/sna/";
		}
		
		url = url + "paperselector.aspx?c=" + c + "&l=" + l + "&cs=" + cs + "&category_id=" + categoryId + "&dcc=" + dcc;
		window.location.href = url;
	}
	else
	{
		document.forms['PrinterSeg'].submit();
	}
}

function setcosttypestate(checked_state)
{
	if( document.SearchAdvanced.selectiontypeids != null)
	{
		for(i=0; i<document.SearchAdvanced.selectiontypeids.length; i++)
		{
			document.SearchAdvanced.selectiontypeids[i].checked = checked_state;
		}
	}
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function ChangeBigImage(cnt, idx, sVal)
{
	if (window.navigator.appName.toLowerCase().indexOf("netscape") == -1)
	{
		for( i = 0; i < cnt ;i++) 
		{
			document.images["smallImage" + i ].style.borderWidth = 1;
			document.images["smallImage" + i ].style.borderColor = '#cccccc';
		}
		document.images["smallImage" + idx].style.borderWidth = 1;
		document.images["smallImage" + idx].style.borderColor = "#000000";
	}
	document.images["bigImage"].src = sVal;
}

function CollectProducts(mainSku,CurrentProfileUrlParams)
{
	var products = '';
	var index = document.forms.length - 1;
	for(i=0;i<document.forms[index].Products.length;i++)
	{
		if (document.forms[index].Products[i].checked == true)
		{
			products += document.forms[index].Products[i].value + ",";
		}
	}
	products += mainSku;
	makeWin('RelatedProducts.aspx?mainsku=' + mainSku + '&sku=' + products + '&' + CurrentProfileUrlParams + '&~lt=popup',575,580,1);
}

function TestSku(customerID, sku, custType, c)
{
	if (sku != "")
	{
		NavigateTo("SkuTestResults.aspx?customerset=" + customerID + "&country=" + c +"&sku=" + sku + "&type=" + custType);
		
	}
	else
	{
		alert("Please enter a sku.");
	}
}

function GoToSkuTest(customerID)
{
	TestSku(customerID, document.forms[0].skuNum.value, document.forms[0].custType.value, document.forms[0].c.value);
}

function SubmitForm(formName)
{
	document.forms[formName].submit();
}


function ImageAtMouseOver(formName,param_value)
{	
	if (document.forms[formName].skuDetails.value.length < 1)
	{
		// change printer image only when a printer has not already been selected
		document.forms[formName].PrinterImage.src = param_value;
	}
}

function ImageAtMouseOut(formName,param_value)
{
	if (document.forms[formName].skuDetails.value.length < 1)
	{
		// change image to blank only when a printer has not already been selected
		document.forms[formName].PrinterImage.src = param_value;		
	}	
}

/*
used in printersupplies - for the printer QI 2216
*/
function VerifyPrinterSelected(formName)
{
	var skuInfo = document.forms[formName].skuDetails.value ;

	if (skuInfo.length > 0 )
	{
		document.forms[formName].action.value = 1;
		document.forms[formName].submit();
	}
	else
	{
		alert (GetAlertSelectPrinterMessage());
	}
}
function SetPrinterSKUDetails(formName,sku,shortDesc,image)
{
	var skuInfo = "";
	skuInfo = skuInfo + sku + "|" + shortDesc;
	document.forms[formName].skuDetails.value = skuInfo;
	document.forms[formName].PrinterImage.src = image;
}
function SetPrinterTypeDetails(formName,printerTypeID)
{
	var printerType = "";	
	document.forms[formName].printerType.value = printerTypeID;
	document.forms[formName].skuDetails.value = "";
	document.forms[formName].submit();	
}


function CheckSkuCount(oThis, count,max, formName,sku)
{
	oThis.value = parseInt(oThis.value);
	var maxm = parseInt(max);
		
	if (isNaN(oThis.value))
	{
		oThis.value = 0;
		alert(GetInvalidQuantityStr());
	}
		
	if (oThis.value < 0)
	{
		oThis.value = 0;		
		alert(GetInvalidQuantityStr());		
	}
		
	if (oThis.value > maxm)
	{
		oThis.value = maxm;
		alert (GetLessThanTenStr());
	}
	
	var data = "sku=" + sku +'|' + oThis.value + '&';
	var emptyData = "";
	
	if (oThis.value > 0 && oThis.value <= maxm)
	{  
		/* store the sku and qty selected in the format sku=<%sku%>|<%qty%>&
		   the reason to store it in the above fashion is
		   1.this is the format that addedtocart page expects
		   2.performance - by presetting the values in the client side, the code behind	
		   can mererly read these values and pass non zero length values to addedtocart feature		
		*/		
		if (count==0 && document.forms[formName].skuAndQty[count]==null)
		{
			document.forms[formName].skuAndQty.value = data;		
		}
		else
		{
			document.forms[formName].skuAndQty[count].value = data;		
		}	
		
	}
	else
	{
		if (count==0 && document.forms[formName].skuAndQty[count]==null)
		{
			document.forms[formName].skuAndQty.value = emptyData;		
		}
		else
		{
			document.forms[formName].skuAndQty[count].value = emptyData;		
		}			
	}	
}

function ValidateQty(formName,actionFlag)
{	
	var nrOfSkusWithValidQty = 0;
	// 2 cases are possible
	// 1: There is more than 1 supply item - value from multiple text boxes are sent
	// in an array in the HttpRequest
	// 2: There is just one supply item - here value from skyAndQty text box is not sent as
	// an array and requires a different way to process it	
	
	if (document.forms[formName].skuAndQty.length > 1)
	{
		//Case 1:
		for(i=0;i<document.forms[formName].skuAndQty.length;i++)
		{
			var skuAndQtyValue = document.forms[formName].skuAndQty[i].value;		
			
			/* if the skuAndQtyValue length is > 0 it means the user has selected a valid qty*/
			if (skuAndQtyValue.length > 0)
			{
				nrOfSkusWithValidQty++;
			}	
		}	
	}
	else
	{	
		//case 2:
		var skuAndQtyValue = document.forms[formName].skuAndQty.value;			
			
		/* if the skuAndQtyValue length is > 0 it means the user has selected a valid qty*/
		if (skuAndQtyValue.length > 0)
		{
			nrOfSkusWithValidQty++;			
		}		
	}
	
	// if the value is greater than 0 from either of these 2 cases, then we have a valid input
	if (nrOfSkusWithValidQty > 0)
	{	
		// user input valid - ready to be submitted to server 
		
		if (document.forms[formName].userAction[0]==null)
		{
			document.forms[formName].userAction.value = actionFlag;
		}
		else
		{
			document.forms[formName].userAction[0].value = actionFlag;					
		}	
		
		document.forms[formName].submit();
	}
	else
	{
		alert(GetAlertInkSelectOkStr());
	}		
}

function SetProductSelectedForPurchase(formName, sku,isConfigurable)
{
	document.forms[formName].ProductSelectedForPurchase.value = sku;
	document.forms[formName].IsConfigurable.value = isConfigurable;
	document.forms[formName].submit();
}

 function changeComboSelect(propertyName, comboText, comboSelect, matchOnValue, exactMatchOnly) {
    if (propertyName=="value") updateComboSelect(comboText, comboSelect, matchOnValue, exactMatchOnly);
  }

  // if matchOnValue is false match using the text of select, if true use it's value
  function updateComboSelect(comboText, comboSelect, matchOnValue, exactMatchOnly) {
    if (comboText.changeCode=="SELECT") {
      comboText.lastIndex=comboSelect.selectedIndex;
      comboText.lastValue = comboSelect.options[comboSelect.selectedIndex].text;
      comboText.changeCode="";
      return;
    }
    var foundMatch = false;
    var searchString = comboText.value.toUpperCase();
    var prevSearchString = comboText.lastValue;
    var prevIndex = parseInt(comboText.lastIndex);
    
    if (searchString=="") {
      comboSelect.selectedIndex = 0;
      comboText.lastIndex="0";
      comboText.lastValue="";
      return;
    }
    
    var l = searchString.length;
    var minIndex = 0;
    var maxIndex = comboSelect.options.length - 1;
    if ( (!matchOnValue) && (!exactMatchOnly) && (prevSearchString != "") && (searchString.length > prevSearchString.length) && (prevSearchString == searchString.substr(0,prevSearchString.length)) ) {
      minIndex = prevIndex;
    }
    var i = minIndex;
    var curMatch = "";
    while (!foundMatch && (i<=maxIndex) ) {
      curMatch = (matchOnValue) ? comboSelect.options[i].value.toUpperCase() : comboSelect.options[i].text.toUpperCase();
      if (!exactMatchOnly) curMatch = curMatch.substr(0,l);
      if (searchString == curMatch) foundMatch = true;
      else i++;
    }
    if (!foundMatch) {
      comboSelect.selectedIndex = 0;
      comboText.lastIndex=0;
      comboText.lastValue="";
      return;
    }

        comboSelect.selectedIndex = i;
        comboText.lastIndex=i;
        comboText.lastValue=searchString;
        return;
  }
  
 function updateComboText(comboSelect, comboText, matchOnValue, exactMatchOnly) {
    if (comboSelect.selectedIndex == -1) comboSelect.selectedIndex = 0;
    if (matchOnValue) {
      comboText.changeCode = "SELECT"
      comboText.value = comboSelect.value;
    }
    else {
      comboText.changeCode = "SELECT"
      comboText.value = (comboSelect.options[comboSelect.selectedIndex].value=="") ? "" : comboSelect.options[comboSelect.selectedIndex].text;
    }
  }