/*******************************
/**  CLIENT SCRIPTS FOR ESHOP **
*******************************/


function SearchEnter()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.quicksearchform.submit();
				
			}
			else
			{
				return true;
			}
		
		}

function LoginEnter()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.loginform.submit();
				
			}
			else
			{
				return true;
			}
		
		}

function SendPassClick()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.forms[0].ForgotButton2.click();
				
			}
			else
			{
				return true;
			}
		
		}
		
		
function AddCatPress()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.categorymanagement.CategorySubmit.click();
				
			}
			else
			{
				return true;
			}
		
		}
		
		
function AddSubCatPress()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.categorymanagement.SubCatSubmit2.click();
				
			}
			else
			{
				return true;
			}
		
		}
		
function OrdersEnter()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.Form1.SearchButton2.click();
				
			}
			else
			{
				return true;
			}
		
		}
		
		
function ProdEnter()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.Form2.SearchButton2.click();
				
			}
			else
			{
				return true;
			}
		
		}

function ShowCurrent2()
{
	var pos = document.ManageSideForm.LinkTypeList[0].checked;
	
	if ( pos )
	{
			// Microsoft Internet Explorer
			if (document.all)
			{
				document.all.ManualLinkDiv.style.visibility="visible";
				document.all.ProductLinkDiv.style.visibility="hidden";
			}
			// Netscape Navigator
			else
			{
				document.ManualLinkDiv.visibility="visible";
				document.ProductLinkDiv.visibility="hide";
			}
	}
	else
	{
			// Microsoft Internet Explorer
			if (document.all)
			{
				document.all.ProductLinkDiv.style.visibility="visible";
				document.all.ManualLinkDiv.style.visibility="hidden";
			}
			// Netscape Navigator
			else
			{
				document.ProductLinkDiv.visibility="visible";
				document.ManualLinkDiv.visibility="hide";				
			}
	}

}
function ShowCert()
{
	//[document.CheckOut.PayList.selectedIndex].
	var pos;
	for ( x = 0; x < document.CheckOut.PayList.length; x ++ )
	{
		if ( document.CheckOut.PayList[x].checked )
		{
			pos = document.CheckOut.PayList[x].value;	
			break;
		}
	}
	
	if ( pos == 'Gift Certificate')
	{
			// Microsoft Internet Explorer
			if (document.all)
			{
				document.all.GiftCertDiv.style.visibility="visible";
				
			}
			// Netscape Navigator
			else
			{
				document.GiftCertDiv.visibility="visible";
				
			}
	}
	else
	{
			// Microsoft Internet Explorer
			if (document.all)
			{
				document.all.GiftCertDiv.style.visibility="hidden";
				
			}
			// Netscape Navigator
			else
			{
				document.GiftCertDiv.visibility="hidden";
				
			}
	}

}

function ShowCertAlt()
{
	//[document.CheckOut.PayList.selectedIndex].
	var pos;
	for ( x = 0; x < document.AltAddr.PaymentTypeList.length; x ++ )
	{
		if ( document.AltAddr.PaymentTypeList[x].checked )
		{
			pos = document.AltAddr.PaymentTypeList[x].value;	
			break;
		}
	}
	
	if ( pos == 'Gift Certificate')
	{
			// Microsoft Internet Explorer
			if (document.all)
			{
				document.all.GiftCertDiv.style.visibility="visible";
				
			}
			// Netscape Navigator
			else
			{
				document.GiftCertDiv.visibility="visible";
				
			}
	}
	else
	{
			// Microsoft Internet Explorer
			if (document.all)
			{
				document.all.GiftCertDiv.style.visibility="hidden";
				
			}
			// Netscape Navigator
			else
			{
				document.GiftCertDiv.visibility="hidden";
				
			}
	}


}







function ShowCurrent()
{
	var pos = document.forms[1].LinkTypeList[0].checked;
	
	if ( pos )
	{
			// Microsoft Internet Explorer
			if (document.all)
			{
				document.all.ManualLinkDiv.style.visibility="visible";
				document.all.ProductLinkDiv.style.visibility="hidden";
			}
			// Netscape Navigator
			else
			{
				document.ManualLinkDiv.visibility="visible";
				document.ProductLinkDiv.visibility="hide";
			}
	}
	else
	{
			// Microsoft Internet Explorer
			if (document.all)
			{
				document.all.ProductLinkDiv.style.visibility="visible";
				document.all.ManualLinkDiv.style.visibility="hidden";
			}
			// Netscape Navigator
			else
			{
				document.ProductLinkDiv.visibility="visible";
				document.ManualLinkDiv.visibility="hide";				
			}
	}

}

function closeAltShip()
{

			if (document.all)
			{
				var modalWidth = '450px';
				var modalheight = '450px';
				
				var confirmed = showModalDialog('Disclaimer.aspx', modalWidth,'dialogWidth='+ modalWidth + ';dialogHeight='+ modalheight +';status=0');
				//alert(confirmed);
				
				if ( confirmed )
				{
					return true;
				}
				
			}
			// Netscape Navigator
			else
			{
				return true;
			}
			
			return false;
}

function doConfirm(controlIn){
    if (confirm("Are you sure you wish to delete this entry?")){
        eval(controlIn);
        }
    }
    
function confirmDropDelete(controlIn){
	if (confirm("Note: if you delete a drop shipping, anyone product associated with will reset to default drop zip.  Proceed?")){
		eval(controlIn);
		}
	}
	
	
function confirmCatDelete(controlIn){
	if (confirm("Note: deleting a category may leave some products uncategorized.  Proceed?")){
		eval(controlIn);
		}
	}
	
function confirmSubCatDelete(controlIn){
	if (confirm("Note: deleting a sub-category may leave some products uncategorized.  Proceed?")){
		eval(controlIn);
		}
	}

function RemoveDepartments()
		{
			var amt = document.Form1.DepartmentList.options.length;
			var curropt;
			
			var x = 0;
			
			while ( x < amt )
			{
				curropt = document.Form1.DepartmentList.options[x];
				
				if ( curropt.selected )
				{
					document.Form1.DepartmentList.remove(x);
					amt--;
				}
					
				x++;
				
			} 
	
		}
		
		function AddDepartment()
		{
			var amt = document.Form1.DepartmentList.options.length;
			
			var i = document.Form1.DeptDropList.selectedIndex;
			
			var optxt = document.Form1.DeptDropList.options[i].text;
			var opval = document.Form1.DeptDropList.options[i].value;
			
			var newop = new Option(optxt,opval);
			
			document.Form1.DepartmentList.add(newop, amt);
	
		}
	
	
	

		function MM_findObj(n, d) 
		{ //v3.0
			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); 
				
			return x;
		}
		
		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_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 QuickBuy(boughtproduct)
		{
			alert(boughtproduct + ' has been added to your cart');
		}
		
		function ProdSearch(linkurl)
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				location.href(linkurl + document.forms[0].txtSearch.value);
				
			}
			else
			{
				return true;
			}
		}
		
		function CheckCartItems(count)
		{
			
			
			if ( count == '0' )
			{
				alert('There are no items in your cart.');
				return false;
			}
			else
			{
				return true;
			}
		
		}
		
		
		function EnterProdManage()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.forms[0].SearchButton.click();
				
			}
			else
			{
				return true;
			}
		
		}
		
		
		function EnterKeyBranch()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.forms[0].AddBranchButton.click();
				
			}
			else
			{
				return true;
			}
		
		}
		
		
		function AddDeptClick()
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				document.forms[0].AddNewDepartmentButton.click();
				
			}
			else
			{
				return true;
			}
		
		}
		
		function PerformLogin(email,pass,path)
		{
			
			if ( (email == '') || (pass == '') )
			{
				alert('Email/Password are required for login');
				
				document.forms[0].Email.value = '';
				document.forms[0].Password.value = '';
				
				document.forms[0].Email.focus();
				
				return false;
			}
		
			var fullpath = path + '?Email=' + email + '&Password=' + pass;
			
			location.href(fullpath);
			
		}
		
		
		
		// SEARCH CLICK - BANNER
		function PerformSearch(linkurl)
		{
			var redirecturl = linkurl + document.forms[0].txtSearch.value;
		
			location.href(redirecturl);
		
		}
		
	
		// ENTER KEY SEARCH - BANNER
		function EnterKeySearch(myurl)
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				var linkurl = myurl + document.forms[0].SearchField.value;
				
				location.href(linkurl);return false;
				
			} 
			else 
			{	
				return true;
			}
			
		}
		
		
		
		// ENTER KEY LOGIN - DYNAMIC BANNER
		function EnterKeyLogin(myurl)
		{
			if ( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) 
			{
				event.cancelBubble = true;
				event.returnValue = false;
				
				PerformLogin(document.forms[0].Email.value, document.forms[0].Password.value, myurl);
				
			} 
			else
			{
				return true;
			}
			
		}
		
		// ALERT USER IF CHECKOUT IS CLICKED WITH EMPTY CART
		function checkOutError(path, cost)
		{
			if (cost != 'Shopping Cart is Empty')
			{
				window.location= path;
			}
			else 
			{
				alert('Cart is empty!');
			}
		}
		
		// COPY CONTACT DETAILS
        function copyContactDetails() 
        {
            document.CheckOut.sFirstName.value = document.CheckOut.FirstName.value;
            document.CheckOut.sLastName.value = document.CheckOut.LastName.value;
            document.CheckOut.sStreet.value = document.CheckOut.Street.value;
            document.CheckOut.sStreet2.value = document.CheckOut.Street2.value;
            document.CheckOut.sCity.value = document.CheckOut.City.value;
            document.CheckOut.sCountryList.selectedIndex = document.CheckOut.CountryList.selectedIndex;
            document.CheckOut.sState.value = document.CheckOut.State.value;
            document.CheckOut.sPostalCode.value = document.CheckOut.PostalCode.value;
            document.CheckOut.sTelephone.value = document.CheckOut.Telephone.value;
            if ( document.CheckOut.nyCountyList != null )
            {
				document.CheckOut.sNYCountyList.selectedIndex = document.CheckOut.nyCountyList.selectedIndex;
				
			}
			
			if ( document.CheckOut.CountyBox != null )
			{
				document.CheckOut.sCountyBox.value = document.CheckOut.CountyBox.value;;
			}
                     
			if ( document.CheckOut.sPostalCode.value != '' )
			{
				document.CheckOut.submit();
			}
			
        }
        
        // COPY CONTACT DETAILS
        function copyContactDetails2() 
        {
            document.Register.sFirstName.value = document.Register.FirstName.value;
            document.Register.sLastName.value = document.Register.LastName.value;
            document.Register.sStreet.value = document.Register.Street.value;
            document.Register.sStreet2.value = document.Register.Street2.value;
            document.Register.sCity.value = document.Register.City.value;
            document.Register.sCountryList.selectedIndex = document.Register.CountryList.selectedIndex;
            document.Register.sState.value = document.Register.State.value;
            document.Register.sPostalCode.value = document.Register.PostalCode.value;
            document.Register.sTelephone.value = document.Register.Telephone.value;
            document.Register.sEveTelephone.value = document.Register.sTelephone.value;
            if ( document.Register.nyCountyList != null )
            {
				document.Register.sNYCountyList.selectedIndex = document.Register.nyCountyList.selectedIndex;
				if( document.Register.State.options[document.Register.State.selectedIndex].value == 'NY' )
				{ 
					document.all.sCountyDiv.style.visibility="visible";
				}
				else
				{
					document.all.sCountyDiv.style.visibility="hidden";
				}
					
			}
			
			
        }
        
          // COPY CONTACT DETAILS
        function copyContactDetails3() 
        {
            document.UpdateProfile.sFirstName.value = document.UpdateProfile.FirstName.value;
            document.UpdateProfile.sLastName.value = document.UpdateProfile.LastName.value;
            document.UpdateProfile.sStreet.value = document.UpdateProfile.Street.value;
            document.UpdateProfile.sStreet2.value = document.UpdateProfile.Street2.value;
            document.UpdateProfile.sCity.value = document.UpdateProfile.City.value;
            document.UpdateProfile.sCountryList.selectedIndex = document.UpdateProfile.CountryList.selectedIndex;
            document.UpdateProfile.sState.value = document.UpdateProfile.State.value;
            document.UpdateProfile.sPostalCode.value = document.UpdateProfile.PostalCode.value;
            document.UpdateProfile.sTelephone.value = document.UpdateProfile.Telephone.value;
            document.UpdateProfile.sEveTelephone.value = document.UpdateProfile.EveTelephone.value;
            if ( document.UpdateProfile.nyCountyList != null )
            {
				document.UpdateProfile.sNYCountyList.selectedIndex = document.UpdateProfile.nyCountyList.selectedIndex;
				if( document.UpdateProfile.State.options[document.UpdateProfile.State.selectedIndex].value == 'NY' )
				{ 
					document.all.sCountyDiv.style.visibility="visible";
				}
				else
				{
					document.all.sCountyDiv.style.visibility="hidden";
				}
				
			}
			
			
			
        }
      
		// FORMAT PHONE FOR 1st PHONENUM
		function FormatPhone1() 
		{
			document.CheckOut.Telephone.value= formatPhone(document.CheckOut.Telephone.value);
		}
		
		// FORMAT PHONE FOR 2nd PHONENUM
		function FormatPhone2() 
		{
			document.CheckOut.sTelephone.value= formatPhone(document.CheckOut.sTelephone.value);
		}
		
		// FORMAT PHONE FOR 3rd PHONENUM
		function FormatPhone3() 
		{
			document.Register.Telephone.value= formatPhone(document.Register.Telephone.value);
		}
		
		// FORMAT PHONE FOR 4th PHONENUM
		function FormatPhone4() 
		{
			document.Register.sTelephone.value= formatPhone(document.Register.sTelephone.value);
		}
		
		// FORMAT PHONE FOR 5th PHONENUM
		function FormatPhone5() 
		{
			document.UpdateProfile.Telephone.value= formatPhone(document.UpdateProfile.Telephone.value);
		}
		
		// FORMAT PHONE FOR 6th PHONENUM
		function FormatPhone6() 
		{
			document.UpdateProfile.sTelephone.value= formatPhone(document.UpdateProfile.sTelephone.value);
		}
		
		// FORMAT PHONE FOR 7th PHONENUM
		function FormatPhone7() 
		{
			document.AltAddr.Telephone.value= formatPhone(document.AltAddr.Telephone.value);
		}
		
		// FORMAT PHONE FOR 8th PHONENUM
		function FormatPhone8() 
		{
			document.contactus.Telephone.value= formatPhone(document.contactus.Telephone.value);
		}
		
		// FORMAT PHONE FOR 9th PHONENUM
		function FormatPhone9() 
		{
			document.contactus.AltPhone.value= formatPhone(document.contactus.AltPhone.value);
		}
		
		// FORMAT PHONE FOR 1st EVEPHONENUM
		function FormatEvePhone1() 
		{
			document.CheckOut.EveTelephone.value= formatPhone(document.CheckOut.EveTelephone.value);
		}
		
		// FORMAT PHONE FOR 2nd EVEPHONENUM
		function FormatEvePhone2() 
		{
			document.CheckOut.sEveTelephone.value= formatPhone(document.CheckOut.sEveTelephone.value);
		}
		
		// FORMAT PHONE FOR 3rd PHONENUM
		function FormatEvePhone3() 
		{
			document.Register.EveTelephone.value= formatPhone(document.Register.EveTelephone.value);
		}
		
		// FORMAT PHONE FOR 4th PHONENUM
		function FormatEvePhone4() 
		{
			document.Register.sEveTelephone.value= formatPhone(document.Register.sEveTelephone.value);
		}
		
		// FORMAT PHONE FOR 5th PHONENUM
		function FormatEvePhone5() 
		{
			document.UpdateProfile.EveTelephone.value= formatPhone(document.UpdateProfile.EveTelephone.value);
		}
		
		// FORMAT PHONE FOR 6th PHONENUM
		function FormatEvePhone6() 
		{
			document.UpdateProfile.sEveTelephone.value= formatPhone(document.UpdateProfile.sEveTelephone.value);
		}
		
		// FORMAT PHONE FOR 7th PHONENUM
		function FormatEvePhone7() 
		{
			document.AltAddr.EveTelephone.value= formatPhone(document.AltAddr.EveTelephone.value);
		}
		
		function formatPhone(num)
		{ 
			var _return=false;
			/*
				* 7181238748 to 1(718)123-8748
			*/ 
			
			num= replaceSubstring(num, "-", "");
			num= replaceSubstring(num, " ", "");
			
			if(num.length != 10)
			{ 
				/* 
				* if user did not enter 10 digit phone number then simply print whatever user entered 
				*/ 
				_return=_OUTPUT?num:false;
			} 
			else
			{ 
				/* formating phone number here */ 
				_return="(";
				var ini = num.substring(0,3);
				_return+=ini+") ";
				var st = num.substring(3,6);
				_return+=st+"-";
				var end = num.substring(6,10);
				_return+=end;
			}
			return _return; 
		} 
	
	// REPLACE A SUBSTRING WITHIN A STRING
	function replaceSubstring(inputString, fromString, toString) 
	{
		// Goes through the inputString and replaces every occurrence of fromString with toString
		var temp = inputString;
		if (fromString == "") 
		{
			return inputString;
		}
		if (toString.indexOf(fromString) == -1) 
		{ // If the string being replaced is not a part of the replacement string (normal situation)
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} 
		else 
		{ // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
			var midStrings = new Array("~", "`", "_", "^", "#");
			var midStringLen = 1;
			var midString = "";
			// Find a string that doesn't exist in the inputString to be used
			// as an "inbetween" string
			while (midString == "") 
			{
				for (var i=0; i < midStrings.length; i++) 
				{
					var tempMidString = "";
					for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
					if (fromString.indexOf(tempMidString) == -1) 
					{
						midString = tempMidString;
						i = midStrings.length + 1;
					}
				}
			} // Keep on going until we build an "inbetween" string that doesn't exist
			// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + midString + toTheRight;
			}
			// Next, replace the "inbetween" string with the "toString"
			while (temp.indexOf(midString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(midString));
				var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} // Ends the check to see if the string being replaced is part of the replacement string or not
		return temp; // Send the updated string back to the user
	
	} // Ends the "replaceSubstring" function


	
