// JavaScript Document
function save2Favorites(saveType,subDomain)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
 url="http://"+subDomain+"/idx/ajax/saveFavorites.php?st="+saveType
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}



function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
function stateChanged() {
if (xmlHttp.readyState==4)
	{ 
		response=xmlHttp.responseText
		var rRecords = new Array();
		arrayCount=0
		while (response.indexOf("~") > 0) {
			rRecords[arrayCount]=response.substring(0,response.indexOf("~"))
			response=response.substring(response.indexOf("~")+1)
			arrayCount=arrayCount+1
		}
		userOK=rRecords[0]
		saveType=rRecords[1]
		if (userOK=="saved"){
			alert("This "+saveType+" has been saved to your favorites")
		}
		if (userOK=="nouser"){
			var answer = confirm ("You must be logged into your Favorites Account to save a "+saveType+".\nDo you wish to log in or create an account?")
			if (answer) {
				gotoURL="http://"+fSubDomain+"/idx/favorites_signin.php?cid="+fcid+"&aid="+faid+"&trackID="+saveTrackID
				window.open(gotoURL,"_top")
			}	
		}
	}
}
