﻿ // 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)
					            var select2=document.getElementById(fillctlname.id);
					            var ar=new Array();
					            ar=str.split('|');
					            //alert(fillctlname);
					            if(ar.length>1)  //If More than one element retured then add it to the dropdown lists
					            {
               					    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 fillselectold(ctlname,pfillctlname,url) //This function is called in the onChange event of the dropdownlist(without Order by)
				{
			       fillctlname=pfillctlname;
//			      
			       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;
//				        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 fillselectsemester(ctlname,pfillctlname,url) //This function is called in the onChange event of the dropdownlist(without Order by)
				{
			       fillctlname=pfillctlname;                  
                   var regdno=ctlname.value;                                              			      
			       if(regdno.length>0)
			       {
			           var uid=regdno.substring(0,1);			           
			           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;
				        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 (regdno.length==0)
					 {
					    RemoveAllOptions(fillctlname);
					 }    
					    return false;
				}
			function fillselectexam(ctlname,pfillctlname,url) //This function is called in the onChange event of the dropdownlist(without Order by)
				{
			       fillctlname=pfillctlname;                  
                   var regdno=ctlname.value;                                              			      
			       if(regdno.length>0)
			       {
			           var uid=regdno.substring(10,12);
			           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+'&get=id';
				        //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 (regdno.length==0)
					 {
					    RemoveAllOptions(fillctlname);
					 }    
					    return false;
				}
				
			//=========================================================	
				function fillselect(ctlname,pfillctlname,url) //This function is called in the onChange event of the dropdownlist
				{   
			       fillctlname=pfillctlname;
			       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;
//				        alert(url);
//				        return false;
					    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,ord) //This function is called in the onChange event of the dropdownlist(with Order by)
				{				
//				alert(document.getElementById(ctlname.id).value);				
			       fillctlname=pfillctlname;
//		      alert(pfillctlname.id);
//		      alert(url);
			       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;
			      
				        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 = document.getElementById(ctl.id).value;
        val = val.toUpperCase();
        val = Trim(val);
        Destctl = ctl;
        Message = msg;
        xmlHttp = GetXmlHttpObject();
        url = url + "?id=" + 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 Trim(str)
     {  
     while(str.charAt(0) == (" ") )
              {  
              str = str.substring(1);
              }
          while(str.charAt(str.length-1) == " " )
              {  
              str = str.substring(0,str.length-1);
              }
          return str;
    }

    function ShowExists()
    {
 
        if (xmlHttp.readyState == 4)
        {
            var output = xmlHttp.responseText;
           
         
            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=document.getElementById(ctl).value;  
       // alert(document.getElementById(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)
    {    
     
        var nval=ctl1.value; 
        var id=new Array();
        id=nval.split(':');
       
        nval=id[1];
        
        nval=' and intitemid='+trim(nval);
//         alert(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;
        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();
        var params = "lorem=ipsum&name=Santosh";
        url=url + "?id=" + val + '&Qno='+qno +'&order=' +order;
      //alert(url);
//        xmlHttp.open("GET",url,false)
//        xmlHttp.onreadystatechange=ShowOutput;
//        xmlHttp.send(null)
        xmlHttp.open("POST",url,false)
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange=ShowOutput;
        xmlHttp.send(params)	
    }
   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(val);
            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 fillradioselect(ctlname,pfillctlname,url,qno) //This function is called in the onChange event of the Radiobutton
				{				
				//alert(document.getElementById(ctlname.id).value);				
			       fillctlname=pfillctlname;
			   //alert(fillctlname);			      			          
			            var params = "lorem=ipsum&name=Santosh";
                        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 +'&RQno='+qno;
					    //alert(url);
    					xmlHttp.open("POST",url,false)
                        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                        xmlHttp.onreadystatechange=stateChanged;
                        xmlHttp.send(params)				        

				}
    //===========================================================================
    
       function PopUpDDl(ctlname,pfillctlname,dept,url) //This function is called in the onChange event of the dropdownlist without dependency of the dropdownlist
				{
			       fillctlname=pfillctlname;
			      
			       if(document.getElementById(ctlname.id).selectedIndex>0)
			       {

			           xmlHttp=GetXmlHttpObject();
    				   
				       if (xmlHttp==null) //If XmlHttpObject Could not be created
					    {
						    alert ("Browser does not support HTTP Request")
						    return
					    }   //End if if (xmlHttp==null)
    					
    					if (dept==0)
				            url=url+"val=0";
				        else
				            url=url+"val="+dept;
//				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;
				}



 /*Added By Biswaprem on 13-06-08 To Split The value of the control
        Static Query Is Used
    */
    
    function GetOutputVal(ctl, fillctl, Dptid, qno, url)
    {   
        var Qr1 = "select sum(intReceivedQnty)-sum(isnull(intReturnedQnty,0))-(Select sum(intQuantity) from hms_str_dept_issue_detail where intItemId=";
        var Qr2 = "and intIssueId in(Select intIssueId from hms_str_dept_issue_header where vchIssuedDept=";
        var Qr3 = "from HMS_STR_Stock_DeptReceive sr,hms_str_Indent i where sr.intIndentId=i.intIndentId and i.vchdeptid=";
        var Qr4 = "and sr.intItemId=";
        FillControl = document.getElementById(fillctl);
        var val=ctl.value;  // Modified Here    
        var ItemId = new Array();
        ItemId = val.split(':');
        val = ItemId[1];
        var Qry = Qr1 + "'" + val + "'" + Qr2 + "'" + Dptid + "'" + "))" + Qr3 + "'" + Dptid + "'" + Qr4 + "'" + val + "'" ;
        if (val != undefined)
          {
            xmlHttp=GetXmlHttpObject();
//            url=url + "?id=" + val + '&Qno='+qno;
            url=url + "?id=" + val + '&Qno='+Qry + '&Type=Custom';
//            alert(url);
//            return false;
            xmlHttp.open("GET",url,false)
            xmlHttp.onreadystatechange=ShowOutput;
            xmlHttp.send(null)
          }
        
    }
    
    
//=====Added By Swetapadma on 15-Jul-2008 for popup the dropdown/Listbox with dependency over two dropdown==========
	function DdlList(ddlctl1,ddlctl2,lst,fld,url,ord) 
	{				
       fillctlname=lst;
       if(document.getElementById(ddlctl2.id).selectedIndex>0)
       {
           var uid=document.getElementById(ddlctl2.id).value;
           var uid1=ddlctl1.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+'&col='+fld+'&colid='+uid1+'&ord='+ord;
	        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(ddlctl2.id).selectedIndex==0)
		 {
		    RemoveAllOptions(fillctlname);
		 }    
		    return false;
	}

//==========================================================================================================

//=====Added By Swetapadma on 10-Jan-2009 for popup the dropdown with dependency over three dropdown==========
//ddlctl1=First Control
//ddlctl2=Second Control
//ddlctl3=third Control
//lst=Control to be filled
//fld1=the field name of table related to first Control
//fld2=the field name of table related to Second Control
//url=ajaxpage url
//ord=order by col name
	function PopupDropdownlist_3DependCtl(ddlctl1,ddlctl2,ddlctl3,lst,fld1,fld2,url,ord) 
	{				
      fillctlname=lst;
       if(document.getElementById(ddlctl3.id).selectedIndex>0)
       {
           var uid1=ddlctl1.value;
           var uid2=ddlctl2.value;
           var uid3=document.getElementById(ddlctl3.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+uid3+'&col1='+ fld1 +'&val1='+ uid1 +'&col2='+ fld2 +'&val2='+ uid2 +'&ord='+ord ;

	        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(ddlctl2.id).selectedIndex==0)
		 {
		    RemoveAllOptions(fillctlname);
		 }    
		    return false;
	}

//==========================================================================================================
/////////Added By Mithun to check particular text exist or not in database given in a control
function ExistsTextCheck(ctl,ctr2,field,qno,url,msg,fl)
    {          
        flag = fl;
        
         
         var val2=document.getElementById(ctr2).value;
        var val=document.getElementById(ctl).value;
        val = val.toUpperCase();
      
        val=Trim(val);
        Destctl = ctl;
        Message=msg;
        xmlHttp=GetXmlHttpObject();
        
        url=url + val2 + '&Text='+ val +'&field='+ field +'&Qno='+qno;
       alert(url);
        xmlHttp.open("GET",url,false)
        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
        xmlHttp.onreadystatechange=ShowExistsText;
        xmlHttp.send(null);
        return valOut;
    }
    
     function ShowExistsText()
    {
 
        if (xmlHttp.readyState == 4)
        {
            var output = xmlHttp.responseText;
       
            if (flag == 0)
            {
                if (output > 0)
                {
                    alert(Message +' Already Exists');
                    document.getElementById(Destctl).value="";
                     document.getElementById(Destctl).focus();
//                    Destctl.value="";
//                    Destctl.focus();
                    valOut = '';
                    
                }
            }
            else if (flag == 1)
            {
                if (output == 1)
                {
                    alert(Message +' does not Exist');
                    document.getElementById(Destctl).value="";
                     document.getElementById(Destctl).focus();
                    valOut = "false";
                }
                else
                {
                    valOut = "true";
                }
            }
            if (flag == 2)
            {
                if (output != '')
                {
                    valOut = output;
                    return output;
                }
            }
        }
    }
    
    ///////////////////Added By Mithun To Check Duplicate Data In List Box
    var intCntr=0;
    function ExistsListBoxCheck(ctrl,ctr2,field,field1,qno,url,msg,fl)
    { 
       
       
        
         //var val1=document.getElementById(ctr1).value;
          
        var val2=document.getElementById(ctr2).value;
       
//         var val3=document.getElementById(ctr3).value;
//        
//        var val4=document.getElementById(ctr4).value;
       // alert(document.getElementById(ctr1).value);
        
       
        var ruservalues='';
        if (document.getElementById(ctrl).length > 0)
                {
                    for (i=0;i<document.getElementById(ctrl).length;i++)
                        {
                            ruservalues = ruservalues + document.getElementById(ctrl).options[i].value + ','; 
                        }
                }   
         
        flag = fl;
        
         
     
       
        Destctl = ctrl;
        Message=msg;
        xmlHttp=GetXmlHttpObject();
        
        url=url + val2 +'&Subject='+ ruservalues +'&Qno='+ qno;
        
        xmlHttp.open("GET",url,false)
        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
        xmlHttp.onreadystatechange=ShowExistslISTbOX;
        xmlHttp.send(null);
        if(intCntr > 0)
            {
                intCntr = 0;
                return false;
            }
        
    }
  function ShowExistslISTbOX()
    {
 
        if (xmlHttp.readyState == 4)
        {
            var output = xmlHttp.responseText;
       
            if (flag == 0)
            {
                if (output > 0)
                {
                    alert(Message +' Already Exists Under That Discipline,Stream,Semester');
                   // document.getElementById(Destctl).value="";
                   
                   document.getElementById(Destctl).focus();
                    
//                    Destctl.value="";
//                    Destctl.focus();
                    valOut = '';
                    intCntr += 1;
                }               
            }
            else if (flag == 1)
            {
                if (output == 1)
                {
                    alert(Message +' does not Exist');
                    document.getElementById(Destctl).value="";
                     document.getElementById(Destctl).focus();
                    valOut = "false";
                }
                else
                {
                    valOut = "true";
                     return true;
                }
            }
            if (flag == 2)
            {
                if (output != '')
                {
                    valOut = output;
                    return output;
                }
            }
        }
    }
    
    
    /////////////////////////Added By Mithun
    function ExistsTextCheck_SCTEVT(ctl,ctr2,field,qno,url,msg,fl)
    {  
        flag = fl;
        var val2=ctr2;//document.getElementById(ctr2).value;
        var val=document.getElementById(ctl).value;
        val = val.toUpperCase();
      
        val=Trim(val);
        Destctl = ctl;
        Message=msg;
        xmlHttp=GetXmlHttpObject();
        
        url=url + val2 + '&Text='+ val +'&field='+ field +'&Qno='+qno;
        xmlHttp.open("GET",url,false)
        xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
        xmlHttp.onreadystatechange=ShowExistsText;
        xmlHttp.send(null);
        return valOut;
    }