// JavaScript Document
function validation(form)
{
		
	//var user_name=form['txtusername'];
	var password=form['txtpassword'];
	var first_name=form['txtfirstname'];
	var last_name=form['txtlastname'];
	var email=form['txtemail'];
	var address1=form['txtaddress'];
	var address2=form['txtaddress2'];
	var country=form['select_country'];
	var state=form['select_state'];
	var city=form['txtcity'];
	var zip_code=form['txtzipcode'];
	var phone1=form['txtareacode'];
	var phone2=form['txtphno1'];
	var phone3=form['txtphno2'];
	var receive_email=form['receive_mail'];
	
	
	var message="";
	var confirmPass=form['txtpassword2'];

	
	
	/*if(user_name.value == "")
	{
		alert("Please choose an User ID for your account. (3 to 20 Characters).");		
		user_name.focus();
		return false;
	}
	else if(!isUserName(user_name.value))
	{
		alert("Please choose a valid User ID for your account. (3 to 20 Characters).");		
		user_name.focus();
		return false;
	}*/
	 
	if(email.value=="")
	{
		alert("Please specify E-mail.");		
		email.focus();
		return false;
	}
	else if(email.value.search(/^[a-z]\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/))
	{
		alert("Please enter valid E-mail ID.");
		email.focus();
		return false;
	}
	
	if(password.value == ""){
		alert("Please enter your Password.");		
		password.focus();
		return false;
	}
	else if(!isPassword(password.value)) {
		alert("Please enter a valid Password. (6 to 20 characters) ");		
		password.focus();
		return false;
	}
	if(confirmPass.value=="")
	{
		alert("Please Re-type your Password.");		
		confirmPass.focus();
		return false;
	}
	else if(password.value!=confirmPass.value)
	{
		alert("Password & Re-type Password should be same.");		
		confirmPass.focus();
		return false;
	}
	if(first_name.value==""){
		alert("Please specify a First Name.");
		first_name.focus();
		return false;
	}
	else if(!isString(first_name.value)) {
		alert("Please specify a valid First Name.");		
		first_name.focus();
		return false;
	}
	else if(first_name.value.length<3) {
		alert("Please specify a valid First Name.");		
		first_name.focus();
		return false;
	}	
	if(last_name.value==""){
		alert("Please specify a Last Name.");		
		last_name.focus();
		return false;
	}
	else if(!isString(last_name.value)) {
		alert("Please specify a valid Last Name.");		
		last_name.focus();
		return false;
	}
	else if(last_name.value.length<3) {
		alert("Please specify a valid Last Name.");		
		last_name.focus();
		return false;
	}	
	
	
	
	if(address1.value=="")
	{
		alert("Please specify Address1.");		
		address1.focus();
		return false;
	}
	else if(address1.value.search(/^[0-9a-zA-Z][0-9a-zA-Z \/.,;'",]+$/))
	{
		alert("Please specify valid address1.");
		address1.focus();
		return false;
	}
	if(address2.value!="")
	{
		if(address2.value.search(/^[0-9a-zA-Z \/.,]+$/))
		{
			alert("Please specify valid address2.");
			address2.focus();
			return false;
		}
	}
	
	if(country.value=="")
	{
		alert("Please specify Country.");		
		country.focus();
		return false;
	}
	if(state.value=="")
	{
		alert("Please specify State.");		
		state.focus();
		return false;
	}

	if(city.value=="")
	{
		alert("Please specify City.");		
		city.focus();
		return false;
	}
	if(city.value.search(/^[a-zA-Z][a-zA-Z ]+$/))
		{
			alert("Please specify valid City.");
			city.focus();
			return false;
		}
	if(zip_code.value=="")
	{
		alert("Please specify Zip Code.");		
		zip_code.focus();
		return false;
	}
	if(zip_code.value.search(/^[0-9]+$/))
	{
		alert("Please specify valid Zip Code.");
		zip_code.focus();
		return false;
	}
	if(phone1.value!="")
	{
		if(!isPhone(phone1.value,3))
		{
			alert("Please specify a valid Phone Number.");		
			phone1.focus();
			return false;
		}
	}
	if(phone2.value!="")
	{
		if(!isPhone(phone2.value,3))
		{
			alert("Please specify a valid Phone Number.");		
			phone2.focus();
			return false;
		}
	}
	if(phone3.value!="")
	{	
		if(!isPhone(phone3.value,4))
		{
			alert("Please specify a valid Phone Number.");		
			phone3.focus();
			return false;
		}
	}
	
	
	
	
	/*if(secret_question.value=="")
	{
		alert("Please specify Secret Question.");		
		secret_question.focus();
		return false;
	}
	if(secret_answer.value=="")
	{
		alert("Please specify Secret Answer.");
		secret_answer.focus();
		return false;
	}
	if(user_type[0].checked)
	{
		var package_list=form['lstPackage'];
		if(package_list.value=="")
		{
			alert("Please select package.");
			package_list.focus();
			return false;
		}
	}*/
	//return false;//user_name.focus();


}
function isPassword(password)
{
		if(password.length<6)
			return false;
		for(var i=0;i<password.length;i++){
			if(password.charAt(i)==" ")
				return false;
		}
		return true;
}

function isAge(age)
{
	var temp="";
	
	for(var i=1;i<age.length;i++)
	{
			temp=age.charAt(i);
			if(!(temp>="0" && temp<="9"))
				return false;
	}
	return true;
}	
function isPhone(phone,no)
{
	var temp="";
	if(phone.length<no)
		return false;
	for(var i=0;i<phone.length;i++)
	{
			temp=phone.charAt(i);
			if(!(temp>="0" && temp<="9"))
				return false;
	}
	return true;
}	
function isUserName(username)
{
	if(username.length<3)
		return false;
	var temp;

	if(!(username.charAt(0)>="A" && username.charAt(0)<="z"))
		return false;
	if((username.charAt(username.length-1)>="A" && username.charAt(username.length-1)<="z") || (username.charAt(username.length-1)>="0" && username.charAt(username.length-1)<="9"))
		temp="";
	else
		return false;
		
	for(var i=0;i<username.length;i++){
		temp=username.charAt(i);
		
		if((temp>="0" && temp<="9") || (temp>="A" && temp<="z") || (temp=="_") || (temp=="."))
			temp="";
		else
			return false;
		
	}
	return true;
	
}
function popUp(url) {
	var view;
	var wid = 450;
	var height = 225;
	var  w = screen.width;
	var h = screen.height;
	var x= h/2-height/2;
	var y = w/2-wid/2; 
	view=window.open(url,"","width="+wid+",height="+height+",top="+x+",left="+y+",resizable=1,scrollbars=1");
}
function phone_no(phone,no)
{
	
	var temp=phone.value;
	if(temp.length==3 && no==1) {
		
		document.forms['txtphone2'].focus();
	}
	if(temp.length==3 && no==2) {
		
		document.forms['txtphone3'].focus();
	}
	//alert(temp.length);
	
}
function isString(str)
{
	patternname=/^[a-zA-Z]+$/;
	if(patternname.test(str))
	{
		return true;
	}
	else
	{
		return false;	
	}
	/*var temp;
	for(var i=0;i<str.length;i++)
	{
		if(!isLetter(str.charAt(i)))
			return false;
							   
	}
	return true;*/
}
function view_detail(val)
{
	if(val!="")
	{
		viewdetail.innerHTML="<a href=\"javascript: popUp('view_details.php?id=" + val + "')\" class='link1'>(View Detail)</a>";	
	}
	else
	{
		viewdetail.innerHTML="";
	}
}

	
