// JScript File

function popup(sqlstr,id,txt,txtid,valid,re)
{
    if(re==null || re=='undefined')
    {
        re='0';
    }
    var win=window.open("PopUp.aspx?sqlstr=" + sqlstr + "&id=" + id + "&txt=" + txt + "&txtid=" + txtid + "&txtval=" + valid + "&orderby=" + txt + "&re=" + re,'popup','scrollbar=1,toolbar=0,menubar=0,resizable=1,status=1,width=370,height=525');
    win.focus();
}

function openForm(url,Name,Param)
{
	var win=window.open(url,Name,Param);
	win.focus();
}

function openForm1(url,Name,Param)
{
	window.showModalDialog(url,Name,Param);
}

function conf(msg)
{
           return confirm(msg);
}


// JScript File
 
 var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
 var AutoStatus=0;
 var AutoList, AutoTxtbox, AutoHdnfield;
 
//Then, the loadXML() function loads a particular .xml file: 

function AutoloadXML(xmlFile) {
        xmlDoc.async="false";
        xmlDoc.onreadystatechange=Autoverify;
        xmlDoc.load(xmlFile);
}

//The loadXML() function then references the verify() function: 

function Autoverify() { 
        if(xmlDoc.readyState!=4)
                return false; 
       
}

function Autotraverse(tree,txtfield,idfield) 
{
				AutoList.options.length=0;
				if (tree!=null || tree!='undefined')
				{
					for(var i=0; i<tree.childNodes.length; i++)
					{
					AutoList.options.length ++;
					AutoList.options[i].text=tree.childNodes[i].getAttribute(txtfield);    
					AutoList.options[i].value=tree.childNodes[i].getAttribute(idfield);    
					AutoList.options[i].style.color='#000099';
					}
				}
                if(AutoTxtbox.value.length>0 )
					AutoList.selectedIndex=0;
				else
					AutoList.selectedIndex=-1;
            
}

function AutoComplete(sql,txtfield,idfield,orderfield)
{
//alert(this.event.keyCode);
if(this.event.keyCode==9 || this.event.keyCode==16)
return false;

	var obj=AutoTxtbox;
	var	  objLeft   = obj.offsetLeft;
     var     objTop    = obj.offsetTop;
      var    objParent = obj.offsetParent;
          
          while( objParent.tagName.toUpperCase() != "BODY" )
          {
            objLeft  += objParent.offsetLeft;
            objTop   += objParent.offsetTop;
            objParent = objParent.offsetParent;
          }
		AutoList.style.left=objLeft+1; 
		AutoList.style.top=objTop+18;
		AutoList.style.display='block';
		if(AutoStatus==0)
		{	
			AutoList.selectedIndex=0;
			AutoStatus=1;
		}	
		else
		{	
		if(this.event.keyCode==38 || this.event.keyCode==40)
			return false;
		}
		if(orderfield==null)
			orderfield=txtfield;
        AutoloadXML("WebService.asmx/GetyPopUpData?SqlStr=" + sql + "'" +   AutoTxtbox.value + "%' order by " + orderfield + " for xml RAW");
			 var doc=xmlDoc.documentElement;
			// alert(doc);
			Autotraverse(doc,txtfield,idfield);       
}

function Autotxtfocus(txt,hdn)
{
	//AutoList=document.getElementById('AutoLstValue');
	if(AutoList)
	{
	//AutoList=document.getElementById('AutoLstValue')
	}
	else
	{
	 //document.body.appendChild(AutoList);
	 AutoList=document.getElementById('AutoLstValue')
	}
	AutoTxtbox=document.getElementById(txt);
	//alert(AutoTxtbox);
	if(hdn==null)
		AutoHdnfield=null;
	else
		AutoHdnfield=document.getElementById(hdn);
}

function Autokdown()
{
	if(this.event.keyCode==27)
		return false;

    if(AutoList.length>0)
    {
		if(this.event.keyCode==38)
		{
			if(AutoList.selectedIndex>0)
			{
			AutoList.selectedIndex--;
			}
			else 
			{
				AutoList.selectedIndex=AutoList.length-1;
			}
			return false;
		}
		else if(this.event.keyCode==40)
		{
			if(AutoList.selectedIndex<AutoList.length-1)
			{
				AutoList.selectedIndex++;
			}
			else
			{
				AutoList.selectedIndex=0;
			}
	        
			return false;
		}
    }
       
}

function Autotxtblur()
{
	if(AutoStatus==1)
	{
		AutoStatus=0;
		AutoList.style.display='none';
		if(AutoList.selectedIndex<0)
		{
			AutoTxtbox.value='';
			if(AutoHdnfield!=null) AutoHdnfield.value=0;
			return false;
		}
		AutoTxtbox.value=AutoList.options.item(AutoList.selectedIndex).text;
		if(AutoHdnfield!=null)
		{
			AutoHdnfield.value=AutoList.options.item(AutoList.selectedIndex).value;
		}
	}
}
