﻿//// JScript File

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;					
	}
	
	
	
	
	function ValidAlpha_SPEC(strValue)
{
  var checkOK = ",'-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789& ";
  var checkStr = strValue;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}

function ValidAlpha_CompanySpec(strValue)
{
  var checkOK = ".,'-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789& ";
  var checkStr = strValue;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}


function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}



function validate(fname,lname,cname,phone1,phone2,phone3,email,strInterest)
{

 var fn = document.getElementById(fname);
 if(fn.value == "")
 {
    alert("First name required");    
    return false;
 }

if(!ValidAlpha_SPEC(fn.value))
{
     alert(" Valid First name requires 1-50 alpha-numeric characters. Please enter a valid name.");
    return false;
}

var ln = document.getElementById(lname);
if(ln.value == "")
{
    alert("Last name required");
    return false;
}

if(!ValidAlpha_SPEC(ln.value))
{
     alert(" Valid Last name requires 1-50 alpha-numeric characters. Please enter a valid name.");
    return false;
}

var fna = trim(fn.value.toLowerCase());
var lna = trim(ln.value.toLowerCase());

if(fna == lna)
{
    alert("First name and Last name can not be identical");
    return false;
}

var cn = document.getElementById(cname);
if(cn.value == "")
{
     alert("Company name is required");
     return false;
}

if(!ValidAlpha_CompanySpec(cn.value))
{
     alert(" Valid Company name requires 1-50 alpha-numeric characters. Please enter a valid name.");
     return false;
}

var hc = document.getElementById(phone1);
var h3 = document.getElementById(phone2);
var h4 = document.getElementById(phone3);

if((hc.value.length)!= 0 || (h3.value.length)!= 0 || (h4.value.length) != 0)
{
    if((hc.value.length)< 3 || (h3.value.length) < 3 || (h4.value.length) < 4)
    {
    alert("Invalid phone number.");
    return false;
    }
}
var email = document.getElementById(email);
if(email.value == "")
{
        alert("Email address required");
        return false;
}
else
{
if (!echeck(email.value))
{
//alert("Invalid Email address");
 return false;
}

}
var interest = document.getElementById(strInterest);
if(interest.selectedIndex==0)
{
        alert("Please select Area of Interest.");
        return false;
}
 return true;
}

 function isZipKey(evt)
      {
         var charCode = (evt.which) ? evt.which : evt.keyCode;
         if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode!=45) && (charCode!=40) && (charCode!=127))
            return false;

         return true;
      }
      
function payment(str)
{
var drop=document.getElementById(str);


}

function validate1(str)
{

var email = document.getElementById(str);
if(email.value == "")
{
alert("Email address required");
return false;
}
else
{
if (!echeck(email.value))
{
 return false;
}
}
return true;
}



 function onlyint(e,field)
{
	if (window.event) keynum = e.keyCode;
	else if (e.which) keynum = e.which;

	if (keynum == "0x08") return true;
	if (keynum == "0x09") return true;
  	if (keynum == "0x20") return true;
	if (keynum == "0x2d" && field == 'phone') return true;
	if (keynum == "0x2E" && field == 'currency') return true;
	if (keynum == "0x2F" && field == 'date') return true;
	if ((keynum >= "0x30") && (keynum <="0x39")) return true;
	return false;
}