// JavaScript Document

//search form validation
function searchuser(thisfrm)
{
	
	var z=document.getElementById('country');
	
	flag=-1;
	for(i=thisfrm.group1.length-1;i>-1;i--)
	{
		if(thisfrm.group1[i].checked)
		{flag=i;
		i=-1;}
	}
	if(flag==-1)
	{
		alert('choose Bride  or Groom');
		return false;
	}
	
	 if( z.value==''||z.value=='select')
	{
		alert('select country');
		z.focus();
		return false;
	}
	if(thisfrm.agefrom.value=='select' || thisfrm.ageto.value=='select')
	{	alert('Select fromage and toage');
		thisfrm.agefrom.focus();
		return false;
	}
	else if(thisfrm.agefrom.value>thisfrm.ageto.value)
	{
		alert('From age should be less than to age');
		thisfrm.agefrom.focus();
		return false;
	}
}

// automatically select age when choose bride or groom
function autoselectage(agemin,ageto)
{
	var sltfrom=document.getElementById('agefrom');
	var sltto=document.getElementById('ageto');
	sltfrom.selectedIndex=agemin;
	sltto.selectedIndex=ageto;
	
}

 /*function registeruser(thisfrm)
 {	
 	if(thisfrm.txtname.value==''||(!thisfrm.nametxt.value.match(/^[a-zA-Z0-9]+$/)))
	{
		alert('Enter your name');
		thisfrm.txtname.focus();
		return false;
	}
	
	 if(thisfrm.txtemail.value=='')
	{
		alert('Enter your emailid');
		thisfrm.txtemail.focus();
		return false;
	}
	
 }*/
 
 
 function validator(){
var dt=new Date();
var year=document.getElementById("year");
		var month=document.getElementById("month");
		var date=document.getElementById("date");
		var fullyear=dt.getFullYear();
var mfrm = document.registration_1;
var alphaExp = /^[a-zA-Z]+$/;
//var phone2 = /\d{5-10}|\(\d\)/;


var months=dt.getMonth();
/*var currentyear=dt.getFullYear(); */
var months;
months[0]="January";
months[1]="February";
months[2]="March";
months[3]="Aprial";
months[4]="May";
months[5]="June";
months[6]="July";
months[7]="Auguest";
months[8]="September";
months[9]="October";
months[10]="November";
months[11]="December"; 
var monthday    = dt.getDate();
   //alert("hai");
	
	 
	 if ( mfrm.firstname.value == '' ) {
		alert ( 'Please enter first name' );
		mfrm.firstname.focus();
		return false;
	}  	
	else if (!mfrm.firstname.value.match(alphaExp) ) {
		alert ( 'First name should be alphabetic' );
		mfrm.firstname.focus();
		return false;				
	}	
	
	/*phone number*/
	
	if ( mfrm.sphone.value == '' ) {
		alert ( 'Please enter your phone number' );
		mfrm.sphone.focus();
		return false;
	}  	
	/*else if (!mfrm.sphone.value.match(phone2) ) {
		alert ( 'Enter a valid phone number' );
		mfrm.sphone.focus();
		return false;				
	}*/	
	
					
	  if ( mfrm.lastname.value == '' ) {
		alert ( 'Please enter last name' );
		mfrm.lastname.focus();
		return false;				
	}
	else if (!mfrm.lastname.value.match(alphaExp) ) {
		alert ( 'Last name should be alphabetic' );
		mfrm.lastname.focus();
		return false;				
	}
	 if(!mfrm.gender[0].checked && !mfrm.gender[1].checked)
	{ 
		alert('Choose your gender');
		document.getElementById('gender1').focus();
		return false;
	}
	 if(year.value=="select" || month.value=="Select" || date.value=="dd")
		{
		alert("Enter  Birthdate");
		year.focus();
		return false;
		}	
	else if((year.value%4==0 && month.value==02) && (date.value==30 || date.value==31))
		{
		alert("please Enter valid date");
		date.focus();
		return false;
		}
		
		else if((year.value%4!=0 && month.value==02) && (date.value==29 || date.value==30 || date.value==31))
		{
		alert("please Enter valid date");
		date.focus();
		return false;
		}
	else if((date.value==31) && (month.value==04 || month.value==06 || month.value==09 || month.value==11 ))
		{
		alert("please Enter valid date");
		date.focus();
		return false;
		} 	
		
		
		else if(month.value>=months && year.value==fullyear && date.value>monthday)
		{
		alert("invalid date");
		date.focus();
		return false;
		}
		
	else if ( mfrm.country.value =='' ) {
		alert ( 'Please input country' );
		mfrm.country.focus();
		return false;
	} else if ( mfrm.state.value == '' ) {
		alert ( 'Please input state or province' );
		mfrm.state.focus();
		return false;
	} else if ( mfrm.city.value == '' ) {
		alert ( 'Please input city' );
		mfrm.city.focus();
		return false;
	}else if ( mfrm.zip.value == '' ) {
		alert ( 'Please input zip code' );
		mfrm.zip.focus();
		return false;
	}
	else if ( mfrm.zip.value.match(alphaExp) ) {
		alert ( 'zip code should be numeric' );
		mfrm.zip.focus();
		return false;				
	}  /* else {
		return true;
	}*/
	//return false; 
	else if(mfrm.yourself.value=="")
	{
		alert('Enter information about yourself');
		mfrm.yourself.focus();
		return false;
	}
	 
	
}


/*registration page3 validations*/

function validator3()
{
	var a= document.getElementById('nickname');
	var b= document.getElementById('pass');
	var c= document.getElementById('conpassword');
	var d= document.getElementById('email');
	var cod=document.getElementById('code');
	
	var uInput = b.value;
	var min=5;
	var max=20;
	
	if(a.value=='')
	{
		alert('Enter user name');
		a.focus();
		return false;
	}
	if(!d.value.match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/)){
		alert("Enter a valid email id");
		d.focus();
		return false;	
		}
	else  if(b.value=='') {
	alert ( 'Enter password' );
		b.focus();
		return false;
		}
	else if(b.value.length < min || b.value.length >max){
	alert("Password length should be  " +min+ " to " +max+ " characters");
		b.focus();
		return false;	
	}
	else if( c.value=="") {
	alert ( 'Retype the password' );
		c.focus();
		return false;
			}
	else if  ( c.value != b.value) {
	alert ( 'The Password and confirmation password does not match!' );
		c.focus();
		return false;
			}
	
		else if (cod.value=="") {
	alert ( 'Enter the code which is shown' );
		cod.focus();
		return false;
			}
			if(registration_3.terms.checked==false)
			{
				alert('Please accept the terms and conditions');
				registration_3.terms.focus();
				return false;
			}
			

}



/*moving items from l-r and r-l in reg2 page  */

function MoveItem(ctrlSource, ctrlTarget, ctrlHidden, ctrlType) {
	
        var Source = document.getElementById(ctrlSource);
        var Target = document.getElementById(ctrlTarget);
		var HiddenCtrl = document.getElementById(ctrlHidden);
        if ((Source != null) && (Target != null)) {
            while ( Source.options.selectedIndex >= 0 ) {
                var newOption = new Option(); // Create a new instance of ListItem
                newOption.text = Source.options[Source.options.selectedIndex].text;
                newOption.value = Source.options[Source.options.selectedIndex].value;
                
                Target.options[Target.length] = newOption; //Append the item in Target
                Source.remove(Source.options.selectedIndex);  //Remove the item from Source
            }// end of while
            if(ctrlType == "R")
				AddItemsToHidden(Target, HiddenCtrl);
			else
				AddItemsToHidden(Source, HiddenCtrl);
			
        }
    }
	
function AddItemsToHidden(Target, HiddenCtrl)
    {
		HiddenCtrl.value = "";
		for(var i=0; i < Target.length; i++)
		{
			HiddenCtrl.value = HiddenCtrl.value + ";" + Target.options[i].value ;
		}	
		
    }
	
	
function validateregister()
	{	
		uname=document.getElementById('txtname');
		gender1=document.getElementById('regf');
		gender2=document.getElementById('regm');
		email=document.getElementById('txtemail');
		if(uname.value=='')
		{
		alert('Enter your name')
		uname.focus();
		return false;
		}
		if(email.value=='')
		{
			alert('Enter your email ID')
			email.focus();
			return false;
		}
		else if(!email.value.match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/))
		{
			alert('Mail ID is in incorrect format')
			email.focus();
			return false;
		}
		if(gender1.value=='' && gender2.value=='')
		{
			alert('choose gender');
			return false;
		}
		
	}
	
/*----home page membership period dynamic display------*/
function display()
	{	
		check=document.getElementById('paid');
		drpdwn=document.getElementById('period');
		if(check.checked==true)
		{	drpdwn.style.display="block";
			
		}
		else drpdwn.style.display="none";
	}
	
	
/*--------------*/
function chkjoinnow()
	{	
		check=document.getElementById('paid');
		drpdwn=document.getElementById('period');
		if(check.checked==true)
		{	drpdwn.style.display="block";
			if(drpdwn.value=='')
			{
			alert('Please select the plan period')
			drpdwn.focus();
			return false;
			}
		}
		else drpdwn.style.display="none";
	}
	
/*-----go by peofiid vlidation in home page------*/
	
function checkempty()
	{	
		var prfid=document.getElementById('profileidtxt');
		if(prfid.value=='')
		{
		alert('Enter profileid');
		prfid.focus();
		return false;
		}
		else if(prfid.value.length!=10)
		{
		alert('Enter profileid correctly');
		prfid.focus();
		return false;
		}
		
	}
	
/*-----------login check in header------------------*/	
function chklogin()
	{
		var uname=document.getElementById('husername');
		var psw=document.getElementById('hpwd');
		if(uname.value=='')
		{
		alert('Enter your emialid or profileid');
		uname.focus();
		return false;
		}
		else if(!uname.value.match(/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/) && uname.value.length!=10)
		{
		alert('Enter your emialid or profileid correctly');
		uname.focus();
		return false;
		}
		if(psw.value=='')
		{
		alert('Enter Password');
		psw.focus();
		return false;
		}
	}
	
/*-------------------------feedback page--------------------------*/
function userfeedback()
	{ 
		var fdname=document.getElementById('fdbname');
		var fdemail=document.getElementById('fdbemail');
		var fdmsg=document.getElementById('fdbmsg');
		var cod=document.getElementById('code');
		if(fdname.value=='')
			{
				alert('Enter your name');
				fdname.focus();
				return false;
			}
		else if(!fdemail.value.match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/) || fdemail.value=='')
			{
				alert('Enter email correctly')
				fdemail.focus();
				return false;
			}
		else if(fdmsg.value=='')
				{
					alert('Enter your feedback')
					fdmsg.focus();
					return false;
				}
		else if (cod.value=="") {
	alert ( 'Enter the code which is shown' );
		cod.focus();
		return false;
			}		
	}
	
/*-----------change password--------------*/
function changepassword(chngfrm)
	{ 
		if(chngfrm.curpsw.value=='')
		{
			alert('Enter current password');
			chngfrm.curpsw.focus();
			return false;
		}
		if(chngfrm.newpsw.value=='')
		{
			alert('New password should not be blank');
			chngfrm.newpsw.focus();
			return false;
		}
		if(chngfrm.newpsw.value!=chngfrm.rnewpsw.value)
		{
			alert('Password and confirm password did not match');
			chngfrm.newpsw.focus();
			return false;	
		}
	}
/*----------------customer support----------*/	
	
function customersupport(supportfrm)
{
	if(supportfrm.email.value=='')
	{	
		alert('Enter your emailid');
		supportfrm.email.focus();
		return false;
	}
	else if(!supportfrm.email.value.match(/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/))
	{
		alert('Invalid email id');
		supportfrm.email.focus();
		return false;
	}
	if(supportfrm.issues.selectedIndex==0)
	{
		alert('Please select your problem');
		supportfrm.issues.focus();
		return false;
	}
	if(supportfrm.feedback.value=='')
	{
		alert('Enter description related to your problem');
		supportfrm.feedback.focus();
		return false;
		
	}
	if(supportfrm.code.value=='')
	{
		alert('Enter the code shown below');
		supportfrm.code.focus();
		return false;
		
	}
	/*if(!supportfrm.mobile.value.match(/^[0-9]{10}/))
	{
		alert('Enter your mobile number');
		supportfrm.mobile.focus();
		return false;
		
	}*/
	
}

/* sending message validation  */


/*message box countdown*/
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}

//hide child registration page
function hidechild(sel)
{
	
	var unmar=sel.options[sel.selectedIndex].value;
	var childtext=document.getElementById('childtxt');
	var child=document.getElementById('childrens');
	if(unmar=='Un Married')
	{
		child.style.display='none';
		childtext.style.display='none';
	}
	else{ child.style.display='block';
	childtext.style.display='block';
	}
}

//forgot password email check
function checkforgotemai()//
{
	//alert('hai')
	var psdre=document.getElementById('email');
	//alert(psdre.value)
	if(psdre.value=="")
	{
		alert('Please enter your email');
		psdre.focus();
		return false;
	}
	if(!psdre.value.match(/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/))
	{
		alert('Invalid email format. Enter your emial correctly');
		psdre.focus();
		return false;
	}
}

//admin change pass word
function adminchangepass()
{
	var newps=document.getElementById('adpass');
	var newcnfps=document.getElementById('adcpass');
	if(newps.value=='')
		{
			alert('New password should not be blank');
			newps.focus();
			return false;
		}
		if(newps.value!=newcnfps.value)
		{
			alert('Password and confirm password did not match');
			newcnfps.focus();
			return false;	
		}
}

//message empty or not validation
function checkmsgempty()
{
	//alert('hai');
	var toid=document.getElementById('toid');
	var message=document.getElementById('premsg');
	if(toid.value=='')
	{
		alert('Enter Profileid');
		toid.focus();
		return false;
	}
	else if(toid.value.length!=10)
	{
		alert('Enter Profileid correctly-');
		toid.focus();
		return false;
	}
	if(message.value=='')
	{
		alert('Enter your message');
		message.focus();
		return false;
	}
}
