//function to preload images on side nav
function swapPage(){
	var URL = unescape(window.document.location);

	if (URL.indexOf("?cat") > -1) { 
		category = URL.charAt( URL.indexOf("?cat=") + 5);
		
		if(category == 4){
			swapnav('olive_oil_blends');
		}else if(category == 5){
			swapnav('vegetable_dips');
		}else if(category == 6){
			swapnav('dessert_mixes');
		}else if(category == 7){
			swapnav('assortment_packs');
		}
		
	}else{
		
		category=0;
	}	

}


function loadImages(){
	about_usOn = new Image();
	about_usOn.src="http://www.gourmetcreations.net/images/nav/about_us_over.jpg";
	about_usOff = new Image();
	about_usOff.src="http://www.gourmetcreations.net/images/nav/about_us_off.jpg";

	olive_oil_blendsOn = new Image();
	olive_oil_blendsOn.src="http://www.gourmetcreations.net/images/nav/olive_oil_blends_over.jpg";
	olive_oil_blendsOff = new Image();
	olive_oil_blendsOff.src="http://www.gourmetcreations.net/images/nav/olive_oil_blends_off.jpg";

	vegetable_dipsOn = new Image();
	vegetable_dipsOn.src="http://www.gourmetcreations.net/images/nav/vegetable_dips_over.jpg";
	vegetable_dipsOff = new Image();
	vegetable_dipsOff.src="http://www.gourmetcreations.net/images/nav/vegetable_dips_off.jpg";

	dessert_mixesOn = new Image();
	dessert_mixesOn.src="http://www.gourmetcreations.net/images/nav/dessert_mixes_over.jpg";
	dessert_mixesOff = new Image();
	dessert_mixesOff.src="http://www.gourmetcreations.net/images/nav/dessert_mixes_off.jpg";

	assortment_packsOn = new Image();
	assortment_packsOn.src="http://www.gourmetcreations.net/images/nav/assortment_packs_over.jpg";
	assortment_packsOff = new Image();
	assortment_packsOff.src="http://www.gourmetcreations.net/images/nav/assortment_packs_off.jpg";

	recipesOn = new Image();
	recipesOn.src="http://www.gourmetcreations.net/images/nav/recipes_over.jpg";
	recipesOff = new Image();
	recipesOff.src="http://www.gourmetcreations.net/images/nav/recipes_off.jpg";

	wholesaleOn = new Image();
	wholesaleOn.src="http://www.gourmetcreations.net/images/nav/wholesale_over.jpg";
	wholesaleOff = new Image();
	wholesaleOff.src="http://www.gourmetcreations.net/images/nav/wholesale_off.jpg";

	linksOn = new Image();
	linksOn.src="http://www.gourmetcreations.net/images/nav/links_over.jpg";
	linksOff = new Image();
	linksOff.src="http://www.gourmetcreations.net/images/nav/links_off.jpg";

	contact_usOn = new Image();
	contact_usOn.src="http://www.gourmetcreations.net/images/nav/contact_us_over.jpg";
	contact_usOff = new Image();
	contact_usOff.src="http://www.gourmetcreations.net/images/nav/contact_us_off.jpg";



}

function swapnav( imgName ){
	var imgSrc = eval("document.images['" + imgName + "'].src");	
	var imgOffSrc = "http://www.gourmetcreations.net/images/nav/" + imgName + "_on.jpg";

	var beginIndex = imgSrc.indexOf("http://www.gourmetcreations.net/images/nav/");
	var imgSrcLength = imgSrc.length;
	imgSrc = imgSrc.substring(beginIndex, imgSrcLength);
	
	document.images[imgName].src = imgOffSrc;
}



function swap( imgName ){
	var imgSrc = eval("document.images['" + imgName + "'].src");	
	var imgOffSrc = "http://www.gourmetcreations.net/images/nav/" + imgName + "_off.jpg";
	var imgOnSrc = "http://www.gourmetcreations.net/images/nav/" + imgName + "_on.jpg";

	var beginIndex = imgSrc.indexOf("http://www.gourmetcreations.net/images/nav/");
	var imgSrcLength = imgSrc.length;
	imgSrc = imgSrc.substring(beginIndex, imgSrcLength);

	//alert(imgSrc + " <> " + imgOnSrc);
	if( imgSrc != imgOnSrc){
		//rollover
		//alert(imgSrc + " =? " + imgOffSrc);
		if( imgSrc == imgOffSrc ){
			document.images[imgName].src = eval(imgName + "On").src;
		}
		//rollout
		else{
			document.images[imgName].src = eval(imgName + "Off").src;
		}
	}
}

function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function FormValidator()
{
	var valid=true;
  if (document.forms[0].email.value == "")
  {
    alert("Please enter a value for the \"email\" field.");
    document.forms[0].email.focus();
    valid = false;
  }

  else if (!isEmailAddr(document.forms[0].email.value))
  {
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    document.forms[0].email.focus();
    valid=false;
  }

  else if (document.forms[0].email.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"email\" field.");
    document.forms[0].email.focus();
     valid=false;
  }

  if( valid ){
  	document.forms[0].submit();
  }


}
