﻿function $(TID)
{
    return document.getElementById(TID);
}

	function xstooltip_findPosX(obj) 
	{
	  var curleft = 0;
	  if (obj.offsetParent) 
	  {
		while (obj.offsetParent) 
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}

	function xstooltip_findPosY(obj) 
	{
		var curtop = 0;
		if (obj.offsetParent) 
		{
			while (obj.offsetParent) 
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}

	function xstooltip_show(tooltipId, parentId, posX, posY)
	{
		it = document.getElementById(tooltipId);
		
		if ((it.style.top == '' || it.style.top == 0) 
			&& (it.style.left == '' || it.style.left == 0))
		{
			// need to fixate default size (MSIE problem)
			it.style.width = it.offsetWidth + 'px';
			it.style.height = it.offsetHeight + 'px';
			
			img = document.getElementById(parentId); 
		
			// if tooltip is too wide, shift left to be within parent 
			if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
			if (posX < 0 ) posX = 0; 
			
			x = xstooltip_findPosX(img) + posX;
			y = xstooltip_findPosY(img) + posY;
			
			it.style.top = y + 'px';
			it.style.left = x + 'px';
		}
		
		it.style.visibility = 'visible'; 
	}

	function xstooltip_hide(id)
	{
		it = document.getElementById(id); 
		it.style.visibility = 'hidden'; 
	}

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="+encodeURIComponent(str);
}


//function showBgImage(index)
//{
//try
//{
//    $("mainnav").getElementsByTagName("li")[index].className="here";
//}
//catch(e){}
//}
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){}
}


// 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="+encodeURIComponent(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 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 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!");  
　　　　　　　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);
                //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);
}





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;



//window.onload=function(){
//    
//    var oA=$("i_log");
//    var xmlhttp1;
//    
//    try
//    {
//        xmlhttp1 = new XMLHttpRequest();
//    }

//    catch( e )
//    {
//        xmlhttp1 = new ActiveXObject( "Microsoft.XMLHTTP" );
//    }
//    //alert(oA);
//    
//    xmlhttp1.onreadystatechange=function()
//    {
//        if( 4 == xmlhttp1.readyState )
//        {
//            if( 200 == xmlhttp1.status )
//            {
//               
//                var value=xmlhttp1.responseText;
//                
//                try
//                {
//                    //alert(value);
//                    if(value=="false")
//                    oA.innerHTML="<a href=\"/aspx/login.aspx\">Login</a>";
//                    else{
//                    oA.innerHTML="<a href=\"/aspx/MemberCenter.aspx\">Member Center</a>";
//                    }
//                }catch(e){}
//                
//            }
//            else
//            {
//                alert("There was a problem with the request.");
//            }
//        }
//    }
//    xmlhttp1.open( "post" , "/aspx/UserAjax.aspx" , true );
//    xmlhttp1.setRequestHeader('Content-type','application/x-www-form-urlencoded');
//    xmlhttp1.send("type=check");
//    
//}


//function checkLogin(){

//}

function _getChildren(arr){
    var childs=[];
    for(var i=0;i<arr.length;i++){
    if(arr[i].nodeType==1) childs.push(arr[i]);
    }
    return childs;
}


ads.addEvent(window,"load",function(){
    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;
                var oElemt=document.createElement("div");
				oElemt.innerHTML=value;
				document.body.appendChild(oElemt);
				
				var oScript=document.createElement("script");
				oScript.src="/js/floatBox.js";
				
				document.body.appendChild(oScript);
                //alert(value);
                //document.getElementById(ControlID).innerHTML=value;
            }
            else
            {
                alert("error");
            }
        }
    }
    xmlhttp.open( "post" , "/FloatBox.aspx" , true );
    xmlhttp.setRequestHeader( 'Content-type' , 'application/x-www-form-urlencoded' );
    xmlhttp.send( "timeid="+((new Date()).getTime()+Math.random()));

});




function subNav(navID,maxNavName,minNavName){
	this.navID = navID;
	this.maxNavName = maxNavName;
	this.minNavName = minNavName;
	};
subNav.prototype = {
	maxNav:null,
	minNav:null,
	init:function(){
		this.maxNav = ads.$c(this.maxNavName,'*',this.navID);
		this.minNav = ads.$c(this.minNavName,'*',this.navID);
		},
	regListener:function(maxMenu,minMenu){
		ads.addEvent(maxMenu,'mouseover',function(){minMenu.style.display = 'block';if (!window.XMLHttpRequest) { ads.$("pro_search").style.visibility = "hidden";}})
		ads.addEvent(maxMenu,'mouseout',function(){minMenu.style.display = 'none';if (!window.XMLHttpRequest) { ads.$("pro_search").style.visibility = "visible";}})
		ads.addEvent(minMenu,'mouseover',function(){maxMenu.getElementsByTagName('a')[0].style.backgroundColor="BDCBD4";})
		ads.addEvent(minMenu,'mouseout',function(){minMenu.style.display = 'none';maxMenu.getElementsByTagName('a')[0].style.backgroundColor="";})
		},
	setMenu:function(){
		this.init();
		for(var i=0; i<this.maxNav.length;i++){			
			this.regListener(this.maxNav[i],this.minNav[i]);
			}
		}
	}
	
ads.addEvent(window,'load',function(){
    try
    {
	navObj = ads.$c("subnav","div","left");
    var nav = new subNav(navObj,"maxMenu","minMenu");
    nav.setMenu();
    }
    catch(e)
    {}
    })
