﻿function Validate()
{
    var rbts = document.getElementById("rbtShell");
    var rbtr = document.getElementById("rbtRaw");
    if((rbts.checked == false) && (rbtr.checked == false))
    {
        alert("Select Required Space");
		rbts.focus();
		return false;
    }
    if(rbts.checked)
    {
        if(document.form1.txtShellSpace.value == "")
        {
            alert("Enter Required Space");
		    document.form1.txtShellSpace.focus();
		    return false;
        }
        else
        {
            if(IsNumeric(document.form1.txtShellSpace.value)==false)
		    {
			alert("Invalid Required Space");
			document.form1.txtShellSpace.focus();
			return false;
		    }
        }
    }    
    if(rbtr.checked)
    {
        if(document.form1.txtRawSpace.value == "")
        {
            alert("Enter Required Space");
		    document.form1.txtRawSpace.focus();
		    return false;
        }
        else
        {
            if(IsNumeric(document.form1.txtRawSpace.value)==false)
		    {
			alert("Invalid Required Space");
			document.form1.txtRawSpace.focus();
			return false;
		    }
        }
    }    
	if(document.form1.txtName.value=="")
	{
		alert("Enter Name");
		document.form1.txtName.focus();
		return false;
	}
	
	if(document.form1.txtDesignation.value=="")
	{
		alert("Enter Designation");
		document.form1.txtDesignation.focus();
		return false;
	}
	if(document.form1.txtCompany.value=="")
	{
		alert("Enter Company Name");
		document.form1.txtCompany.focus();
		return false;
	}
	if(document.form1.txtAddress.value=="")
	{
		alert("Enter Address");
		document.form1.txtAddress.focus();
		return false;
	}
	if(document.form1.txtCity.value=="")
	{
		alert("Enter City");
		document.form1.txtCity.focus();
		return false;
	}
	if(document.form1.txtState.value=="")
	{
		alert("Enter State");
		document.form1.txtState.focus();
		return false;
	}
	if(document.form1.txtCountry.value=="")
	{
		alert("Enter Country");
		document.form1.txtCountry.focus();
		return false;
	}
	if(document.form1.txtZip.value=="")
	{
		alert("Enter Zip Code");
		document.form1.txtZip.focus();
		return false;
	}
	else
	{
		if(IsNumeric(document.form1.txtZip.value)==false)
		{
			alert("Invalid Zip Code");
			document.form1.txtZip.focus();
			return false;
		}
	}
	if(document.form1.txtEmail.value.length == 0)
	{
	    alert("Enter Email");
		document.form1.txtEmail.focus();
		return false;
	}
	if(echeck(document.form1.txtEmail.value) == false)
	{
	    //alert("Invalid Email");
		document.form1.txtEmail.focus();
		return false;
	}	
	if(document.form1.txtWeb.value=="")
	{
		alert("Enter Website");
		document.form1.txtWeb.focus();
		return false;
	}
	else
	{
	    if(valURL(document.form1.txtWeb.value) == false)
	    {
	        document.form1.txtWeb.focus();
		    return false;
	    }
	}	
	if(document.form1.txtPhCC.value.length>0)
	{
		if(IsNumeric(document.form1.txtPhCC.value)==false)
		{
			alert("Invalid Country Number");
			document.form1.txtPhCC.focus();
			return false;
		}
	}
	else
	{
			alert("Invalid Country Code");
			document.form1.txtPhCC.focus();
			return false;
	}
	if(document.form1.txtPhAC.value.length>0)
	{
		if(IsNumeric(document.form1.txtPhAC.value)==false)
		{
			alert("Invalid Area Code");
			document.form1.txtPhAC.focus();
			return false;
		}
	}
	else
	{
			alert("Invalid Area Code");
			document.form1.txtPhAC.focus();
			return false;
	}
	if(document.form1.txtTel.value.length>7)
	{
		if(IsNumeric(document.form1.txtTel.value)==false)
		{
			alert("Invalid Telephone Number");
			document.form1.txtTel.focus();
			return false;
		}
	}
	else
	{
			alert("Invalid Telephone Number");
			document.form1.txtTel.focus();
			return false;
	}
	if(document.form1.txtFax.value.length>7)
	{
		if(IsNumeric(document.form1.txtFax.value)==false)
		{
			alert("Invalid Fax Number");
			document.form1.txtFax.focus();
			return false;
		}
	}
	else
	{
			alert("Invalid Fax Number");
			document.form1.txtFax.focus();
			return false;
	}
	if(document.form1.txtMobile.value.length>9)
	{
		if(IsNumeric(document.form1.txtMobile.value)==false)
		{
			alert("Invalid Mobile Number");
			document.form1.txtMobile.focus();
			return false;
		}
	}
	else
	{
			alert("Invalid Mobile Number");
			document.form1.txtMobile.focus();
			return false;
	}
	if(document.form1.txtBInterest.value=="")
	{
		alert("Enter your Business Interest");
		document.form1.txtBInterest.focus();
		return false;
	}
}
	
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}
function fillstr()
{
    var semail = querySt("email");
    if(semail != null)
    {
        document.form1.txtEmail.value = semail;
    }
}
function valURL(strString) { 
    var v = new RegExp(); 
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
    if (!v.test(strString)) { 
        alert("You must supply a valid URL."); 
        return false; 
    } 
}
function IsNumeric(strString)
{
    var strValidChars = "0123456789()";
    var strChar;
    var blnResult = true;
    if (strString.length == '') return false;
// test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
    {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
        {
            blnResult = false;
        }
    }
    return blnResult;
}
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 ID")
		    return false
		 }

 		 return true					
	}

