
sitename = location.href;
//alert("sitename : "+sitename);

var first=sitename.indexOf('//');

//alert("first 1: "+first);
if(first!=-1) 
{

	second=sitename.indexOf('/',first+2);
		//alert("second : "+second);
	domain= sitename.substring (first+2, second );
	//alert("domain : "+domain);
}


var strHref = window.location.href;
//var arr = strHref.split("sibisoft.com");
var arr = strHref.split(domain);
var xmlHttp = createXmlHttpRequestObject();
var serverAddress = arr[0] + domain +'/views/sbct.php';
//var serverAddress = arr[0] + 'sibisoft.com:8888/inc/sbct.php';
var showErrors = false;
var cache = new Array();

function createXmlHttpRequestObject() {
	var xmlHttp;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		for (var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++) {
			try {
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e) {}
		}
	}
	
	if (xmlHttp) return xmlHttp;
}

function displayError(message) {
	if (showErrors) {
		showErrors = false;
		alert('An error has attempt: \n' + message);
		setTimeout('select_sbct();', 10000);
	}
}

function select_sbct(inputValue,fieldID) {
	//alert(inputValue);
	//alert(fieldID);
	if (xmlHttp) {
		if (fieldID)
		{
			inputValue = encodeURIComponent(inputValue);
			cache.push('inputValue=' + inputValue + '&fieldID=' + fieldID);
		}
		try
		{
			if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) && cache.length > 0)
			{
				var cacheEntry = cache.shift();
				xmlHttp.open("POST", serverAddress, true);
				xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHttp.onreadystatechange = handleRequestStateChange;
				xmlHttp.send(cacheEntry);
			}
		}
		catch(e) {
			displayError(e.toString());
		}
	}
}

function handleRequestStateChange() {
	//alert(xmlHttp.status);
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			try
			{
				//alert("12345");
				readResponse();
			}
			catch(e) {
				displayError(e.toString());
			}
		}
		else
		{
			displayError(xmlHttp.statusText);
		}
	}
}

function readResponse() {
	//alert("dert");
	//var response = xmlHttp.responseText;
	//alert("sss");
	responseXml = xmlHttp.responseXML;
	
	xmlDoc = responseXml.documentElement;
	
	result_count = xmlDoc.getElementsByTagName('result_count')[0].firstChild.data;
	
	result_has_price = xmlDoc.getElementsByTagName('result_has_price')[0].firstChild.data;
	if(result_count > 0)
	{
		var sel;
		sel = '<select name="sc2id"  class="text_select" style="height: 25px;">';
		sel = sel + '<option value="0">جميع الاقسام</option>';
		for (var i=0;i<result_count;i++)
		{
			result_id = xmlDoc.getElementsByTagName('result_id')[i].firstChild.data;
			
			result_value = xmlDoc.getElementsByTagName('result_value')[i].firstChild.data;
			
			sel = sel + '<option value="'+result_id+'">'+result_value+'</option>';
			//alert(result_id);
		}
		sel = sel + '</select>';
		
		//alert('sbct if');
		document.getElementById('div1').style.display = "none";
		document.getElementById('div2').style.display = "block";
		
		//document.getElementById('div4').style.display = "block";
		
		document.getElementById('sbct').innerHTML = sel;

	} // end of if	
	else
	{
		sel = '';	
		
		document.getElementById('div1').style.display = "none";
		document.getElementById('div23').style.display = "none";
		document.getElementById('div2').style.display = "none";
		
		document.getElementById('sbct').innerHTML = sel;
		document.getElementById('sc2id').value = 0;
	}
	
	if (result_has_price == 1)
	{
		document.getElementById('div23').style.display = "block";
		//alert("it has a price");
	}
	else
	{
		document.getElementById('div23').style.display = "none";
		//alert("it not has a price");
	}
	
	//exit;
	setTimeout('select_sbct();', 100);
}