/*
* Global client utility scripts that can be accessed
* from any page in the site. This file is
* included in the main site template.
*/
function gotoLogin(){window.location = "/checkout/checkout.asp";return false;}

// Validate the Email Address using Regular Expressions
function validate(emailad) {

	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
		alert("Please enter a valid email address (ex: fred@mysite.com) !");
		document.EmailForm.EmailAddress.focus();
	}
	else {
		//we have a clean email address.
		document.EmailForm.submit()
	}
}
function IsEmail(emailad) {

	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
		return false;
	}
	else {
		return true;
	}
}
/*
Notes:
'exclude' checks 5 conditions:
a) characters that should not be in the address
b) characters that should not be at the start
c) & d) characters that shouldn't be together
e) there's not more than one '@'
'check' checks there's at least one '@', later followed by at least one '.'
'checkend' checks the address ends with a period followed by 2 or 3 alpha characters
N.B. Javascript 1.2 only works with version 4 browsers and higher.
*/

// Change Menu Color on Mouse Over
function changeto(highlightcolor){
	source=event.srcElement
	if (source.tagName=="TD"||source.tagName=="TABLE")
	return
	
	while(source.tagName!="TD")
		source=source.parentElement
		if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
		source.style.backgroundColor=highlightcolor
}

function changeback(originalcolor){
	if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
		return
	if (event.toElement!=source)
		source.style.backgroundColor=originalcolor
}

function navigateURL(urlChars){sealWin = window.open(urlChars,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=550,height=400');self.name = "mainWin";}
function OpenCertDetails(){thewindow = window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=USVICT23-7X', 'anew', config='height=400,width=495,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');}	
function popURL(url){sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=500,height=500'); self.name = "mainWin";}  
function popMV(url){sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=825,height=775'); self.name = "mainWin";}  
function GCPop(url){sealWin=window.open(url,"win",'toolbar=1,location=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=500,height=500');self.name = "mainWin";}  
function dLength(item, len){return (item.length >= len);}
function error(elem, text){if (errfound) return; window.alert(text); elem.focus(); errfound = true;}
function ValidateShipping(form)
	{
		if (form.Shipping_First_Name.value.length==0)
		{
			alert("Please enter the first name of the shipping contact");
			form.Shipping_First_Name.focus();
			return (false);
		}
	   
		if (form.Shipping_Last_Name.value.length==0)
		{
			alert("Please enter the last name of the shipping contact");
			form.Shipping_Last_Name.focus();
			return (false);
		}
	   
		if (form.Shipping_Address.value.length==0)
		{
			alert("Please enter the Shipping street address");
			form.Shipping_Address.focus();
			return (false);
		}
	   
		if (form.Shipping_City.value.length==0)
		{
			alert("Please enter city");
			form.Shipping_City.focus();
			return (false);
		}
		
		if(form.Shipping_Zip.value.length!=5)
	    {
			alert("Invalid zipcode format. Sample 34807");
	        form.Shipping_Zip.focus();
	        return (false);
	    }
	   	
		if (form.Shipping_State.value.length < 2)
		{
			alert("Please select a 2 character state abbreviation");
	        form.Shipping_State.focus();
	        return (false);
		}
		
		if (form.s1BillingPhone.value.length < 10)
		{
			alert("Please enter your Phone Number");
			form.s1BillingPhone.focus();
			return (false);
		}
	    
	    if (form.s1Email.value.length < 8)
		{
			alert("Please enter you email address.");
			form.s1Email.focus();
			return false;
		} 
	return(true);
}

function ScreenPop(){thewindow = window.open('http://www.newbalancetampa.com/n-ergy.htm', 'anew', config='height=550,width=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');}

function vldCustUdte(form)
{
	var errCnt = 0;
	var e = "AN ERROR SITUATION HAS OCCURRED\n========================\n";
	
	if (form.bfn.value.length==0)
	{
		errCnt += 1;
		e += ("- Please enter your first name.\n");
	}
	
	if (form.bln.value.length==0)
	{
		errCnt += 1;
		 e += ("- Please enter your last name.\n");
	}
	
	if (form.badd1.value.length==0)
	{
		errCnt += 1;
		 e += ("- Please enter your street address.\n");
	}
	
	if (form.bcty.value.length==0)
	{
		errCnt += 1;
		e +=("- Please enter your city.\n");
	}
	
	if(form.bzc.value.length < 5)
	{
		errCnt += 1;
		e +=("- Invalid zipcode format. Sample 00000-0000.\n");
	}
	
	if (form.bph.value.length < 10)
	{
		errCnt += 1;
		e +=("- Please enter your Phone Number.\n");
	}
	
	if (IsEmail(form.bem.value) == false)
	{
		errCnt += 1;
		e +=("- Please enter you email address.\n");
	} 
	
	if (form.bpw.value.length == 0)
	{
		errCnt +=1;
		e +=("- Please enter your account password.\n");
	}
	if (errCnt != 0)
	{
		alert(e);
		return false;
	}
	else
	{
		return(true);
	}
}

function ImproveOurSite() {
    window.open(location.protocol + "//" + location.host + '/improve_our_site.asp', 'ImproveOurSite', 'width=540,height=295,scrollbars=yes,left=60,top=60');
}