var ShowAjaxField = function(url,fld,val){
	var action = fld.split("_")[0];
	
	 var value;
	 
	var field = fld;
	var browser = navigator.appName; 
	var searchbox=val;
	var url = url;
	this.show=show;
	this.class_showcomplete=class_showcomplete;
	var request = null;
	var obj = document.getElementById(field);
	var fld_length = 0;
	if(obj[1])
	{
		if(obj[1].value == '' || obj[1].value == '$$$$$$')
		   fld_length = 2;
	}
	else if(obj[0])
	{
		if(obj[0].value == '' || obj[0].value == '0')
		   fld_length = 1;
	}
	
	obj.length = fld_length;
	
	
	
	//detect the client browser
			if(browser == "Microsoft Internet Explorer"){
						request = new ActiveXObject("Microsoft.XMLHTTP");
			}else{
			            request = new XMLHttpRequest();
			}
			
	 this.show();
	 function show(){
		 
		     value = document.getElementById(searchbox).value;
			 document.getElementById(searchbox).value='Searching';
		     url = url + "/frontend/docs/show.php?action="+action+"&value="+value; 
			 request.open('get',url,true);
			 request.onreadystatechange = class_showcomplete; 
			 request.send('');
			
	    }//end this.show function
	
	   function class_showcomplete(){
		
		  if(request.readyState == 4 || request.readyState == "complete"){ 
		   var answer = request.responseText;
		 
		   
		   if(answer == ':::')
		   {
		    //check element exist or not
			 if(document.getElementById(field+'2'))
			 {
				 if(confirm(value +" was not found in our database.Do you want to add in database"))
				 {
					obj.value = "$$$$$$";
					if(field == "textbook")
					{
						document.getElementById("add"+field).style.display = 'block';
						document.getElementById(field+'2').value = value;
					}
					else
					{
						document.getElementById(field+'2').style.display = 'block';
						document.getElementById(field+'2').value = value;
					}
				 }
			 }
		   }
			
		   var res = answer.split(":::");
		   
		   var keys = res[0].split("###");
		   var vals = res[1].split("###");
		   
		  
		   
		   var results = keys.length - 1;
		   //obj[0] = new Option("<-- Not in List -->","",true,false);
		   for(i=0; i<keys.length;i++)
		   {
			      obj[i+fld_length] = new Option(vals[i],keys[i],false,false);
		   }
		     //document.getElementById(searchbox).value=(results)+' Result(s) found';
		    document.getElementById(searchbox).value='Search completed';
		}
		else
		{
			document.getElementById(searchbox).value+='.';
		}
		  
	}//end function showcoplete
	
	
	
  }//end of main function 




 
function checkkey(e,fld,val)
{
	   if(e.keyCode == 13)
	   {
			
			return false;
			
	   }
}