

function onKeyPressBlockChacter(event)
{
   var isNS4 = (navigator.appName=="Netscape")?1:0;
    
	if(!isNS4){if( event.keyCode > 57 || event.keyCode == 32 || event.keyCode == 47 || event.keyCode == 39 || event.keyCode == 34 || event.keyCode == 46 || event.keyCode == 44 || event.keyCode == 43) event.returnValue = false;}else{if( event.which > 57 ||  event.which  == 32 ||  event.which  == 47 || event.which  == 39 || event.which  == 34 || event.which  == 46 || event.which  == 44 || event.which  == 43) return false;}
	//if(!isNS4){if(event.keyCode >8 || event.keyCode < 45) event.returnValue = false;}else{if(event.which ==8 || event.which < 45) return false;}
	
}



var whitespace = " \t\n\r"

function isEmpty(s)
{
   return ((s == null) || (s.length == 0))
}
function isWhitespace (s)
{  var i;
	// Is s empty?
	if (isEmpty(s)) return true;

	 // Search through string's characters one by one
	 // until we find a non-whitespace character.
	 // When we do, return false; if we don't, return true.
	 for (i = 0; i < s.length; i++)
	 {   
		 // Check that current character isn't whitespace.
		 var c = s.charAt(i);
 
		 if (whitespace.indexOf(c) == -1) return false;
	 }
 
	 // All characters are whitespace.
	 return true;
}
function BuildStr(s, s1)
{
	  if (s.length> 0) s = s + "\n";
	  s = s + s1;
	  return s;
}

function isCharsInBag (s, bag)
{  
  var i;
  // Search through string's characters one by one.
  // If character is in bag, append to returnString.

  for (i = 0; i < s.length; i++)
  {   
	  // Check that current character isn't whitespace.
	  var c = s.charAt(i);
	  if (bag.indexOf(c) == -1) return false;
  }
  return true;
}

function IsNumeric(val) {
	var validChars = "0123456789-";
	for (var x=0; x<val.length; x++) {
		if (!(validChars.indexOf(val.charAt(x)) != -1)) {
			return false;
			break;
		}
	}
	return true;
}
function Validate(theForm)
{
	var errMesg = "";
	var diplayMesg = "";

	
	var Q = ""; // this block determines lifespan of Q
	{
	if (isWhitespace(theForm.fname.value))
		{
		Q += "  First Name\n";
		}
		
	if (isWhitespace(theForm.lname.value))
		{
		Q += "  Last Name\n";
		}
	
	if (isWhitespace(theForm.address.value))
		{
		Q += "  Address\n";
		}
		
	if (isWhitespace(theForm.city.value))
		{
		Q += "  City\n";
		}
	
	if(document.getElementById('state_cd').disabled){
		if(document.getElementById('del_state').value==''){
			Q += "  State\n";
		}
	} else 	if(document.getElementById('del_state').disabled){
		if(document.getElementById('state_cd').value==""){
			Q += "  State\n";
		}
	} else{ Q += "  State\n";}
    if (isWhitespace(theForm.zip.value))
		{
		Q += "  Zip\n";
		}		
		
	if (isWhitespace(theForm.email.value))
		{
		Q += "  E-mail\n";
		}
	
	else if (echeck(theForm.email.value)==false)
	{
	   Q += "E-mail is Invalid\n";
	}	
	else if(!isCharsInBag( theForm.email.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
	{
	  Q += "E-mail contains Invalid Characters\n";
	}
	
	if (isWhitespace(theForm.phone.value))
		{
		Q += "  Phone\n";
		}	
	
	if(theForm.phone.value.length > 1)
	{
		if(!IsNumeric(theForm.phone.value)){
				 Q += "  Please enter numeric value for Phone\n";
			}	
	}		
	if(theForm.cellphone.value.length > 1)
	{
		if(!IsNumeric(theForm.cellphone.value)){
				 Q += "  Please enter numeric value for Cell Phone\n";
			}	
	}		

/*	if (isWhitespace(theForm.cellphone.value))
		{
		Q += "  Cell Phone\n";
		}	
*/	//else if (phonecheck(theForm.cellphone.value)==false)
	//{
	//   Q += "Enter Proper Phone number\n";
	//}				
				
				
	if ( Q.length > 0 )
		{
		diplayMesg = "Please provide Valid values for\n" + Q ;
		//errMesg += "Please provide Valid values for\n" + Q ;
		}
	}

 
	if (errMesg == "" && diplayMesg == "")
	{
		//theForm.submit();
		return true;
	}
	
	else
	{
	
			if(diplayMesg!="")
			{
				alert(diplayMesg);
				return false;			
			}
			else
			{
				alert(errMesg);
				return false;
			}	
	}
}

/*Start : Function for email Check */
function echeck(str) {

	if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
	else
	return false;
	}
	
/*function forcheck phone */
function phonecheck(str) {
    
	var e=document.orderform.phone.value;
		var phoneLength=e.length;
		//alert(phoneLength);
		if (phoneLength != 12 ) 
		{
		  //alert("please enter proper phone number");
		  //document.f.phone.focus();
		  return false;
		}
		if (phoneLength == 12 ) 
		{
		   var phoneStr=e.split("-");
		   var p1,p2,p3;
		   var phoneStrLength=phoneStr.length;
		   if (phoneStrLength!=3)
		   {
			 //alert("please enter proper phone number");
			 //document.f.phone.focus();
			 return false;
		   }
		   p1=phoneStr[0];
		   p2=phoneStr[1];
		   p3=phoneStr[2];
		   
		   if(   ((p1.length)!=3) && ((p2.length)!=3) && ((p3.length)!=4) )
		   {
			   // alert("please enter proper phone number");
				//  document.f.phone.focus();
				 return false;
		   } 
			
		}
		return true;
}	



/*code for date validation (mm/dd/yyyy) format */	
	var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}



