﻿// JScript File
//---trim function

function Trim(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}
//------------function to test if field is blank or not

function isBlank(s,f)
{
    if(Trim(s).length==0)
    {
	    //alert("Please enter your " + f);
             return false;
     }

}
//---function to test valid time
 function isValidTime(s)
 {
     s=Trim(s);
     //if(s.length==0)
    // {
     // alert("Please enter time in HH:MM AM/PM format");
    //          return false;
     //}
       var regNo= new RegExp(/^(\d{2}):(\d{2})\s{1}([AP]M)$/);//(/^([1-9]|1[0-2]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/);	
        if (!regNo.test(s))
         {
         //     alert("Please enter time in HH:MM AM/PM format");
              return false;
         }
 }

//-----function to test US phone nos---------
function isValidPhone(s)
{ 
 if(Trim(s).length==0)
     {
       //alert("Please enter your Phone no.");
      return false;
     }
//  var re = new RegExp(/^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/);
//  if(!re.test(s))
// {
//      alert("Specify Phone in US phone format");
//     return false;
// }
}

//-------------function to test valid email id
function isValidEmail(s)
{
 var pos1 = s.indexOf('@');
var pos2 = s.indexOf('.');
var str=s;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i	;
  if(s.length==0)
 {
  //alert("Please enter current Email Address");
  return false;
 }
 if((s!="") && (pos1 == - 1))
    {
	//alert("Please enter a valid email address!");
		return false;
	}
	
if((s!="") && pos2 == -1)
    {
	//alert("Please enter a valid email address!");
	return false;
	}
	
if (!filter.test(str))
  {
	//alert("Please enter a valid email address!");
		return false;
  }	
}


//--- function for webURL
function isvalidURL(s)
{
  if (s.length=0)
  {
             //alert("Please enter your Company URL");
             //  s.focus();
                  return false;
  }
  else
   {
   	   var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!v.test(s)) 
    {
      //  alert("You must supply a valid URL(starting with http://www. or https://www.)");
        return false;
    } 
       }
}

function isAlpha(s,f) {
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ';
var val=lwr+upr;
  if(Trim(s)=="")
  {
 // alert("Please enter your "+f);
   return false;
  }
  s=Trim(s);
  for (i=0; i<s.length; i++) {
    if (val.indexOf(s.charAt(i),0) == -1) 
    {
   // alert(f+ " can be alphabetical value only");
    return false;
    }
  }
 }
 //---------function to test zipcode------
function isValidZipcode(s)
{
      reZip = new RegExp(/\d{5}(-\d{4})?/);	
      if(Trim(s).length==0)
      {
      // alert("Please enter your Zipcode");
         return false;
      }

      if (!reZip.test(s)) 
    {
        // alert("Zip Code Is Not Valid!");
         return false;
    }
}
//--------------------------------------------------
function checklength(len) {
var con=eval(document.getElementById("txtComments"));
if (document.getElementById("txtComments").value.length>len ) {
alert("Comments cannot exceed "+len+" characters");
con.value=String(con.value).substr(0,len);
return false;
} 
}

//'=================================================================
function test_valid()
{
var retVal=0;
 if(isBlank(document.getElementById('txtName').value,"Name")==false)
 {
  //document.getElementById('txtName').focus();
   //return false;
  document.getElementById('Name').className='tdError';
  retVal=retVal+1;
 
 }
 else
 {
  document.getElementById('Name').className='tdColor';
 }

 if(isValidPhone(document.getElementById('txtPhone').value)==false)
 {
  //document.getElementById('txtPhone').focus();
  //return false;
  document.getElementById('Phone').className='tdError';
  retVal=retVal+1;
 
 }
 else
 {
  document.getElementById('Phone').className='tdColor';
 }
 
 if(isValidEmail(document.getElementById('txtEmail').value)==false)
 {
  //document.getElementById('txtEmail').focus();
 // return false;
 document.getElementById('Email').className='tdError';
  retVal=retVal+1;
 
 }
 else
 {
  document.getElementById('Email').className='tdColor';
 }
 
 
 
 
 
 
 
 
//if((Trim(document.getElementById('txtBesttime').value).length>0)&&(Trim(document.getElementById('txtBesttime').value)!="HH:MM AM/PM")){
//   if(isValidTime(document.getElementById("txtBesttime").value)==false)
 //   {
   // document.getElementById("txtBesttime").value="HH:MM AM/PM";
      //  return false;
 //document.getElementById('BestTime').className='tdError';
 //document.getElementById('txtBesttime').value="HH:MM AM/PM";
 // retVal=retVal+1;
 
// }
// else
// {
 // document.getElementById('BestTime').className='tdColor';
// }
//}


//if(Trim(document.getElementById('txtComments').value).length==0)
//{
// document.getElementById('txtComments').focus();
// return false;
//}

 
 
// if((Trim(document.getElementById('txtCity').value).length>0)&&(isAlpha(document.getElementById('txtCity').value,"City")==false))
// {
//    document.getElementById('txtCity').focus();
//    return false;
// }
// if((Trim(document.getElementById('txtState').value).length>0)&&(isAlpha(document.getElementById('txtState').value,"State")==false))
// {
//    document.getElementById('txtState').focus();
//    return false;
// }
// if((Trim(document.getElementById('txtZip').value).length>0)&&(isValidZipcode(document.getElementById('txtZip').value,"Zipcode")==false))
// {
//    document.getElementById('txtZip').focus();
//    return false;
// }
// 


if(retVal>0) 
{

return false;
}
else
{
if (document.getElementById('chktermscondi').checked==false)
{
alert("Have you read Terms and Disclaimers? Please check the Terms and Disclaimers checkbox");
  return false;
}
return true;
}
 



 }
 
 //-------------------------------------------------
 function gup( name )
 {  
   name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
   var regexS = "[\\?&]"+name+"=([^&#]*)"; 
   var regex = new RegExp( regexS );  
   var results = regex.exec( window.location.href );  
   if( results == null )  
     return ""; 
      else  
        return results[1];
   }
   
   function packg()
   {
   var frank_param = gup('packg'); 
  // alert(frank_param);
   document.getElementById('packg').value=frank_param;
   }
   