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) {
	if (pField.value=="") {
		alert(psCaption + " <%=smValidateEmpty%>");
		pField.focus();
		return false;
	} else 
		return true;
}

function validateform(f){
	b = true;
	b = b && isFieldEmpty("<%=smEmail%>", f.email);
	return b;
}

	function isFieldEmailAddress(poField, psCaption) {
		re = /.+@.+\..+/ ;
								
		if (!re.test(poField.value)) {
			alert(psCaption);
			poField.focus();
			return false;
		} else
			return true;
	}

	function isFieldEmpty(psCaption, pField) {
		if (pField.value=="") {
			alert(psCaption + " cannot be empty");
			pField.focus();
			return false;
		} else 
			return true;
	}

	function validateform(f){
		b = true;
		b = b && isFieldEmpty("<%=smEmail%>", f.email);
		b = b && isFieldEmailAddress(f.email, "Please enter a valid <%=smEmail%>");
		return b;
	}
	function isFieldEmailAddress2(poField, psCaption) {
		re = /.+@.+\..+/ ;
								
		if (!re.test(poField.value)) {
			alert(psCaption);
			poField.focus();
			return false;
		} else
			return true;
	}

	function isFieldEmpty2(psCaption, pField) {
		if (pField.value=="") {
			alert(psCaption + " cannot be empty");
			pField.focus();
			return false;
		} else 
			return true;
	}

	function validateform2(f){
		b = true;
		b = b && isFieldEmpty2("Email", f.email2);
		b = b && isFieldEmailAddress2(f.email2, "Please enter a valid Email");
		return b;
	}

	function validatemaintform(f){
		b = true;
		b = b && isFieldEmpty2("Name", f.name);
		b = b && isFieldEmpty2("Unit", f.unit);
		b = b && isFieldEmpty2("Notes", f.notes);
		b = b && isFieldEmpty2("Phone", 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 );
}