// JavaScript Document

var disp_area="";

var http = getHTTPObject(); // We create the HTTP Object



function getHTTPObject()

{

	var xmlHttp;

	try

	{

		// Firefox, Opera 8.0+, Safari

		xmlHttp=new XMLHttpRequest();

		return xmlHttp;

	}

	catch (e)

	{

	// Internet Explorer

		try

		{

			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

			return xmlHttp;

		}

		catch (e)

		{

			try

			{

				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

				return xmlHttp;

			}

			catch (e)

			{

				alert("Your browser does not support AJAX!");

				return false;

			}

		}

	}

}

        

function handleHttpResponse() {   

	if (http.readyState == 4) {

		  if(http.status==200) {

			  	var results=http.responseText;

				document.getElementById(disp_area).innerHTML = results;

		  }

	}

}



//function getSearchResult(disparea, toCntry, sortBy) {

function getSearchResult(pCountry, pSortBy) {

	

	disp_area = "search_result";

	var toCntry="";

	var sortBy="";

	

	//Create links for pages

	//alert("test link");

	

	

	if(pCountry==0 && pSortBy=="default"){



		toCntry = document.getElementById("selCountry").value;

		sortBy ="rcv_call_frm_UK";

		//sortBy = document.getElementById("selSortBy").value;

		

		

	}else{

	

		toCntry = pCountry;

		

		if(pSortBy==1)	sortBy = "call_to_UK";

		else if(pSortBy==2)	sortBy = "rcv_call_frm_UK";

		else if(pSortBy==3)	sortBy = "call_within_country";

		else if(pSortBy==4)	sortBy = "txt_msg";

	}

	

	writeCookie("coc_country", toCntry, 1);

	writeCookie("coc_sortBy", sortBy, 1);

	

	/*document.getElementById('spn_sortby').innerHTML=sortBy;

	document.getElementById('spn_country').innerHTML=toCntry;*/

	

	if(toCntry){

			var linkCountry=toCntry;

			var linkCountryD=toCntry;



			linkCountry=toCntry.replace(/ /,"-");
			
			linkCountry=linkCountry.replace(/ /,"-");
			linkCountry=linkCountry.replace(/ /,"-");
			linkCountry=linkCountry.replace(/ /,"-");

			linkCountry=linkCountry.toLowerCase();

document.getElementById("dRelatedLinks1").innerHTML = "<a href='http://www.roamingsims.com/country/"+linkCountry+".php'>Available Roaming Sims for "+linkCountryD+"</a>";

		}

	

	document.getElementById(disp_area).innerHTML = "<center><img src=\"images/search_result.gif\"/><br />Searching for the best roaming prices<br>	Independent Roaming Rates Comparision<br>	&copy; RoamingSims.com	</center>";

	var url = "incs/getdata.php?toCntry="+escape(toCntry)+"&sortBy="+escape(sortBy); // The server-side script



	http.open("GET", url , true);

	http.onreadystatechange = handleHttpResponse;

	http.send(null);

}



//Cookie functions

// Example:



// writeCookie("myCookie", "my name", 24);



// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.



function writeCookie(name, value, hours)



{



  var expire = "";



  if(hours != null)



  {



    expire = new Date((new Date()).getTime() + hours * 3600000);



    expire = "; expires=" + expire.toGMTString();



  }



  document.cookie = name + "=" + escape(value) + expire;



}



// Example:



// alert( readCookie("myCookie") );



function readCookie(name)



{



  var cookieValue = "";



  var search = name + "=";



  if(document.cookie.length > 0)



  { 



    offset = document.cookie.indexOf(search);



    if (offset != -1)



    { 



      offset += search.length;



      end = document.cookie.indexOf(";", offset);



      if (end == -1) end = document.cookie.length;



      cookieValue = unescape(document.cookie.substring(offset, end))



    }



  }



  return cookieValue;



}





