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_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_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 checkForSpecialChar(str, obj) {
     var str1 = str;
     var str2 = obj;
     var i,j;
     var ch;

     for (i=0; i<str2.length; i++) {
        ch = str2.charAt(i);
        for (j=0; j<str1.length; j++)
            if (ch == str1.charAt(j)) break; 
        if (j == str1.length) break;
     }
     if (i != str2.length) {
       return(true);
     }
     else return (false);
}
function trim(s)
{
        s = s.replace( /^\s*/, "" );
        s = s.replace( /\s*$/, "" );
        return s;
}

function isEmail(str)
{
  re = new RegExp("[`~!#$%&*()+=|{}':;,?/><^\"\']");
  r =  str.match(re);
  if (r || str.indexOf("[") >= 0 || str.indexOf("]")>=0 || str.indexOf("\\")>=0 || str.indexOf(" ")>=0)
  {
 	return false;
  }
    var supported = 0;
  if (window.RegExp)
  {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported)
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

function validate()
{
	if(trim(document.form1.fname.value) == "")
	{
		alert ("Please enter Name")
		document.form1.fname.focus()
		return false;
	}
	if(trim(document.form1.city.value) == "")
	{
		alert ("Please enter City")
		document.form1.city.focus()
		return false;
	}
	if(trim(document.form1.tel.value) == "")
	{
		alert ("Please enter Telephone")
		document.form1.tel.focus()
		return false;
	}

}

function validateme()
{
	if(trim(document.frm1.dep_cd.value) == "")
	{
		alert ("Please enter your Code")
		document.frm1.dep_cd.focus()
		return false;
	}
	
	
	if(trim(document.frm1.dep_pwd.value) == "")
	{
		alert ("Please enter password")
		document.frm1.dep_pwd.focus()
		return false;
	}
	if (checkForSpecialChar ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", document.frm1.dep_pwd.value))
   {
       document.frm1.dep_pwd.value="";
	    alert ("Please note that the Password cannot contain invalid characters");
       document.frm1.dep_pwd.focus()
       return false;
   }
	
}

function validatequery()
{
	if(trim(document.form1.email.value)== "" || isEmail(document.form1.email.value) != true)
		{
			alert("Plese enter your valid Email ");
			document.form1.email.focus();
			return false;
		}
	if(trim(document.form1.remark.value) == "")
	{
		alert ("Please enter remark")
		document.form1.remark.focus()
		return false;
	}
}

function winopener(str,winname)
{
 window.open (str,winname,"width=610, height=500,resizable=0,scrollbars=1'");
 }

function passchange()
{
	
	
	if(trim(document.form1.mypass.value) == "")
	{
		alert ("Please enter your old password.")
		document.form1.mypass.focus()
		return false;
	}
	
	if(trim(document.form1.mypass.value).length < "5")
	{
		alert ("Please note that the Password can only be 8 characters long.")
		document.form1.mypass.focus()
		return false;
	}
	
	if (checkForSpecialChar ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_", document.form1.mypass.value))
   {
       document.form1.mypass.value="";
	    alert ("Please note that the Password cannot contain invalid characters");
       document.form1.mypass.focus()
   		return false;
   }
	
	if(trim(document.form1.mynewpass.value) == "")
	{
		alert ("Please enter your new password.")
		document.form1.mynewpass.focus()
		return false;
	}
	
	if(trim(document.form1.mynewpass.value).length < "8")
	{
		alert ("Please note that the Password can only be 8 characters long.")
		document.form1.mynewpass.focus()
		return false;
	}
	
	if (checkForSpecialChar ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_", document.form1.mynewpass.value))
   {
       document.form1.mynewpass.value="";
	    alert ("Please note that the Password cannot contain invalid characters");
       document.form1.mynewpass.focus()
		return false;
   }
	
	
	if(trim(document.form1.myconfpass.value) == "")
	{
		alert ("Please confirm your password.")
		document.form1.myconfpass.focus()
		return false;
	}
	
	if(trim(document.form1.myconfpass.value).length < "8")
	{
		alert ("Please note that the Password can only be 8 characters long.")
		document.form1.myconfpass.focus()
		return false;
	}
	
	if (checkForSpecialChar ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_", document.form1.myconfpass.value))
   {
       document.form1.myconfpass.value="";
	    alert ("Please note that the Password cannot contain invalid characters");
       document.form1.myconfpass.focus()
		return false;
   }
   
	
	
	if(trim(document.form1.mynewpass.value)!= trim(document.form1.myconfpass.value))
	 {
	 alert ("Password mismatch");
       document.form1.myconfpass.focus()
		return false;
	 }
	document.form1.action="changepass.asp"
	document.form1.submit();
}

function myconf()
{
	document.form2.action="email_conf.asp"
	document.form2.submit();
}

function validateemail()
{
	if(trim(document.form1.conf_email.value)== "" || isEmail(document.form1.conf_email.value) != true)
		{
			alert("Plese enter your valid Email ");
			document.form1.conf_email.value ="";
			document.form1.conf_email.focus();
			return false;
		}
	if(trim(document.form1.conf_add1.value)== "")
		{
			alert("Plese enter your address ");
			document.form1.conf_add1.focus();
			return false;
		}	
	if(trim(document.form1.conf_city.value)== "")
		{
			alert("Plese enter your city ");
			document.form1.conf_city.focus();
			return false;
		}
	if(trim(document.form1.conf_state.value)== "")
		{
			alert("Plese enter your state ");
			document.form1.conf_state.focus();
			return false;
		}
		if(trim(document.form1.conf_pin.value)== "")
		{
			alert("Plese enter your Pincode ");
			document.form1.conf_pin.focus();
			return false;
		}
if (checkForSpecialChar ("0123456789", document.form1.conf_pin.value))
   {
       document.form1.conf_pin.value="";
	    alert ("Please enter valid Pincode");
       document.form1.conf_pin.focus()
		return false;
   }		
		
	document.form1.action="confirm.asp"
	document.form1.submit();
}
