function isempty(val)
{
 flag=false;
 if(val.value=="") flag=true;
 else
 {
  flag=true;
  for(i=0;i<val.value.length;i++)
   if(val.value.substr(i,1)!=" ") flag=false;
 }
 if(flag==true)
  {
   alert("You MUST Enter This Column.  Please Enter...");
   return true;
  }
 else
  return false;
}

function isurl(val)
{
 theinput=val.value;
 thelength=theinput.length;
 if(thelength>0)
 {
  loc=0;
  for(i=0;i<thelength-2;i++)
  {
   thestr=theinput.substr(i,3);
   if(thestr=="://") loc=i;
  }
  isnot="`!@$^*(){}[]\|;',<>";
  url=true;
  if(loc==0) url=false;
  for(i=0;i<thelength;i++)
   for(j=0;j<isnot.length;j++)
    if((theinput.substr(i,1)==isnot.substr(j,1))||(theinput.substr(i,1)=='"')) url=false;
  if(url==true) return true;
  else
  {
   alert("Please enter a valid URL.");
   return false;
  }
 }
 else
  return true;
}

function isnum(val)
{
 if(isempty(val))
  return false;
 num=true;
 theinput=val.value;
 theinput.replace(" ",""); 
 thelength=theinput.length;
 for(i=0;i<thelength;i++)
 {
  thechar=theinput.substring(i,i+1);
  if((thechar<"0" || thechar>"9") && (thechar!=".")) num=false;
 }
 if(num==false)
  {
   alert(" Please enter a number value");
   return false;
  }
 else
  return true;
}

function ismoney(val)
{
 if(isempty(val))
  return false;
 var theinput=val.value; 
 var thelength=theinput.length;
 var money=true;

 for(i=0;i<thelength;i++)
 {
  thechar=theinput.substr(i,1);
  if((thechar<"0" || thechar>"9") && (thechar!=".")) money=false;
 }
 if(money==false)
  {
   alert(" Please enter a valid currency value");
   return false;
  }
 else
  return true;
} 
    
function ispin(val)
{
 if(val.value=="")
  return true;
 var theinput=val.value; 
 var thelength=theinput.length;
 var pincode=true;
 if(thelength!=6) pincode=false;
 else
  for(i=0;i<6;i++)
  {
   thechar=theinput.substring(i,i+1);
   if(thechar<"0" || thechar>"9") pincode=false;
  }
 if(pincode==false)
 { 
  alert("The Pin Value is not a valid one.  Please enter 6-digited Pin value");
  return false;
 }
 else
  return true;
}

function iszip(val)
{
 if(isempty(val))
  return false;
 var theinput=val.value; 
 var thelength=theinput.length;
 var pincode=true;
 if(thelength!=5) pincode=false;
 else
  for(i=0;i<5;i++)
  {
   thechar=theinput.substring(i,i+1);
   if(thechar<"0" || thechar>"9") pincode=false;
  }
 if(pincode==false)
 { 
  alert("The Zip Value is not a valid one.  Please enter again");
  return false;
 }
 else
  return true;
}

function islogin(val)
{
 if(isempty(val))
  return false;
 var theinput=val.value; 
 var thelength=theinput.length;
 var login=true;
 if(thelength<6) login=false;
 if(login==false)
 { 
  alert("Minimum 6 characters allowed. Digits, Letters and Underscore. Please enter again");
  return false;
 }
 else
  return true;
}

function isphone(val)
{
 if(isempty(val))
  return false;
  theinput=val.value; 
  phonenumber=true;
  for(i=0;i<theinput.length;i++)
   {
    thechar=theinput.substring(i,i+1);
    if(thechar<"0" || thechar>"9")
       { if(thechar!=" " && thechar!="-" && thechar!="+")  phonenumber=false;}      
   }
  if(phonenumber==false)
  { 
   alert("The Phone Value is not a valid one.  Please enter again");
   return false;
  }
  else
   return true;
}

function isemail(val)
{
 if(isempty(val))
  return false;
 theinput=val.value; 
 theemail=true;
 thelength=theinput.length;
 if(thelength<5) theemail=false;
 for(i=0;i<thelength;i++)
 {
  thechar=theinput.substr(i,1).toUpperCase();
  if(!(thechar>="A" && thechar<="Z"))
   if(!(thechar>="0" && thechar<="9"))
    if(thechar!="." && thechar!="@" && thechar!="_" && thechar!="-")
	 theemail=false;
 }
 //alert(theemail);
 atloc1=0;atloc2=0;decloc=0;
 atloc1=theinput.indexOf("@");
 atloc2=theinput.lastIndexOf("@");
 decloc=theinput.indexOf(".");
 if(atloc1==0 || decloc==0 || atloc1!=atloc2 || Math.abs(atloc1-decloc)<2 || decloc==(thelength-1)) theemail=false;
 if(theemail==false)
 { 
  alert("The e-mail Value is not a valid one.  Please enter again");
  return false;
 }
 else
  return true;
}

function issame(val1,val2)
{
 if(isempty(val2))
  return false;
 sameval=true;
 theinput1=val1.value;
 theinput2=val2.value;
 thelength1=theinput1.length;
 thelength2=theinput2.length;
 if(thelength1!=thelength2) sameval=false;
 else
 {
  if(theinput1!=theinput2) sameval=false;
 } 
 if(sameval==false)
 { 
  alert("The Password entered is not the same.  Please enter again");
  return false;
 }
 else
  return true;
}

function isccno(val)
{
 if(!(isnum(val)))
    return false;
 isccnum=false;
 total=0;
 theinput=val.value;
 thelength=theinput.length;
 for(i=thelength-1;i>=1;i-=2)
 {
  total=total+parseInt(theinput.substr(i,1),10);
  tmp=parseInt(theinput.substr(i-1,1))*2;
  if(tmp<10)
    total+=tmp;
  else
    total+=(tmp%10)+((tmp-(tmp%10))/10);
 }
 if(thelength%2==1)
  total+=parseInt(theinput.substr(0,1));
 if(total%10==0)
  isccnum=true; 
 
 if(isccnum==false)
 {
  alert("The CC Number is not a valid one.  Please enter again");
  return false;
 }
 else
  return true;
}

