// declare a global  XMLHTTP Request object
var XmlHttpObj;

// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla
function CreateXmlHttpObj()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox) 
	if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpObj = new XMLHttpRequest();
	}
}

// this function called when state of  XmlHttpObj changes
// we're interested in the state that indicates data has been
// received from the server
/*function StateChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
			//PopulateCountryList(XmlHttpObj.responseXML.documentElement);
			alert(XmlHttpObj.responseText);
			return  XmlHttpObj.responseText	;
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}*/
//var productLookup = getXMLHttpRequest();
function fnGetDetails(recId,name)
{
	document.getElementById("submit_search").disabled="true";
	destination="../search/getDetails.php"
		 var select_array=new Array("cmbBoard","cmbSubject","cmbCity","cmbYear","cmbSchool","cmbStandard");
					
		var k='';
		for(var j=0;j<select_array.length;j++)
			{	
			if(document.getElementById(select_array[j]).value!='All')
				{ 				
				var value2=document.getElementById(select_array[j]).value;
				k+=document.getElementById(select_array[j]).name+"_"+value2+","				
				}			
			}
		//alert(k)
					
			
	par="recId="+ recId +"&querystring="+k+"&name="+name
	
	var data="";
	var x=0;
	 CreateXmlHttpObj()
	
  	// verify XmlHttpObj variable was successfully initialized
	
	if(XmlHttpObj)
	{		
	      XmlHttpObj.onreadystatechange=function()
		   {   
			   if(XmlHttpObj.readyState == 4)
	              {
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{			
		 //  var select_array=new Array("cmbArea","cmbSubArea","cmbCategory","cmbSubCategory","cmbBrand","cmbCity");
		   var retData_ajax=XmlHttpObj.responseText;
		   			//document.getElementById("refresh").innerHTML=retData_ajax;
				//	document.getElementById("text").innerHTML=retData_ajax;
		   if(retData_ajax=='')
		   {
		document.getElementById("refresh").innerHTML="<div ><a href='javascript:location.reload()' ><img src='../images/icons/refresh_nodiscounts.gif' style='border:0px' ></a><br><font color=#c93632 ><b>No Papers Available</b></font></div>";
			document.getElementById("allowid").innerHTML="<input type='hidden' name='allow1'   id='allow1' value='no'   />";
			document.getElementById("submit_search").disabled="true";
		   }
		   else
		   {
			document.getElementById("allowid").innerHTML="<input type='hidden' name='allow1'   id='allow1' value='yes'   />";
			
			var retData_ajax_array= retData_ajax.split("@@@@@")
			if(retData_ajax!='')
		{      
			var unique_array= new Array(0);
			
			for (var i=0;i<retData_ajax_array.length;i++)
			{	
				if(retData_ajax_array[i]!='')
				{
					
		     	var with_content=retData_ajax_array[i].split("^^^^^")
		     	var content=with_content[0];
			    unique_array[i]=content; 
				
				}
			}
			var unique_return_array= new Array(0);
			
			unique_return_array=unique(unique_array);
			
			for (var i=0;i<unique_return_array.length;i++)
			{	
			      if(document.getElementById(unique_return_array[i]).value=="All")
				  {
					  document.getElementById(unique_return_array[i]).length=1;
				  }
			}
			
			
			
		}
		
		
		if(retData_ajax!='')
		{
			
			for (var i=0;i<retData_ajax_array.length;i++)
			{	
				if(retData_ajax_array[i]!='')
				{
					//alert(retData_ajax_array[i])
			var with_content=retData_ajax_array[i].split("^^^^^")
			var content=with_content[0];
			
			//alert("content"+content)
			var option_array=with_content[1].split("#####")
			var option_value=option_array[0];
			//alert(option_value)
			var option_content=option_array[1];
			//alert(content)
				
				if((option_content!='')&&(document.getElementById(content).value=='All'))
				{   
				
					
					document.getElementById(content).length=document.getElementById(content).length + 1
					document.getElementById(content).options[document.getElementById(content).length - 1].value=option_value
					document.getElementById(content).options[document.getElementById(content).length - 1].text=option_content
					
				}
						
			
			
				}
			}
			//document.getElementById("refresh").innerHTML="<a href='javascript:window.location=\"../index.php\"' ><img src='../img/refresh.gif' style='border:0px' ></a>";
			document.getElementById("refresh").innerHTML=" ";
		}//get loopalert("enablinf");
			document.getElementById("submit_search").disabled=""
		}	
			
		 }
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	             }
		   }
		  XmlHttpObj.open("POST",destination,true)
          XmlHttpObj.setRequestHeader("Content-type","application/x-www-form-urlencoded")
          XmlHttpObj.setRequestHeader("Content-length", par.length)
          XmlHttpObj.setRequestHeader("Connection", "close")
          XmlHttpObj.send(par)
		 
		 // alert(XmlHttpObj.responseText)
	    //  data = XmlHttpObj.responseText				
		  
	}

//
//alert(data)
/*return data*/
}

function unique(a) {
	
	tmp = new Array(0);
	
	for(i=0;i<a.length;i++){
		if(!contains(tmp, a[i])){
			tmp.length+=1;
			tmp[tmp.length-1]=a[i];
		}
	}
	return tmp;
}

function contains(a, e) {
	for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}