/**
 * @author romanas.m
 */

 
var xmlHttp;
var activeDetails;

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
 	{
 		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}
	catch (e)
 	{
 		//Internet Explorer
 		try
  		{
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}
 		catch (e)
  		{
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
}

function showUser(str)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
 	{
 		alert ("Jūsų naršeklė nepalaiko HTTP užklausų");
 		return;
 	}

	var url="getuser.php";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{ 
 		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
 	} 
}

function productSearchRequest(searchStr, searchMadeBy)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
 	{
 		alert ("Browser does not support HTTP Request");
 		return;
 	}

	var url="ajax_be/getproduct.php";
	url=url+"?req="+searchStr+"&prod="+searchMadeBy;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=productSearchResult;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function productSearchResult() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{ 
 		document.getElementById("resultBody").innerHTML=xmlHttp.responseText;
 	} 
}


function getServiceDescription(itemId, divId)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
 	{
 		alert ("Browser does not support HTTP Request");
 		return;
 	}

	if(activeDetails){
		document.getElementById(activeDetails).innerHTML="";
	}

	if(activeDetails == divId){
		document.getElementById(activeDetails).innerHTML="";
		activeDetails = "";
	}else{
		activeDetails = divId;
	
		var url="ajax_be/getsrvdescription.php";
		url=url+"?req="+itemId;
		url=url+"&sid="+Math.random();
		
		xmlHttp.onreadystatechange = function getServiceDescriptionResult()
		{
			
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		 		document.getElementById(divId).innerHTML=xmlHttp.responseText;
		 	}		
		}
		
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);		
	}
}

