var bIE;
var bMozilla;
var bSafari;
var bOpera;
var nv_ua = navigator.userAgent.toLowerCase();

if(nv_ua.indexOf("msie") != -1){
    bIE=true;
}else if(nv_ua.indexOf("safari") != -1){
    bSafari=true;
}else if(nv_ua.indexOf("opera") != -1){
    bOpera=true;
}else if(nv_ua.indexOf("mozilla") != -1){
    bMozilla=true;
}

function createXmlHttp(){
    var xmlhttp,alerted;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
        try {
            xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
        }catch (e) {
        try {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
        } catch (E) {
            alert("You must have Microsofts XML parsers available")
        }
    }
    @else
        alert("You must have JScript version 5 or above.")
        xmlhttp=false
        alerted=true
    @end @*/
    if (!xmlhttp && !alerted) {
       try {
          xmlhttp = new XMLHttpRequest();
       } catch (e) {
          alert("对不起，你的浏览器不支持xmlhttp。")
       }
    }
    return xmlhttp;
}

function go(strUrl) {
if (xmlhttp) {
  xmlhttp.open("post", strUrl,true);
  xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlhttp.onreadystatechange=RSchange;
  xmlhttp.send(null);
 }
}

function RSchange(){
  if (xmlhttp.readyState==4) {
  }
}

function ge(id){
  el=document.getElementById(id);
  return el;
}

function ges(tagname){
  var elarray = document.getElementsByTagName(tagname);
  return elarray;
}

function updatepos(){
    var tipposition = GetAbsoluteLocationEx(ge('typtip'));
    bbb_outer_div.style.top = tipposition.absoluteTop-200;
    bbb_outer_div.style.left = tipposition.absoluteLeft-550;
}

function closetypetip(event){
    event = event || window.event;
    var objTarget = event.target || event.srcElement;
    if(objTarget.id != 'bbb_outer_div' && objTarget.id != 'bbb_inner_div'){
        if(objTarget.name != 'usertype'){
            try{
                ge('bbb_outer_div').style.display='none';
            }catch(e){
            }
        }
    }
}

document.onclick=closetypetip;

function closetip(tipid){
    ge(tipid).innerHTML = '';
}

function getalertmsg(alertimg,alertmsg,alerttype){
    var strHTML = '';
    if(alerttype=='success'){
        strHTML = strHTML + '<font color="#33cc00">'+ alertmsg+'</font>';
	}else {
        strHTML = strHTML + '<font color="#ff6600">'+ alertmsg+'</font>';
	}
    return strHTML;
}

function irpr(){
    var imgarray = document.getElementsByTagName('img');
    for(var i=0;i<imgarray.length;i++){
        if(imgarray[i].name=='tipimg'){
            if(imgarray[i].src.indexOf('icon_error')>-1){
                return false;
            }
        }
    }
    return true;
}

function showsubmenu(xid){
	var xidx=document.getElementById(xid);
	if(xidx.style.display=="none"){
		xidx.style.display="block";
	}else{
		xidx.style.display="none";
	}
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
    var arVersion = navigator.appVersion.split("MSIE")
    var xversion = parseFloat(arVersion[1])
    if ((xversion >= 5.5) && (document.body.filters))
    {
       for(var j=0; j<document.images.length; j++)
       {
          var img = document.images[j]
          var imgName = img.src.toUpperCase()
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText
             if (img.align == "left") imgStyle = "float:left;" + imgStyle
             if (img.align == "right") imgStyle = "float:right;" + imgStyle
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
             img.outerHTML = strNewHTML
             j = j-1
          }
       }
    }    
}
window.attachEvent("onload", correctPNG);

function selectcountry(id,w,h){
	var ps=getPageSize();
	var xps=ps.split(",");
	var ps1=getPageScroll();
	var xps1=ps1.split(",");
	var hhh=parseInt(xps1[1])+(parseInt(xps[3]/2)-parseInt(h)/2);
	var hhh=150;
	var www=parseInt(xps1[0])+(parseInt(xps[2]/2)-parseInt(w)/2);
	var DIV=document.createElement("div");
	DIV.id="alert_win";
	DIV.style.display="block";
	document.body.appendChild(DIV);
	var xparents=document.getElementById("alert_win");
	xdiv='<div id="mask" class="bg" style="top:0;left:0;position: absolute;z-index:100000;width:100%;height:'+xps[1]+'px;"></div>';
	xdiv=xdiv+'<DIV class=beian_winBG id=beian_popup style="top:'+hhh+'px;left:'+www+'px;width:'+w+'px;height:'+h+'px;">';
	xdiv=xdiv+'<div id="divOneStep" style="z-index:100002;width:100%;height:'+h+'px;position:absolute;">';
	xdiv=xdiv+'<div style="width:100%;height:40px;"><div style="float:left; width:150px; padding:5px;"></div><div style="float:right; width:50px;padding:10px; text-align:right;"><a href="javascript:;" onClick="xclose();"><img src="/zh-cn/images/btn-close.png" border="0" /></a></div></div>';
	xdiv=xdiv+'<div style="padding:40px 50px; 20px 50px;" class="xlan">';
	xdiv=xdiv+'  <div class="clear"><a href="/zh-cn/"><em>China - 简体中文</em></a></div>';
	xdiv=xdiv+'  <div class="clear" style="padding:5px 0px;"><a href="/en/"><em>Global - English</em></a></div>';
	xdiv=xdiv+'</div>';
	xdiv=xdiv+'</div>';
	xdiv=xdiv+'<div style="z-index:100001;position:absolute;"><iframe id="frmOneStep" width="100%" height="200" frameborder="0" scrolling="no" src="about:blank"></iframe></div></DIV>';
	$("#alert_win").append(xdiv);
}

function xclose(){
	var xtip=document.getElementById("alert_win");
	xtip.parentNode.removeChild(xtip);
}

function message(id,rcate){
	var rcontent=document.getElementById("rcontent").value;
	if(rcontent==""){
		ge("xtip").innerHTML="<span class=highlight>留言内容不能为空</span>";
		return false;
	}
	var xmlhttp=createAjax();
	if (xmlhttp) {
		xmlhttp.open('post','/inc/xmessage.asp?id='+id+'&rcate='+escape(rcate)+'&rcontent='+escape(rcontent),true);
		ge("xtip").innerHTML="<img src='/images/loading.gif'>正在处理，请稍候……";
		xmlhttp.onreadystatechange=function() {		 
			if (xmlhttp.readyState==4 && xmlhttp.status==200){
				xtext=xmlhttp.responseText;
				if(xtext=="ok"){
					ge("xtip").innerHTML="提交成功!";
					xclose();
					window.location="message.asp";
					return false;
				}else{
					ge("xtip").innerHTML="提交失败...";
				}
			}else {
			}
		}
	xmlhttp.send(null); 
	}
}

function getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			//arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			arrayPageSize = pageWidth+","+pageHeight+","+windowWidth+","+windowHeight;
			return arrayPageSize;
}

function getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = xScroll+","+yScroll;
			return arrayPageScroll;
}

function delx(id,page) {
	if(confirm('确定删除吗？')){
		window.location=page+"?flag=del&id="+id;
		return false;
	}else{
		return false;				
	}
	return false;
}

