function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum);}
	 else {limitCount.value = limitNum - limitField.value.length;}
}
var authe = {};
	
authe.registerme=function(frm){
	if(frm == 'register_form'){
		
		frm=document.getElementById(frm);
		
			var first_name = frm.first_name.value;
			var last_name = frm.last_name.value;
			var mail	 = frm.mail.value;
			var pass = frm.pass.value;
			var cpass = frm.cpass.value;	
			var mobile = frm.mobile.value;
			var user_city = frm.user_city.value;
			var user_locality = frm.user_locality.value;
			var dob = frm.dob.value;			
			
			if(!isNull(mail,'Please provide email.','mail')){frm.mail.focus(); return false;}
			if(!isMail(mail,'Please provide valid email.','mail')){frm.mail.focus(); return false;}
			if(!isNull(pass,'Please provide password.','pass')){frm.pass.focus(); return false;}
			if(!isNull(cpass,'Please provide confirm password.','cpass')){frm.cpass.focus(); return false;}
			var regex=/^[0-9A-Za-z]+$/; 
			if(!regex.test(pass)){
				alert("Provide Password Alpha Numeric Combination.");
				frm.pass.focus();
				return false;
			}
			if(!regex.test(cpass)){
				alert("Provide Password Alpha Numeric Combination.");
				frm.cpass.focus();
				return false;
			}
			if(!isLength(pass,'Password must be greater then 6 character.','pass',6)){frm.pass.focus(); return false;}
			if(!isComparePassword(pass,cpass,'Your password and confirm password does not match.','cpass')){frm.cpass.focus(); return false;}
			if(!isNull(first_name,'Please provide first name.','first_name')){frm.first_name.focus(); return false;}
			var regex1=/^[A-Za-z]+$/; 
			if(!regex1.test(first_name)){
				alert("Provide first name with alphabetics only.");
				frm.first_name.focus();
				return false;
			}

			
			if(!isNull(last_name,'Please provide last name.','last_name')){frm.last_name.focus(); return false;}
			if(!regex1.test(last_name)){
				alert("Provide last name with alphabetics only.");
				frm.last_name.focus();
				return false;
			}
			if(!isNull(mobile,'Please provide mobile number.','mobile')){frm.mobile.focus(); return false;}
			if(isNaN(mobile))
			{
					alert("Mobile number should be numeric.");
					frm.mobile.focus(); 
					return false;
			}
			if(!(frm.male.checked || frm.female.checked))
			{
				alert("please provide gender.");
				return false;
			}
			if(!isNull(user_city,'Please select city.','user_city')){frm.user_city.focus(); return false;}
			if(!isNull(user_locality,'Please select locality.','user_locality')){frm.user_locality.focus(); return false;}
			if(!isNull(dob,'Please provide date of birth.','dob')){frm.dob.focus(); return false;}
			//if(frm.tearms_and_condition.checked)
			//{		
				var URL=APPLICATION_URL+"authentication/doregister?ajaxcall=true";
				frm.action=URL;
				frm.submit();
			//}
			//else
			//{
				//alert("Please check I agree all terms and conditions ckeckbox.");
				//return false;
			//}
		
	}
}
authe.getpassword=function(form)
{
	var frm = document.getElementById(form);
	var name = frm.email.value;
	//if(name == "")
    //{
	  //alert("Please enter email address.");
	 // document.getElementById("email").focus();
	 // return false;
   // }
   // else
   // {
		/*if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  
		xmlhttp.onreadystatechange=function()
		  {
			  
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{			
			alert(xmlhttp.responseText);
				getElementId("register_DIV").innerHTML=xmlhttp.responseText;
			}
		  }
		 
		  
		  var URL=APPLICATION_URL+"authentication/sendpassword";
		xmlhttp.open("GET",URL,true);
		xmlhttp.send();*/
		/*var preloader=new ShowLoader();
		var URL=APPLICATION_URL+"authentication/sendpassword?ajaxcall=true";
		var formObject=getElementId(frm);	
		handleSuccess=function(o){		
			getElementId("register_DIV").innerHTML=xmlhttp.responseText;
		}
		callback={success:handleSuccess,failure:this.handleFailure}
		YAHOO.util.Connect.setForm(formObject);
		YAHOO.util.Connect.asyncRequest("POST",URL,callback);*/
		var URL=APPLICATION_URL+"authentication/sendpassword?email="+name;
		frm.action=URL;
		frm.submit();
	//}
}
authe.validateEmail=function(email){
	
	$.ajax({
		url:APPLICATION_URL+"authentication/emailvalidatity/"+email+"?ajaxcall=true",
		dataType:"html",
		success:function(data)
		{
		//	alert(data);
			document.getElementById('emailvalidate').innerHTML=data;
			if(data.indexOf('not')>=0)
			{
			document.getElementById('mail').focus();
			}
		}
	});
}
authe.loginme=function(frm){
	
	
	var formObject = document.getElementById("login_form");
	
	var preloader=new ShowLoader();
	var URL=APPLICATION_URL+"authentication/dologin?ajaxcall=true";
	//var formObject=getElementId(frm);	
	
	handleSuccess=function(o){		
	//alert(o.responseText);
		if(o.responseText.search("abcdef123456") > 0)
		{
				
			var responseArray = o.responseText.split("abcdef123456");
		
			//alert(responseArray);
			if(parseInt(responseArray[1]) == 1 || parseInt(responseArray[2]) == 1){				
				if(responseArray[0].search("add_business") > 0)
				{					
					document.location.href = APPLICATION_URL+"business/add_business";
				}
				else if(responseArray[0].search("my_local") > 0)
				{					
					document.location.href = APPLICATION_URL+"mylocal/mylocal";
				}
				else if(responseArray[0].search("follow") > 0)
				{					
					document.location.href = APPLICATION_URL+"myaccount/followingBusiness";
				}
				else if(responseArray[0].search("businessview") > 0)
				{			
						
					document.location.href = APPLICATION_URL+responseArray[1].substr(1,responseArray[1].length);
				}			
				else
				{
				
					if(o.responseText.search("NOPASSWORD") > 0)
					{
						alert("Invalid username or password");
						document.location.href = APPLICATION_URL+"authentication/login";
					}
					document.location.href = APPLICATION_URL+"myaccount";
				}
			} else {
				if(o.responseText.search("NOPASSWORD") > 0)
				{
					alert("Invalid username or password");
					document.location.href = APPLICATION_URL+"authentication/login";
				}
				document.location.href = APPLICATION_URL+"authentication/login";
			}
		}
		else
		{
			if(o.responseText.search("NOPASSWORD") > 0)
			{
				alert("Invalid username or password");
				document.location.href = APPLICATION_URL+"authentication/login";
			}		
			else if(parseInt(o.responseText) == 1){
				document.location.href = APPLICATION_URL+"myaccount";				
			} else {
				
				document.location.href = APPLICATION_URL+"authentication/login";
			}
		}
	}
	callback={success:handleSuccess,failure:this.handleFailure}
	YAHOO.util.Connect.setForm(formObject);
	YAHOO.util.Connect.asyncRequest("POST",URL,callback);
}
function isNull(val,msg,id){
		
		if(val.length > 0 && val != ""){
			return true;
		}else{
			alert(msg);
			document.getElementById(id).value = "";
			document.getElementById(id).focus();
			return false;
		}
	}
function isComparePassword(pass1,pass2,msg,id){
		if(pass1 != pass2){
				alert(msg);
				document.getElementById(id).focus();
				return false;
		}else{
				return true;
		}
}
function isMail(val,msg,id){
	var	reg =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
		if(reg.test(val) == false) {
			alert(msg);			
			document.getElementById(id).focus();
			return false;
		}else{
			return true;
		}
	}
function isLength(val,msg,id,len){
		if(val.length < len){
			alert(msg);
			document.getElementById(id).value ="";
			document.getElementById(id).focus();
			return false;
		}else{
			return true;
		}
}
function registerValidation(frm){
		fullname = frm.fullname.value.trim();
		mail	 = frm.mail.value.trim();
		pass = frm.pass.value.trim();
		cpass = frm.cpass.value.trim();
		prvc = frm.prvc.value.trim();		
		if(!isNull(fullname,'Please provide full name.','fullname',frm)){frm.fullname.focus(); return false;}
		if(!isNull(mail,'Please provide email.','mail')){frm.mail.focus(); return false;}
		if(!isMail(mail,'Please provide valid email.','mail')){frm.mail.focus(); return false;}
		if(!isNull(pass,'Please provide password.','pass')){frm.pass.focus(); return false;}
		var regex=/^[0-9A-Za-z]+$/; //^[a-zA-z]+$/
		if(!regex.test(pass)){
			alert("Provide Password Alpha Numeric Combination.");
			frm.pass.focus();
			return false;
		}
		if(!isLength(pass,'Password must be greater then 6 character.','pass',6)){frm.pass.focus(); return false;}
		if(!isNull(cpass,'Please provide confirm password.','cpass')){frm.cpass.focus(); return false;}		
		if(!isComparePassword(pass,cpass,'Your password is mismatch.','cpass')){frm.cpass.focus(); return false;}
		if(!isNull(prvc,'Please select privacy.','prvc')){frm.prvc.focus(); return false;}		
		return true;		
}
function getPage(id){
	frm = document.getElementById('pages_form');
	frm.page.value = id;
	frm.action = APPLICATION_URL+"authentication/ViewAllText";
	frm.submit();
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function getSearch(){
	if( document.getElementById('search').value != "SEARCH")
	{
		frm = document.getElementById('pages_form');		
		frm.page.value = document.getElementById('search').value;
		frm.action = APPLICATION_URL+"myaccount/searchcontent";		
		frm.submit();
		return true;
	}
	alert("Enter any keyword to search.");
	return false;
}
function text_box_focus(th)
{
	document.getElementById("search").value = "";
}
function text_box_blur(th)
{
	if(document.getElementById("search").value == "")
	{
		document.getElementById("search").value = "SEARCH";
	}
}
function check_enter(e)
{
	var unicode = e.charCode ? e.charCode : e.keyCode
	if(unicode == 13)
	{
		authe.loginme();
	}
}
function submit_forgot_pass(e)
{
	var unicode = e.charCode ? e.charCode : e.keyCode
	if(unicode == 13)
	{
		authe.getpassword('forgot_form');
	}
}
function fetchLocality(val)
{
	if(val != "")
	{
		var URL = APPLICATION_URL+"authentication/fetchAllLocalityOfCity/"+val+"?ajaxcall=true";
		handleSuccess=function(o){		
			//alert(o.responseText);		
			document.getElementById("show_locality_type").innerHTML = o.responseText;		
		}		
		callback={success:handleSuccess,failure:this.handleFailure}
		YAHOO.util.Connect.asyncRequest("GET",URL,callback)
	}
	else
	{
		document.getElementById("show_locality_type").innerHTML = '<select id="selected_locality" name="selected_locality" class="selct_user_type"><option value="">Select Locality</option></select>';
	}
}


