<!--
/*
  JAVASCRIPT COMMON VALIDATIONS
*/

//Objects for Various Validations
var objenName				= "@$#()=/!*ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789,'- :.+%/ ";
var objName 				= '"?&<>/\\[]{}~^';
var objNumber   			= ".0123456789";
var objSpecialNumber  		= "-+ ,.0123456789%";
var objCurrency   			= ".0123456789";
var objWholeNumber  		= "0123456789";
var objPassword		  		= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-0123456789";//+_#$&*!@=?/><^~|\][{}.
var objTelephone    		= "-()0123456789,+";
var objMNumber   			= "0123456789";
var objFax		    		= "-()0123456789,+";
var objEmail    			= ".@0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
var objAlpha 				= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz -";
var objAlphaNumeric 		= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789,- :.+% ";
var objPageName				= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789- :.+% ";
var objTitle		 		= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz.";
var objFileName				= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-0123456789/?=";

var objCode					= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-0123456789";
var objSpecialChar 			= "@&$#()=/!*ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789,'- :.+%/ ";
var objZipCode 				= "0123456789";
var objAlphaNumericOnly		= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var objOnlyAlpha 			= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz ";
var objFoldername			= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
var objUrl					= "/:.-\ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
var objAll					=	'';
var objSpecialUserChar 		= "-[]'ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789 ";
var objDecimalNumber  		= "-+.0123456789";
var objresultval			= '"&<>/\\[]{}~^=+-|`!@#$%*?';
var objhourval				= '"\'&<>/\\[]{}~^=+-|`!@#$%*?;,ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'; 
 
/* Max Lengths for Various Values */
var nameMaxLength			= 	50;
var largeNameMaxLength		=	80;
var usernameMaxLength		= 	50; 
var pwdMaxLength			= 	25;
var phoneMaxLength			=	40;  
var faxMaxLength			=	40;  
var codeMaxLength			=	25;
var textareaMaxLength		=	255;
var ZipCodeMaxLength		=	7;
var EmailMaxLength			=	80;
var mediumtextMaxLength		=	500;
var SectionMaxLength	=	250;
var objPageTitle		= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz:. ";

/****************************************************************************/	
function isRule(oComp, sRule, nLength, fdecimal, minLength,fieldName,maxLength)
{
    //alert(sRule)
	if(fdecimal == "" || typeof(fdecimal) == "undefined")
	{
		fdecimal = false;
	}

	//If the object is not specified return false
	if (typeof(oComp) == 'undefined' || oComp == null || oComp == '')
	{
		alert(g_js_error_obj_not_defined);
		return false;
	}
	//If neither rule nor max length is specified, return false
	else if (typeof(sRule) == 'undefined' && typeof(nLength) == 'undefined')
	{
		alert(g_js_error_max_input);
		return false;
	}

	var noErrorFlg = true;
	
	if(sRule != objAll)
	{
		//If object is specified and either of rule is specified,
		if(typeof(sRule) != 'undefined' && sRule != null)
		{
			var temp;
			sRule = sRule + "";
			var discardChars = false;
			if(sRule.length > 0 && sRule.charAt(0) == "~")
			{
				sRule = sRule.substring(1);
				discardChars = true;
			}
	
			if(typeof(oComp) == "undefined" || typeof(sRule) == "undefined")
				return false;
	
			for (var i = 0;i < oComp.value.length;i++)
			{
				temp = oComp.value.charAt(i);
	
				if((!discardChars && sRule.indexOf(temp) == -1) || (discardChars && sRule.indexOf(temp) >= 0))
				{
					alert(g_js_invalid_charac);
					oComp.value = oComp.value.substring(0,i);// + (oComp.value.length > i ? oComp.value.substring(i+1):"");
					noErrorFlg = false;
					break;
				}
			}
		}
	}
	if(nLength)
	{
	
		if(fdecimal)
		{
			nLength -= fdecimal;
			var dp = oComp.value.indexOf(".");
			var p1;
			var p2 = "";;
			if(dp >= 0)
			{
				p1 = oComp.value.substring(0,dp);
				p2 = oComp.value.substring(dp+1);
			}
			else
			{
				p1 = oComp.value;
			}
			if(p1.length > nLength)
			{
				oComp.value = oComp.value.substring(0,nLength);
				return noErrorFlg;
			}
			for(var i = 0;i < p2.length;i++)
			{
				var ch = p2.charAt(i);
				if(ch < '0' || ch > '9')
				{
					oComp.value = p1 + "." + p2.substring(0,i);
					return noErrorFlg;
				}
			}
			if(p2.length > fdecimal)
			{
				oComp.value = p1 + "." + p2.substring(0,fdecimal);
			}
		}
		else if(oComp.value.length > nLength)
		{
			oComp.value = oComp.value.substring(0,nLength);
			//oComp.focus();
			//noErrorFlg = false;
		}
		else if(minLength && oComp.value.length < minLength)
		{
			alert(g_please_enter_atleast + minLength + g_charac);
			oComp.focus();
			noErrorFlg = false;
		}
		else if(maxLength && oComp.value.length > maxLength)
		{
			alert(g_please_enter_less + maxLength + g_charac);
			oComp.focus();
			noErrorFlg = false;
		}
	}
	return noErrorFlg;
}

/****************************************************************************/	
function isRuleDisAllow(oComp, sRule, nLength, fdecimal, minLength,fieldName,maxLength)
{
    //alert(sRule)
	if(fdecimal == "" || typeof(fdecimal) == "undefined")
	{
		fdecimal = false;
	}

	//If the object is not specified return false
	if (typeof(oComp) == 'undefined' || oComp == null || oComp == '')
	{
		alert(g_js_error_obj_not_defined);
		return false;
	}
	//If neither rule nor max length is specified, return false
	else if (typeof(sRule) == 'undefined' && typeof(nLength) == 'undefined')
	{
		alert(g_js_error_max_input);
		return false;
	}

	var noErrorFlg = true;
	
	if(sRule != objAll)
	{
		//If object is specified and either of rule is specified,
		if(typeof(sRule) != 'undefined' && sRule != null)
		{
			var temp;
			sRule = sRule + "";
			var discardChars = false;
			if(sRule.length > 0 && sRule.charAt(0) == "~")
			{
				sRule = sRule.substring(1);
				discardChars = true;
			}
	
			if(typeof(oComp) == "undefined" || typeof(sRule) == "undefined")
				return false;
	
			for (var i = 0;i < oComp.value.length;i++)
			{
				temp = oComp.value.charAt(i);
	
				if((!discardChars && sRule.indexOf(temp) >= 0) || (discardChars && sRule.indexOf(temp) >= 0))
				{
					alert(g_js_invalid_charac);
					oComp.value = oComp.value.substring(0,i);// + (oComp.value.length > i ? oComp.value.substring(i+1):"");
					noErrorFlg = false;
					break;
				}
			}
		}
	}
	if(nLength)
	{
	
		if(fdecimal)
		{
			nLength -= fdecimal;
			var dp = oComp.value.indexOf(".");
			var p1;
			var p2 = "";;
			if(dp >= 0)
			{
				p1 = oComp.value.substring(0,dp);
				p2 = oComp.value.substring(dp+1);
			}
			else
			{
				p1 = oComp.value;
			}
			if(p1.length > nLength)
			{
				oComp.value = oComp.value.substring(0,nLength);
				return noErrorFlg;
			}
			for(var i = 0;i < p2.length;i++)
			{
				var ch = p2.charAt(i);
				if(ch < '0' || ch > '9')
				{
					oComp.value = p1 + "." + p2.substring(0,i);
					return noErrorFlg;
				}
			}
			if(p2.length > fdecimal)
			{
				oComp.value = p1 + "." + p2.substring(0,fdecimal);
			}
		}
		else if(oComp.value.length > nLength)
		{
			oComp.value = oComp.value.substring(0,nLength);
			//oComp.focus();
			//noErrorFlg = false;
		}
		else if(minLength && oComp.value.length < minLength)
		{
			alert(g_please_enter_atleast + minLength + g_charac);
			oComp.focus();
			noErrorFlg = false;
		}
		else if(maxLength && oComp.value.length > maxLength)
		{
			alert(g_please_enter_less + maxLength + g_charac);
			oComp.focus();
			noErrorFlg = false;
		}
	}
	return noErrorFlg;
}

/****************************************************************************/	
//Email Validation
function isEmail(newstr)
{
	var emailexp = /^[a-z][a-z_0-9\-\.]+@[a-z_0-9\-\.]+\.[a-z]{2,5}$/i
	//Check that the email entry is valid
	if (!emailexp.test(newstr) || newstr.indexOf("..") >= 0)
	{
		return false;
	}
	return true;
}
/****************************************************************************/	

/****************************************************************************/
function CheckAllCheckBoxes(obj_form) 
{	    	    	    

	for(var i = 0; i < obj_form.length; i++) 
    {
         elm = obj_form.elements[i]
		 if (elm.type == 'checkbox') 
         {   
			if(elm.checked == false)          
			elm.checked = true	;				
				
       }
   }
}
/****************************************************************************/	

/****************************************************************************/
function UnCheckAllCheckBoxes(obj_form) 
{	    	    	    

	for(var i = 0; i < obj_form.length; i++) 
    {
         elm = obj_form.elements[i]
		 if (elm.type == 'checkbox') 
         {   
			if(elm.checked == true)          
			elm.checked = 	false;				
				
       }
   }
}
/****************************************************************************/
function CheckAtleastOneSelected(obj_form)
{
	var confirm_msg;
	var selectCount = 0;
	for(i = 0; i < obj_form.length; i++) 
    {
         elm = obj_form.elements[i]
		 if (elm.type == 'checkbox') 
         {   
		 	if(elm.checked == true) 
			{       
				selectCount++;
			}
		 }
	}
	
	if(selectCount <= 0)
	{
		alert(select_atleast_one);
		return false;
	}
	return true;
}

function removeSelected(frmObj){
	var ret;
	ret = CheckAtleastOneSelected(frmObj);
	if(ret)
	{
		if (confirm_delete(g_delete_confirm_msg))
		{	
			frmObj.mode.value = "deleteselected";
			frmObj.submit();
		}	
	}
}

//function to delete record
function confirm_delete(delete_msg)
{
	var msg;
	
	if (confirm(delete_msg)){
		return true;
	}else{
		return false;
	}
}

//function to update status of record
function confirm_status(status_msg)
{
	var msg = status_msg;
	if(confirm(msg)){
		return true;
	}else{
		return false;
	}
}
// function to set the focus
function setInitialFocus(form_object)
{
	if(form_object )
	{
		form_object.focus();
	}
}

/**
 * This function is used to remove all options from the select tag
 * @param {Object} selectbox
 */		
function removeAllOptions(selectbox)
{
	var i;

	for(i=selectbox.options.length - 1;i>=0;i--)
	{
		selectbox.remove(i);
	}
}
/**
 * This function is used to add the option to select tag
 * @param {Object} selectbox
 * @param {Object} text
 * @param {Object} value
 */	
function addOption(selectbox,text,value,selval)
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	if(selval == value && selval !=''){
	optn.selected = true;
	}
	selectbox.options.add(optn);
}	







var gval;



// function to use ajax
//function createRequestObject(){
//	var request_o; //declare the variable to hold the object.

//	var browser = navigator.appName; //find the browser name
//	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
//		request_o = new ActiveXObject("Microsoft.XMLHTTP");
		
//	}else{
		/* Create the object using other browser's method */
//		request_o = new XMLHttpRequest();
//	}
//	return request_o; //return the object
//}
//var httpXML = createRequestObject(); 
function getbranches(agentid,id){
	var url=  "agent_branch_ajax.php?agent_id="+agentid;
	new Ajax.Request(url, {
	  method: 'get',
  	  onSuccess: function(transport) {
  	var response =transport.responseXML.documentElement;
      var branch_ref = $('branch_ref');
	  TotalArt = response.getElementsByTagName('TotalBranch')[0].firstChild.data;
			removeAllOptions(branch_ref);
			addOption(branch_ref,"select","");	
		if ( TotalArt > 0 ){
			result_id = Array();
		   result_name = Array();
				for ( i = 0 ; i < TotalArt ; i++ ){
					result_name[i] = response.getElementsByTagName('branchref')[i].firstChild.data;
					result_id[i] = response.getElementsByTagName('branchrefcode')[i].firstChild.data;
					addOption(branch_ref,result_name[i],result_id[i],id);
				}
				
			}
  }
});

}
function getpropertysubtype(categoryid,id){
	var url=  "property_category_ajax.php?category_id="+categoryid;
new Ajax.Request(url, {
  method: 'get',
  onSuccess: function(transport) {
  		var response =transport.responseXML.documentElement;

    var property_sub_id = $('property_sub_id');


	TotalArt = response.getElementsByTagName('TotalSubType')[0].firstChild.data;
				removeAllOptions(property_sub_id);
				addOption(property_sub_id,"Select","");			
			if ( TotalArt > 0 ){
					result_id = Array();
				result_name = Array();
				for ( i = 0 ; i < TotalArt ; i++ ){
					result_name[i] = response.getElementsByTagName('subtype')[i].firstChild.data;
					result_id[i] = response.getElementsByTagName('subtypecode')[i].firstChild.data;
					addOption(property_sub_id,result_name[i],result_id[i],id);
				}
			}
  }
});

}

function getproperty_price_range(range,id,type){
	var url=  "price_range_ajax.php?range="+range+"&type="+type;
new Ajax.Request(url, {
  method: 'get',
  onSuccess: function(transport) {
  		var response =transport.responseXML.documentElement;

    var save_price_range = $('save_price_range');
	var p_range =  range.split('-');
	
	$('save_price_from').value = p_range[1];
	$('save_price_to').value = p_range[0];


	TotalArt = response.getElementsByTagName('TotalPriceRange')[0].firstChild.data;
				removeAllOptions(save_price_range);
				addOption(save_price_range,"Any","-1");			
			if ( TotalArt > 0 ){
					result_id = Array();
				result_name = Array();
				for ( i = 0 ; i < TotalArt ; i++ ){
					result_name[i] = response.getElementsByTagName('price_range_display')[i].firstChild.data;
					result_id[i] = response.getElementsByTagName('price_range_value')[i].firstChild.data;
					addOption(save_price_range,result_name[i],result_id[i],id);
				}
			}
  }
});

}
function pricerange(property_type,start,end){
	var url = "property_pricerange.php?type="+property_type;
	url=url +	"&start="+start+"&end="+end;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport){
			var prresponse = transport.responseText;
		     $('price_div').update(prresponse);
		}
	});
}


function price(property_type){
	
	var url = "property_price.php?type="+property_type;
//	url=url +	"?"+search_string+"&search_type="+property_type;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport){
			var presponse = transport.responseText;
		     $('price_div').update(presponse);
	bedrooms();

			 
		}
	});
}

function bedrooms(){
	var url = "property_bedrooms.php";
	//	url=url +	"?"+search_string+"&search_type="+property_type;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport){

			var bresponse = transport.responseText;
		     $('bedrooms_div').update(bresponse);
	addedtosite();			 
		}
	});
}

function addedtosite(){
	var url = "property_addedtosite.php";
		//url=url +	"?"+search_string+"&search_type="+property_type;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport){

			var aresponse = transport.responseText;
		     $('addedtosite_div').update(aresponse);
			 newresale();
		}
	});
}

function newresale(){
	var url = "property_newresale.php";
		//url=url +	"?"+search_string+"&search_type="+property_type;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport){

			var aresponse = transport.responseText;
		     $('newresale_div').update(aresponse);
			 propertytype();
		}
	});
}

function propertytype(){
	var url = "property_propertytype.php";
		//url=url +	"?"+search_string+"&search_type="+property_type;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport){

			var aresponse = transport.responseText;
		     $('propertytype_div').update(aresponse);
		}
	});
}


function property_search(property_type,extrastring,pfrom ,pto){

	if(property_type == 2)
	{
		var url = "property_search_for_rent.php";	
	}
	else
	{
		var url = "property_search_for_sale.php";
	}
	//url=url +	"?location="+search_string+"&search_property=1&search_radius="+search_radius+"&page="+page+"&rec_per_page="+rec_per_page;	
url=url +"?"+extrastring;	

	new Ajax.Request(url, {
		method: 'get',
		onCreate:function(){$('indicator1').style.display='';},
		onSuccess: function(transport){
			 var P_S_R = $('property_search_result');
			var response = transport.responseText;
		     P_S_R.update(response);
			 $('indicator1').style.display='none';
			  if(pfrom !='' && pto !=''){
				pricerange(property_type,pfrom,pto);
				bedrooms();
			  }
			  else{
		 	price(property_type);			  	
			  }

		}
	});

}

function property_search1(property_type,search_string,extrastring){

	if(property_type == 2)
	{
		var url = "property_search_for_rent.php";	
	}
	else
	{
		var url = "property_search_for_sale.php";
	}
//	url=url +	"?location="+search_string+"&search_property=1&search_radius="+search_radius+"&page="+page+"&rec_per_page="+rec_per_page;	
//	url=url +	"?"+search_string+extrastring;	
	new Ajax.Request(url, {
		method: 'get',
		onCreate:function(){$('indicator1').style.display='';},
		onSuccess: function(transport){
			 var P_S_R = $('property_search_result');
			var response = transport.responseText;
		     P_S_R.update(response);
			 $('indicator1').style.display='none';
		 	price(search_string,property_type);
		}
	});

}




 function handleRequest(){
	if (httpXML.readyState == 4) {
				var response = httpXML.responseXML.documentElement;
		if (gval == "branches") {
			TotalArt = response.getElementsByTagName('TotalBranch')[0].firstChild.data;

			if ( TotalArt > 0 ){
				removeAllOptions($('branch_ref'));
				addOption($('branch_ref'),"select","");			
					result_id = Array();
				result_name = Array();
				for ( i = 0 ; i < TotalArt ; i++ ){
					result_name[i] = response.getElementsByTagName('branchref')[i].firstChild.data;
					result_id[i] = response.getElementsByTagName('branchrefcode')[i].firstChild.data;
					addOption($('branch_ref'),result_name[i],result_id[i]);
				}
			}
		}
	}
}


//function to delete record
function confirm_remove(delete_msg,save_id)
{
	if (confirm(delete_msg)){
		window.location = "?action=remove&search_id="+save_id;
	}else{
		return false;
	}
}

function toggleme(togglename,imagepath){


	if($(togglename+'_image').className=='img-'){
		$(togglename+'_div').hide();		

		$(togglename+'_image').className="img+"
		$(togglename+'_image').src=imagepath+'icon+.gif'
	}else{
		$(togglename+'_div').show();		

		$(togglename+'_image').className="img-"
		$(togglename+'_image').src=imagepath+'icon-.gif'
		
	}
	
}

function validaterefindsearch(){

if($('search_property_r').value==''){

	$('search_property_r').focus();
		alert('Please enter your location.');
	return false;
}
	
}

function redirect_url(url){
	window.location = url;
}

function changeClass(obj,newclass)
{	
	obj.className = newclass;
}
-->