﻿function ShowSubMenu(show_id,hide_ids)
{
    if(hide_ids != "")
    {
        for(var i=0;i<hide_ids.split(",").length;i++)
        {
            try
            {
                document.getElementById(hide_ids.split(",")[i]).style.display='none';
            }catch(e){}
        }
    }
    
    try
    {
        document.getElementById(show_id).style.display='block';
    }
    catch(e){}
}


function Search_Click()
{
    var str=document.getElementById("SearchStr").value;
    if(str == "")
    {return;}
    location.href ="/Search.aspx?Key="+str;
}

function showBgImage(index)
{
try
{
    document.getElementById("mainnav").getElementsByTagName("A")[index].className="yellow";
}
catch(e){}
}

// JScript 文件
function getCookie (sCookieName)
{
    var sName=sCookieName+"=", ichSt, ichEnd;
    var sCookie=document.cookie;

    if ( sCookie.length && ( -1 != (ichSt = sCookie.indexOf(sName)) ) )
    {
        if (-1 == ( ichEnd = sCookie.indexOf(";",ichSt+sName.length) ) )
            ichEnd = sCookie.length;
        return unescape(sCookie.substring(ichSt+sName.length,ichEnd));
    }
    
    return null;
}
   
function setCookie (sName, vValue)
{
    var argv = setCookie.arguments, argc = setCookie.arguments.length;
    var sExpDate = (argc > 2) ? "; expires="+argv[2].toGMTString() : "";
    var sPath = "; path=/";// (argc > 3) ? "; path="+argv[3] : "";
    var sDomain = (argc > 4) ? "; domain="+argv[4] : "";
    var sSecure = (argc > 5) && argv[5] ? "; secure" : "";
    document.cookie = sName + "=" + escape(vValue,0) + sExpDate + sPath + sDomain + sSecure + ";";
}
    
function deleteCookie (sName)
{
    document.cookie = sName + "=" + getCookie(sName) + "; expires=" + (new Date()).toGMTString() + ";";
}

//------------------------------------

function setProductInqurie(pid,ask)
{
    var oldCookie = getCookie("InquireList")==null?"":getCookie("InquireList");
    if(pid.replace(" ","") != "" && oldCookie.indexOf(pid+",")<0)
    {
        setCookie("InquireList",oldCookie+pid+",");
    }
    if(ask==true)
    {
        if(window.confirm("Inquiry for the product was submitted successfully. Shift to the page of products inquired ?"))
        {
            location.href="/InquiryBasket.aspx";
        }
    }
}

function selectAll()
{
    var cbs = document.getElementsByName("CheckBox_Prod");
    var check_ids = "";
    for(var i=0;i<cbs.length;i++)
    {
        if(cbs[i].checked == true)
        {
            check_ids += cbs[i].value+",";
            setProductInqurie(cbs[i].value,false);
        }
    }
    //alert(getCookie("InquireList"));
    if(check_ids != "")
    {
        if(window.confirm("Inquiry for the product was submitted successfully. Shift to the page of products inquired ?"))
        {
            location.href="/InquiryBasket.aspx";
        }
    }
    else
    {
        alert("Pls select products");
    }
    //
    //event.returnValue = false;
    return false;
}

function pcSearch()
{
    var maxtype=document.getElementById("ProdClassSearch1_drtype");
    var _id = maxtype.options[maxtype.selectedIndex].value;
    var id = _id.replace("max_","").replace("min_","");
    //
    var key = document.getElementById("ProdClassSearch1_KeyText1").value;
    if(_id.indexOf("min")>=0)
    {
        location.href = "/Search.aspx?cid="+id+"&key="+key;
    }
    else if(_id.indexOf("max")>=0)
    {
        location.href = "/Search.aspx?maxid="+id+"&key="+key;
    }
    else
    {
        if(key=="")
        {return;}
         location.href = "/Search.aspx?key="+key;
    }
}
function GetPages(ID,Type)
{
    var xmlhttp;
    try
    {
        xmlhttp = new XMLHttpRequest();
    }
    catch( e )
    {
        xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
    }
    
    xmlhttp.onreadystatechange=function()
    {
        if( 4 == xmlhttp.readyState )
        {
            if( 200 == xmlhttp.status )
            {
               
                var value=xmlhttp.responseText;
                
                try
                {
                document.getElementById("new_btn2").innerHTML=value;
                }catch(e){}
                document.getElementById("new_btn").innerHTML=value;
            }
            else
            {
                return null;
            }
        }
    }
    xmlhttp.open( "post" , "/GetPages.aspx" , true );
    xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    xmlhttp.send("PID="+escape(ID)+"&Type="+escape(Type));
}



function Ajax_getLeave( ControlID , productID ,currentPage )
{
    var xmlhttp;
    try
    {
        xmlhttp = new XMLHttpRequest();
    }
    catch( e )
    {
        xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
    }
    
    xmlhttp.onreadystatechange=function()
    {
        if( 4 == xmlhttp.readyState )
        {
            if( 200 == xmlhttp.status )
            {
               
                var value=xmlhttp.responseText;
                document.getElementById(ControlID).innerHTML=value;
            }
            else
            {
                return null;
            }
        }
    }
    xmlhttp.open( "post" , "/aspx/Ajax.aspx" , true );
    xmlhttp.setRequestHeader( 'Content-type' , 'application/x-www-form-urlencoded' );
    xmlhttp.send( "productID=" + escape( productID ) + "&currentPage=" + escape(currentPage));
}
function Ajax_setLeave(productID,name,email,content)
{

    var xmlhttp;
    try
    {
        xmlhttp = new XMLHttpRequest();
    }
    catch( e )
    {
        xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
    }
    
    xmlhttp.onreadystatechange=function()
    {    
        if( 4 == xmlhttp.readyState )
        {
            if( 200 == xmlhttp.status )
            {
               
                var value=xmlhttp.responseText;
                alert(value);
                //document.getElementById(ControlID).innerHTML=value;
            }
            else
            {
                alert("error");
            }
        }
    }
    xmlhttp.open( "post" , "/aspx/Ajax.aspx" , true );
    xmlhttp.setRequestHeader( 'Content-type' , 'application/x-www-form-urlencoded' );
    xmlhttp.send(  "insert=true&productID=" + escape( productID ) + "&name="+ name + "&email="+email + "&content="+content);
}

function Ajax_getLeave2( ControlID , productID ,currentPage )
{
    var xmlhttp;
    try
    {
        xmlhttp = new XMLHttpRequest();
    }
    catch( e )
    {
        xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
    }
    
    xmlhttp.onreadystatechange=function()
    {
        if( 4 == xmlhttp.readyState )
        {
            if( 200 == xmlhttp.status )
            {
               
                var value=xmlhttp.responseText;
                document.getElementById(ControlID).innerHTML=value;
            }
            else
            {
                return null;
            }
        }
    }
    xmlhttp.open( "post" , "/aspx/Ajax2.aspx" , true );
    xmlhttp.setRequestHeader( 'Content-type' , 'application/x-www-form-urlencoded' );
    xmlhttp.send( "productID=" + escape( productID ) + "&currentPage=" + escape(currentPage));
}
function Ajax_setLeave2(productID,name,email,content)
{

    var xmlhttp;
    try
    {
        xmlhttp = new XMLHttpRequest();
    }
    catch( e )
    {
        xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
    }
    
    xmlhttp.onreadystatechange=function()
    {    
        if( 4 == xmlhttp.readyState )
        {
            if( 200 == xmlhttp.status )
            {
               
                var value=xmlhttp.responseText;
                alert(value);
                //document.getElementById(ControlID).innerHTML=value;
            }
            else
            {
                alert("error");
            }
        }
    }
    xmlhttp.open( "post" , "/aspx/Ajax2.aspx" , true );
    xmlhttp.setRequestHeader( 'Content-type' , 'application/x-www-form-urlencoded' );
    xmlhttp.send(  "insert=true&productID=" + escape( productID ) + "&name="+ name + "&email="+email + "&content="+content);
}



function $(){
	var elements = new Array();
	
	for(var i = 0; i<arguments.length; i++){
		var element=arguments[i];
		if(typeof arguments[i] == 'string'){
			element = document.getElementById(element);
			}
		if(arguments.length == 1){
			return element;
			}
		elements.push(element);		
		}
	return elements;
	}