var s;
var l;
var c=0;
var type1
var m_type = 1;
var rowcount=0;
var response = "";
var CategoryID = 2;
function on_complete()
{    
	if(response == null || response == "")
	{	    
	    s = 2;
		document.getElementById("dv1").style.display="none";
	}
	else
	{	    
	    var offset1
	    if(m_type == 2)
	    { offset1 = document.getElementById("txtFootKey"); }
	    if(m_type == 1)
	    { offset1 = document.getElementById("txtheaderKey"); }
	    var offset2 = document.getElementById("dv1");
	    var width = offset1.offsetWidth;
	    var left = zb(offset1);
	    var top =  Yb(offset1) + offset1.offsetHeight;	    
	    var name1="";
		offset2.style.borser = "black 1px  solid";
		offset2.style.left = left + "px";
		offset2.style.top = (top+1) + "px";
		offset2.style.width = width + "px";	
		l = rowcount;
		s = 1;
		c = l;
		offset2.style.display="block";		
		offset2.innerHTML = response;		
	}
}


function ChangeMenu(index)
{
    CategoryID = index;
}
/*
function createScript()
{
    document.getElementsByTagName("head")[0].appendChild(element); 
    if(CategoryID == 1)
    {
        if(m_type == 2)
        { element.src = "http://searchui.search.mainone.com/mo_company_in.cgi?keyword="+document.getElementById("txtFootKey").value; }
        if(m_type == 1)
        { element.src = "http://searchui.search.mainone.com/mo_company_in.cgi?keyword="+document.getElementById("txtheaderKey").value; }
    }
    if(CategoryID == 2)
    {
        if(m_type == 2)
        { element.src = "http://searchui.search.mainone.com/mo_business_in.cgi?keyword="+document.getElementById("txtFootKey").value; }        
        if(m_type == 1)
        { element.src = "http://211.144.140.131/mo_business_in.cgi?keyword="+document.getElementById("txtheaderKey").value; }
    }
    if(CategoryID == 3)
    {
        if(m_type == 2)
        { element.src = "http://searchui.search.mainone.com/mo_product_in.cgi?keyword="+document.getElementById("txtFootKey").value; }
        if(m_type == 1)
        { element.src = "http://searchui.search.mainone.com/mo_product_in.cgi?keyword="+document.getElementById("txtheaderKey").value; }
        
    }
    element.type = "text/javascript";
    element.language = "javascript";    
}


var element = document.createElement("script");
if(document.all)
{        
    element.onreadystatechange = function()   
    {        
        var state = element.readyState;        
        if (state == "loaded" || state == "interactive" || state == "complete")         
        {            
            writeContent();
        }
    };
}
else 
{  
    document.addEventListener( "DOMContentLoaded",writeContent , false ); 
    //document.addEventListener( "load",writeContent , false ); 
    //element.onload = function()
    //{        
      //  writeContent();
   // };
}
*/
var js ;
var file = "";
function createScript_1()
{   
    if(CategoryID == 1)
    {
        if(m_type == 2)
        { file = "http://searchui.search.mainone.com/mo_company_in.cgi?keyword="+document.getElementById("txtFootKey").value; }
        if(m_type == 1)
        { file = "http://searchui.search.mainone.com/mo_company_in.cgi?keyword="+document.getElementById("txtheaderKey").value; }
    }
    if(CategoryID == 2)
    {
        if(m_type == 2)
        { file = "http://searchui.search.mainone.com/mo_business_in.cgi?keyword="+document.getElementById("txtFootKey").value; }        
        if(m_type == 1)
        { file = "http://searchui.search.mainone.com/mo_business_in.cgi?keyword="+document.getElementById("txtheaderKey").value; }
    }
    if(CategoryID == 3)
    {
        if(m_type == 2)
        { file = "http://searchui.search.mainone.com/mo_product_in.cgi?keyword="+document.getElementById("txtFootKey").value; }
        if(m_type == 1)
        { file = "http://searchui.search.mainone.com/mo_product_in.cgi?keyword="+document.getElementById("txtheaderKey").value; }
        
    }
    var html_doc = document.getElementsByTagName('head')[0];
    js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', file);
    html_doc.appendChild(js); 
    js.onreadystatechange = function () 
    {        
        var state = js.readyState;
        if (state == "loaded" || state == "interactive" || state == "complete")
        {
            writeContent();
        }
    }
    js.onload = function () 
    {
        writeContent();
    }
    return false;
}

function writeContent()
{    
    var keyword = ""; 
    if(m_type == 2){ keyword = document.getElementById("txtFootKey").value;}    
    if(m_type == 1){ keyword = document.getElementById("txtheaderKey").value;}        
    if(keyword == "" || keyword.indexOf("请输入") >=0) { return ;}    
    var strJosn = null;
    if(!window.str_Josn) return;    
    if(typeof(str_Josn) != "undifined" && str_Josn != null)
    {strJosn= str_Josn;}    
    if(strJosn != null || strJosn != "" )
    {        
        response = strJosn[1];
        rowcount = strJosn[2];
        on_complete();        
        //document.getElementsByTagName("head")[0].removeChild(element);
        try
        {
            document.getElementsByTagName("head")[0].removeChild(js);
        }
        finally{js=null;}
    }
}
window.onload = function()
{
    createScript_1();    
}

function mouse_over(arg)
{
    arg.style.color='#ffffff';
    arg.style.background='#2f75d5';
    arg.style.border='solid 1px #1c63cb';    
}
function mouse_out(arg)
{
    arg.style.color='#343434';
    arg.style.background='#ffffff';    
}
function mouse_down(arg)
{    
    if(m_type == 2)
    { document.getElementById("txtFootKey").value=arg.cells[0].innerHTML;}
    if(m_type == 1)
    { document.getElementById("txtheaderKey").value=arg.cells[0].innerHTML;}
}
/*2008-04-10 xlg add End*/
function zb(s)
{
    return kb(s,"offsetLeft")
}
function Yb(s)
{
    return kb(s,"offsetTop")
}
function kb(s,na)
{
    var wb=0;
    while(s)
    {
        wb+=s[na];
        s=s.offsetParent
    }
    return wb
}
function call1(type)
{    
    m_type = type;
 	document.getElementById("dv1").style.display="none";
}

function call2(type)
{    
    if(CategoryID != 1 && CategoryID != 2 && CategoryID != 3) {return;}
    var keyword = "";
    m_type = type;
    if(m_type == 2)
    { keyword = document.getElementById("txtFootKey").value; }
    if(m_type == 1)
    { keyword = document.getElementById("txtheaderKey").value; } 
    if(keyword == "" || keyword.indexOf("请输入") >=0)
	{	    
		document.getElementById("dv1").style.display="none";
		return;
	}	
    createScript_1();   
}
function call_server(event,type) 
{    
    if(CategoryID != 1 && CategoryID != 2 && CategoryID != 3) {return;}
    m_type = type;
	_e = event;
	var e = _e.keyCode ? _e.keyCode : _e.which;	
	if((e!=40)&&(e!=38)&&(e!=13))           //38-Up键;40-Down键;13-Enter回车键
	{	
	    var keyword = "";	    
	    if(m_type == 2)
	    {keyword = document.getElementById("txtFootKey").value;}
	    if(m_type == 1)
	    {keyword = document.getElementById("txtheaderKey").value;}
	    if(keyword != "" &&  keyword.indexOf("请输入") < 0)
	    {	        
		    createScript_1();            
	    }
	    if(keyword == "" || keyword.indexOf("请输入") >= 0)
	    {
    		document.getElementById("dv1").style.display="none";
		}		
	}
	else
	{	    
	    var sgtable = document.getElementById("sg_table");
		type1 = 1;		
		if(e==40&&s==1)
		{			    	    
			if(c==l)
			{		
			    //alert(l);	    
			    //alert(sgtable.rows[0]);
			    sgtable.rows[0].style.background="#2F75D5";
				sgtable.rows[0].style.color="#ffffff";
				sgtable.rows[0].style.border="solid 1px #1c63cb";												
				c=0;
			}
			else if(c==l-1)
			{
			    sgtable.rows[c].style.color="#343434";
				sgtable.rows[c].style.background="#ffffff";
				c=0;
				sgtable.rows[c].style.background="#2F75D5"
				sgtable.rows[c].style.color="#ffffff";
				sgtable.rows[c].style.border="solid 1px #1c63cb";			   
			}
			else
			{			    
			    sgtable.rows[c].style.color="#343434";
				sgtable.rows[c].style.background="#ffffff";
				
				c++;
				sgtable.rows[c].style.background="#2F75D5";
				sgtable.rows[c].style.color="#ffffff";
				sgtable.rows[c].style.border="solid 1px #1c63cb";
				if(m_type == 2)
			    {document.getElementById("txtFootKey").value=sgtable.rows[c].cells[0].innerHTML;}
			    if(m_type == 1)
			    {document.getElementById("txtheaderKey").value=sgtable.rows[c].cells[0].innerHTML;}
		    }		    
		}
		if( e==38 && s==1 )
		{
			if(c==l)
			{
			    sgtable.rows[l-1].style.background="#2F75D5";
				sgtable.rows[l-1].style.color="#ffffff";
				sgtable.rows[l-1].style.border="solid 1px #1c63cb";
				c=l-1;				
			}
			else if(c==0)
			{
			    sgtable.rows[c].style.color="#343434";
				sgtable.rows[c].style.background="#ffffff";
				c=l-1;							
				sgtable.rows[c].style.background="#2F75D5";
				sgtable.rows[c].style.color="#ffffff";
				sgtable.rows[c].style.border="solid 1px #1c63cb";			    
			}
			else
			{
			    sgtable.rows[c].style.background="#ffffff";
				sgtable.rows[c].style.color="#343434";
				c--;
				sgtable.rows[c].style.background="#2F75D5";
				sgtable.rows[c].style.color="#ffffff";
				sgtable.rows[c].style.border="solid 1px #1c63cb";				
			}
			if(m_type == 2)
		    {document.getElementById("txtFootKey").value=sgtable.rows[c].cells[0].innerHTML;}
		    if(m_type == 1)
		    {document.getElementById("txtheaderKey").value=sgtable.rows[c].cells[0].innerHTML;}
		}
		if( e==13&&s==1&&c!=l)
		{
		    if(m_type == 2)
		    {document.getElementById("txtFootKey").value=sgtable.rows[c].cells[0].innerHTML;}		     
		    if(m_type == 1)
		    {document.getElementById("txtheaderKey").value=sgtable.rows[c].cells[0].innerHTML;}
			document.getElementById("dv1").style.display="none";
			type1 = 0;
			event.returnValue="ture";
		}		
	}
}

