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_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 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 GetCategory(psField){
	if (psField.options[psField.selectedIndex].value!="empty"){
		document.location="products.asp?cat=" + psField.options[psField.selectedIndex].value + "&hierarchy=0";
	}
}

function isFieldEmpty(psCaption, pField) {
  re = /[A-Za-z]{3,}/;
		if (!re.test(pField.value)) {
			alert(psCaption);
			pField.focus();
			return false;
		} else 
			return true;
	}

function isFieldEmailAddress(poField, psCaption) {
    var re;
    
    re = /<\w+.*>|;|\(|\)|\-{2,}|\\|\/|<|>|[|]|\.{2,},:\\/;
    if (re.test(poField.value)) 
    {
      alert(psCaption);
      poField.focus();
      return false;
    } else {
    
	    re = /^["]{0,1}[A-Za-z][.!#$%&'*\+-\/=?^_`\{\|\}~\w]{0,62}\w["]{0,1}@\w[-\w]{0,61}\w\.\w{2,}/;
	    if (!re.test(poField.value)) 
        {
          alert(psCaption);
          poField.focus();
          return false;
        } else
          return true;
    }
	}

function isZipEmpty(psCaption, pField) {
  re = /[0-9]{5}-?[0-9]{0,4}/;
		if (!re.test(pField.value)) {
			alert(psCaption);
			pField.focus();
			return false;
		} else 
			return true;
	}
  
function isPhoneFieldEmpty(psCaption, pField) {
  re = /\(?[0-9]{3}\)?[\s. \-]*[0-9]{3}[\s. \-]*[0-9]{4}/;
		if (!re.test(pField.value)) {
			alert(psCaption);
			pField.focus();
			return false;
		} else 
			return true;
	}

function isStateEmpty(psCaption, pField) {
  re = /[A-Za-z]{2}/;
		if (!re.test(pField.value)) {
			alert(psCaption);
			pField.focus();
			return false;
		} else 
			return true;
	}
  
function validatecontactform(f) {
   var b;
  b = isFieldEmailAddress(f.email, "Please enter a valid email id");
  b = b && isPhoneFieldEmpty("Please enter your phone number.", f.phone);
  return b;
}

function validateform(f){
  b = true;
  b = b && isFieldEmpty("Name is too short", f.name);
  b = b && isFieldEmpty("Address is too short", f.address);
  b = b && isFieldEmpty("City is too short", f.city);
  b = b && isStateEmpty("State is too short", f.state);
  b = b && isZipEmpty("Zip code invalid",f.zipcode);
  b = b && isFieldEmailAddress(f.email, "Please enter a valid email id");
  b = b && isPhoneFieldEmpty("Phone is invalid",f.phone);
  return b;
}

	/* Opens a new window where to show the image.
	 *
	 * sName		- Image title.
	 * sCode		- Product or category code.
	 * sImage		- Image name.
	 * sImageType	- Image type.
	 */
	function showLargerPhoto(sName, sCode, sImage, sImageType) {
		var w, h;
		
		if (showLargerPhoto.arguments.length == 6) {
			w = parseInt(showLargerPhoto.arguments[4]) + 60;
			h = parseInt(showLargerPhoto.arguments[5]) + 90;
		} else {
			w = 550;
			h = 550;
		}
	
		sImagePath = ((sImageType=="p") ? "prodimages/" : "catimages/") + sImage;
		open(
			"picviewer.asp?name=" + escape(sName) + "&code=" + escape(sCode) + "&Image=" + escape(sImagePath), 
			"picviewer",
			"directories=no,location=no,menubar=no,resizeable=yes,status=no,toolbar=no,scrollbars=yes,width=" + w + ",height=" + h,
			true);
	}

function loadPopUp( filename ) {
 var sFeatures;
 sFeatures = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizeable=yes,width=515,height=500,top=" + ( screen.width / 2 -350) + ",left=" + ( screen.height / 2 -200);
 window.open( filename , "EventPopUp", sFeatures );
}