// JavaScript Document
// @author Ashutosh K Tripathi

var http ; // global variable for ajax xmlhttp request
var lastPriceRow ; // global variable to check what last row was for price/rent details

//function createRequestObject
// @iparam void
// @oparam xmlhttpRequest Object
//function to actually create global xmlhttpRequest Object 
function createRequestObject()
        {
	      var xmlhttp=false;
	      try 
	       {
	 	    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	       }catch (e) 
	        {try 
		     {
			   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  		 }catch (E) 
		      {
		       xmlhttp = false;
	  	      }
	       }
	     if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
	      {
		   try 
		   {
			xmlhttp = new XMLHttpRequest();
	       }catch (e) 
		    {
			 xmlhttp=false;
		    }
	     }
	    if (!xmlhttp && window.createRequest) 
	    {
		try 
		 {
			xmlhttp = window.createRequest();
		 }catch (e) 
		  {
			xmlhttp=false;
		  }
	  }	
	return xmlhttp;
   }  //Create Request Object function ends.

//function getSubCat
// @iparam void
// @oparam xmlhttpRequest Object
//request function to get States for a given country using ajax
function getSubCat()
{
  var mf = document.forms[0];
  var val = mf.Category.options[mf.Category.selectedIndex].value ;
  if(val!=""&&val!='0'){
  http=createRequestObject();
  http.onreadystatechange = function(){getSubCatResponse();};
  http.open("GET", "asphp/AMDUserProcess.php?purpose=LoadSubCat&id="+val, true);
  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  http.send(null);
  mf.SubCategory.options.length = 0;
  mf.SubCategory.options[0] = new Option("Loading...","");
  }
  else if(val=='0'){
  mf.SubCategory.options.length = 0;
  mf.SubCategory.options[0] = new Option("---","");
  }
  else{
  mf.SubCategory.options.length = 0;
  mf.SubCategory.options[0] = new Option("---","");
  }
}

//function getStateByCountryResponse
// @iparam void
// @oparam xmlhttpRequest Object
//response function to get States for a given country using ajax
function getSubCatResponse()
{
	 if(http.readyState==4){	  
	  if(http.status==200){		
	    var mf = document.forms[0];
	    var response = http.responseText ;
		SubCatArr = response.split("|");
		mf.SubCategory.options.length = 0;
		if(mf.Category.options[0].value=="All"){
		 mf.SubCategory.options[0] = new Option("--All--","All");
		 mf.SubCategory.selectedIndex = 0 ;
		}
		else
		 mf.SubCategory.options[0] = new Option("Select","");
		for(var i=0; i<SubCatArr.length-1; i++){
		  var CodeValArr = SubCatArr[i].split("+");
		  mf.SubCategory.options[i+1] = new Option(CodeValArr[1],CodeValArr[0]);
		 }
	   }
	 }
}
