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 aboutus() {
	gzRestoreImage();
	document.getElementById("aboutusover").style.display = "inline";
	this.style.display = "none";
}

function services() {
	gzRestoreImage();
	document.getElementById("servicesover").style.display = "inline";
	this.style.display = "none";
}

function products() {
	gzRestoreImage();
	document.getElementById("productsover").style.display = "inline";
	this.style.display = "none";
}

function news() {
	gzRestoreImage();
	document.getElementById("newsover").style.display = "inline";
	this.style.display = "none";
}

function faq() {
	gzRestoreImage();
	document.getElementById("faqover").style.display = "inline";
	this.style.display = "none";
}

function contactus() {
	gzRestoreImage();
	document.getElementById("contactusover").style.display = "inline";
	this.style.display = "none";
}

function gzSetEvents() {

	document.getElementById("aboutusover").onmouseout = gzRestoreImage;
	document.getElementById("aboutus").onmouseover = aboutus;
	document.getElementById("servicesover").onmouseout = gzRestoreImage;
	document.getElementById("services").onmouseover = services;
	document.getElementById("productsover").onmouseout = gzRestoreImage;
	document.getElementById("products").onmouseover = products;
	document.getElementById("newsover").onmouseout = gzRestoreImage;
	document.getElementById("news").onmouseover = news;
	document.getElementById("faqover").onmouseout = gzRestoreImage;
	document.getElementById("faq").onmouseover = faq;
	document.getElementById("contactusover").onmouseout = gzRestoreImage;
	document.getElementById("contactus").onmouseover = contactus;
}

function gzRestoreImage() {
	document.getElementById("aboutusover").style.display = "none";
	document.getElementById("aboutus").style.display = "inline";
	document.getElementById("servicesover").style.display = "none";
	document.getElementById("services").style.display = "inline";
	document.getElementById("productsover").style.display = "none";
	document.getElementById("products").style.display = "inline";
	document.getElementById("newsover").style.display = "none";
	document.getElementById("news").style.display = "inline";
	document.getElementById("faqover").style.display = "none";
	document.getElementById("faq").style.display = "inline";
	document.getElementById("contactusover").style.display = "none";
	document.getElementById("contactus").style.display = "inline";
}
function isFieldEmailAddress(poField, psCaption) {
		re = /\w{3,}@\w{3,}\.\w{3,}/ ;
		if (!re.test(poField.value)) {
			alert(psCaption);
			poField.focus();
			return false;
		} else
			return true;
	}

	function isFieldEmpty(psCaption, pField) {
  re = /[A-Za-z0-9\-.\)\(]{3,}/;
		if (!re.test(pField.value)) {
			alert(psCaption);
			pField.focus();
			return false;
		} else 
			return true;
	}
  
function isStateFieldEmpty(psCaption, pField) {
  re = /[A-Za-z0-9]{2,}/;
		if (!re.test(pField.value)) {
			alert(psCaption);
			pField.focus();
			return false;
		} else 
			return true;
}

function isPhoneFieldEmpty(psCaption, pField) {
  re = /\d{3}\D*\d{3}\D*\d{4}/;
    if (!re.test(pField.value)) {
      re = /[\d, \ ]{10,15}/;
      if (!re.test(pField.value)) {
        alert(psCaption);
        pField.focus();
        return false;
      }
      else {
        return true;
      }
		} else 
			return true;
	}
  
	function validateform3(f){
		b = true;
//		b = b && isFieldEmpty("<%=smEmail%>", f.email);
		b = b && isFieldEmailAddress(f.email, "Please enter a valid email address");
		b = b && isFieldEmpty("Please enter a valid first name", f.fname);
		b = b && isFieldEmpty("Please enter a valid last name", f.lname);
    b = b && isPhoneFieldEmpty("Please enter a valid phone number",f.phone);
		return b;
	}

  	function validateform(f){
		b = true;
    b = b && isFieldEmpty("Company Name is too short", f.company);
    b = b && isFieldEmpty("Address is too short", f.address1);
    b = b && isFieldEmpty("City is too short", f.city);
    b = b && isStateFieldEmpty("State is too short", f.state);
    b = b && isFieldEmpty("Postal Code is too short",f.postalcode);
    b = b && isFieldEmpty("Country is too short",f.country);
    b = b && isPhoneFieldEmpty("Phone is invalid",f.phone);
		b = b && isFieldEmpty("First Name is too short", f.fname);
		b = b && isFieldEmpty("Last Name is too short", f.lname);
		b = b && isFieldEmailAddress(f.email, "Please enter a valid email id");
		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 + " field is 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;
	}

	/* 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);
	}
