
// declare a global  XMLHTTP Request object
var XmlHttpObjFav, XmlHttpObjFavSidebar;
// base url for main 
var base_url_main;
var add_or_remove;

// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla
function CreateXmlHttpObjFav()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObjFav = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObjFav = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpObjFav = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox)
	if(!XmlHttpObjFav && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpObjFav = new XMLHttpRequest();
	}
	
	//for sidebar filter
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObjFavSidebar = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObjFavSidebar = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			XmlHttpObjFavSidebar = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox)
	if(!XmlHttpObjFavSidebar && typeof XMLHttpRequest != "undefined")
	{
		XmlHttpObjFavSidebar = new XMLHttpRequest();
	}
}



// called from onChange or onClick event of the continent dropdown list
function add_remove_fav(job_id, base_url)
{
	
	

	// for other functions
	base_url_main = base_url;
	var image_tag_name;
	var image_tag_name_compl;
	var image_src_compl;
	var image_src_compl_arr;
	var arr_length;
	var check ;
	image_tag_name = "imgFavLink_" + job_id;
	image_src_compl = document.getElementById(image_tag_name).src;
	image_src_compl_arr = image_src_compl.split("/");
	arr_length = image_src_compl_arr.length;
	if(image_src_compl_arr[arr_length-1] == "fav.gif")
	{
		check = "add";
		add_or_remove = "add";
	}
	else
	{
		check = "remove";
		add_or_remove = "remove";
	}
	
	fav_count = document.getElementById("hdnFavCount").value
	// url of page that will send xml data back to client browser
	var requestUrl;

	if(base_url == "")
		{
		requestUrl = "ajax_fav_results.php?job_id=" + job_id+ "&check=" +check+ "&fav_count=" +fav_count;
		}
	else
		{
		requestUrl =base_url + "recruiter/ajax_fav_results.php?job_id=" + job_id+ "&check=" +check+ "&fav_count=" +fav_count;
		}

	CreateXmlHttpObjFav();
	//XmlHttpObjFav =1;

	// verify XmlHttpObjFav variable was successfully initialized
	if(XmlHttpObjFav)
	{
		// assign the StateChangeHandlerFav function ( defined below in this file)
		// to be called when the state of the XmlHttpObjFav changes
		// receiving data back from the server is one such change
		XmlHttpObjFav.onreadystatechange = StateChangeHandlerFav;

		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObjFav.open("POST", requestUrl,  true);
		// send request to server, null arg  when using "GET"
		XmlHttpObjFav.send(null);
	}
	
	
	
	

	
}


// this function called when state of  XmlHttpObjFav changes
// we're interested in the state that indicates data has been
// received from the server
function StateChangeHandlerFav()
{
	
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObjFav.readyState == 4)
	{

		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObjFav.status == 200)
		{

			PopulateCountryListFav(XmlHttpObjFav.responseText);
			//if(add_or_remove == 'remove')
			//{
				//if(main!=1)
					//location.reload(true);
			//}
		}
		else
		{
		}
	}
	
}
// this function called when state of  XmlHttpObjFav changes
// we're interested in the state that indicates data has been
// received from the server


// populate the contents of the country dropdown list
function PopulateCountryListFav(countryNode)
{
var job_id;
var result;
var fav_count;
var arr;
arr = countryNode.split(",");

job_id = arr[0];
result = arr[1];
fav_count = arr[2];

image_tag_name = "imgFavLink_" + job_id;

	if(result == 1)
	{
		if(base_url_main == "")
		{
			document.getElementById(image_tag_name).src = "images/fav-h.gif";
		}
		else
		{
			
			document.getElementById(image_tag_name).src = base_url_main + "images/fav-h.gif";
		}
		
	}
	else if(result == 2)
	{
		if(base_url_main == "")
		{
			document.getElementById(image_tag_name).src = "images/fav.gif";
		}
		else
		{
		
			document.getElementById(image_tag_name).src = base_url_main + "images/fav.gif";
		}
		
	}
	document.getElementById("spnFavCount").innerHTML = fav_count;
	document.getElementById("hdnFavCount").value = fav_count;
}



	

