var contentUrl = "https://infinity.icicibank.co.in";


function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function


//removing the right spaces

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function



//Validate Function 


function validate(value,checkOk)
{
	var checkStr = value;
	var allValid = true;
			
			for (i = 0;  i < checkStr.length;  i++)
				{
					ch = checkStr.charAt(i);
					for (j = 0;  j < checkOk.length;  j++)
						if (ch == checkOk.charAt(j))
						break;
						if (j == checkOk.length)
						{
							allValid = false;
							break;
						}
				}
			
					if (!allValid)
					{
						return (false);
									
					}
					else { return (true); }
	}


	
function Form1_Validator(theForm)
{
		flag=true;
	
		function emptystring(value)
			{
			 if (value=="") return (false);
			 else return(true);
			}

		// First Name 
		theForm.first_name.value = LTrim(theForm.first_name.value);
		theForm.first_name.value = RTrim(theForm.first_name.value);

		if (!emptystring(theForm.first_name.value))
			 {
			alert("Please enter your First name");
			theForm.first_name.focus();
			flag=false;
			return (false);
			}
  
		 else {

			  var checkOk = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' .";
					if (!(validate(theForm.first_name.value,checkOk)))
					{
					alert("Please enter a valid First name");
					theForm.first_name.focus();
					flag=false;
					return (false);
					}
				}

//Middle Name
	theForm.middle_name.value = LTrim(theForm.middle_name.value);
		theForm.middle_name.value = RTrim(theForm.middle_name.value);
		if (!(theForm.middle_name.value==""))
		{
			var checkOk = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -' .";
					if (!(validate(theForm.middle_name.value,checkOk)))
						{
						alert("Please enter a valid Middle Name");
						theForm.middle_name.focus();
						flag=false;
						return (false);
						}
	}



	 //Last Name 
	 theForm.last_name.value = LTrim(theForm.last_name.value);
		theForm.last_name.value = RTrim(theForm.last_name.value);

		if (!emptystring(theForm.last_name.value))
			 {
				alert("Please enter your Last name");
				theForm.last_name.focus();
				flag=false;
				return (false);
			}
  
		 else {

			var checkOk = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' .";
				if (!(validate(theForm.last_name.value,checkOk)))
					{
					alert("Please enter a valid Last name");
					theForm.last_name.focus();
					flag=false;
					return (false);
					}
				}
		

//Profession
		 if (theForm.profession.value=="")
		 {
			alert("Please select your Profession");
			theForm.profession.focus();
			flag=false;
			return (false);
		}
 
 //For Income Range
		
		if (theForm.income_range.value=="")
		 {
			alert("Please select the Income Range");
			theForm.income_range.focus();
			flag=false;
			return (false);
		}

	//Validation for the address field
	theForm.address.value=LTrim(theForm.address.value);
	theForm.address.value=RTrim(theForm.address.value);
		if (!(emptystring(theForm.address.value)))
			{
				alert("Please enter your address");
				theForm.address.focus();
				flag=false;
				return (false);
			}
	

 //City
if (theForm.selCity.value=="")
		 {
			alert("Please select your city");
			theForm.selCity.focus();
			flag=false;
			return (false);
		}

 //Validation for Pin Code
	theForm.pincode.value=LTrim(theForm.pincode.value);
	theForm.pincode.value=RTrim(theForm.pincode.value);
 
	if (!emptystring(theForm.pincode.value))
		 {
			alert("Please enter your pincode");
			theForm.pincode.focus();
			flag=false;
			return (false);
		}
	  else 
		{
           var checkOk ="0123456789";
			if (!(validate(theForm.pincode.value,checkOk)))
				{
				alert("Please enter a valid pincode.");
				//theForm.pincode.value="";
				theForm.pincode.focus();
				flag=false;
				return (false);
				}
			else if (theForm.pincode.value.length!=6)
			{
				alert("Please enter a valid pincode.");
			//	theForm.pincode.value="";
				theForm.pincode.focus();
				flag=false;
				return (false);
			}
		}
	
//Check for Phone Number
 		theForm.residence.value=LTrim(theForm.residence.value);
		theForm.residence.value=RTrim(theForm.residence.value);
		theForm.office.value=LTrim(theForm.office.value);
		theForm.office.value=RTrim(theForm.office.value);
		theForm.mobile.value=LTrim(theForm.mobile.value);
		theForm.mobile.value=RTrim(theForm.mobile.value);
		if ((theForm.residence.value==""))
		{
			alert("Please enter your Residence telephone number");
			theForm.residence.focus();
			flag=false;
			return (false);
		}
 if (!(theForm.residence.value==""))
			{
				var checkOk ="0123456789";
				if (!(validate(theForm.residence.value,checkOk)))
				{
				alert("Please enter  a valid Residence Phone number");

				theForm.residence.focus();
				theForm.residence.value="";
				flag=false;
				return (false);
				}
			}

		 if (theForm.office.value=="")
		{
			alert("Please enter your Office telephone number");
			theForm.office.focus();
			flag=false;
			return (false);
		}
	

	 if (!(theForm.office.value==""))
			{
				var checkOk ="0123456789";
				if (!(validate(theForm.office.value,checkOk)))
				{
				alert("Please enter  a valid Office Phone number");
				theForm.office.value="";
				theForm.office.focus();
				flag=false;
				return (false);
				}
		}
			
	 if (!(theForm.mobile.value==""))
			{
				var checkOk ="0123456789";
				if (!(validate(theForm.mobile.value,checkOk)))
				{
				alert("Please enter  a valid Mobile number");
				theForm.mobile.value="";
				theForm.mobile.focus();
				flag=false;
				return (false);
				}
			}
		
	 
	if (flag)
	{
		//alert("Thank you for applying for an ICICI Bank product. Our representative will be getting in touch with you shortly.");
		return(true);
	}


}

