function ajaxclass()
{
	this.Method = "GET";//OR "POST" 
    this.Async = true; //OR false (asynchronous or synchronous call) 
    this.request = null;

	this.init = function() 
    {
          if (window.XMLHttpRequest) // if Mozilla, Safari etc
		  {
	          this.request = new XMLHttpRequest();
		  }
          else if (window.ActiveXObject)
          { // if IE
			try 
			{
				 this.request = new    ActiveXObject("Msxml2.XMLHTTP");			 
			} 
			catch (e)
			{
				try
				{ 
					this.request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){}
				}
			}

			 if(this.request)
			 {   
			 		/* KRD: Following is the old code
			 		//Local URL
					this.url = "http://fedora/CarDeals/admin/" + this.JSONArray.CallPage + this.JSONArray.Querystring;
					
					//Live URL
					//this.url = "http://www.planetace.net/CarDeals/admin/" + this.JSONArray.CallPage + this.JSONArray.Querystring;	
			 		*/
			 		var curUrl = new String(window.location);
					if(curUrl.indexOf("admin/") == -1){
			 			this.url = curUrl.substring(0,curUrl.lastIndexOf("/"))+"/admin/" + this.JSONArray.CallPage + this.JSONArray.Querystring;
					}
					else{
						this.url = curUrl.substring(0,curUrl.lastIndexOf("/"))+"/" + this.JSONArray.CallPage + this.JSONArray.Querystring;
					}
					
					this.request.onreadystatechange=this.handleResponse;

					this.request.open(this.JSONArray.Method, this.url , this.JSONArray.Async);
					this.request.send(null);					
			 }//end of request
			 
			 
    }  // end of init
	  
	
    this.JSONArray = {  
						"Method" : "POST", 					//Method type
						"Async"  : true, 					//Call type
						"CallPage" : "ajaxcallpage.php", 	//page or webservice
						"Querystring" : "", 				//Query string
						"dependentType" : null,				//[0,1,2,3] for isEdit 
						"isEdit": [
									{
										"textBoxId" : null, 	//0 then this element
										"dropDownId" : null, 	//1 then this element
										"default" : null, 		//2 then this element
										"misc":null 			//3 then this element
									}
								  ]
	
						}; //end of array
	  		
		
	var self = this; // To handle lose of focus
	this.handleResponse = function()
	{	
		if(self.request.readyState == 4 && self.request.status == 200)
		{
			try
			{
				var data  = "";
				data = self.request.responseText;				
	
			   switch(self.JSONArray.dependentType)
			   {
//					case 0:
//						 PopulateTextBox(self.JSONArray.isEdit[0].textBoxId,data);						
//						break;
					case 1:
						
						populatedropdown(self.JSONArray.isEdit[0].dropDownId,data);
						break;
//					case 2:
//						//default
//						PopulateDefault(self.JSONArray.isEdit[0].default,data);
//						break;
//					case 3:
//						//misc
//						PopulateDivision(self.JSONArray.isEdit[0].misc,data);
//						break;						
				}
				
			}
			catch(e) {}
						
		}
					
	}  //end of handle response
		
				
	function populatedropdown(controlid, data)
	{	
		var targetconrol;
		var controlarray = controlid.split(":");
		if(controlid=="tblbodystyle")
		{
			document.getElementById('tblbodystyle').innerHTML=data;
			
		}
		else
		{	
			for (var c=0; c<controlarray.length; c++)
			{	
				var obj;
				obj = "document.frm." + controlarray[c];					
				obj = eval(obj);
				
				if (c==0)
					targetconrol = obj;
				
				var length=0;
		
				length = obj.options.length;		
				
				for(var i=length;i!=0;i--)
				{
					obj.remove(i);
				}
				
				obj.selectedIndex=0;
			}	
			//alert(data);		
			var d = data.split("~");
			var intIndex = 0;
			
			for (var i=0; i<d.length; i++)
			{
				var v = d[i].split("|");						
				
				if (v.length==4)
				{
					if (v[3]=="true") 
					{
						intIndex = i+1;
					}
					targetconrol.options[i+1] = new Option(v[0], v[1], v[2], v[3]);							
				}
			}
			
			targetconrol.selectedIndex=intIndex;	
		}
	}	

} //end of class


function getajaxdata(type, dependentvalue, selval, targetcontrolid, onchangecontrolid)
{	
	var obj = new ajaxclass(); //Object creation
	obj.JSONArray.Method = "GET"; //Setting Method 
//	obj.JSONArray.isEdit[0].textBoxId="first";//Textboxid for response

	if (onchangecontrolid != "" && onchangecontrolid != undefined)
	{
		obj.JSONArray.isEdit[0].dropDownId=targetcontrolid  + ":" + onchangecontrolid;//drop downlist for response
	}
	else
	{
		obj.JSONArray.isEdit[0].dropDownId=targetcontrolid;//drop downlist for response
	}

	obj.JSONArray.dependentType=1; //0->Textbox, 1->drop downlist,  //2->tagId, 3->Misc and so on
	
	obj.JSONArray.Method = "GET";
	obj.JSONArray.CallPage = "ajaxcallpage.php";
	obj.JSONArray.Querystring= "?q=" + type + "&id=" + dependentvalue + "&selval=" + selval; 
	//alert(obj.JSONArray.Querystring);
	obj.init();//Initiate the AjaxCall
}


function searchrecord()
{
	document.frm.submit();	
}
