﻿function $(TID)
{
    return document.getElementById(TID);
}

function ShowSubMenu(show_id,hide_ids)
{
    if(hide_ids != "")
    {
        for(var i=0;i<hide_ids.split(",").length;i++)
        {
            try
            {
                $(hide_ids.split(",")[i]).style.display='none';
            }catch(e){}
        }
    }
    
    try
    {
        $(show_id).style.display='';
    }
    catch(e){}
}


function Search_Click()
{
    var str=$("SearchStr").value;
    if(str == "")
    {return;}
    location.href ="/aspx/Search.aspx?Key="+encodeURI(str);
}



// 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)
{
if(ask == true){
    setCookie("InquireList",pid+",");
    location.href="/aspx/Products_Feedback.aspx";
}else{
    var oldCookie = getCookie("InquireList")==null?"":getCookie("InquireList");
    if(pid.replace(" ","") != "" && oldCookie.indexOf(pid+",")<0)
    {
        setCookie("InquireList",oldCookie+pid+",");
    }
}
}

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);
        }
    }
    if(check_ids != "")
    {
            //location.href="/aspx/InquiryBasket.aspx";
            location.href="/aspx/Products_Feedback.aspx";
    }
    else
    {
        alert("Pls select products");
    }
    //
    //event.returnValue = false;
    return false;
}


function pcSearch()
{
    var maxtype= $("ProdClassSearch1_drtype");
    var _id = maxtype.options[maxtype.selectedIndex].value;
    //
    var key = document.getElementById("ProdClassSearch1_KeyText1").value;
    if( key=="" && _id == "")
    {return;}
    location.href = ("/aspx/Search.aspx?TypeID="+_id+"&key="+encodeURI(key));
    
}
function pcSearch2()
{
    var maxtype= $("ProdClassSearch2_drtype");
    var _id = maxtype.options[maxtype.selectedIndex].value;
    //
    var key = document.getElementById("ProdClassSearch2_KeyText1").value;
    if( key=="" && _id == "")
    {return;}
    location.href = ("/aspx/Search.aspx?TypeID="+_id+"&key="+encodeURI(key));
    
}
function clickThisImg(Name)
{
    
    $("Img").src="/UserFiles/Image/"+Name;
}

function chgH3_Style(id)
{
    try
    {  
    $( id ).className="here";
    }catch(e){}
}

function chgH4_Style(id)
{
    try
    {  
    $( id ).className="here";
    }catch(e){}
}

function showContent(obj,a_id)
{
    var ps = "p_Description,p_Specification,p_Picture,p_Case";
    for(var i=0;i<ps.split(",").length;i++)
    {
        try
        {
            $(ps.split(",")[i]).style.display = "none";
        }
        catch(e){}
    }
    obj.style.display = "block";
    
    //
    var as="a_show_Description,a_show_Specification,a_show_Picture,a_show_Case,";//background:#EBF1F8; color:#2E3192;
    for(var i=0;i<as.split(",").length;i++)
    {
        try
        {
            $(as.split(",")[i]).style.background = "#7298CB";
            $(as.split(",")[i]).style.color = "#FFFFFF";
        }
        catch(e){}
    }
    $(a_id).style.backgroundColor = "#EBF1F8";
    $(a_id).style.color = "#2E3192";
    try{
    window.event.returnValue =false;
    }catch(e){}
    return false;
}
function AddClick( ID , TYPE )
{
    var url="<iframe width=0 height=0 style='display:none' src='/aspx/AddClick.aspx?TYPE="+TYPE;
    url+="&IDentityID=";
    url+=ID;
    url+="'></iframe>";
    document.write(url);
}
function AjaxGetPro_Next( ControlID , ObjectID , 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;
                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( "IdentityID=" + escape( ObjectID ) + "&Type=" + escape( Type ) );
}
function AjaxGetRemmProd( ControlID , ObjectID )
{
    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( "GetREMMPROD=" + escape( ObjectID ));
}

function AjaxPageClass( control,pars ){
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(control).innerHTML=value;
                }catch(e){}
                
            }
            else
            {
                return null;
            }
        }
    }
    xmlhttp.open( "post" , "/aspx/AjaxGetPages.aspx" , true );
    xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    xmlhttp.send(pars);
}


// JavaScript Document
(function(){

//ADS命名空间
if(!window.ads){window['ads'] = {}}

//检查js是否能正确运行
function runCheck(other){
	if(other===false 
	   || !Array.prototype.push
	   || !Object.hasOwnProperty
	   || !document.createElement
	   || !document.getElementsByTagName
	   ){
		return false;
		}
	return true;
	}
window['ads']['runCheck'] = runCheck;

//根据ID获取元素，可同时获取多个
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;
	}
window['ads']['$'] = $;

//根据Class获取元素
function $c(className,tag,parent){
	parent = parent || document;
	tag = tag || '*';
	if(!(parent = $(parent))){return false;}
	
	//查找匹配标签
	var allTags = (tag == "*" && parent.all) ? parent.all : parent.getElementsByTagName(tag);
	
	var elements = new Array();
	
	//正则表达式，判断className是否正确
	className = className.replace(/\-/g,"\\-");
	var regex = new RegExp("(^|\\s)" + className + "(\\s|$)");
	
	var element;
	for(var i=0;i<allTags.length;i++){
		element = allTags[i];
		if(regex.test(element.className)){
			elements.push(element);
			}
		}
	if(elements.length == 1) return elements[0];
	return elements;
	}
window['ads']['$c'] = $c;

//根据html标签获取元素
function $t(tag,parent){
	parent = parent || document;
	tag = tag || '*';
	if(!(parent = $(parent))){return false;}
	
	//查找匹配标签
	var allTags = (tag == "*" && parent.all) ? parent.all : parent.getElementsByTagName(tag);
	
	var elements = new Array();
	
	if(allTags.length == 1){return allTags[0]};
	
	for(var i=0;i<allTags.length;i++){
		elements.push(allTags[i]);
		}
	return elements;
	}
window['ads']['$t'] = $t;



function getRequestObject(url,options) {
    // Initialize the request object
    var req = false;
    if(window.XMLHttpRequest) {
        var req = new window.XMLHttpRequest();
    	}
	else if (window.ActiveXObject) {
        var req = new window.ActiveXObject('Microsoft.XMLHTTP');
    	}
    if(!req) return false;

    options = options || {};
    options.method = options.method || 'GET';
    options.send = options.send || null;

    req.onreadystatechange = function() {
        switch (req.readyState) {
            case 1:
                // 载入中                
                if(options.loadListener) {
                    options.loadListener.apply(req,arguments);
                }
                break;
            case 2:            
                // 载入完成
                if(options.loadedListener) {
                    options.loadedListener.apply(req,arguments);
                }
                break;
            case 3:
                // 交互
                if(options.ineractiveListener) {
                    options.ineractiveListener.apply(req,arguments);
                }
                break;
            case 4:
				//载入完成，如果失败抛出异常				
                try { 
                if (req.status && req.status == 200) {
                    var contentType = req.getResponseHeader('Content-Type');
					//通过正则提供Content-Type(contentType可能存在其它字符，如charset=utf-8)
                    var mimeType = contentType.match(/\s*([^;]+)\s*(;|$)/i)[1];
                                        
                    switch(mimeType) {
                        case 'text/javascript':
                        case 'application/javascript':
 
                            if(options.jsResponseListener) {
                                options.jsResponseListener.call(
                                    req,
                                    req.responseText
                                );
                            }
                            break;
                        case 'application/json':

                            if(options.jsonResponseListener) {
                                try {
                                    var json = parseJSON(
                                        req.responseText
                                    );
                                } catch(e) {
                                    var json = false;
                                }
                                options.jsonResponseListener.call(
                                    req,
                                    json
                                );
                            }
                            break;
                        case 'text/xml':
                        case 'application/xml':
                        case 'application/xhtml+xml':
						
                            if(options.xmlResponseListener) {
                                options.xmlResponseListener.call(
                                    req,
                                    req.responseXML
                                );
                            }
                            break;
                        case 'text/html':                            
                            if(options.htmlResponseListener) {                                
                                options.htmlResponseListener.call(
                                    req,
                                    req.responseText
                                );
                            }
                            break;
                    }
                
                    if(options.completeListener) {
                        options.completeListener.apply(req,arguments);
                    }

                } else {
                    if(options.errorListener) {
                        options.errorListener.apply(req,arguments);
                    }
                }
                

                } catch(e) {
                    alert('Response Error: ' + e);
                }
                break;
        }
    };
    req.open(options.method, url, true);

    req.setRequestHeader('X-ADS-Ajax-Request','AjaxRequest');
    return req;
}
window['ads']['getRequestObject'] = getRequestObject;


function ajaxRequest(url,options) {
    var req = getRequestObject(url,options);
    return req.send(options.send);
}
window['ads']['ajaxRequest'] = ajaxRequest;
//END


//添加、移除事件
function addEvent(node,type,listener){
	if(!runCheck()){return false;}
	if(!(node = $(node))){return false;}
	
	//W3C添加事件方法
	if(node.addEventListener){
		node.addEventListener(type,listener,false);
		return true;
		}
	//MSIE添加事件方法
	else if(node.attachEvent){
		node['e'+type+listener] = listener;
		node[type+listener] = function(){
			node['e'+type+listener](window.event);
			}
		node.attachEvent('on'+type,node[type+listener]);
		return true;
		}
	return false;
	}
window['ads']['addEvent'] = addEvent;

function removeEvent(node,type,listener){
	if(!runCheck()){return false;}
	if(!(node = $(node))){return false;}
	
	//W3C添加事件方法
	if(node.removeEventListener){
		node.removeEventListener(type,listener,false);
		return true;
		}
	//MSIE添加事件方法
	else if(node.detachEvent){
		node.detachEvent('on'+type,node[type+listener]);
		node[type+listener] = null;	
		return true;
		}
	return false;
	}
window['ads']['removeEvent'] = removeEvent;

})();

function _getChildren(arr){
    var childs=[];
    for(var i=0;i<arr.length;i++){
    if(arr[i].nodeType==1) childs.push(arr[i]);
    }
    return childs;
}

function showBgImage(index)
{
    try
    {
//        var _par=document.getElementById("mainnav");
//        var _ulChild=_getChildren(_par.childNodes);
//        var _liChild=_getChildren(_ulChild[0].childNodes);
    //    $("mainnav").getElementsByTagName("li")[index].className="here";
        liChild[index].className="here";
        //alert(liChild[index].innerHTML);
    }
    catch(e){}
}



ads.addEvent(window,'load',function(){

	ads.ajaxRequest("/aspx/UserAjax.aspx?type=check",{
		htmlResponseListener:function(req){
		    if(req != "false"){
		    try{
		        //ads.$("loginName").innerHTML = req;
		        ads.$("login_form").innerHTML = ads.$("loginInfo").innerHTML;
		        }catch(e){}
		        }
		    }
		});


    ads.addEvent('sign_in','click',function(){
        var userName = ads.$("userName").value;
        var password = ads.$("password").value;
		ads.ajaxRequest("/aspx/UserAjax.aspx?type=login&UserName=" + userName + "&password="+password,{
			htmlResponseListener:function(req){
			    if(req == "true"){
                try{
			        ads.$("login_form").innerHTML = ads.$("loginInfo").innerHTML;
			        }catch(e){}
			        }
			    else{
			        alert(req);
			        }
			    }
			});
        })
    })
    
    
    
    
    
function checkLogin( control){
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
                {
                alert(value);
                    document.getElementById(control).className=value;
                }catch(e){}
                
            }
            else
            {
                return null;
            }
        }
    }
    xmlhttp.open( "get" , "/aspx/cklog.aspx" , true );
    xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    xmlhttp.send(null);
}



//产品内容品的产品评论脚本
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/MsgAjax.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;
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;  
　　　　　　flag = pattern.test(email);  
　　　　　　if(!flag)  
　　　　　　{  
　　　　　　　alert("Your email address is not correct!");  
　　　　　　　closeAlert();
　　　　　　　return false;  
　　　　　　}
    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);
                closeAlert();
                //document.getElementById(ControlID).innerHTML=value;
            }
            else
            {
                alert("error");
            }
        }
    }
    xmlhttp.open( "post" , "/aspx/MsgAjax.aspx" , true );
    xmlhttp.setRequestHeader( 'Content-type' , 'application/x-www-form-urlencoded' );
    xmlhttp.send(  "insert=true&productID=" + escape( productID ) + "&name="+ name + "&email="+email + "&content="+content);
}
