
/*
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;}
	
}

*/

//alert("A");

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 submitme(theForm)
{
	//alert("A");
	var i="";
	var Q1 = ""; // this variable is used to focus on the first blank field
	var errMesg = ""; // this variable is used to display  messages
	var diplayMesg = ""; // this variable is used to display error messages
	var Q = ""; // this block determines lifespan of Q
	
	
		
	
	
	if (isWhitespace(theForm.name.value))
		{
		Q += "  Name\n";
		Q1 += "name ";
		}
	else if(!isCharsInBag(document.order.name.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. "))
	{
	  errMesg += "Name contains Invalid Characters\n";
	}
	
	if (isWhitespace(document.order.address.value))
	  {
   	  	Q += "  Mailing Address\n";
		Q1 += "address ";
	 }
	else if(!isCharsInBag(document.order.address.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#-_,. "))
	{
	  errMesg += "Address contains Invalid Characters\n";
	}
		
	if(isWhitespace(document.order.city.value))
	  {
   	  	Q += "  City\n";
		Q1 += "city ";
	  }
	else if(!isCharsInBag(document.order.city.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "))
	{
	  errMesg += "City contains Invalid Characters\n";
	}
	
	if (order.state.value=="")
		{
		Q += "  Select State\n";
		Q1 += "state ";
		}		
		
		
	if (isWhitespace(order.phone.value))
		{
		Q += "  Phone\n";
		Q1 += "phone ";
		}	
		
	if (isWhitespace(order.cellphone.value))
		{
		Q += "  Cell Phone\n";
		Q1 += "cellphone ";
		}		
			
/*
else if(!isCharsInBag( order.phone.value, "0123456789"))
	{
	  errMesg += "Invalid Phone Number.\n";
	}
*/	
	if (isWhitespace(document.order.email.value))
		{
			Q += "  Email Address\n";
			Q1 += "email ";
		}
		
	else if(!echeck(document.order.email.value))
		{
		 errMesg += "Invalid Email Address\n";
		}	
		else if(!isCharsInBag(document.order.email.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
		{
		  errMesg += "Email Address contains Invalid Characters\n";
		}
	
		
		var radio=document.getElementsByName("myshipDetail");
	if(radio[0].checked==false && radio[1].checked==false)
	{
		Q += "  Shipping Details\n";
		
	}
	if((document.order.t_storage10.value == "") && (document.order.t_storage20.value == ""))
	{
		Q += "  Any Storage Option\n";
		Q1 += "t_storage10 "; 
	}
	
	if(document.order.fmon.value == "")
	{
		Q += "  From month\n";
		Q1 += "fmon ";
	}

	if(document.order.fdate.value == "")
	{
		Q += "  From date\n";
		Q1 += "fdate ";
	}
	
		
	if(document.order.fyear.value == "")
	{
		Q += "  From Year \n";
		Q1 += "fyear ";
	}
	
	if(document.order.tmon.value == "")
	{
		Q += "  To month\n";
		Q1 += "tmon ";
	}
	
	if(document.order.tdate.value == "")
	{
		Q += "  To date\n";
		Q1 += "tdate ";
	}
	if(document.order.tyear.value == "")
	{
		Q += "  To Year \n";
		Q1 += "tyear ";
	}
	
	/*
	if (isWhitespace(theForm.cellphone.value))
		{
		Q += "  Cell Phone\n";
		}	
		
	else if(!isCharsInBag(theForm.cellphone.value, "0123456789"))
	{
	  Q += "Invalid Cell Phone Number.\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 ;
		}

	if (errMesg == "" && diplayMesg == "")
	{
		//theForm.submit();
	}
	else
	{
			if(diplayMesg!="")
			{
				alert(diplayMesg);
				
				i=Q1.split(" ");
							 
				var a = i[0];
				
				
				if(i[0] == "name"){
				document.order.name.focus();
				 
				}
				
				else if(i[0] == "address"){
				document.order.address.focus();
				}
				
				else if(i[0] == "city"){
				document.order.city.focus();
				}
				
				else if(i[0] == "state"){
				document.order.state.focus();
				}
				
				else if(i[0] == "phone"){
				document.order.phone.focus();
				}
				
				else if(i[0] == "cellphone"){
				document.order.cellphone.focus();
				}
				else if(i[0] == "email"){
				document.order.email.focus();
				}
				else if(i[0] == "t_storage10"){
				document.order.t_storage10.focus();
				}
				
				else if(i[0] == "fmon"){
				document.order.fmon.focus();
				}
				
				else if(i[0] == "fdate"){
				document.order.fdate.focus();
				}
							
				else if(i[0] == "fyear"){
				document.order.fyear.focus();
				
				}
				else if(i[0] == "tmon"){
				document.order.tmon.focus();
				}
				
				else if(i[0] == "tdate"){
				document.order.tdate.focus();
				}
				else if(i[0] == "tyear"){
				document.order.tyear.focus();
				}
				
				
				//alert(Q1);
				//} 
				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.order.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
}


*/
