var xmlHttp;

var xmlHttp2;

var url2;

var id;



function showDataInput()

{

	//alert('Converting...')

id = "curAmt";

document.getElementById(id).innerHTML="Loading...";

str = document.getElementById('cmb_curFrom').value;

strto = document.getElementById('cmb_curTo').value;

val = document.getElementById('txt_curFrom').value;

var url="convert.php?from=" + str + "&to=" + strto + "&val=" + val;

xmlHttp=GetXmlHttpObject(stateChanged);

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

xmlHttp.send(null);

}



function stateChanged() 

{ 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{ 

document.getElementById(id).innerHTML=xmlHttp.responseText ;

} 

} 



function GetXmlHttpObject(handler)

{ 

objXmlHttp=null;



if (navigator.userAgent.indexOf("Opera")>=0)

{

alert("This example doesn't work in Opera") ;

return ;

}

if (navigator.userAgent.indexOf("MSIE")>=0)

{ 

var strName="Msxml2.XMLHTTP";

if (navigator.appVersion.indexOf("MSIE 5.5")>=0)

{

strName="Microsoft.XMLHTTP";

} 

try

{ 

objXmlHttp=new ActiveXObject(strName);

objXmlHttp.onreadystatechange=handler ;

return objXmlHttp;

} 

catch(e)

{ 

alert("Error. Scripting for ActiveX might be disabled");

return;

} 

} 

if (navigator.userAgent.indexOf("Mozilla")>=0)

{

objXmlHttp=new XMLHttpRequest();

objXmlHttp.onload=handler;

objXmlHttp.onerror=handler;

return objXmlHttp;

}

} 



/**

*	Function to load the values in Select element from the CSV values

*/

function loadSelect(id, strCSV)

{

var location_names =  new Array();
location_names['4'] = 'Dubai Marina';
location_names['5'] = 'Dubai Silicon Oasis';
location_names['6'] = 'Jumeirah Village South';
location_names['7'] = 'Culture Village';



		objSelect = document.getElementById(id);

		objSelect.length=0;

		arrOptions = strCSV.split(',');

		len = arrOptions.length;
		if(len >1)
		{
		objSelect.options[objSelect.length] = new Option('Any','0');
		}
		for(i=0;i<len;i++)

		{

			objSelect.options[objSelect.length] = new Option(location_names[arrOptions[i]],arrOptions[i]);

		}

}

function loadBuildings(id, strCSV)

{





		objSelect = document.getElementById(id);

		objSelect.length=0;

		arrOptions = strCSV.split('||');

		len = arrOptions.length;
		if(len >1)
		{
			
		objSelect.options[objSelect.length] = new Option('Any','0');
		}

		for(i=0;i<len;i++)

		{
			
			arrOptions2 =arrOptions[i].split('=>');
			
			objSelect.options[objSelect.length] = new Option(arrOptions2[1],arrOptions2[0]);

		}

}


function loadLocation()

{

	emi = document.getElementById('b_type').value;

	//alert('Emirates : ' + emi );

	if(jsLocation[emi])

	{

		//alert('Shops :' + jsLocation[emi]);

		//jsLocation['ajman'] = 'Store 1';

		//alert(jsLocation['ajman']); //document.getElementById('b_type').value

		loadSelect('b_location',jsLocation[emi]);

		//alert('Shop Changed going to fetch store info');

		showBuildingInfo();

	}

	/*

	else

		alert('No shops found');*/

	

}

/*

function showStoreInfo()

{



	

	//alert(document.getElementById('b_type').value);

	//alert(document.getElementById('storeName').value);

	emirates = document.getElementById('b_type').value;

	//alert('here');

	store = document.getElementById('b_location').value;

	alert('here2');

	

	url2="getStoreInfo.php?emirates=" + emirates + "&store=" + store;

	alert(url2);

	xmlHttp2=GetXmlHttpObject(displayStoreInfo);

	xmlHttp2.open("GET", url2 , true);

	xmlHttp2.send(null);

}

*/



function showStoreInfo()

{		 

	showShopInfo();

	return;	

}



function displayStoreInfo() 

{ 

	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")

	{ 

		//alert(xmlHttp2.responseText);

		document.getElementById('storeAddress').innerHTML=xmlHttp2.responseText ;

	} 

} 



function showBuildingInfo()

{

	

//	emirates = document.getElementById('b_type').value;

	

	emi = document.getElementById('b_type').value;

	stor = document.getElementById('b_location').value

	url2="test.php?b_type=" + emi + "&b_location=" + stor;

	

	new Ajax.Request(url2,

	  {

		method:'get',

		onSuccess: function(transport){

		//  document.getElementById('storeAddress').innerHTML = transport.responseText;
		//alert ( transport.responseText);
		loadBuildings('b_id',transport.responseText);
		

		}

	  });

		
		
	
	

	



}