﻿ // JScript File
/*
 Created By : Kedarnath Nayak
 This file is to be included(<scrict src="ajaxscript.js"/>) in all the pages whereever dropdownlist is to be filled without postback
 File Name            :      ajaxscript.js
 Description          :      To fill the dropdowns without postback and showing the layers without postback
 Modification History: 
   
*/
		  var xmlHttp=null;
		  var fillctlname;   //DropDownlist to be filled
	      var fillctl;       //Use in the function GetLayerInfo() For using in  the  ShowLayerInfo()
	      var qurl;          //Use in the function GetLayerInfo() for using in the ShowLayerInfo()
	      var pctlname;      //Use in the function GetLayerInfo() for using in the ShowLayerInfo()
	      var plstartno;      //Use in the GetLayerInfo1() for hinding the starting layer no
	      var layno;          //Use in the GetLayerInfo1() for hiding this no of layers
          var order;             //for ordering the name

		   function GetXmlHttpObject() //Creates the XmlHttpObject
				{ 
				    
					var objXMLHttp=null;
					if (window.XMLHttpRequest)	
						{
							objXMLHttp=new XMLHttpRequest()
						}
					else if (window.ActiveXObject)
						{
							
							objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
						}
						
					return objXMLHttp;
				} 
				
				function stateChanged() //This function is called for populating the DropDownlists  by function fillselect()
				{ 
				  	
					    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
					    { 
					            var str=xmlHttp.responseText.toString();
//				                alert(str); 
//				                return false;
//				                var select2 = document.getElementById(fillctlname.id);
				                var select2 = document.getElementById(fillctlname);
					            var ar=new Array();
					            ar=str.split('|');
					             
					            if(ar.length>1)  //If More than one element retured then add it to the dropdown lists
					            {
					                fillctlname = document.getElementById(fillctlname);
               					    RemoveAllOptions(fillctlname); //Remove all the Options 
						            for(var i=0;i<ar.length-1;i++)
						            {
						                var e=document.createElement("option");
						                var el=ar[i].split(',')
						                e.value=el[0];
						                e.innerText=el[1];
						                select2.appendChild(e);
        						        
						            } //End For
                                }   //End if(ar.length>1)
                                else if(ar.length==1) //If No Record Returned
                                {  
                                  RemoveAllOptions(fillctlname);  //Remove all the Options 
                                }  //End Else If
                            
				        }  //End of xmlHttp.readyState
				    
				    
				}
				
				function fillselectnew(ctlname,pfillctlname,url,ord) //This function is called in the onChange event of the dropdownlist

                                                {                                               

//                                              alert(document.getElementById(ctlname.id).value);                                               

                                           fillctlname=pfillctlname;

//                                       alert(fillctlname);

                                           if(document.getElementById(ctlname.id).selectedIndex>0)

                                           {

                                               var uid=document.getElementById(ctlname.id).value;

                                               xmlHttp=GetXmlHttpObject();

                                                   

                                                       if (xmlHttp==null) //If XmlHttpObject Could not be created

                                                                {

                                                                            alert ("Browser does not support HTTP Request")

                                                                            return

                                                                }   //End if if (xmlHttp==null)

                                                            

                                                        url=url+uid+'&ord='+ord;

//                                           alert( url);

                                                        xmlHttp.open("GET",url,false)

                                                        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );

                                                                xmlHttp.onreadystatechange=stateChanged

                                                                xmlHttp.send(null)

                                                            }

                                                            else if (document.getElementById(ctlname.id).selectedIndex==0)

                                                             {

                                                                RemoveAllOptions(fillctlname);

                                                             }    

                                                                return false;

                                                }


				
				
				
				
				function fillselect(ctlname,pfillctlname,url) //This function is called in the onChange event of the dropdownlist
				{
				    			
			       fillctlname=pfillctlname;
			    // alert(fillctlname);
			       if(document.getElementById(ctlname.id).selectedIndex>0)
			       {
			           var uid=document.getElementById(ctlname.id).value;
//			           alert(uid);
			           xmlHttp=GetXmlHttpObject();
    				   
				       if (xmlHttp==null) //If XmlHttpObject Could not be created
					    {
						    alert ("Browser does not support HTTP Request")
						    return
					    }   //End if if (xmlHttp==null)
    					
				        url=url+uid  ;
		           //alert( url);
				        xmlHttp.open("GET",url,false)
				        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
				   	    xmlHttp.onreadystatechange=stateChanged
					    xmlHttp.send(null)
					}
					else if (document.getElementById(ctlname.id).selectedIndex==0)
					 {
					    RemoveAllOptions(fillctlname);
					 }    
					    return false;
				}
				
				//Used For Passing Optional Parameter
				
				function fillselectOPT(ctlname,pfillctlname,url,OptPar,ctlOPT) //This function is called in the onChange event of the dropdownlist
				{				
//				 alert(document.getElementById(ctlname.id).value);				
			       fillctlname=pfillctlname;
			       var OptVal=ctlOPT.value;
			       if(document.getElementById(ctlname.id).selectedIndex>0)
			       {
			           var uid=document.getElementById(ctlname.id).value;
			           xmlHttp=GetXmlHttpObject();
    				   
				       if (xmlHttp==null) //If XmlHttpObject Could not be created
					    {
						    alert ("Browser does not support HTTP Request")
						    return
					    }   //End if if (xmlHttp==null)
    					
				        url=url+uid+'&OptPar='+OptPar+'&OptVal='+OptVal;
				        xmlHttp.open("GET",url,false)
				        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
				   	    xmlHttp.onreadystatechange=stateChanged
					    xmlHttp.send(null)
					}
					else if (document.getElementById(ctlname.id).selectedIndex==0)
					 {
					    RemoveAllOptions(fillctlname);
					 }    
					    return false;
				}
				
				function GetLayerInfo(gctlname,url,pfillctl,pqurl,ord) /* Retrieve the no.of data for the layers to be shown */
				{
				    xmlHttp=GetXmlHttpObject();
				    fillctl=pfillctl;
					qurl=pqurl;
					pctlname=gctlname;
					order=ord;
					//alert(document.getElementById(gctlname.id).id);
				    var paramvalue=document.getElementById(gctlname.id).value;
				   if (xmlHttp==null)
					{
						alert ("Browser does not support HTTP Request")
						return
					} 
				    url=url+paramvalue;
				    //alert(url);
				    url=url+'&opt1=layer&opt2=layers'
				//   alert(url);
				    xmlHttp.open("GET",url,false)
				    xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
			        xmlHttp.onreadystatechange=ShowLayerInfo
					xmlHttp.send(null)
				}
				
				function GetLayerInfoDyn(gctlname,trname,tdname,url,pfillctl,pqurl) /* Retrieve the no.of data for the layers to be shown */
				{
				
				    xmlHttp=GetXmlHttpObject();
				    fillctl=pfillctl;
					qurl=pqurl;
					tr=trname;
					td=tdname;
					pctlname=gctlname;
					//alert(document.getElementById(gctlname.id).value);
				    var paramvalue=document.getElementById(gctlname.id).value;
				   if (xmlHttp==null)
					{
						alert ("Browser does not support HTTP Request")
						return
					} 
				    url=url+paramvalue;
				    url=url+'&opt1=layer&opt2=layers'
				    
				   // alert(url);
				    xmlHttp.open("GET",url,false)
				    xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
			        xmlHttp.onreadystatechange=ShowLayerInfoDyn()
			         alert(tr);
					xmlHttp.send(null)
				}
				
				function ShowLayerInfoDyn()   //Displays or the Hides no. of Layers
				{ 
//				  alert(xmlHttp.readyState);
                    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
					{ 
					        var str=xmlHttp.responseText.toString();
					        var values=str.split(',');
					        //hidealllayersDyn(tr);
					         for(var i=0;i<3;i++) //HIde all the layers
					                {
					              
					                  document.getElementById(tr+i).style.display="None";
					                }
					        alert(values[1]-1)
					        for(var i=0;i<values[1]-1;i++) //display the no. of layers
					        {
					          document.getElementById(tr+i).style.display="";
					          //alert(document.getElementById('LTR'+i).id);
					        }
					         if(values.length==1)
					         { 
					           for(var i=0;i<3;i++) //HIde the no. of layers when first item(--select--) is selected
					                {
					                  document.getElementById(tr+i).style.display="None";
					                }
					         }
//					         document.getElementById('LCAP0').innerText=values[2];
//					         document.getElementById('LCAP1').innerText=values[3];
//					         document.getElementById('LCAP2').innerText=values[4];
                            for(var i=0;i<3;i++) //HIde the no. of layers when first item(--select--) is selected
                             {
                                var ctlno = parseInt(i) + parseInt(plstartno);
					            document.getElementById(td+ctlno).innerText=values[i+2];
                             }
					         fillselect(pctlname,fillctl,qurl);
					}
					alert(tr);
				}
				
                function GetLayerInfo1(gctlname,url,pfillctl,pqurl,startno,totno,ord) /* Retrieve the no.of data for the layers to be shown along with the starting number of the layers*/
				{
				   
				    xmlHttp=GetXmlHttpObject();
				    fillctl=pfillctl;
					qurl=pqurl;
					plstartno=startno;
					pctlname=gctlname;
					order=ord;
					layno=totno;
				    var paramvalue=document.getElementById(gctlname.id).value;
				   if (xmlHttp==null)
					{
						alert ("Browser does not support HTTP Request")
						return
					} 
				    url=url+paramvalue;
				    url=url+'&opt1=layer&opt2=layers'
				    xmlHttp.open("GET",url,false)
				    xmlHttp.onreadystatechange=ShowLayerInfo1
					xmlHttp.send(null)
				}
				
				function ShowLayerInfo1()   //Displays or the Hides no. of Layers
				{
				  if (xmlHttp.readyState==4)
					{ 
					        var str=xmlHttp.responseText.toString();
					        var values=str.split(',');
					        //document.getElementById("hidLayers").value=values[1];
					        //alert(values[1]);
					        //alert(document.getElementById("hidLayers").value);
					        hidealllayers1();
					        for(var i=0;i<values[1]-1;i++) //display the no. of layers
					        {
					            var ctlno = parseInt(i) + parseInt(plstartno);
					            document.getElementById('LTR'+ctlno).style.display="";
					        }
					         if(values.length==1)
					         { 
					           for(var i=0;i<3;i++) //HIde the no. of layers when first item(--select--) is selected
					                {
					                   var ctlno = parseInt(i) + parseInt(plstartno);
					                    document.getElementById('LTR'+ctlno).style.display="None";
					                    //document.getElementById('LTR'+i).style.display="None";
					                }
					         }
					         
					         for(var i=0;i<3;i++) //HIde the no. of layers when first item(--select--) is selected
                             {
                                var ctlno = parseInt(i) + parseInt(plstartno);
					            document.getElementById('LCAP'+ctlno).innerText=values[i+2];
                             }
                             
					         //document.getElementById('LCAP0').innerText=values[2];
					         //document.getElementById('LCAP1').innerText=values[3];
					         //document.getElementById('LCAP2').innerText=values[4];
					         
					         fillselect(pctlname,fillctl,qurl,order);
					}
				}
				
				function ShowLayerInfo()   //Displays or the Hides no. of Layers
				{
				    if (xmlHttp.readyState==4)
					{ 
					        var str=xmlHttp.responseText.toString();
					        var values=str.split(',');
					        //alert(values);
					        hidealllayers();
					       //alert(values[1]-1)
					        for(var i=0;i<values[1]-1;i++) //display the no. of layers
					        {
					          document.getElementById('LTR'+i).style.display="";
					          //alert(document.getElementById('LTR'+i).id);
					        }					        
					         if(values.length==1)
					         { 
					           for(var i=0;i<3;i++) //HIde the no. of layers when first item(--select--) is selected
					                {
					                  document.getElementById('LTR'+i).style.display="None";
					                }
					         }
					         document.getElementById('LCAP0').innerText=values[2];
					         document.getElementById('LCAP1').innerText=values[3];
					         document.getElementById('LCAP2').innerText=values[4];
					         order=' order by vchdivname';					         
					         fillselect(pctlname,fillctl,qurl,order);
					}
				}
				
				
				function RemoveAllOptions(fillctlname)
				{
//				try
//				{
if (fillctlname.type == "text")
  document.getElementById(fillctlname.id).value="";
else
  {
				  for(var i=document.getElementById(fillctlname.id).length;i>0;i--)
					  {
					    document.getElementById(fillctlname.id).remove(i);
//					    if (document.getElementById(fillctlname.id).options[i]!=null)
//					        document.getElementById(fillctlname.id).options[i]=null;
					  } //End For
					  if(document.getElementById(fillctlname.id).length==1)
					     document.getElementById(fillctlname.id).options[0].selectedindex=0;
}
//                }
//                catch(e)
//                {
//                }
//        lctl = document.getElementById(fillctlname.id);
//		var opt = document.createElement("option");
//		opt.value= "0";
//		opt.innerText = "-Select-";
//		lctl.appendChild(opt);

				}
				
				function hidealllayers()
				{
				   for(var i=0;i<3;i++) //HIde all the layers
					                {
					                  document.getElementById('LTR'+i).style.display="None";
					                }
				}
				function hidealllayersDyn(trname)
				{
				   for(var i=0;i<3;i++) //HIde all the layers
					                {
					                  document.getElementById(trname+i).style.display="None";
					                }
				}
				function hidealllayers1()
				{
				   for(var i=0;i<layno;i++) //HIde all the layers
                   {
                        var ctlno = parseInt(i) + parseInt(plstartno)
                        document.getElementById('LTR'+ctlno).style.display="None";
                   }
				}
				
				
				 function wait(millis) 
                    {
                        var date = new Date();
                        var curDate = null;
                        do { curDate = new Date(); } 
                        while(curDate-date < millis);
                    } 
                
    var flag;
    var valOut = "";
  function Exists(ctl,qno,url,msg,fl)
    { 
   
        flag = fl;
        var val=ctl.value;
        val = val.toUpperCase();
        Destctl = ctl;
        Message=msg;
        xmlHttp=GetXmlHttpObject();
        
        url=url + val + '&Qno='+qno;
     
        xmlHttp.open("GET",url,false)
        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
        xmlHttp.onreadystatechange=ShowExists;
        xmlHttp.send(null);
        return valOut;
    }
    
    function ShowExists()
    {
 
        if (xmlHttp.readyState == 4)
        {
            var output = xmlHttp.responseText;
           
//            alert(output);
//            return false;
            
            if (flag == 0)
            {
                if (output > 0)
                {
                    alert(Message +' Already Exists');
                    Destctl.value="";
                    Destctl.focus();
                    valOut = '';
                }
            }
            else if (flag == 1)
            {
                if (output == 0)
                {
                    alert(Message +' does not Exist');
                    Destctl.value="";
                    Destctl.focus();
                    valOut = "false";
                }
                else
                {
                    valOut = "true";
                }
            }
            if (flag == 2)
            {
                if (output != '')
                {
                    valOut = output;
                    return output;
                }
            }
        }
    }
    
    
    
    var FillControl;
  //To fill query result in textbox from a dropdown selceted value 
    function GetOutput(ctl, fillctl, qno, url)
    {          
        FillControl = document.getElementById(fillctl);
         
        var val=ctl.value;        
        xmlHttp=GetXmlHttpObject();
        url=url + "?id=" + val + '&Qno='+qno;
//        alert(url);
        xmlHttp.open("GET",url,false)
        xmlHttp.onreadystatechange=ShowOutput;
        xmlHttp.send(null)
    }
    
    //To fill query result in textbox from two control selceted value 
    function GetOutput2ctl(ctl,ctl1, fillctl,fillctl1,fillctl2,fillctl3, qno, url)
    {    
//     alert("inside");
        var nval=ctl1.value; 
        var id=new Array();
        id=nval.split(':');
        nval=id[1];
        nval=' and intitemid='+trim(nval);
        //nval=trim(nval);       
        FillControl = fillctl;
         FillControl1 = fillctl1;
          FillControl2 = fillctl2;
           FillControl3 = fillctl3;
        //alert(fillctl);       
        var val=ctl.value;        
        xmlHttp=GetXmlHttpObject();
        url=url + "?id="+ val +'&ord='+ nval +'&Qno='+qno;
//   alert(url);
        xmlHttp.open("GET",url,false)
        xmlHttp.onreadystatechange=ShowResult;
        xmlHttp.send(null)
    }
   function ShowResult()
    {
    
        if (xmlHttp.readyState==4)
        {        
            var val = xmlHttp.responseText;
//alert(val);
 var id=new Array();
        id=val.split(',');

                FillControl.value = id[0];
                FillControl1.value = id[1];
                FillControl2.value =id[2];
                FillControl3.value =id[3];
           
        }
    }
  //To fill query result in textbox from a dropdown selceted value with order by 
   function GetOutputOrder(ctl, fillctl, qno, url,order)
    {       
        FillControl = document.getElementById(fillctl);
         
        var val=ctl.value;
        xmlHttp=GetXmlHttpObject();
        url=url + "?id=" + val + '&Qno='+qno +'&order=' +order;
       // alert(url);
        xmlHttp.open("GET",url,false)
        xmlHttp.onreadystatechange=ShowOutput;
        xmlHttp.send(null)
    }
   var FillControl1;
   var FillControl2;
  //To fill query result in lables from a dropdown selceted value 
    function GetlblOutput(ctl, fillctl,fillctl1,fillctl2,url,ord)
    {       
        FillControl = document.getElementById(fillctl);
        FillControl1 = document.getElementById(fillctl1);
        FillControl2 = document.getElementById(fillctl2);
        
        var val=ctl.value;
        xmlHttp=GetXmlHttpObject();
        url=url + val +'&pno='+ 1 + '&ord='+ord;
       //alert(url);        
        xmlHttp.open("GET",url,false)
        xmlHttp.onreadystatechange=ShowlblOutput;
        xmlHttp.send(null)
    }
   //To fill query result in dropdown with order by from a textbox value
   function GetOutputddl(ctlname,pfillctlname,url,ord)
   {                
                fillctlname=document.getElementById(pfillctlname);
                  if(document.getElementById(ctlname.id).value!="")
			       {
			           var uid=document.getElementById(ctlname.id).value;
			            var id=new Array();
                        id=uid.split(':');
                        uid=id[1];
                        uid=trim(uid);                      
			           xmlHttp=GetXmlHttpObject();
    				   
				       if (xmlHttp==null) //If XmlHttpObject Could not be created
					    {
						    alert ("Browser does not support HTTP Request")
						    return
					    }   //End if if (xmlHttp==null)
    					
				        url=url+uid+'&ord='+ord;
				     // alert(url);
				        xmlHttp.open("GET",url,false)
				        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
				   	    xmlHttp.onreadystatechange=stateChanged				   	   
					    xmlHttp.send(null)
					}
					else if (document.getElementById(ctlname.id).value=="")
					 {
					    RemoveAllOptions(fillctlname);
					 }    
					    return false;
   } 
    function ShowOutput()
    {
    
        if (xmlHttp.readyState==4)
        {        
            var val = xmlHttp.responseText;
             //alert(FillControl);
            if (val=='')
            val=0;
           
         
            if (FillControl.type == "text")
                FillControl.value = val;
            else
                FillControl.innerText = val;
        }
    }
    function ShowlblOutput()
    {
    
        if (xmlHttp.readyState==4)
        {
            var val = xmlHttp.responseText.toString();
             var ar=new Array();
			 ar=val.split(',');
         //alert(val);
         //    alert(document.getElementById(fillctl));
         // alert(FillControl.type);
         if (val == '')
           val=0;
            if (FillControl.type == "text")
                FillControl.value = val;
            else
                FillControl.innerHTML = ar[2];
                FillControl1.innerHTML = ar[1];
        }
    }
     function GetOutput1(ctl, fillctl,hidectl, qno, url)
    {
        FillControl = document.getElementById(fillctl);
        HideControl = document.getElementById(hidectl);
        var val=ctl.value;
        xmlHttp=GetXmlHttpObject();
        url=url + "?id=" + val + '&Qno='+qno;
//       alert(url);
        xmlHttp.open("GET",url,false)
        xmlHttp.onreadystatechange=ShowOutput1;
        xmlHttp.send(null)
    }
    
    function ShowOutput1()
    {
        if (xmlHttp.readyState==4)
        {
            var val = xmlHttp.responseText;
         // alert(val);
            if (FillControl.type == "text")
                FillControl.value = val;
            else
                FillControl.innerText = val;
           if (val == '')
               {
                HideControl.style.display="";
                FillControl.style.display="None";
               }
           else
               {
                HideControl.style.display="None";
                FillControl.style.display="";
               }
        }
    }
    
    //For Autocomplete
    
  function autocomplete(txtctl,divctl,url,query,vchOrderBy)
    {
       xmlHttp=GetXmlHttpObject();
        if (xmlHttp==null)
		    {
			    alert ("Browser does not support HTTP Request")
			    return
		    } 
		    
		 if (txtctl.value != '')
		    query=query+ "UPPER('"+ txtctl.value +"%') ORDER BY "+ vchOrderBy +" ";
		 else
		    query=query+ "UPPER('0%') ORDER BY "+ vchOrderBy +" ";
		    
	    url=url+ "?Auto=true&Query="+ query ;
   	    xmlHttp.onreadystatechange=function()
   	    {

                if (xmlHttp.readyState == 4)         
                        {     	

                            //alert(xmlHttp.responseText);
                            if(xmlHttp.responseText=="")	
                                {				
                                divctl.innerHTML ='';
                                divctl.style.display = "none";
                                } 		
                            else				
                                {					
                                 divctl.style.display= "block"; 					
                                 divctl.innerHTML =xmlHttp.responseText;
                              
                                }		
                               	
               	        txtctl.focus();
               	        	
                       }
                       

   	    }
   	    
   	    xmlHttp.open("GET",url,false);
   	    
   	    xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	    xmlHttp.send(null);

  }
  
  
  //Testing
    function Testautocomplete(txtctl,divctl)
    {
       xmlHttp=GetXmlHttpObject();
        if (xmlHttp==null)
		    {
			    alert ("Browser does not support HTTP Request")
			    return
		    } 
		    
	
  
	 url="../autoAjax.aspx?id=" + txtctl.value;
   	    xmlHttp.onreadystatechange=function()
   	    {

                if (xmlHttp.readyState == 4)         
                        {     	

                            
                            if(xmlHttp.responseText=="")	
                                {				
                                divctl.innerHTML ='';
                                divctl.style.display = "none";
                                } 		
                            else				
                                {					
                                 divctl.style.display= "block"; 					
                                 divctl.innerHTML =xmlHttp.responseText;
                              
                                }		
                               	
               	        txtctl.focus();
               	        	
                       }
                       

   	    }
   	    
   	    xmlHttp.open("GET",url,false);
   	    
   	    xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	    xmlHttp.send(null);

  }

    //RadioButton OnChange Dropdownlist Filled
    
    function fillDDL(str,pfillctlname,url) //This function is called in the onChange event of the Radiobutton
				{
			       fillctlname=document.getElementById(pfillctlname);			      
			           var uid=str;
			           xmlHttp=GetXmlHttpObject();
    				   
				       if (xmlHttp==null) //If XmlHttpObject Could not be created
					    {
						    alert ("Browser does not support HTTP Request")
						    return
					    }  
                        url=url+uid;
				        xmlHttp.open("GET",url,false)
				        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
				   	    xmlHttp.onreadystatechange=stateChanged
					    xmlHttp.send(null)

					    return false;
				}
				
//Added by Swetapadma Swain on 12-Mar-2008				
  //=========To fill query result in textbox from a Textbox value ===========	
  var Tctl;
 function fillTextbox(txtctl,filltxt,qry,url)
    {
         FillControl = document.getElementById(filltxt);
         Tctl= document.getElementById(txtctl);
        xmlHttp=GetXmlHttpObject();
        url=url + "?Qry=" + qry;
        // alert(url);
        xmlHttp.open("GET",url,false)
        xmlHttp.onreadystatechange=ShowText;
        xmlHttp.send(null)
    }
  function ShowText()
    {
    
        if (xmlHttp.readyState==4)
        {
            var val = xmlHttp.responseText;
         if (val.length == "11")
           {
            if (FillControl.type == "text")
                if (val=="08 Oct 1900")
                    {
                     FillControl.value = ""; 
                    alert ("Please Enter the Date");
                    Tctl.focus();
                   }
                else
                 FillControl.value = val;
           }
         else
          {
           FillControl.value = "";
            alert ("Please enter a valid Date");
            Tctl.focus();
           }
          
        }
    }
    
    function Exists1(ctl,qno,url,msg,fl)
    {    
        flag = fl;
        var val=ctl.value;
        var valarr=new Array();
        valarr=val.split(':');        
        val=trim(valarr[1]);       
        val = val.toUpperCase();
        Destctl = ctl;
        Message=msg;
        xmlHttp=GetXmlHttpObject();
        url=url + val + '&Qno='+qno;
      //alert(url);
        xmlHttp.open("GET",url,false)
        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
        xmlHttp.onreadystatechange=ShowExists;
        xmlHttp.send(null);
        return valOut;
    }
    
    
//    function ExistsNew(ctl,ctl1,otherField,qno,url,msg,fl)
//    { 
//   
//        flag = fl;
//        var val=ctl.value;
//        var val1= document.getElementById(ctl1).value;
//        val = val.toUpperCase();
//        val1=val1.toUpperCase();
//        Destctl = ctl;
//        Message=msg;
//        xmlHttp=GetXmlHttpObject();
//        url=url + val + ','+ otherField +'&val1='+ val1 +'&Qno='+qno;
//        xmlHttp.open("GET",url,false)
//        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
//        xmlHttp.onreadystatechange=ShowExists;
//        xmlHttp.send(null);
//        return valOut;
//    }
 //******** Modified the Query on 12-06-2009 to add an extra Parameter as Branch Id *********//
 function ExistsNew(ctl,ctl1,otherField,ctlBrnch,fldBrnch,qno,url,msg,fl)
    { 
   
        flag = fl;
        var val=ctl.value;
        var val1= document.getElementById(ctl1).value;
        var val2=document.getElementById(ctlBrnch.id).value;
        val = val.toUpperCase();
        val1=val1.toUpperCase();
        val2=val2.toUpperCase();
        Destctl = ctl;
        Message=msg;
        xmlHttp=GetXmlHttpObject();
        url=url + val + ','+ otherField +'&val1='+ val1 +'&Qno='+qno+'&Val2='+val2+'&fld2='+fldBrnch;
        xmlHttp.open("GET",url,false)
        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
        xmlHttp.onreadystatechange=ShowExists;
        xmlHttp.send(null);
        return valOut;
    }

    //===========================================================================