﻿var strWait = "<table border=0 cellspacing=0 cellpadding=3 width=100% height=100px><tr><td width=60% align=right><img src='"+strHttpServerPath+"/img/checking.gif'/></td><td width=40% valign=middle align=left> Please wait...</td></tr></table>";
//divGraph
var strOldDivData = ""
	function fnAddToFavorite()
	{
		if(0 >= fnAddToFavorite.arguments.length)
			return;
		intMLSNum = fnAddToFavorite.arguments[0];
		objDiv = document.getElementById("divFavorite"+fnAddToFavorite.arguments[0]);
		strOldDivData = objDiv.innerHTML;
		objDiv.innerHTML = strWait;
		strFileName = "addtofavorite.php"
		//alert('<?php echo HTTP_SERVER._WEBMASTER;?>/' + strFileName + '?intResId='+ intResId);
		fnFavoriteResProcess = function(){
				if(0 >= fnFavoriteResProcess.arguments.length)
					return;
				page_request = fnFavoriteResProcess.arguments[0];
				objDiv = fnFavoriteResProcess.arguments[1];
				if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
				{
					//alert(page_request.responseText);
					strResponceText = trimWhitespace(page_request.responseText);
					if(0 <= strResponceText.indexOf("ERROR") && 2 >= strResponceText.indexOf("ERROR"))
					{
						alert("ERROR");
					}
					else if("SessionExpired" == strResponceText)
					{
						//alert("Login require!!");
						if(confirm("You are require to login or register to add any property in your favorite list. \n Do you want to login / register now?"))
						{
							window.location = strHttpServerPath+'/userlogin.html';
							objDiv.innerHTML = strOldDivData;
							return ;
						}
						else
						{
							objDiv.innerHTML = strOldDivData;
							return false;
						}
					}
					else
					{
						strDisplay = strResponceText;
					}
					objDiv.innerHTML = strDisplay;
				}
			}//function end
		sendAjaxRequest(strHttpServerPath+'/' + strFileName + '?mlsnum='+ intMLSNum, fnFavoriteResProcess, objDiv);
	}
	//function sendAjaxRequest(url,fnFunctionName,objDiv)
	function sendAjaxRequest()
	{
		if(0 >= sendAjaxRequest.arguments.length)
			return;
		url = sendAjaxRequest.arguments[0];
		fnFunctionName = sendAjaxRequest.arguments[1];
		var page_request = false;
	
		if (window.XMLHttpRequest) // if Mozilla, Safari etc
		{
			page_request = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{ // if IE
			try 
			{
				page_request = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e)
			{
				try
				{
					page_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){}
			}
		}
		else
		{
			return false;
		}
		//strLastContent = document.getElementById(containerid).innerHTML;
		//document.getElementById(containerid).innerHTML = document.getElementById("divWait").innerHTML;
		strFun = "fnFunctionName(page_request,";
		//alert(sendAjaxRequest.arguments.length);
		for(j=2; j < (sendAjaxRequest.arguments.length-1); j++)
		{
			strVar = "myAeg"+j+"=sendAjaxRequest.arguments["+j+"];";
			eval(strVar);
			strFun += "myAeg"+j+", ";
			//alert ("loop: "+j+ " -> "+strFun);
		}
		//strFun += "sendAjaxRequest.arguments["+j+"])";
		strVar = "myAeg"+j+"=sendAjaxRequest.arguments["+j+"];";
		eval(strVar);
		strFun += "myAeg"+j+") ";
		//page_request.onreadystatechange=fnFunctionName;
		page_request.onreadystatechange=function()
		{
			//fnFunctionName(page_request,sendAjaxRequest.arguments[2]);
			//alert(strFun);
			eval(strFun);
		}
	
		page_request.open('GET', url, true);
		page_request.send(null);
		//document.getElementById(containerid).innerHTML = "<img src=\"<?php echo HTTP_SERVER._IMAGES?>/pleasewait.gif\" border=\"0\">";
	}