/**************************************************************************************************************
    *     filename      	: specYourOwn.js													                                                      			*
    *     Description 	: This javascript page has been developed to Validate the spec-your-own form					*
    *     Author        	: Biswajit Roy, Developer, Soft_Solutions4u, Chennai, India                                					*
	* 	  Modified By   	: Biswajit Roy, Developer, Soft_Solutions4u, Chennai, India                                					*
    *     Date        		: 23.09.2009                                                                              											*
    *     LastModified	: 23.09.2009                                                                              											*
***************************************************************************************************************/	

	function populate(){
		document.getElementById('formname').submit();
	}
	
	function check(){
		if(document.formname.fname.value==""){
			alert("Enter Your First Name");
			document.formname.fname.value="";
			document.formname.fname.focus();
			return false;
		}
		
		if(document.formname.fname.value.search(/^[a-zA-Z]+$/)){
			alert("First Name Should Be Characters Only");
			document.formname.fname.value="";
			document.formname.fname.focus();
			return false;
		}
		
		if(document.formname.lname.value==""){
			alert("Enter Your Last Name");
			document.formname.lname.value="";
			document.formname.lname.focus();
			return false;
		}
		
		if(document.formname.lname.value.search(/^[a-zA-Z]+$/)){
			alert("Last Name Should Be Characters Only");
			document.formname.lname.focus();
			document.formname.lname.value="";
			return false;
		}
		
		
		if(document.formname.email.value==""){
			alert("Please enter your email id");
			document.formname.email.value="";
			document.formname.email.focus();
			return false;
		}
		
		
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.formname.email.value))){
			alert("Please enter a valid email id");
			document.formname.email.value="";
			document.formname.email.focus();
			return false;
		}

               if(!(document.getElementById('zip').disabled)){
                      if(document.formname.zipcode.value==""){
			alert("Enter The ZipCode Field");
			document.formname.zipcode.value="";
			document.formname.zipcode.focus();
			return false;
		}
		
		if(document.formname.zipcode.value.search(/^[0-9]+$/)){
			alert("ZipCode Field Should Be Numeric");
			document.formname.zipcode.value="";
			document.formname.zipcode.focus();
			return false;
		}
		
		if(document.formname.zipcode.value==""){
			alert("Enter The ZipCode Field");
			document.formname.zipcode.value="";
			document.formname.zipcode.focus();
			return false;
		}
		
		if(document.formname.zipcode.value.search(/^[0-9]+$/)){
			alert("ZipCode Field Should Be Numeric");
			document.formname.zipcode.value="";
			document.formname.zipcode.focus();
			return false;
		}
 
                }
		
		
			
		checkedVal=document.getElementById('pcontact').checked;		
		area = document.getElementById('area').value;
		pre = document.getElementById('pre').value;
		suff = document.getElementById('suff').value;
		area=trim(area);
		pre=trim(pre);
		suff=trim(suff);			
		phoneNumber = area+pre+suff;	
		
		if(checkedVal == true || phoneNumber != ""){		
							
			
			if(phoneNumber==""){
				alert("Please enter the Phone number !");
				document.formname.area.value="";
				document.formname.pre.value="";
				document.formname.suff.value="";
				document.formname.area.focus();
				return false;
			}
			
			if(area=="" || pre=="" || suff==""){
				alert("Please enter a valide Phone number !");
				document.formname.area.value="";
				document.formname.pre.value="";
				document.formname.suff.value="";
				document.formname.area.focus();
				return false;
			}
			
			if((document.formname.pre.value.search(/^[0-9]+$/)) || document.formname.pre.value.search(/^[0-9]+$/) || document.formname.suff.value.search(/^[0-9]+$/)){
				alert("Please enter only numeric value for Phone Number");
				document.formname.area.value="";
				document.formname.pre.value="";
				document.formname.suff.value="";
				document.formname.area.focus();
				return false;
			}	
			
		}		
	}
	
	
	
	//  Javascript Trim
	
	function trim(str, chars) {
		return ltrim(rtrim(str, chars), chars);
		}
		
	function ltrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
	
	function rtrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
