// JavaScript Document
function validmodel(th)
{
	if(th.email.value<=0)
	{
		alert("Enter email");
		th.email.focus();
		return false;
	}
	else
	{
		var e=echeck(th.email.value);
		if(e==false)
		{
			th.email.value="";
			th.email.focus();
			return false;
		}
	}
	if(th.password.value<=0)
	{
		alert("Enter Password");
		th.password.focus();
		return false;
	}
	if(th.cnf_password.value<=0)
	{
		alert("Enter Confirm Password");
		th.cnf_password.focus();
		return false;
	}
	if(th.cnf_password.value!=th.password.value)
	{
		alert("Password Doesn't confirms");
		th.cnf_password.value="";
		th.cnf_password.focus();
		return false;
	}
	if(th.keyword.value<=0)
	{
		alert("Please Select Keyword");
		th.keyword.focus();
		return false;
	}
	if(th.bdate.value<=0)
	{
		alert("Please Enter Birth Date");
		th.bdate.focus();
		return false;
	}
	if(th.gender.value<=0)
	{
		alert("Please Sekect Gender");
		th.gender.focus();
		return false;
	}
	if(th.company.value<=0)
	{
		alert("Please Enter Company Name");
		th.company.focus();
		return false;
	}
	if(th.firstname.value<=0)
	{
		alert("Please Enter First Name");
		th.firstname.focus();
		return false;
	}
	else
	{
		var invalidchar = new Array('#','"','\\','/','!','@','$','%','^','&','*','?',':','~','`','(',')','_','+','=','{','}','[',']','|','<','>',';','-','1','2','3','4','5','6','7','8','9','0');
		var x = validate_characters(th.firstname.value,invalidchar);
		if(x == false)
		{
			alert("Please Enter valid First Name");
			th.firstname.value  = "" ;			
			th.firstname.focus() ;
			return false;
		}
	}
	if(th.lastname.value<=0)
	{
		alert("Please Enter Last Name");
		th.lastname.focus();
		return false;
	}
	else
	{
		var invalidchar = new Array('#','"','\\','/','!','@','$','%','^','&','*','?',':','~','`','(',')','_','+','=','{','}','[',']','|','<','>',';','-','1','2','3','4','5','6','7','8','9','0');
		var x = validate_characters(th.lastname.value,invalidchar);
		if(x == false)
		{
			alert("Please Enter valid Last Name");
			th.lastname.value  = "" ;			
			th.lastname.focus() ;
			return false;
		}
	}
	if(th.streetaddress.value<=0)
	{
		alert("Please Enter Street Address");
		th.streetaddress.focus();
		return false;
	}
	if(th.country.value<=0)
	{
		alert("Please Select Country");
		th.country.focus();
		return false;
	}
	if(th.state.value<=0)
	{
		alert("Please Select State");
		th.state.focus();
		return false;
	}	
	if(th.zipcode.value<=0)
	{
		alert("Please Enter Zip Code");
		th.zipcode.focus();
		return false;
	}
	if(th.workphone.value<=0)
	{
		alert("Please Enter Work Phone");
		th.workphone.focus();
		return false;
	}
		if(th.city.value<=0)
	{
		alert("Please Enter City");
		th.city.focus();
		return false;
	}
	if(th.hear.value<=0)
	{
		alert("Please Select Valid Option");
		th.hear.focus();
		return false;
	}
	if(th.explain.value<=0)
	{
		alert("Please Enter Who Refered You");
		th.explain.focus();
		return false;
	}
	if(th.feet.value<=0)
	{
		alert("Please Select feet!");
		th.feet.focus();
		return false;
	}
	if(th.inch.value<=0)
	{
		alert("Please Select inch!");
		th.inch.focus();
		return false;
	}
	if(th.weight.value<=0)
	{
		alert("Please Enter weight!");
		th.weight.focus();
		return false;
	}
	if(th.measurement.value<=0)
	{
		alert("Please Enter measurement!");
		th.measurement.focus();
		return false;
	}
	if(th.haircolor.value<=0)
	{
		alert("Please Enter haircolor!");
		th.haircolor.focus();
		return false;
	}
	if(th.eyecolor.value<=0)
	{
		alert("Please Enter eyecolor!");
		th.eyecolor.focus();
		return false;
	}
	if(th.skills.value<=0)
	{
		alert("Please Enter skills!");
		th.skills.focus();
		return false;
	}
	if(th.foreign_language.value<=0)
	{
		alert("Please Enter Foreign Language!");
		th.foreign_language.focus();
		return false;
	}
	if(th.shoe_size.value<=0)
	{
		alert("Please Enter Shoe Size!");
		th.shoe_size.focus();
		return false;
	}
	if(th.dress_size.value<=0)
	{
		alert("Please Enter Dress Size!");
		th.dress_size.focus();
		return false;
	}
	if(th.photo.value== "")
	{
		alert("Enter photo");
		th.photo.focus();
		return false;
	}
	else
	{
		var x = LimitAttach(th.photo.value);
		if(x == false)
		{
			return false ;
		}
	}
}
var extArray = new Array(".jpeg", ".jpg",".png");
function LimitAttach(file) 
{
	var fileName = file;
	if (!fileName) return false;
	ext = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) 
	{
	   if (extArray[i] == ext) return true
	}
	alert("Please only Upload Files that end in types:  "
	+ (extArray.join("  ")) + "\nPlease select a new "
	+ "file to upload and submit again.");
	return false;
}
function validate_characters(string,invalidchar)
{	
	var invalid=true;
	for(var i=0;i<string.length;i++)
	{
		var p = string.charAt(i);
		for(j=0;j<invalidchar.length;j++)
		{	
			if(p == invalidchar[j])
			{
				invalid=false;
				break;
			}
		}
	}
	return invalid;
}
function ValidateNo(NumStr, String)
{    
	for(var Idx=0; Idx<NumStr.length; Idx++)    
	{
		var Char = NumStr.charAt(Idx);
		var Match = false;        
		for(var Idx1=0; Idx1<String.length; Idx1++)        
		{            
			if(Char == String.charAt (Idx1))                
			Match = true;        
		}        
		if (!Match)            
			return false;    
	}    
	return true;
} 
function echeck(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	{
	   alert("Invalid E-mail ID");
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID");
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID");
		return false;
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID");
		return false;
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID");
		return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID");
		return false;
	 }
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID");
		return false;
	 }
	 return true;				
}
function underscore(th)
{
	var my=th;
	var attherate=my.indexOf("_");
	var lastattherate = my.lastIndexOf("_");
	//var dotpos=my.lastIndexOf("_");
	var posspace = my.indexOf(" ");
	var totallen = my.length;
	if (   attherate!=lastattherate)
		return false;
	else
		return true;
}