// 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="";
	if(pCountry==0 && pSortBy=="default"){

		toCntry = document.getElementById("selCountry").value;
		sortBy =1;
		//sortBy = document.getElementById("selSortBy").value;
	}else{
	
		toCntry = pCountry;
		
		if(pSortBy==1)	sortBy = 1;
		else if(pSortBy==2)	sortBy = 2;
		
	}
	
	writeCookie("coc_country", toCntry, 1);
	writeCookie("coc_sortBy", sortBy, 1);
	
	/*document.getElementById('spn_sortby').innerHTML=sortBy;
	document.getElementById('spn_country').innerHTML=toCntry;*/
	
	document.getElementById(disp_area).innerHTML = "<center><img src=\"http://www.roamingsims.com/images/search_result.gif\" alt=\"Searchin Image Alt\"/><br />Searching for the best roaming prices<br>	Independent Roaming Rates Comparision<br>	&copy; RoamingSims.com</center>";
	var url = "incs/getdata2.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;

}


