/*------------AJAX POPUP JAVASCRIPT ------ By: Pranav Thakar----*/
var http = null;
http = getHTTPObject(); // We create the HTTP Object	
function getHTTPObject() 
{
  var xmlhttp=null;
    try 
	{
      xmlhttp = new XMLHttpRequest();
    } catch (e) 
	{
 		try
		{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
    }
  return xmlhttp;
}
function show_overlay(show,content,win_width)
{	
	win_left=0;
	win_left=(screen.width/2)-(win_width/2);	
	/*win_width=560;*/
	if(show)
	{
		//document.getElementById("sbox-overlay").style.display='block';
		
		//document.getElementById("sbox-overlay").style.visibility='visible';
		
		document.getElementById("sbox-window").style.visibility='visible';

		document.getElementById("sbox-content").style.visibility='visible';
		
		document.getElementById("sbox-btn-close").style.visibility='visible';

		document.getElementById("sbox-content").innerHTML=content;
		document.getElementById("sbox-content").style.backgroundColor="#FFFFCC";
		document.getElementById("sbox-window").style.marginTop="150px";

		if(win_width === undefined)
		{}
		else
		{
			document.getElementById("sbox-window").style.width =win_width+'px';
			document.getElementById("sbox-content").style.width =win_width+'px';
		}

		if (win_left === undefined)

		{}

		else

		{
			document.getElementById("sbox-window").style.left =win_left+'px';
		}
	}
	else
	{
		document.getElementById("sbox-content").innerHTML=content;
		document.getElementById("sbox-content").style.backgroundColor="#FFFFCC";

		//document.getElementById("sbox-overlay").style.visibility='hidden';

		document.getElementById("sbox-window").style.visibility='hidden';

		document.getElementById("sbox-content").style.visibility='hidden';
		
		document.getElementById("sbox-btn-close").style.visibility='hidden';
		
		//document.getElementById("sbox-overlay").style.display='none';
	}
}
function handleHttpResponse()
{ 	
	if (http.readyState == 4) 
	{  
	  	var results=http.responseText.split("*^");
		if(results)
		{ 
			show_overlay(1,results[2],results[1]);
		}		
	}
}

function showComp(compid) 
{
	var theUL = document.getElementById("sbox-content"); 
	var url="./moreInfo.php?compid="+compid;
	theUL.innerHTML = '<div>&nbsp;</div><div style=" height:80px" align="center"><img src="./images/loadingg.gif"></div><div>&nbsp;</div>';
	show_overlay(1,theUL.innerHTML,460);
	http.open("GET",url, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

function conv_currency2(url, parameters) 
{
	http.onreadystatechange = conv_currencypost;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	http.send(parameters);
}

function conv_currencypost() {
  if (http.readyState == 4) {
	 if (http.status == 200) {
		result = http.responseText;
		document.getElementById("div_currency").innerHTML = result;
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}

function conv_currency(obj) {
  var poststr = "fig=" + encodeURI( document.getElementById("amount").value )+
  				"&to=" + encodeURI( document.getElementById("to").value)+
				"&frm="+ encodeURI( document.getElementById("frm").value);
  document.getElementById("div_currency").innerHTML='<div style=" height:30px" align="center"><img src="./images/loadingg.gif"></div>';
  conv_currency2('currency.php', poststr);
}

function sendmob_msg(url, parameters) 
{
	http.onreadystatechange = send_smspost;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	http.send(parameters);
}

function send_smspost() {
  if (http.readyState == 4) {
	 if (http.status == 200) {
		result = http.responseText;
		document.getElementById("div_sendmsg").innerHTML = result;
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}

function sendsms(obj) {
  var poststr = "txtmobno=" + encodeURI( document.getElementById("txtmobno").value )+
  				"&compid=" + encodeURI( document.getElementById("compid").value )+
  				"&txtarrmessage=" + encodeURI( document.getElementById("txtarrmessage").value);				
  document.getElementById("div_sendmsg").innerHTML='<div style=" height:30px" align="center"><img src="./images/loadingg.gif"></div>';
  sendmob_msg('ajax_postsms.php', poststr);
}