function ShowCatalogSimplified(CatalogOID, ticket)
{
	ShowCatalog(CatalogOID, ticket, "ViewCatalog.aspx?Left=1:amp:Right=-1:amp:CatalogOID=" + CatalogOID);
	
}

function ShowCatalog(CatalogOID, Password, ShowPage)
{
	var intWidth = screen.width;
	var width = 970;
	var height = 656;
	if (intWidth > 1500)
	{
		width = 1415;
		height = 944;
	}
	
	if (intWidth < 1024)
	{
		width = 748;
		height = 512;
	}
	var property = "top=0, left=0, width=" + width + ", height=" + height;
	//alert(ShowPage);
	var wincatalog = window.open("http://209.155.0.87/activemerchandiser/CatalogView.aspx?CatalogOID=" + CatalogOID + "&SupplierID=300001&ShowPage=" + ShowPage + "&Password=" + Password, 'CatalogViews', property);
	//var wincatalog = window.open("http://www.activemerchandiser.com/CatalogView.aspx?CatalogOID=" + CatalogOID + "&SupplierID=5&ShowPage=" + ShowPage + "&Password=" + Password, 'CatalogViews', property);
	//var wincatalog = window.open("http://localhost/activemerchandiser/CatalogView.aspx?CatalogOID=" + CatalogOID + "&ShowPage=" + ShowPage + "&Password=" + Password, 'CatalogViews', property);
	wincatalog.focus();
}

function movetotop()
{
	if (navigator.userAgent.toLowerCase().indexOf( 'win' ) + 1) 
	{
		var csLoc = new String(window.parent.document.location);

		if (csLoc.toLowerCase().indexOf('#_top') == -1)
		{
			window.parent.document.location.replace(csLoc + '#_top');
		}
		else
		{
			window.parent.document.location.replace(csLoc);
		}
	}
}


function PrintPageWithoutButton()
{
window.print();
	document.getElementById("lblprint").style.visibility = "visible"; 
	document.getElementById("tdButtons").style.visibility = "visible"; 
	
	window.print();
	
	document.getElementById("lblprint").style.visibility = "visible";
	document.getElementById("tdButtons").style.visibility = "visible";
}

function ToStoreLocator()
{
	var zip = document.getElementById("txtStoreZip").value;
						
	var intValue = parseInt(zip);
	if (!isNaN(intValue))
		window.location.replace("store_locator.aspx?zip=" + zip);
	else
		window.location.replace("store_locator.aspx");
}


					


function ChangeFrameClient(OID)
{
	//alert(OID);
	if (OID == -1)
	{
		document.getElementById('imgtop_left').src = "images/spacer.gif";
		document.getElementById('imgtop_right').src = "images/spacer.gif";
		document.getElementById('imgbottom_left').src = "images/spacer.gif";
		document.getElementById('imgbottom_right').src = "images/spacer.gif";
		
		cellBckImg('tdtop', "images/spacer.gif");
		cellBckImg('tdbottom', "images/spacer.gif");
		cellBckImg('tdleft', "images/spacer.gif");
		cellBckImg('tdright', "images/spacer.gif");
	}
	else
	{
		document.getElementById('imgtop_left').src = "images/frames/" + OID + "_top_left.jpg";
		document.getElementById('imgtop_right').src = "images/frames/" + OID + "_top_right.jpg";
		document.getElementById('imgbottom_left').src = "images/frames/" + OID + "_bottom_left.jpg";
		document.getElementById('imgbottom_right').src = "images/frames/" + OID + "_bottom_right.jpg";
				
		cellBckImg('tdtop', "images/frames/" + OID + "_top.jpg");
		cellBckImg('tdbottom', "images/frames/" + OID + "_bottom.jpg");
		cellBckImg('tdleft', "images/frames/" + OID + "_left.jpg");
		cellBckImg('tdright', "images/frames/" + OID + "_right.jpg");
	}
}
			
function cellBckImg(idcell, imgName) 
{ 
	//alert(imgName);
	document.getElementById(idcell).style.background = "url(" + imgName + ")"; 
} 
		


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
    }
  }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
  }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function CAS_preloadImages() {
	MM_preloadImages('images/nav/logo_on.gif','images/nav/product_on.gif','images/nav/search_on.gif',
						  'images/nav/yourrep_on.gif','images/nav/login_on.gif','images/nav/faq_on.gif',
						  'images/nav/contact_on.gif')
}

function cleartext(inputBox){
            if (inputBox.defaultValue==inputBox.value)
            inputBox.value = ""
}  

function searchonenter(evt)
{
            var keyCode = 0;
            var ret_val = true; 

            if (evt) 
            {
                        keyCode = evt.keyCode || evt.which;
            }
            else 
            {
                        keyCode = window.event.keyCode;
            }   

            //Allow searching for ENTER key only
            if (keyCode == 13)
            {
                        //alert(keyCode);
                        tosearchresult();
            }
} 
function toInventoryStatus()
{
	var SearchEntry = document.getElementById("txtQuickSearch2").value;

	if (SearchEntry != "")
	{
			window.location.replace("product_line.aspx?MySKU=" + SearchEntry + "&category=-20001#_top");
	}
}

function searchInventoryStatus(evt)
{
            var keyCode = 0;
            var ret_val = true; 

            if (evt) 
            {
                        keyCode = evt.keyCode || evt.which;
            }
            else 
            {
                        keyCode = window.event.keyCode;
            }   

            //Allow searching for ENTER key only
            if (keyCode == 13)
            {
                        //alert(keyCode);
                        toInventoryStatus();
                        return false;
             }
} 
function ToSearchResult()
{
	var SearchEntry = document.getElementById("txtQuickSearch").value;

	if (SearchEntry != "")
		window.location.replace("search_results.aspx?Type=QuickSearch&Entry=" + SearchEntry);
	else
		window.location.replace("search_results.aspx?Type=QuickSearch&Entry=");
}

function SubmitMe(destination1) {
 var dest = destination1
 if (dest != 'excel') {
 document.FormInTemplate.action = 'rptInvWorksheet1.aspx';
 }
 else {
 document.FormInTemplate.action = 'rptInvWorksheetExcel.aspx';
 }
 //document.FormInTemplate.method = 'post';
 document.getElementById('showbutton1').style.display = 'none';
 document.getElementById('showmessage1').style.display = 'block'; 
 document.FormInTemplate.submit();
 }

function PrintPage4ViewDetails()
{
	document.getElementById("tdButtons").style.visibility = "hidden"; 
	window.print();
	document.getElementById("tdButtons").style.visibility = "visible";
	
	document.getElementById("HidCommand").value="PrintPage";
	
}

function AnyQuantityEntered() 
{
	for (i=0; i < document.FormInTemplate.elements.length; i ++)
	{
		if (document.FormInTemplate.elements[i].id.indexOf("txt") != -1)
			if (document.FormInTemplate.elements[i].value != "")
				return true;			
	}
	return false;
}
function AddToOrderStandard()
{
	
			document.getElementById("HidCommand").value="Normal";
			document.FormInTemplate.submit();
		
}

function AddToOrder()
{
	if (document.getElementById('HidSKUsforInvalid').value == "" )
	{
		if (AnyQuantityEntered())
		{
			document.getElementById("HidCommand").value="AddToOrder";
			document.FormInTemplate.submit();
		}
		else
		{
			alert("Please enter quantity for at least one item.");
		}
	}
	else
	{
		alert("Invalid quantity entry for Item #" + document.getElementById('HidSKUsforInvalid').value + ".");
	}
}

function AddAndCheckout()
{
	if (document.getElementById('HidSKUsforInvalid').value == "" )
	{
		if (AnyQuantityEntered())
		{
			document.getElementById("HidCommand").value="AddAndCheckout";
			document.FormInTemplate.submit();
		}
		else
		{
			alert("Please enter quantity for at least one item.");
		}
	}
	else
	{
		alert("Invalid quantity entry for Item #" + document.getElementById('HidSKUsforInvalid').value + ".");
	}
}
			
			
function HiResClick()
{
			document.getElementById("HidCommand").value="HiResClick";
			document.FormInTemplate.submit();
}

function ValidateAll()
{
	var ListofData = document.getElementById("HidValidationInfo").value;
	alert(ListofData);
	while (ListofData.indexof(';') != -1)
	{
		var strSubstring = ListofData.substr(0, ListofData.indexof(';'))
					
		var sku = strSubstring.substr(0, strSubstring.indexof(','))
		strSubstring = strSubstring.substr(strSubstring.indexof(','))
		var min = strSubstring.substr(0, strSubstring.indexof(','))
		var incre = strSubstring.substr(strSubstring.indexof(','))
		alert('sku=' + sku + 'min' + min + 'incre' + incre);
		ValidateQuantity(sku, min, incre);
	}
}

function ValidateQuantity(sku, minimum, increment)
{
				//alert(sku);
				
				//alert(increment);
	var Valid = true;
	var ErrorMessage = "";
	if (document.getElementById('txt' + sku).value != "")
	{
		Valid = IsInteger('txt' + sku);
             
		if (Valid == false)
		ErrorMessage = "Please enter an integer quantity for Item #" + sku + ".";
						
		//quantity must be a multiple of increment
		if (Valid == true)
		{
			intQuantity = parseInt(document.getElementById('txt' + sku).value);
			//quantity must be larger than Minimum
			if (intQuantity < minimum)
			{
				//Valid = false;
				ErrorMessage += "The quantity entered for Item #" + sku + " must be larger than " + minimum + "."
				document.getElementById('txt' + sku).value = minimum
			}
			intQuantity = parseInt(document.getElementById('txt' + sku).value);
			var Mode = 0;
			if (increment != 0) Mode = intQuantity % increment;
			if (Mode != 0)
			{
				Valid = false;
				ErrorMessage += "The quantity entered for Item #" + sku + " must be a multiple of " + increment + "."
			}
		}
	}
	
	var strHidSKUsforInvalid = document.getElementById('HidSKUsforInvalid').value;
	if (Valid==false)
	{	
		if (strHidSKUsforInvalid.indexOf(sku) == -1)
		{
			if (document.getElementById('HidSKUsforInvalid').value != "")
				document.getElementById('HidSKUsforInvalid').value += ", ";
			document.getElementById('HidSKUsforInvalid').value += "#" + sku;
						
		}
	}
	else
	{
		if (strHidSKUsforInvalid.indexOf("#" + sku) != -1)
		{
			if (strHidSKUsforInvalid.indexOf("#" + sku) == strHidSKUsforInvalid.length - sku.length - 1)
				if (strHidSKUsforInvalid.length != sku.length + 1)
					strHidSKUsforInvalid = strHidSKUsforInvalid.replace(", " + "#" + sku, "");
				else
					strHidSKUsforInvalid = strHidSKUsforInvalid.replace("#" + sku, "");
			else	
				strHidSKUsforInvalid = strHidSKUsforInvalid.replace("#" + sku + ", ", "");
							
			document.getElementById('HidSKUsforInvalid').value = strHidSKUsforInvalid;
						
		}
					
				
	}
	if (ErrorMessage != "")
		alert(ErrorMessage);
}


function IsInteger(ID)
{
				
	var intValue = parseInt(document.getElementById(ID).value);
	if (!isNaN(intValue))
	{
		//alert("true");
		document.getElementById(ID).value = intValue;
		return true;
	}

	if (isNaN(intValue))
	{
		//alert("false");
		return false;
	}
}
function PrintPage4ViewDetails()
{
	document.getElementById("tdButtons").style.visibility = "hidden"; 
	window.print();
	document.getElementById("tdButtons").style.visibility = "visible";
	
	document.getElementById("HidCommand").value="PrintPage";
	
}

function AnyQuantityEntered() 
{
	for (i=0; i < document.FormInTemplate.elements.length; i ++)
	{
		if (document.FormInTemplate.elements[i].id.indexOf("txt") != -1)
			if (document.FormInTemplate.elements[i].value != "")
				return true;			
	}
	return false;
}
function AddToOrderStandard()
{
	
			document.getElementById("HidCommand").value="Normal";
			document.FormInTemplate.submit();
		
}

function AddToOrder()
{
	if (document.getElementById('HidSKUsforInvalid').value == "" )
	{
		if (AnyQuantityEntered())
		{
			document.getElementById("HidCommand").value="AddToOrder";
			document.FormInTemplate.submit();
		}
		else
		{
			alert("Please enter quantity for at least one item.");
		}
	}
	else
	{
		alert("Invalid quantity entry for Item #" + document.getElementById('HidSKUsforInvalid').value + ".");
	}
}

function AddAndCheckout()
{
	if (document.getElementById('HidSKUsforInvalid').value == "" )
	{
		if (AnyQuantityEntered())
		{
			document.getElementById("HidCommand").value="AddAndCheckout";
			document.FormInTemplate.submit();
		}
		else
		{
			alert("Please enter quantity for at least one item.");
		}
	}
	else
	{
		alert("Invalid quantity entry for Item #" + document.getElementById('HidSKUsforInvalid').value + ".");
	}
}
			
function ValidateAll()
{
	var ListofData = document.getElementById("HidValidationInfo").value;
	alert(ListofData);
	while (ListofData.indexof(';') != -1)
	{
		var strSubstring = ListofData.substr(0, ListofData.indexof(';'))
					
		var sku = strSubstring.substr(0, strSubstring.indexof(','))
		strSubstring = strSubstring.substr(strSubstring.indexof(','))
		var min = strSubstring.substr(0, strSubstring.indexof(','))
		var incre = strSubstring.substr(strSubstring.indexof(','))
		alert('sku=' + sku + 'min' + min + 'incre' + incre);
		ValidateQuantity(sku, min, incre);
	}
}

function ValidateQuantity(sku, minimum, increment)
{
				//alert(sku);
				
				//alert(increment);
	var Valid = true;
	var ErrorMessage = "";
	if (document.getElementById('txt' + sku).value != "")
	{
		Valid = IsInteger('txt' + sku);
             
		if (Valid == false)
		ErrorMessage = "Please enter an integer quantity for Item #" + sku + ".";
						
		//quantity must be a multiple of increment
		if (Valid == true)
		{
			intQuantity = parseInt(document.getElementById('txt' + sku).value);
			//quantity must be larger than Minimum
			if (intQuantity < minimum)
			{
				//Valid = false;
				ErrorMessage += "The quantity entered for Item #" + sku + " must be larger than " + minimum + "."
				document.getElementById('txt' + sku).value = minimum
			}
			intQuantity = parseInt(document.getElementById('txt' + sku).value);
			var Mode = 0;
			if (increment != 0) Mode = intQuantity % increment;
			if (Mode != 0)
			{
				Valid = false;
				ErrorMessage += "The quantity entered for Item #" + sku + " must be a multiple of " + increment + "."
			}
		}
	}
	
	var strHidSKUsforInvalid = document.getElementById('HidSKUsforInvalid').value;
	if (Valid==false)
	{	
		if (strHidSKUsforInvalid.indexOf(sku) == -1)
		{
			if (document.getElementById('HidSKUsforInvalid').value != "")
				document.getElementById('HidSKUsforInvalid').value += ", ";
			document.getElementById('HidSKUsforInvalid').value += "#" + sku;
						
		}
	}
	else
	{
		if (strHidSKUsforInvalid.indexOf("#" + sku) != -1)
		{
			if (strHidSKUsforInvalid.indexOf("#" + sku) == strHidSKUsforInvalid.length - sku.length - 1)
				if (strHidSKUsforInvalid.length != sku.length + 1)
					strHidSKUsforInvalid = strHidSKUsforInvalid.replace(", " + "#" + sku, "");
				else
					strHidSKUsforInvalid = strHidSKUsforInvalid.replace("#" + sku, "");
			else	
				strHidSKUsforInvalid = strHidSKUsforInvalid.replace("#" + sku + ", ", "");
							
			document.getElementById('HidSKUsforInvalid').value = strHidSKUsforInvalid;
						
		}
					
				
	}
	if (ErrorMessage != "")
		alert(ErrorMessage);
}


function IsInteger(ID)
{
				
	var intValue = parseInt(document.getElementById(ID).value);
	if (!isNaN(intValue))
	{
		//alert("true");
		document.getElementById(ID).value = intValue;
		return true;
	}

	if (isNaN(intValue))
	{
		//alert("false");
		return false;
	}
}
