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 validate(email)
{
if (document.form1.accept.checked==false)
	{
	alert('You must accept the Terms and Conditions of Komatpillar.com to register.')
	document.form1.accept.focus()
	return false
	}
if (document.form1.fn.value=='')
	{
		alert('Please enter your first name!')
		document.form1.fn.focus()
		return false
	}
	
if (document.form1.ln.value=='')
	{
		alert('Please enter your last name!')
		document.form1.ln.focus()
		return false
	}
	
if (document.form1.em.value=='')
	{
		alert('Please enter your email address!')
		document.form1.em.focus()
		return false
	}
	
if (document.form1.pa.value=='')
	{
		alert('Please enter your password!')
		document.form1.pa.focus()
		return false
	}
	else
		{
		if (document.form1.cp.value=='')
		{
			alert('Please confirm your password!')
			document.form1.cp.focus()
			return false
		}
		else
			{
			if (document.form1.cp.value!=document.form1.pa.value)
				{
				alert('The password you entered is different from your previously entered password!\nPlease enter the same password.')                 
				document.form1.cp.value=""
				document.form1.cp.focus()
			    return false
				}
			}
		}
	
var emailID=document.form1.em
	
		if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	
 var url=document.form1.we
 
 if ((document.form1.we.value!='http://') && (document.form1.we.value!='')){
	 if (urlcheck(url.value)==false){
 		url.value=""
		url.focus()
		return false
	}	
}
	return true
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		 return true
	}


function urlcheck(url){
//validate a URL
   
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
	
    if (!v.test(url)) {
        alert("You must supply a valid URL.");
        return false; 
	}
 		 return true					
}


function openCenteredWindow(url, height, width, name, parms) {
   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( (screen.height - height) / 2);
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
  //var win = window.open(url, name);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
   return win;
}
