		
function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

var http = createRequestObject();

function clearDivs() {
	for(var j = 0 ; j < 15 ; j++ )
	{
		document.getElementById('chk'+j).innerHTML = '';
		document.getElementById('chkc'+j).style.display = 'none';
	}					
	for(var j = 0 ; j < 5 ; j++ )
	{
		document.getElementById('self'+j).innerHTML = '';
		document.getElementById('selfi'+j).style.display = 'none';
	}					

}

function getProducts(Index){

	/* Create the request. The first argument to the open function is the method (POST/GET),and the second argument is the url... 
		document contains references to all items on the page We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the index of the selected item. 
	*/
//	alert(Index);	
	http.open('get', 'inc/process.php?'+ Index +'&rand='+Math.random(1));
	/* Define a function to call once a response has been received. This will be our handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST method. */
	http.send(null);
}

function handleProducts(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object has a property called readyState with several states:
		0: Uninitialized		1: Loading		2: Loaded		3: Interactive		4: Finished */
	if(http.readyState != 4){		
			document.getElementById('divone').style.display = '';
			document.getElementById('divtwo').style.display = 'none';
			document.getElementById('submit').disabled = true;
	}
	if(http.readyState == 4){ 	//Finished loading the response
		/* We have got the response from the server-side script,let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		if (http.status == 200) {
            // ...processing statements go here...
        	
			var response = http.responseText;
			response = response.split("&");
			if(response[0] == 'news') {
				document.getElementById('divone').style.display = 'none';
				document.getElementById('divtwo').style.display = '';
				document.getElementById('submit').disabled = false;
				
				if(response[1] == '0') {
					document.getElementById('divtwo').innerHTML = 'Your information has been submitted';  }
				else if(response[1] == '1') {
					document.getElementById('divtwo').innerHTML = 'Your information has been deleted'; }
				else if(response[1] == '2') {
					document.getElementById('divtwo').innerHTML = 'Your information was not correct'; }
				else if(response[1] == '3') {
					document.getElementById('divtwo').innerHTML = 'Your information already existed'; }
					
			} else {
				document.getElementById('divone').style.display = 'none';
				document.getElementById('divtwo').style.display = '';
				document.getElementById('submit').disabled = false;
			}

//		else if(response != 'contact')
/*		
		for(var i = 0 ; i < response.length ; i++ )
		{
			if(!(response[i].indexOf("checks=") == -1)){ 
					var checks = response[i].split("=");
					checks = checks[1].split(",");
					if(checks[1] == "") {break;}
					for(var j = 0 ; j < checks.length ; j++ )
					{
						document.getElementById('chk'+j).innerHTML = checks[j];
						document.getElementById('chkc'+j).style.display = '';
					}					
			}
			if(!(response[i].indexOf("self=") == -1)){ 
					var self = response[i].split("="); 
					self = self[1].split(","); 
					if(self[1] == "") {break;}
					for(var j = 0 ; j < self.length ; j++ )
					{
						document.getElementById('self'+j).innerHTML = self[j];
						document.getElementById('selfi'+j).style.display = '';
					}		
			}
		}		

		/* And now we want to change the product_categories &lt;div&gt; content.we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
//		document.getElementById('product_cage').innerHTML = response;
		} else {
            alert("There was a problem retrieving the data:\n" +
                http.statusText);
        }
	}
}



function gettask(Index){
	http.open('get', 'inc/tasks.php?mode='+ Index +'&rand='+Math.random(1));
	http.onreadystatechange = handletask; 
	http.send(null);
}

function handletask(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object has a property called readyState with several states:
		0: Uninitialized		1: Loading		2: Loaded		3: Interactive		4: Finished */
	if(http.readyState != 4){		
	//		document.getElementById('divone').style.display = '';
	//		document.getElementById('divtwo').style.display = 'none';
	//		document.getElementById('submit').disabled = true;
	}
	if(http.readyState == 4){ 	//Finished loading the response
		/* We have got the response from the server-side script,let's see just what it was. using the responseText property of 			the XMLHttpRequest object. */
		if (http.status == 200) {      // ...processing statements go here...
			var response = http.responseText; 
			if(response == 'Database not Available') {	document.getElementById('result').innerHTML = response;		}
			else {		//alert(response);	document.getElementById('result').innerHTML = response;
				var restext = ""; var product = "";
				response = response.split("|Next|");
				if(response[0] == 'products'){ 
					for(var i = 1 ; i < response.length ; i++ )
					{	if(response[i].indexOf("&") != -1){ 
						restext += "<br /><br />";
						product = response[i]; product = product.split("&");
						restext += "<table cellspacing=\"0\" width=\"80%\" border=\"0\">";
						pthis = product[1].split("="); 
						restext += "<tr onclick=\"taskinfo('" + response[i] + "');\" style=\"cursor:pointer\">";
						restext += "<th width=\"80%\" align=\"left\" colspan=\"2\" class=\"mthrr\"><label class=\"mthl\">" + pthis[1] + "</label></th>";
						pthis = product[4].split("="); 
						restext += "<td rowspan=\"3\" class=\"mthr\"><img height=\"80\" width=\"80\" src=\"" + pthis[1] + "\"</td></tr>";
						pthis = product[2].split("="); 
						restext += "<tr><td width=\"24%\" class=\"mthrr\">" + pthis[0] + "</td><td width=\"76%\" class=\"mthr\">" + pthis[1] + "</td></tr>";	
						pthis = product[5].split("="); 
						restext += "<tr><td width=\"24%\" class=\"mthrr\">" + pthis[0] + "</td><td width=\"76%\" class=\"mthr\">" + pthis[1] + "</td></tr>";	
						restext += "<tr><td width=\"100%\" colspan=\"3\" align=\"right\" style=\"cursor:pointer\" onclick=\"taskinfo('" + response[i] + "');\"";
						restext += "><img height=\"20\" src=\"./img/igoback_f01.jpg\"></td></tr>";	
						restext += "</table>";
						restext += "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
						restext += "------------------------------------------------------------------";
						restext += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />";
					}	}			
				} else if(response[0] == 'projects'){
					for(var i = 1 ; i < response.length ; i++ )
					{	if(response[i].indexOf("&") != -1){ 
						restext += "<br /><br />";
						product = response[i]; product = product.split("&");
						restext += "<table cellspacing=\"0\" width=\"80%\" border=\"0\">";
						pthis = product[1].split("="); 
						restext += "<tr onclick=\"taskinfo('" + response[i] + "');\" style=\"cursor:pointer\">";
						restext += "<th width=\"80%\" align=\"left\" colspan=\"2\" class=\"mthrr\"><label class=\"mthl\">" + pthis[1] + "</label></th>";
						pthis = product[4].split("="); 
						restext += "<td rowspan=\"3\" class=\"mthr\"><img height=\"80\" width=\"80\" src=\"" + pthis[1] + "\"</td></tr>";
						pthis = product[2].split("="); 
						restext += "<tr><td width=\"24%\" class=\"mthrr\">" + pthis[0] + "</td><td width=\"76%\" class=\"mthr\">" + pthis[1] + "</td></tr>";	
						pthis = product[5].split("="); 
						restext += "<tr><td width=\"24%\" class=\"mthrr\">Company Name</td><td width=\"76%\" class=\"mthr\">" + pthis[1] + "</td></tr>";	
						restext += "<tr><td width=\"100%\" colspan=\"3\" align=\"right\" style=\"cursor:pointer\" onclick=\"taskinfo('" + response[i] + "');\"";
						restext += "><img height=\"20\" src=\"./img/igoback_f01.jpg\"></td></tr>";	
						restext += "</table>";
						restext += "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
						restext += "------------------------------------------------------------------";
						restext += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />";
					}	}								
				} else if(response[0] == 'clients'){
					
				} else { alert(response[0]); }
			}
			document.getElementById('allresult').innerHTML = restext;
		} else {  alert("There was a problem retrieving the data:\n" + http.statusText);   }
	}
}

function taskinfo(id) {
	restext = "";
	if(id.indexOf("&") == -1){ return; }
	restext += "<br /><br />";
	product = id.split("&");
	restext += "<table cellspacing=\"0\" width=\"80%\" border=\"0\">";
	pthis = product[1].split("="); 
	restext += "<tr onclick=\"backinfo();\" style=\"cursor:pointer\">";
	restext += "<th width=\"80%\" align=\"left\" colspan=\"2\" class=\"mthrr\"><label class=\"mthl\">" + pthis[1] + "</label></th>";
	pthis = product[4].split("="); 
	restext += "<td rowspan=\"3\" class=\"mthr\"><img height=\"80\" width=\"80\" src=\"" + pthis[1] + "\"</td></tr>";
	pthis = product[5].split("="); 
	restext += "<tr><td width=\"24%\" class=\"mthrr\">" + pthis[0] + "</td><td width=\"76%\" class=\"mthr\">" + pthis[1] + "</td></tr>";	
	pthis = product[6].split("="); 
	restext += "<tr><td width=\"24%\" class=\"mthrr\">" + pthis[0] + "</td><td width=\"76%\" class=\"mthr\">" + pthis[1] + "</td></tr>";	
	pthis = product[2].split("="); 	
	restext += "<tr><td width=\"100%\" colspan=\"3\" align=\"center\" style=\"cursor:pointer\" class=\"mthr\"><br />" + pthis[1] + "</td></tr>";	
	pthis = product[3].split("="); 	
	restext += "<tr><td width=\"100%\" colspan=\"3\" align=\"center\" style=\"cursor:pointer\" class=\"mthr\"><br />" + pthis[1] + "</td></tr>";	
	restext += "<tr><td width=\"100%\" colspan=\"3\" onclick=\"backinfo();\" align=\"right\" style=\"cursor:pointer\"><br />";
	restext += "<img src=\"./img/igoback_f02.jpg\"></td></tr>";			

	restext += "</table>";

	resall = document.getElementById('allresult');
    resall.style.display = "none";
	resone = document.getElementById('result');
	resone.innerHTML = restext;	
	resone.onclick = backinfo;
}

function backinfo() {
	resone = document.getElementById('result');
	resone.innerHTML = "";	
    resall = document.getElementById('allresult');
    resall.style.display = "";
}

function detailed(id) {
    info_x = document.getElementById('the_info');
    info_x.style.display = "block";

    shutter_x = document.getElementById('shutter');
	shutter_x.className = "shutter";

    shutter_x.onclick = hideShutter;
	info_x.className = "info";
	info_x.innerHTML = id;    
}

function hideShutter () {
	shutter_x = document.getElementById('shutter');
	info_x = document.getElementById('the_info');
	// clear info
	info_x.innerHTML = "";
	info_x.className = "";
	shutter_x.className = "";
	
	info_x.style.display = "none";
}
