// JavaScript Document Created by Loganathan N, <logudotcom@yahoo.com> On 10-December-2004.

// basic function to validate the form fields
function validate_form_step1(mode) {
	var mode;
	// based on mode we need to redirect
	if (mode == "1") {
		document.frmprofile.hmode.value = 1;
	} else if (mode == "2") {
		document.frmprofile.hmode.value = 2;
	} else {
		document.frmprofile.hmode.value = '';	
	}
	// Name
	if (document.frmprofile.txtname.value == ""){
		alert("Please enter your Name.");
		document.frmprofile.txtname.focus();
		return false;
	}		
	// Age
	if (document.frmprofile.txtage.value == '') {
		alert("Please enter your Age.");
		document.frmprofile.txtage.focus();
		return false;
	} else if (isNaN(document.frmprofile.txtage.value)){
		alert("Please enter valid Age.");
		document.frmprofile.txtage.focus();
		return false;
	}
	var ageFrom = parseInt(document.frmprofile.txtage.value);
	if (ageFrom < 18) {
		alert("you should be 18 years old.");
		document.frmprofile.txtage.focus();
		return false;
	}
	// Address
	if (document.frmprofile.txtaddress.value =="") {
		alert("Please enter Address.");
		document.frmprofile.txtaddress.focus();
		return false;
	} else if (document.frmprofile.txtaddress.length >= 20) {
		alert("Please enter atleast 20 chars in Address.");
		document.frmprofile.txtaddress.focus();
		return false;
	}	
	// Email
	if (document.frmprofile.txtemail.value == ""){
		alert("Please enter Email.");
		document.frmprofile.txtemail.focus();
		return false;
	} else if (document.frmprofile.txtemail.value.indexOf("@") < 2 || document.frmprofile.txtemail.value.indexOf(".") < 0 ) {
		alert ("Please enter valid Email.");
		document.frmprofile.txtemail.focus();
		return false;
	}
	// Confirm Email
	if (document.frmprofile.txtcemail.value == ""){
		alert("Please enter Retype Email.");
		document.frmprofile.txtcemail.focus();
		return false;
	} else if (document.frmprofile.txtcemail.value.indexOf("@") < 2 || document.frmprofile.txtcemail.value.indexOf(".") < 0 ) {
		alert ("Please enter valid Retype Email.");
		document.frmprofile.txtcemail.focus();
		return false;
	}
	// Verify
	if (document.frmprofile.txtemail.value != document.frmprofile.txtcemail.value) {
		alert("Please verify the Email and Retype Email!");
		document.frmprofile.txtemail.focus();
		document.frmprofile.txtemail.select();
		return false;
	}	
	// Password
	if (document.frmprofile.txtpwd.value == "")	{
		alert("Please enter Password.");
		document.frmprofile.txtpwd.focus();
		return false;		
	} else if (document.frmprofile.txtpwd.value.length < 4) {
		alert("Your Password should be atleast 4 character(s)!");
		document.frmprofile.txtpwd.focus();
		return false;					
	}	
	// Confirm Password
	if (document.frmprofile.txtcpwd.value == "") {
		alert("Please enter Confirm Password.");
		document.frmprofile.txtcpwd.focus();
		return false;		
	} else if (document.frmprofile.txtcpwd.value.length < 4) {
		alert("Your Confirm Password should be atleast 4 character(s)!");
		document.frmprofile.txtcpwd.focus();
		return false;					
	}	
	// Verify
	if (document.frmprofile.txtpwd.value != document.frmprofile.txtcpwd.value) {
		alert("Please verify the Confirm Password!");
		document.frmprofile.txtcpwd.focus();
		return false;
	}
	// Secret Question
	if (document.frmprofile.txtsq.value == '') {
		alert("Please enter your Secret Question?");
		document.frmprofile.txtsq.focus();
		return false;
	}
	// Secret Word
	if (document.frmprofile.txtcw.value == '') {
		alert("Please enter your Secret Word?");
		document.frmprofile.txtcw.focus();
		return false;
	}	
	// submit  the form
	document.frmprofile.submit();
	return true;
}
// ends common  validation



function validate_form_step2()
{		
	// I seek / I prefer
	if (document.frmprofile2.txtoffer.value == "") {
		alert ("Please enter your Propose Information!");
		document.frmprofile2.txtoffer.focus();
		return true;
	}
	// My hunting
	if (document.frmprofile2.txthunting.value == "") {
		alert ("Please enter your Hunting Information!");
		document.frmprofile2.txthunting.focus();
		return true;
	}
	// My special interests
	// My Psyche Dissected
	// My Affiliations
	// My Definition of Ideal Spouse
	// Introducing to my Date	
	// My Idea of Ideal Dating Partner		
	document.frmprofile2.submit();
	return true;
}


/*
		Quick Search
*/

function validate_qsearch()
{
	if (document.frmqsearch.txtafrom.value == ''){
		alert("Please enter Age From");
		document.frmsearch.txtafrom.focus();
		return false;
	}
	var ageFrom = parseInt(document.frmqsearch.txtafrom.value);
	if (ageFrom < 18) {
		alert("you should be 18 years old");
		document.frmsearch.txtafrom.focus();
		return false;
	}
	
	if (document.frmqsearch.txtato.value == ''){
		alert("Please enter Age To");
		document.frmsearch.txtato.focus();
		return false;
	}

}

// to check the no of child
function check_age() {	
	//var strMS = document.frmprofile.txtage.value;	
	var strMS = document.frmprofile.txtage.options[document.frmprofile.txtage.selectedIndex].value;
	if (strMS == 0)	{
		document.frmprofile.txt2age.disabled = false;
	} else if (strMS != 0) {
		if (document.frmprofile.txt2age.value != ''){
			alert("Please enter age in once!");			
			document.frmprofile.txt2age.value='';
			//document.frmprofile.txtage.select();
			return false;
		} else {
			document.frmprofile.txt2age.disabled = true;
		}
	} else {
		document.frmprofile.txt2age.disabled = false;
	}
}

// to display photo thumbnail view
function extension(frmName) {
if(frmName.logo.value != "") {		
	var len = frmName.logo.value.length;
	var type = frmName.logo.value.substr(len-3,3);

	if (type == "jpg" || type == "bmp" || type == "gif" || type == "png" ||type == "JPG" || type == "BMP" || type == "GIF" || type == "peg" || type == "PEG") {	
		document.picphoto.src="file:///" + frmName.logo.value;
		frmName.picphoto.height =90;
		frmName.picphoto.width =100;
		return true;
	} else {
		frmName.logo.value = '  ';
		alert("Please upload only jpg/bmp/gif/png file");
		return false;				
	} 
 } 		
}


// to open new window
function terms_openWin(Url,Name,Width,Height,Scrollbars)  {
	var features = 'status=no left=0 top=0,scrollbars=' + Scrollbars + ',width=' + Width + ',height=' + Height;
	window.open(Url, Name, features );
} // href="javascript:terms_openWin('termsandconditions.html','CB', 550, 400, 'yes')"


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 taLimit() {
	var taObj=event.srcElement;
	if (taObj.value.length==taObj.maxLength*1) return false;
}

function taCount(textname,no) { 
	var taObj=event.srcElement;
	if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
	document.frmprofile.elements[textname].value=taObj.value.length;
	if(taObj.value.length==taObj.maxLength*1) alert("You can enter only "+no+" characters");
}
function taCount2(textname,no) { 
	var taObj=event.srcElement;
	if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
	document.frmprofile2.elements[textname].value=taObj.value.length;
	if(taObj.value.length==taObj.maxLength*1) alert("You can enter only "+no+" characters");
}

// Number Validate Check..Not Require...But Format Check
function NumberValidate(txtCtrl, val)
{
	Remove_Spaces(txtCtrl);
	var fLength = txtCtrl.value.length;
	//alert(fLength);
	
	if (fLength == 0) {
 		return false;
	}	
	// Required but check Empty
	if (txtCtrl.value == "" || isNaN(txtCtrl.value)){ 	
			alert("The value ' " + txtCtrl.value + " ' in '" + val +"' is not a vaild data.\n\r" +  
				"Please enter Numeric Values!");		
			txtCtrl.focus();
			txtCtrl.select();
			return false;	
	}		
}

function Remove_Spaces(txtCtrl){
  txtCtrl.value = txtCtrl.value.replace(/\r/g, " ");

  txtCtrl.value = txtCtrl.value.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");

  txtCtrl.value = txtCtrl.value.replace(/'/g, "");

  txtCtrl.value = txtCtrl.value.replace(/ +/g, " "); 

  txtCtrl.value = txtCtrl.value.replace(/^\s/g, "");

  txtCtrl.value = txtCtrl.value.replace(/\s$/g, "");
  
  if (txtCtrl.value == ' '){	
	 txtCtrl.value = '';
   } 
 }
