//this javascript file is to contain all of the common features
//to all of the pages in the BCP website

//*------------------------
// BEGIN IMAGE SWAPPING
//---

//--
//restore the image to the static state
//--
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;
}

//--
//preload images supplied to function from the body/onLoad function call
//--
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_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;
}

//--
//replace image with mouseover image
//--
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];}
}

//---
// END IMAGE SWAPPING
//*------------------------



//*------------------------
// BEGIN SEARCH FORM VALIDATION
//---

function validateSearch()
{
 	if(document.searchForm.search.value == "")
	{
	 	window.alert("Please enter a valid search argument.");
		document.searchForm.search.focus();
		return false;
	}
	
	return true;
}

//---
// END SEARCH FORM VALIDATION
//*------------------------


//*------------------------
// BEGIN ORDER FORM VALIDATION
//---
function validateOrder()
{
}
//---
// END ORDER FORM VALIDATION
//*------------------------


//*------------------------
// BEGIN CUSTOMER FORM VALIDATION
//---
function validateCustForm(func)
{
    if(func == "add")
	{
 	   if (document.cust.email.value == "" || document.cust.pass.value == "" )
	   {
    	  window.alert( "Please enter an email address and password." );
          document.cust.email.focus();
		  return false;
   	    }
		else if (document.cust.pass.value != document.cust.confpass.value)
		{
          window.alert( "Passwords entered do not match. Please reenter" );
          document.cust.pass.focus();
   		  return false;
        }
	}
	
	if (document.cust.billFirst.value == "" || document.cust.billLast.value == "" 
	         || (document.cust.billAdd1.value == "" && document.cust.billAdd2.value == "") 
			 || document.cust.billCity.value == "" || document.cust.billZip.value == "" 
			 || (document.cust.billCountry.value == "United States of America" && document.cust.billState.value == "") 
			 || (document.cust.billCountry.value == "Canada" && document.cust.billState.value == "") 
			 || document.cust.tele.value == "")
	{
        window.alert( "Please enter all required bill to fields." );
        document.cust.billFirst.focus();
		return false;
    }
	else if (document.cust.shipFirst.value == "" || document.cust.shipLast.value == "" 
	         || (document.cust.shipAdd1.value == "" && document.cust.shipAdd2.value == "") 
			 || document.cust.shipCity.value == "" || document.cust.shipZip.value == "" 
			 || (document.cust.shipCountry.value == "United States of America" && document.cust.shipState.value == "") 
			 || (document.cust.shipCountry.value == "Canada" && document.cust.shipState.value == "") 
			 )
	{
        window.alert( "Please enter all required ship to fields." );
        document.cust.shipFirst.focus();
		return false;
    }

		return true;

}
//---
// END CUSTOMER FORM VALIDATION
//*------------------------


//*------------------------
// BEGIN TEXTAREA CHARACTER LIMIT
//---
function limitText(field, maxlimit)
{
  if (field.value.length > maxlimit)
  {
    field.value = field.value.substring(0, maxlimit);
  }
}
//---
// END TEXTAREA CHARACTER LIMIT
//*------------------------


//*------------------------
// BEGIN JAVASCRIPT COOKIE MANIPULATION
//---
function setCookie(name, value, seconds) 
{
	if (typeof(seconds) != 'undefined') {
		var date = new Date();
		date.setTime(date.getTime() + (seconds*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else {
		var expires = "";
	}
	
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name)
{ 
	name = name + "=";
	var carray = document.cookie.split(';');

	for(var i=0;i < carray.length;i++) {
		var c = carray[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
	}

	return null;
}
 
function deleteCookie(name)
{
		this.setCookie(name, "", -1);
}
//---
// END JAVASCRIPT COOKIE MANIPULATION
//*------------------------
