function Trim(str) {

  return rTrim( lTrim( str ) );

}



function lTrim( str ) {

  while (str.charAt(0) == " ") {

      str = str.substring(1);

  }

 return str;

}



function rTrim( str ) {

   while (str.charAt(str.length - 1) == " ") {

      str = str.substring(0, str.length - 1);

  }

 return str;

}



function validateEmail( emailString ){  
		str = emailString;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if ((str.search(/\$/)!=-1)||(str.search(/\*/)!=-1)||(str.search(/\^/)!=-1)||(str.search(/\#/)!=-1)||(str.search(/\!/)!=-1)||(str.search(/\%/)!=-1)||(str.search(/\&/)!=-1)||(str.search(/\?/)!=-1)||(str.search(/\+/)!=-1)||(str.search(/\=/)!=-1)||(str.search(/\|/)!=-1)||(str.search(/\-/)!=-1)||(str.search(/\}/)!=-1)||(str.search(/\]/)!=-1)||(str.search(/\[/)!=-1)||(str.search(/\}/)!=-1)||(str.search(/\~/)!=-1)||(str.search(/\\/)!=-1)||(str.search(/\//)!=-1)||(str.search(/\)/)!=-1)||(str.search(/\(/)!=-1))

		{
			$("span#email").hide("slow");
			$("span#email1").show("slow");
			setTimeout("close_msg('span#email1')",3000);
			//alert("Only @, _ and . special characters allowed");        

			return false

		}

		

		if (str[lstr-1]=="."){

		   //alert("Invalid E-mail ID")
		   $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		   $("span#email2").show("slow");
		   setTimeout("close_msg('span#email2')",3000);

		   return false

		}



		if (str.indexOf(at)==-1){

		  // alert("Invalid E-mail ID")
		    $("span#email").hide("slow");
		    $("span#email1").hide("slow");
			$("span#email2").show("slow");
			setTimeout("close_msg('span#email2')",3000);
			
		   return false

		}



		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		  // alert("Invalid E-mail ID")
		    $("span#email").hide("slow");
		    $("span#email1").hide("slow");
			$("span#email2").show("slow");
			setTimeout("close_msg('span#email2')",3000);
		   return false

		}



		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		   // alert("Invalid E-mail ID")
		     $("span#email").hide("slow");
		   $("span#email1").hide("slow");
	
  $("span#email2").show("slow");
  setTimeout("close_msg('span#email2')",3000);
		    return false

		}



		 if (str.indexOf(at,(lat+1))!=-1){

		   // alert("Invalid E-mail ID")
		     $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		
  $("span#email2").show("slow");
  setTimeout("close_msg('span#email2')",3000);
		    return false

		 }



		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		   // alert("Invalid E-mail ID")
		     $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		
		  $("span#email2").show("slow");
		  setTimeout("close_msg('span#email2')",3000);
		    return false

		 }



		 if (str.indexOf(dot,(lat+2))==-1){

		 //   alert("Invalid E-mail ID")
		   $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		
	  $("span#email2").show("slow");
	  setTimeout("close_msg('span#email2')",3000);
		    return false

		 }

		

		 if (str.indexOf(" ")!=-1){

		  //  alert("Invalid E-mail ID")
		   $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		  
		   $("span#email2").show("slow");
		   setTimeout("close_msg('span#email2')",3000);

		    return false

		 }



 		 return true;

}


function validate(obj){
	
	$("div#error_msg").hide('slow');
	//$("div#error_msg").hide('slow');
	//temp.style.display='none';
	
	if(Trim(obj.fname.value)==''){
		txt="Please Enter your First name";
	}else if(Trim(obj.lname.value)==''){
		txt="Please Enter your Last name";
	}else if(Trim(obj.email.value)==''){
		txt="Please Enter your Email Id";
	}else if(!validateEmail(obj.email.value)){
		txt="Invalid Email Id format";
 	}else if(Trim(obj.phone.value)==''){
		txt="Please Enter your phone num";
 	}else if(Trim(obj.zip.value)==''){
		txt="Please Enter your zip code";
	}else if(obj.debt.selectedIndex==''){
		txt="Please select your debt information";
	}else{
		return true;
	}	
	$('#error_msg').html(txt);
	$("div#error_msg").show('slow');
	obj.fname.focus();
	return false;
	
}




function goahead(obj){
		//document.getElementById(obj).style.display="block";
		
		for(i=1;i<14;i++){
			$("div#loc"+i).slideUp("slow");
		}
		$("div#"+obj).slideDown("slow");

	}



