/* null checking */
//alert('java function');


function check_fields(form_name,f_name,d_name,c_array)
{

	var incre=0;
	for (incre=0; incre<c_array; incre++)
	{
		var frm="document."+form_name+"."+f_name[incre]+".value";
		var foc="document."+form_name+"."+f_name[incre];
		
		if(trimSpaces(eval(frm))=="")
		{	
		   alert(d_name[incre]+" is a Required Field .");
			  var foc_field=eval(foc);
			  
			  foc_field.focus();
			  return false;
		}		
		
	}
	
	return true;
}


function trimSpaces(stringValue) 
{
	   // Checks the first occurance of spaces and removes them
	   for(i = 0; i < stringValue.length; i++) 
	   {
		    if(stringValue.charAt(i) != " ") 
		     {			break;		}
	   }
	
	   if(i > 0) 
	   {		stringValue = stringValue.substring(i);	}
	
	   // Checks the last occurance of spaces and removes them
	   strLength = stringValue.length - 1;
	   for(i = strLength; i >= 0; i--) 
	   {
		   if(stringValue.charAt(i) != " ") 
		   {		break;		}
	   }
	
	   if(i < strLength) 
	   {		stringValue = stringValue.substring(0, i + 1);	}
	
	   // Returns the string after removing leading and trailing spaces.
	return stringValue;
}


/* character checking */
function checkAllowedChars(strToCheck, allowedChars) 
{
     var acLen     = allowedChars.length;
     var stcLen     = strToCheck.length;
     strToCheck     = strToCheck.toLowerCase();
     var i;
     var j;
     var rightCount = 0;
     for(i = 0; i < acLen; i++)
     {
          switch(allowedChars.charAt(i))
          {
          case 'A':
               for(j = 0; j< stcLen; j++)
               {
                    rightCount += strToCheck.charAt(j) >= 'a' && strToCheck.charAt(j) <= 'z';
               }
               break;
          case 'N':
               for(j = 0; j< stcLen; j++)
               {
                    rightCount += strToCheck.charAt(j) >= '0' && strToCheck.charAt(j) <= '9';
               }
               break;
          default:
               for(j = -1; -1 != (j = strToCheck.indexOf(allowedChars.charAt(i), j + 1)); rightCount++);
               break;
          }
     }
     if(rightCount == stcLen)
     {
          return true;
     }
     return false;
}


function checkEmail(emailString)
{
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) 
	{
		alert("Please Enter A Valid Email Address .");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) 
	{
		alert("Please Enter A Valid Email Address .");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) 
	{
		alert("Please Enter A Valid Email Address .");
		return false;
	}
	
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) 
	{
		alert("Please Enter A Valid Email Address .");
		return false;
	}
	return true;
}



// 	field_name,display_name,count_array,file_type,count_file_type
function check_file(f_name,d_name,c_array,f_type,c_f_array)
{
	 var incre=0;

	for (incre=0; incre<c_array; incre++)
	{
  var flag =0;
		var frm	=	"document."+f_name[incre]+".value";
		
		if(eval(frm)!="")
		{	
			var file	=	eval(frm).split(".");
			var ext		=	file[file.length-1].toLowerCase();

			for (increment=0; increment<c_f_array; increment++)
			{
			 if(f_type[increment]==ext)
				{
					flag = 1;
				}

			}			
		}		
		if(flag == 0)
		{
    			alert("Invalid File Type In "+d_name[incre]);
    			return false;
		}		
	}
return true;
}





function check_int_fields(formname,f_name,d_name,c_array)
{
	var incre=0;	
	for (incre=0; incre<c_array; incre++)
	{
		var frm="document."+formname+"."+f_name[incre]+".value";
		var foc="document."+formname+"."+f_name[incre];
		
		if(isNaN(eval(frm)))
		{	
		   alert(d_name[incre]+" Should Be A Number .");
			  var foc_field=eval(foc);
			  foc_field.focus();
			  return false;
		}		
	}
	return true;
}



function check_greater(min_val,max_val,d_name,c_array)
{
	var incre=0;
	for (incre=0; incre<c_array; incre++)
	{
		var frm_min="document."+min_val[incre]+".value";
		var foc_min="document."+min_val[incre];
		var frm_max="document."+max_val[incre]+".value";
		var foc_max="document."+max_val[incre];
		if(eval(frm_min)>eval(frm_max))
		{	
		      alert(d_name[incre]+" Must Be Larger .");
			  var foc_field=eval(foc_min);
			  foc_field.focus();
			  return false;
		}		
	}	
	return true;
}





// Make the XMLHttpRequest object
var http_request = false;
function makeRequest(url) 
{

    if(window.XMLHttpRequest)
	   {
      	http_request = new XMLHttpRequest();
   	} 
   	else if(window.ActiveXObject) 
   	{
      	http_request = new ActiveXObject("Microsoft.XMLHTTP");
   	} 
   	else 
   	{
      	alert('Problem creating the XMLHttpRequest object');
   	}
   	http_request.open('get', url);
   	http_request.onreadystatechange = alertContents();
   	http_request.send(null);
}

function alertContents() 
{
   alert(http_request.readyState);
   		if(http_request.status == 200)
		   {
				
   		if(http_request.readyState == 4)
     {
     	var response = http_request.responseText;
	     alert(response);
	     document.newsletter.getElementById('newsletter').innerHTML='0';
     }
   		//alert(response);
	         	//window.open("fckeditor.php?name="+name+"&content="+content.value,'fckeditor',"menubar=1,resizable=0,width=720,height=450,top=100,left=100");
		}
	
}

function check_intgreat_val(min,max)
{
	
	var min,max;
	
	if(parseFloat(min) > parseFloat(max))
	{
			alert('Minimum Total Should Be Less Than Maximum Total')
			return false
	}
	if(parseFloat(min) < 0)
	{
		alert('Negative Value Is Not Allowed') 
		return false
	}
	else if(parseFloat(max) < 0)
	{	
		alert('Negative Value Is Not Allowed') 
		return false
	}

	return true
}

function check_intgreat_val2(min,max)
{
	
	var min,max;
	
	if(parseFloat(min) > parseFloat(max))
	{
			alert('Start Range Should Be Less Than End Range')
			return false
	}
	if(parseFloat(min) < 0)
	{
		alert('Negative Value Is Not Allowed') 
		return false
	}
	else if(parseFloat(max) < 0)
	{	
		alert('Negative Value Is Not Allowed') 
		return false
	}

	return true
}







function isInteger(value) 
{  return (parseInt(value) == value); }

var integer = /^\d+$/;

function validateInteger(form,myField) 
{
  if (!isInteger(eval("document."+form+"."+myField+".value"))) 
  {    
    alert('Invalid Integer Value Entered . \n');
    eval("document."+form+"."+myField+".focus()");
    return false
  }

  if (window.RegExp && !integer.test(eval("document."+form+"."+myField+".value"))) {
    
    alert('Invalid Integer Value Entered . \n');
    eval("document."+form+"."+myField+".focus()");
   return false
  }
	

  return true;
}





//  Function To Check Minimum - Maximum value  (Int - Integer Value)


function checkGreaterInt(min_field,max_field,min_text,max_text,form_name)
{
  
 var min_value="document."+form_name+"."+min_field+".value";
 var max_value="document."+form_name+"."+max_field+".value";
 var temp;
 
        if(isNaN(eval(min_value)))
	    {	
     	alert(min_text+" Should Be A Number . ");
        temp="document."+form_name+"."+min_field;
        eval(temp).focus();
        return false;	 
	    }
		
	    if(isNaN(eval(max_value)))
        {	
	       alert(max_text+" Should Be A Number . ");
        temp="document."+form_name+"."+max_field;
        eval(temp).focus();
        return false;	 
	    }
		
	    
	    if(isInteger(eval(min_value)))
	    {    }
	    else
	    {
	     
	    alert(min_text+" Should Not Be A Decimal Number . ");
        temp="document."+form_name+"."+min_field;
        eval(temp).focus();
        return false;	
	    }
	    
	    if(isInteger(eval(max_value)))
	    {    }
	    else
	    {
	    alert(max_text+" Should Not Be A Decimal Number . ");
        temp="document."+form_name+"."+max_field;
        eval(temp).focus();
        return false;	
	    }
	    
	    
     if(parseInt(eval(min_value))<0)
     {
        alert(min_text+" Should Be Greater Than Or Equal To Zero . ");
        temp="document."+form_name+"."+min_field;
        eval(temp).focus();
        return false;
     }
 
     if(parseInt(eval(max_value))<0)
     {
        alert(max_text+" Should Be Greater Than Or Equal To Zero . ");
        temp="document."+form_name+"."+max_field;
        eval(temp).focus();
        return false;
     }
 
     if(parseInt(eval(max_value))<=parseInt(eval(min_value)))
     {
        alert(max_text+" Should Be Greater Than "+min_text+" . ");
        temp="document."+form_name+"."+max_field;
        eval(temp).focus();
        return false;
      }
 
 return true;
}



//  Function To Check Minimum - Maximum value  (Float - Decimal Value)


function checkGreaterFloat(min_field,max_field,min_text,max_text,form_name)
{
  
 var min_value="document."+form_name+"."+min_field+".value";
 var max_value="document."+form_name+"."+max_field+".value";
 var temp;
 
     if(isNaN(eval(min_value)))
	    {	
     	  alert(min_text+" Should Be A Number . ");
        temp="document."+form_name+"."+min_field;
        eval(temp).focus();
        return false;	 
	    }
		
	    if(isNaN(eval(max_value)))
     {	
	       alert(max_text+" Should Be A Number . ");
        temp="document."+form_name+"."+max_field;
        eval(temp).focus();
        return false;	 
	    }
		
     if(parseFloat(eval(min_value))<0)
     {
        alert(min_text+" Should Be Greater Than Or Equal To Zero . ");
        temp="document."+form_name+"."+min_field;
        eval(temp).focus();
        return false;
     }
 
     if(parseFloat(eval(max_value))<0)
     {
        alert(max_text+" Should Be Greater Than Or Equal To Zero . ");
        temp="document."+form_name+"."+max_field;
        eval(temp).focus();
        return false;
     }
 
     if(parseFloat(eval(max_value))<=parseFloat(eval(min_value)))
     {
        alert(max_text+" Should Be Greater Than "+min_text+" . ");
        temp="document."+form_name+"."+max_field;
        eval(temp).focus();
        return false;
      }
 
 return true;
}

// Function To Check Whether The Value Entered Is A Non Negative Float 

function check_numeric(sText)
{   
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}




/*
**Function to check password entry when change ing pwd


*/
  function checkPass()
		{
				
				if(document.frmpsd.newpassword.value=="")
				{
					alert("Please Enter Your New Password .");
					document.frmpsd.newpassword.value=="";
					document.frmpsd.newpassword.focus();
					return false;	
				}	
				if(document.frmpsd.confirmpassword.value=="")
				{
					alert("Please Confirm Your New Password .");
					document.frmpsd.confirmpassword.value=="";
					document.frmpsd.confirmpassword.focus();
					return false;	
				}
				if(document.frmpsd.newpassword.value!=document.frmpsd.confirmpassword.value)
				{
					alert("Password Mismatch .");
					document.frmpsd.confirmpassword.value=="";
					document.frmpsd.confirmpassword.focus();
					return false;
				}	
		}	

		
		
		/*
**Function to check password entry when changeing pwd of customer at user side


*/
  function checkPassUser()
		{
				
				if(document.frmpsd.newpassword.value=="")
				{
					alert("Please Enter Your New Password .");
					document.frmpsd.newpassword.value=="";
					document.frmpsd.newpassword.focus();
					return false;	
				}	
				if(document.frmpsd.confirmpassword.value=="")
				{
					alert("Please Confirm Your New Password .");
					document.frmpsd.confirmpassword.value=="";
					document.frmpsd.confirmpassword.focus();
					return false;	
				}
				if(document.frmpsd.newpassword.value!=document.frmpsd.confirmpassword.value)
				{
					alert("Password Mismatch .");
					document.frmpsd.confirmpassword.value=="";
					document.frmpsd.confirmpassword.focus();
					return false;
				}	
		}	
		
		function check2Emails(email1,email2) {
			if(email1==email2) {
			
				return true;
			}
			else {
				alert('Two email should be equal.');
				return false;
			}
		}
		
			function emptyTextBox(contrlName,value1) {
		//		alert('sdfsdfsd');
			///alert('-'+contrlName+'-'+value1+'-');
				if(contrlName==value1) {
					//contrlName='';
					//alert(document.getElementById('s_search').value);
				//	alert(document.search_form.s_search.value);
			  document.search_form.s_search.value=' ';
			 // 
					}
		}
		
function form_submit(a){
 //alert(a);
 document.onkeydown = checkKeycode()
}



function checkKeycode(e) {
var keycode;
//alert(keycode);
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if(keycode == 13){
//void(0);
document.search_form.submit();
//window.location='/user/search_all.php?s_state=\'+document.search_form.s_state.value+\'&s_city=\'+document.search_form.s_city.value+\'&s_search=\'+document.search_form.s_search.value+\'\'';
//check_form();
}
}

function gotoStateReview(state,stat){
	//alert(stat);
	if(state=='all'){
		//alert('please select a state');
		 window.location= site_url + "/active_adult_communities/National.html";
	}
	else {
     
		  window.location= site_url + "/active_adult_communities/"+ state +".html";
		  //window.location.href="reviews/"+ state +".html"
	
	}
}


function notifyme(form){
	///alert(form.text_nofifyme.value);
	
			if(checkEmail(form.text_nofifyme.value))
			{
				
				 window.location=site_url +"/Newsletter.html?email="+form.text_nofifyme.value;
				 return false;
			}
			else {
				return false;
			}
		
			
}
function notifyMeText(e,form){
	
var keycode;

if( typeof( e.keyCode ) == 'number'  ) {
    //DOM
    e = e.keyCode;
  } else if( typeof( e.which ) == 'number' ) {
    //NS 4 compatible
    e = e.which;
  } else if( typeof( e.charCode ) == 'number'  ) {
    //also NS 6+, Mozilla 0.9+
    e = e.charCode;
  } else {
    //total failure, we have no way of obtaining the key code
    return;
  }
 
  keycode=e;
		if(keycode == 13){
			return notifyme(form)
		}
		
}




function subscribe_newsletter(){
	if(checkEmail(document.newsletter_subscribe.newsletter_email.value)) {
			   window.location=site_url +"/Newsletter.html?email="+document.newsletter_subscribe.newsletter_email.value;
			}
}
		

function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url))
    {
        return true;
    }else
    {
						alert("Please enter a valid URL .")
    		return false;
    }
} 

function popup(url,title,param)
{
	 
	window.open (url,'',param); 
}



function popupAlert(pageurl,okLabel,okOnClick,buttonClass,pagewidth)
{ 
    if(okOnClick=='')
        okOnClick = 'Dialog.okCallback()';
    if(pagewidth==0)
        pagewidth = 550;

    Dialog.alert({url: pageurl, options: {method: 'get'}},  
                 {className: 'alphacube', width:pagewidth, okLabel: okLabel, okOnClick: okOnClick,
                 buttonClass: buttonClass,closable:true,
                 showEffectOptions: {duration: 0.7}, hideEffectOptions: {duration: 0.3}});
}

function popupInfo(pageurl,pagewidth)
{ 
    if(pagewidth==0)
        pagewidth = 550;
        
    Dialog.info({url: pageurl, options: {method: 'get'}},  
                 {className: 'alphacube', width:pagewidth,closable:true,
                 showEffectOptions: {duration: 0.7}, hideEffectOptions: {duration: 0.3}});
}

function popupConfirm(pageurl,okLabel,okOnClick,cancelLabel,cancelOnClick,buttonClass,pagewidth)
{ 
    if(okOnClick=='')
        okOnClick = 'Dialog.okCallback()';
    if(cancelOnClick=='')
        cancelOnClick = 'Dialog.cancelCallback()';
    if(pagewidth==0)
        pagewidth = 550;  

    Dialog.confirm({url: pageurl, options: {method: 'get'}},  
                 {className: 'alphacube',buttonClass: buttonClass, width:pagewidth,closable:true,
                 okLabel: okLabel,okOnClick: okOnClick,cancelLabel: cancelLabel,cancelOnClick: cancelOnClick,
                 showEffectOptions: {duration: 0.7}, hideEffectOptions: {duration: 0.3}});
}