function email_validate(mail)
{
	
	//-----------------function to validate email address----------//
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))
		return true;
	else 	
		return false;	
}
function showPasswordAmount(){
valPassword = true;
	if(!$('password_amount').visible()) {
		$('password_enter').hide();
		$('password_amount').show();
	}
	
}
function showPasswordvalidation(){
valPassword = true;
	if(!$('password_vali').visible()) {
		$('password_amount').hide();
		$('password_vali').show();
	}
	
}
function password_validate(password)
{
	//-----------------function to validate email address----------//
	if (/^\w*(?=\w*\d)(?=\w*[a-z])\w*$/.test(password))
		return true;
	else 	
		return false;	
}
function IsValidDate(Day,Mn,Yr){
	
				
	var daysInMonth = DaysArray(12);
	if ((Mn==2 && Day>daysInFebruary(Yr))  || Day > daysInMonth[Mn]){
		return false
	}
	else 
	{
		return true ;
	}		
}
function daysInFebruary (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
} 
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
 
 function signupForm()
{
  
	var re = /^\w*(?=\w*\d)(?=\w*[a-z])\w*$/;
	var p=$('txtpassword').value;
	
	$('username_unavail').hide();
	$('email_unavail').hide();
	$('email_invalid').hide();
	$('password_amount').hide();
	$('password_enter').hide();
	$('password_vali').hide();
	$('agree_chk').hide();
	$('date_vali').hide();
	$('date_unavail').hide();
	$('date_greater').hide();
	
	var days = 0;var years = 0;
	var difference = 0;
	dateofbirth = new Date($('selectbyear').value,$('selectbmonth').value,$('selectbdate').value);
	today = new Date(pyear,pmonth,pday);
	difference = today - dateofbirth;
	days = Math.round(difference/(1000*60*60*24));
	
	if($('username').value ==''){
		Effect.Appear('username_unavail',{duration:0.3});
		return false;
	}
	
	else if($('txtemail').value ==''){
		Effect.Appear('email_unavail',{duration:0.3});
		return false;
	} 
	
	else if (email_validate($('txtemail').value) == false) {
		Effect.Appear('email_invalid',{duration:0.3});
		return false;
	}
	
	//Re-Check password
	else if($('txtpassword').value ==''){
		Effect.Appear('password_enter',{duration:0.3});
		return false;
	}
	
	else if($('txtpassword').value.length<6)
	{
		showPasswordAmount();
		return false;
	}
	else if (!re.test(p)) {
		showPasswordvalidation();
		return false;
	}
	else if($('selectbdate').value=='' || $('selectbmonth').value=='' || $('selectbyear').value=='')
	{
		Effect.Appear('date_unavail',{duration:0.3});
		return false;
	}
	else if(!IsValidDate($('selectbdate').value,$('selectbmonth').value,$('selectbyear').value))
	{
		Effect.Appear('date_vali',{duration:0.3});
		return false;
	}
	if(days < 4748 )
	{
		Effect.Appear('date_greater',{duration:0.3});
		return false;
	}
	else if($('cbaccept').checked==false)
	{
		Effect.Appear('agree_chk',{duration:0.3});
		return false;
	}
	else 
	{
		var time =	det_time();
		document.getElementById('local_time').value	=	time;
		$('quickSignup_1').hide(); 
		Formname=document.signupfrm;
		Formname.action=UrlArr['module_register_url']+"/registration/validationEmail";
		Formname.submit();
	}		 
}

function det_time()
{
	var d = new Date();
	var c_hour = d.getHours();
	var c_min = d.getMinutes();
	var c_sec = d.getSeconds();
	var t = c_hour + ":" + c_min + ":" + c_sec;
	return t;
}
 
 function checkname()
 {
 
 	document.getElementById('usernamemsgid').className="txtFiveB";
 	if(document.getElementById('username').value=='')
	{
		document.getElementById('usernamemsgid').innerHTML=ErrorMsgArray['errcantempty'];
	}
	else
	{
		document.getElementById('usernamemsgid').innerHTML=ErrorMsgArray['lblok'];
		document.getElementById('usernamemsgid').className="txtSixB";
	}
 }
 
function checkemail()
{
	var email=document.getElementById('txtemail').value;
	document.getElementById('emailmsgid').className="txtFiveB";
	if(email=='')
	{
		document.getElementById('emailmsgid').innerHTML=ErrorMsgArray['errcantempty'];
	}
	else 
	{
		if(!email_validate(email))
		{
			document.getElementById('emailmsgid').innerHTML=ErrorMsgArray['lblmustvalidemail'];
		}	
		else
		{
			 $j.ajax(
			 {
				type: "POST",
				url: UrlArr['module_register_url']+'/registration/checkemail/'+email,
				data:'',
				success: function(msg)
					{
						if(msg=='yes')
						{
							document.getElementById('emailmsgid').innerHTML=ErrorMsgArray['lblok'];
							document.getElementById('emailmsgid').className="txtSixB";
						}
						else
						{
							document.getElementById('emailmsgid').innerHTML=ErrorMsgArray['emailnotavailable'];
							document.getElementById('emailmsgid').className="txtFiveB";
						}
					}
			  });
  		 }
	}
	
} 
function checkpassword()
{
	var password=document.getElementById('txtpassword').value;
	document.getElementById('passwordmsgid').className="txtFiveB";
	if(password=='')
	{
		document.getElementById('passwordmsgid').innerHTML=ErrorMsgArray['errcantempty'];
	}
	else 
	{	
		if(password.length<6)
		{
			document.getElementById('passwordmsgid').innerHTML=ErrorMsgArray['lblsixchar'];
		} 
		else
		{
			if(!password_validate(password))
			{
				document.getElementById('passwordmsgid').innerHTML=ErrorMsgArray['lblmustmin1char1alpha'];
			}	
			else
			{
				document.getElementById('passwordmsgid').innerHTML=ErrorMsgArray['lblok'];
				document.getElementById('passwordmsgid').className="txtSixB";
			}
		}
	}
}

function checkdate()
{
	var day=document.getElementById('selectbdate').value;
	var month=document.getElementById('selectbmonth').value;
	var year=document.getElementById('selectbyear').value;
	
	document.getElementById('bdatemsgid').className="txtFiveB";
	
	if(day=='')
	{
		document.getElementById('bdatemsgid').innerHTML=ErrorMsgArray['lblselectday'];
	}
	else if(month=='')
	{
		document.getElementById('bdatemsgid').innerHTML=ErrorMsgArray['lblselectmonth'];
	}
	else if(year=='')
	{
	    document.getElementById('bdatemsgid').innerHTML=ErrorMsgArray['lblselectyear'];
	}
	else
	{
	     if(!IsValidDate(day,month,year))
		 {   	
         	document.getElementById('bdatemsgid').innerHTML=ErrorMsgArray['lblselectvalidday'];
		 }
  		 else
		 {   
			var days = 0;var years = 0;
			var difference = 0;
			dateofbirth = new Date(year,month,day);
			today = new Date(pyear,pmonth,pday);
			difference = today - dateofbirth;
			 
			days = Math.round(difference/(1000*60*60*24));
			
			if(days >=4748)
			{ 
				document.getElementById('bdatemsgid').innerHTML=ErrorMsgArray['lblok'];
				document.getElementById('bdatemsgid').className="txtSixB";
			}
			else
			{
				document.getElementById('bdatemsgid').innerHTML=ErrorMsgArray['notavaliddate'];
				document.getElementById('bdatemsgid').className="txtFiveB";
			}
		}
	}
}

function savevisitor()
{
	var email=document.getElementById('txtvisitormail').value;
	if(email=='Your E-mail Address')
	{
		document.getElementById('visitormessageid').innerHTML=ErrorMsgArray['errcantempty'];
	} 
	 
	else if (!email_validate(email)) {
		document.getElementById('visitormessageid').innerHTML=ErrorMsgArray['lblmustvalidemail'];
	}
	else 
	{
		 $j.ajax(
			 {
				type: "POST",
				url: UrlArr['module_register_url']+'/registration/visitor/'+email,
				data:'',
				success: function(msg)
					{
						if(msg=='yes')
						{
							 document.getElementById('visitormessageid').innerHTML=ErrorMsgArray['visitormessage'];
							 document.getElementById('txtvisitormail').value='';
						}
					}
			  });
	}	
}
  function submitform()
  {
  	if(document.getElementById("txtphone").value=='+91..')
	{
		document.getElementById("txtphone").value='';
	}
	if(document.getElementById("txtemail").value=='Email Id')
	{
		document.getElementById("txtemail").value='';
	}
	if(document.getElementById("txtims").value=='IM Id')
	{
		document.getElementById("txtims").value='';
	}
	if(document.getElementById("txtwebsite").value=='WebSite')
	{
		document.getElementById("txtwebsite").value='';
	}
	if(document.getElementById("txtschoolname").value=='Highschool Name')
	{
		document.getElementById("txtschoolname").value='';
	}
	if(document.getElementById("txtcourse").value=='Course Name')
	{
		document.getElementById("txtcourse").value='';
	}
	if(document.getElementById("addressline1").value=='Address Line1')
	{
		document.getElementById("addressline1").value='';
	}
	if(document.getElementById("addressline2").value=='Address Line2')
	{
		document.getElementById("addressline2").value='';
	}
  	if(document.getElementById("txtcity").value=='City')
	{
		document.getElementById("txtcity").value='';
	}
    if(document.getElementById("txtzipcode").value=='Zipcode')
	{
		document.getElementById("txtzipcode").value='';
	}
	
  	document.getElementById("saveprofilefrm").submit();
 }
function getStateList(val, recordno, widthcss)
{
	$j.ajax(
	{
		type: "POST",
		url: webURL+'/addressbook/getstate/contact_State/contact_State/'+val+'/'+recordno+'/'+widthcss,
		data:'&countryid='+val+'&recordno='+recordno+'&width='+widthcss,
		success:function(msg)
		{
			document.getElementById('dynamicState_'+recordno).innerHTML = msg;
		}
	});
}


function checksenddatacontact()
{
	document.getElementById('errmsg').innerHTML="";
	var name=document.getElementById('name').value;
	var textmsg=document.getElementById('textmsg').value;
	var email=document.getElementById('email').value;
	if(name=='' || textmsg=='' || email=='')
	{
	document.getElementById('errmsg').innerHTML=ErrorMsgArray['lblmustvalidemail'] ;
	
	}
	else 
	{
		if(email_validate(email))
	  	{
			document.getElementById('val').value=1;
			document.contactusfrm.submit();
	  	}
	  	else
	  	{
	  		document.getElementById('errmsg').innerHTML=ErrorMsgArray['lblmustvalidemail'] ;
	  	}
	}
}

function cleardatacontact()
{  
 	 document.getElementById('name').value='';
 	document.getElementById('textmsg').value=''; 

   document.getElementById('email').value=0;
document.getElementById('type').selectedIndex=0;
}


function name_validate(name)
{
	
	if (/^[a-zA-Z]*$/.test(name))
	{
		return true;}
	else 	
		return false;	
}