var xmlHttp
function showHint(r_url,id_name, vars) {
	window.focus();
	//document.body.style.cursor = "wait";
	if(!document.getElementById('waiting')) {
		document.getElementById(id_name).innerHTML += "<div id=\"waiting\">Loading...</div>";
		ProgressBarControl('waiting').flt();
	
		if (r_url.length==0) {
			document.getElementById(id_name).innerHTML=""
			return
		}
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) {
			alert ("Browser does not support HTTP Request")
			return
		}
		var url=r_url
		//url=url+"&sid="+Math.random()
		xmlHttp.onreadystatechange=function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				document.getElementById(id_name).innerHTML=xmlHttp.responseText
			}	
		}
		xmlHttp.open("POST",url,true)
		xmlHttp.setRequestHeader( 'Content-type','application/x-www-form-urlencoded' );
		xmlHttp.setRequestHeader( 'Content-length', url.length );
		xmlHttp.setRequestHeader( 'Connection', 'close' );
		xmlHttp.send(vars)
	}
}

function ProgressBarControl(id)
{

    var sy=0;
    var heit = (screen.height/2)-84;
    var sx = (screen.width/2)-170 ;
    var a = document.body.id;
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var d = document;
    var px = document.layers ? "" : "px";  
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;
	pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
	el.cy = sy+heit+pY;
	el.sy = sy+heit;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.flt()", 40);
		//alert( this.cy);
	}
	return el;
}
	
function stateChanged(id_name) {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		//alert(id_name);
		document.getElementById(id_name).innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject() {
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

function send_variables(vars_to_send,senddiv,php) {
	if(!senddiv) senddiv = "phones_list";
	if(!php) php = "show_phones.php";
	php = domain+"/wireless/launch/"+php;
	vars_to_send += '&type='+document.getElementById('type').options[document.getElementById('type').selectedIndex].value+'&fbrand='+document.getElementById('fbrand').options[document.getElementById('fbrand').selectedIndex].value+'&price='+document.getElementById('price').options[document.getElementById('price').selectedIndex].value;
	if(document.getElementById('f_search_on').value == '1') vars_to_send += '&f_search='+document.getElementById('f_search').value;
	if(document.getElementById('fcarrier')) {
		vars_to_send += '&fcarrier='+document.getElementById('fcarrier').options[document.getElementById('fcarrier').selectedIndex].value;
	}
	checks_arr = new Array("camera","wifi","email","music","bluetooth","threeg","internet","myfaves","hotspot","fmradio","slot","speaker","video","voicedial","gps","qwerty","sqwerty");
	for(i=0;i<checks_arr.length;i++) {
		if(document.getElementById(checks_arr[i]).checked == true) {
			vars_to_send += '&'+checks_arr[i]+'=1';
		}
	}
	//alert(php+"|"+senddiv+"|"+vars_to_send);
	if(senddiv == "index") {
		location.href=domain+'/'+oc+'/?'+vars_to_send;
	} else {
		showHint(php,senddiv,vars_to_send);
	}
}

function foo()
{
  var vars_to_send,senddiv,php; 
  function timoutFunc()
  {
    send_variables(vars_to_send,senddiv,php);
  }
  this.setVal = function(set_vars_to_send,set_senddiv,set_php)
  {
    vars_to_send = set_vars_to_send;
	senddiv = set_senddiv;
	php = set_php;
  }
  this.causeTimeout = function(timeout)
  {
    t=document.getElementById('to_id').value; if(t) clearTimeout(t);
	t=setTimeout(timoutFunc, timeout);
	document.getElementById('to_id').value = t;
  }
}


function escapeHTML(someText) {
	  var div = document.createElement('div');
	  var text = document.createTextNode(someText);
	  div.appendChild(text);
	  return div.innerHTML;
	}