// JavaScript Document
function ShowInput(id)
{
	inputid = id.replace('text','')  + 'input';
	document.getElementById(id).style.display = 'none';
	document.getElementById(inputid).style.display = '';
	document.getElementById(inputid).select();
}
function HideInput(id)
{
	textid = id.replace('input','')  + 'text';
	document.getElementById(id + 'input').style.display = 'none';
	document.getElementById(textid).style.display = '';
}
function HideText(id)
{
	textid = id.replace('input','')  + 'text';
	document.getElementById(id).style.display = 'none';
	document.getElementById(textid).style.display = '';
}
function ProcessKeyPressed(e, textvalue, fieldname, tablename, refid, titletag, fieldtitle, type, id_field)
{
	var keynum;
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	//alert(keynum);
	if (keynum == 13)
		{
			AjaxUpdate2(textvalue, fieldname, tablename, refid, titletag, fieldtitle, type, id_field);
			return true;
		}
	else
		return false;
}
function AjaxUpdate2(textvalue, fieldname, tablename, refid, titletag, fieldtitle, type, id_field)
{
	//alert(Showtitle);
//	newid = id.replace('input', '').replace('text', '');  
	//document.getElementById(newid + 'wait').innerHTML = '<img src=\'images/wait.gif\' alt=\'Please wait...\'>';
	if (textvalue=="")
	{
		return;
	}
	
	showvalue=textvalue;
	
	if (type=='option')
	{
			res = textvalue.split('=');
			//alert(res[0]);
			if (res[0]==0)
				{showvalue=" "; textvalue=res[0];}
			else	
				{showvalue=res[1]; textvalue=res[0];}
			
	}
	//alert(textvalue);	
	document.getElementById(titletag).innerHTML=fieldtitle+" "+showvalue;
	
	//alert(textvalue);
	var xmlHttp;
	try
	{    
		// Firefox, Opera 8.0+, Safari    
		xmlHttp=new XMLHttpRequest();    
	}
	catch (e)
	{    
		// Internet Explorer    
		try
		{      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e)
		{      
			try
			{        
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e)
			{        
				alert("Your browser does not support AJAX!");
				return false;
			}      
		}    
	}  
//using POST method
	var pageurl = "index.php?option=com_realtyna&view=ajax&format=raw";
	var params;
	//textvalue, fieldname, tablename, refid
	params = "textvalue=" + textvalue + "&fieldname=" + fieldname + "&tablename=" + tablename + "&refid=" + refid + "&id_field=" + id_field + "&function=updatebuilding";
	//xmlHttp.open("GET", pageurl + '?' + params ,true);
	xmlHttp.open("POST", pageurl ,true);
//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
	xmlHttp.onreadystatechange = function() 
	{ 
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) 
		{
			if(xmlHttp.responseText!="")
			{ 
				UpdateResult = xmlHttp.responseText;
		
			}
		}
	}
}
function AjaxCombo(textvalue,type,cat,div)
{
	var waitdiv="";
	showvalue=textvalue;
	if (type=='option')
	{
			res = textvalue.split('=');
			//alert(res[0]);
			if (res[0]==0)
				{textvalue=res[0];}
			else
				{textvalue=res[0];}
	}
	call_function="";
	if (cat=="state")
	{
		waitdiv="statewait";
		call_function = "getStatesRealtedCountry_search";
	}
	else if (cat=="city")
	{
		waitdiv="citywait";
		call_function = "getCitiesRealtedState_search";
	}
	else if (cat=="zone")
	{
		waitdiv="zonewait";
		call_function = "getZonesRealtedCity_search";
		//call_function = "createZoneList_search";
	}
	else if( cat=="allcity")
	{
		waitdiv="citywait";
		call_function="getAllCitiesRealtedState_search"
	}
	if(document.getElementById(waitdiv)!=null)
		document.getElementById(waitdiv).innerHTML='<img src="'+getJURI()+'components/com_realtyna/images/wait.gif" />';
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
//using POST method
	var pageurl = "index.php?option=com_realtyna&view=ajax&format=raw";
	var params;
	params = "cid=" + textvalue + "&function="+call_function;
	//xmlHttp.open("GET", pageurl + '?' + params ,true);
	xmlHttp.open("POST", pageurl ,true);
//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			if(xmlHttp.responseText!="")
			{
				Result = xmlHttp.responseText;
				if(document.getElementById(waitdiv)!=null)
					document.getElementById(waitdiv).innerHTML="";
				document.getElementById(div).innerHTML = Result;
			}
		}
	}
}
function findElement(element_id) {
  if (document.getElementById && document.getElementById(element_id)) {
    return document.getElementById(element_id);
  } else {
    return false;
  }
}
function hideElement(element_id) {
  element = findElement(element_id)
  if (element) {
    element.style.display = 'none';
    return element;
  } else {
    return false;
  }
}
function showElement(element_id) {
  element = findElement(element_id)
  if (element) {
    element.style.display = '';
    return element;
  } else {
    return false;
  }
}
function check()
{
 
	if (document.getElementById("Bedrooms").value!="" && isInteger(document.getElementById("Bedrooms").value)==false)
	{
		alert("Please enter a valid Bedrooms NO.");
		document.getElementById("Bedrooms").focus();
		return false;
	}
	if (document.getElementById("Floors").value!="" && isInteger(document.getElementById("Floors").value)==false)
	{
		alert("Please enter a valid Floors NO.");
		document.getElementById("Floors").focus();
		return false;
	}
	if (document.getElementById("Bathrooms").value!="" && isInteger(document.getElementById("Bathrooms").value)==false)
	{
		alert("Please enter a valid Bathrooms NO.");
		document.getElementById("Bathrooms").focus();
		return false;
	}
	if (document.getElementById("Units").value!="" && isInteger(document.getElementById("Units").value)==false)
	{
		alert("Please enter a valid Units NO.");
		document.getElementById("Units").focus();
		return false;
	}
	if (document.getElementById("LivingArea").value!="" && isInteger(document.getElementById("LivingArea").value)==false)
	{
		alert("Please enter a valid LivingArea NO.");
		document.getElementById("LivingArea").focus();
		return false;
	}
	if (document.getElementById("UnitNo").value!="" && isInteger(document.getElementById("UnitNo").value)==false)
	{
		alert("Please enter a valid UnitNo NO.");
		document.getElementById("UnitNo").focus();
		return false;
	}
	if (document.getElementById("PostalCode").value!="" && isInteger(document.getElementById("PostalCode").value)==false)
	{
		alert("Please enter a valid PostalCode NO.");
		document.getElementById("PostalCode").focus();
		return false;
	}
	if (document.getElementById("Mortgage").value!="" && isInteger(document.getElementById("Mortgage").value)==false)
	{
		alert("Please enter a valid Mortgage.");
		document.getElementById("Mortgage").focus();
		return false;
	}
	if (document.getElementById("Price").value!="" && isInteger(document.getElementById("Price").value)==false)
	{
		alert("Please enter a valid Price.");
		document.getElementById("Price").focus();
		return false;
	}
	
	return true;
	
	
	
}function checkobject(obj)
{
 switch (obj)
 {
	case "Bedrooms":
	if (document.getElementById("Bedrooms").value!="" && isInteger(document.getElementById("Bedrooms").value)==false)
	{
		alert("Please enter a valid Bedrooms NO.");
		//document.getElementById("Bedrooms").focus();
		return false;
	}
	break;
	case "Floors":
	if (document.getElementById("Floors").value!="" && isInteger(document.getElementById("Floors").value)==false)
	{
		alert("Please enter a valid Floors NO.");
		//document.getElementById("Floors").focus();
		return false;
	}
	break;
	case "Bathrooms":
	if (document.getElementById("Bathrooms").value!="" && isInteger(document.getElementById("Bathrooms").value)==false)
	{
		alert("Please enter a valid Bathrooms NO.");
		//document.getElementById("Bathrooms").focus();
		return false;
	}
	break;
	case "Units":
	if (document.getElementById("Units").value!="" && isInteger(document.getElementById("Units").value)==false)
	{
		alert("Please enter a valid Units NO.");
		//document.getElementById("Units").focus();
		return false;
	}
	break;
	case "LivingArea":
	if (document.getElementById("LivingArea").value!="" && isInteger(document.getElementById("LivingArea").value)==false)
	{
		alert("Please enter a valid LivingArea NO.");
		//document.getElementById("LivingArea").focus();
		return false;
	}
	break;
	case "UnitNo":
	if (document.getElementById("UnitNo").value!="" && isInteger(document.getElementById("UnitNo").value)==false)
	{
		alert("Please enter a valid UnitNo NO.");
		//document.getElementById("UnitNo").focus();
		return false;
	}
	break;
	case "PostalCode":
	if (document.getElementById("PostalCode").value!="" && isInteger(document.getElementById("PostalCode").value)==false)
	{
		alert("Please enter a valid PostalCode NO.");
		//document.getElementById("PostalCode").focus();
		return false;
	}
	break;
	case "Mortgage":
	if (document.getElementById("Mortgage").value!="" && isInteger(document.getElementById("Mortgage").value)==false)
	{
		alert("Please enter a valid Mortgage.");
		//document.getElementById("Mortgage").focus();
		return false;
	}
	break;
	case "Price":
	if (document.getElementById("Price").value!="" && isInteger(document.getElementById("Price").value)==false)
	{
		alert("Please enter a valid Price.");
		//document.getElementById("Price").focus();
		return false;
	}
	break;
	
	return true;
	
 }
	
}
function AjaxChangeUsage(st)
{
	document.getElementById('waitspan').innerHTML = getWaitImage();
	try
	{    
		// Firefox, Opera 8.0+, Safari    
		xmlHttp=new XMLHttpRequest();    
	}
	catch (e)
	{    
		// Internet Explorer    
		try
		{      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e)
		{      
			try
			{        
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e)
			{        
				alert("Your browser does not support AJAX!");
				return false;
			}      
		}    
	}
	if(document.getElementById("usage_2").checked)
		comer=1;
	else
		comer=0;
	if(document.getElementById("usage_1").checked)
		resid=1;
	else
		resid=0;
	xmlHttp.open("POST", "index.php", true);
	var params = "option=com_realtyna&view=ajax&format=raw&function=change_property_usage&resid="+resid+"&comer="+comer+"&searchtype="+st;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);	
		xmlHttp.onreadystatechange = function() 
		{ 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) 
			{ 
				if(xmlHttp.responseText!="")
				{ 
					Result = xmlHttp.responseText;
					document.getElementById('categorydiv').innerHTML=Result;
					document.getElementById('waitspan').innerHTML = '';
				}
			}
		}
}
