function Cookie(){
	Cookie.GetCookie = function(name){   
		var arg = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		var j = 0;
		while(i < clen){
			j = i + alen;
			if(document.cookie.substring(i, j) == arg)
				return Cookie.GetCookieVal(j);
			i = document.cookie.indexOf(" ", i) + 1;
			if(i == 0) break;
		}
		return null;
	}
	Cookie.GetCookieVal = function(offset) {   
		var endstr = document.cookie.indexOf (";", offset);
		if(endstr == -1) endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
	Cookie.DeleteCookie = function(name) {   
		var exp = new Date();
		var cval = Cookie.GetCookie(name);
		exp.setTime(exp.getTime() - 1);
		document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	}
	Cookie.SetCookie = function(name, value, days) {
		var path = "/";
		var domain = null;
		var secure = false;
		var expires = new Date();
		Cookie.DeleteCookie(name);
		expires.setTime(expires.getTime() + (days * 86400000));
		document.cookie = name + "=" + value + "; expires=" + expires.toGMTString() + ((domain == null) ? "" : ("; domain=" + domain)) + ((path == null) ? "" : ("; path=" + path)) +  ((secure == true) ? "; secure" : "");
	}
}Cookie();

//设置菜单
function SetPhoneTypeSelect(mainID, expandID, menuID, con1, con2, btn_return, btn_jump1, btn_jump2){
	var url = "http://www.pandaapp.com/script/download_phoneType.js";
	var charset = "utf-8";
	var cookieDays = 30;
	var typeInfo = [
		{ name:"Windows Mobile", menu:"window mobile", url:"http://download.pandaapp.com/?app=soft&controller=wm&psys=ppc" },
		{ name:"Android", menu:"android", url:"http://download.pandaapp.com/?app=soft&controller=android" },
		{ name:"Symbian", menu:"symbian", url:"http://download.pandaapp.com/?app=soft&controller=s60&psys=3" },
		{ name:"iPhone", menu:"iphone", url:"http://download.pandaapp.com/?app=soft&controller=iphone" }
	];
	
	var script = document.createElement("script"), main = document.getElementById(mainID), expand = document.getElementById(expandID), menu = document.getElementById(menuID), items, mobile_info = Cookie.GetCookie("mobile_info"), mobile_url = Cookie.GetCookie("mobile_url"), temp, btn = document.getElementById(btn_return), jump1 = document.getElementById(btn_jump1), jump2 = document.getElementById(btn_jump2);
	con1 = document.getElementById(con1);con2 = document.getElementById(con2);
	if(menu) items = menu.getElementsByTagName("li");
	if(con1 && con2){
		if(mobile_info && mobile_url){
			con2.style.display = "block";
			con1.style.display = "none";
			for(var i = 0; i < typeInfo.length; i++)
				if(typeInfo[i].name == mobile_info) temp = typeInfo[i];
				
		}else{
			con2.style.display = "none";
			con1.style.display = "block";
		}
	}
	if(btn) btn.onclick = function(){ con2.style.display = "none"; con1.style.display = "block"; Cookie.DeleteCookie("mobile_info"); Cookie.DeleteCookie("mobile_url"); }
	if(jump1) jump1.onclick = function(){ if(mobile_url) window.location.href = mobile_url; else alert("Please select your cell phone model"); }
	if(jump2) jump2.onclick = function(){ if(mobile_url) window.location.href = mobile_url; else alert("Please select your cell phone model"); }
	script.setAttribute('type', 'text/javascript');
	script.setAttribute("src", url);
	script.setAttribute("charset", charset);
	function mouseselect(){
		var msg = document.createElement("option");
		msg.innerHTML = "Select phone model";expand.innerHTML = "";
		expand.appendChild(msg);
		if(!phoneType) return;
		for(var i = 0; i < phoneType.length; i++)
			if(i == this.value){
				for(var k = 0; k < phoneType[i].type.length; k++){
					msg = document.createElement("option");
					msg.value = phoneType[i].type[k].platform;
					msg.innerHTML = phoneType[i].type[k].name;
					expand.appendChild(msg);
				}
				break;
			}
	}
	function expandSelect(){
		if(typeInfo){
			for(var i = 0; i < typeInfo.length; i++)
				if(typeInfo[i].name == this.value){
					temp = typeInfo[i];
					mobile_url = temp.url;
					Cookie.SetCookie("mobile_info", temp.name, cookieDays);
					Cookie.SetCookie("mobile_url", temp.url, cookieDays);
				}
		}
	}
	function ajaxCallBack(){
		var state = this.readyState, returnValue, msg = document.createElement("option");
		try{if(!phoneType){ phoneType = null; }}catch(err){ return; }
		main.innerHTML = "";
		msg.innerHTML = "Select phone brand"; main.appendChild(msg);
		for(var i = 0; i < phoneType.length; i++){
			msg = document.createElement("option")
			msg.value = i;
			msg.innerHTML = phoneType[i].name;
			main.appendChild(msg);
		}
		main.onchange = mouseselect;
		expand.onchange = expandSelect;
	}
	document.getElementsByTagName("head")[0].appendChild(script);
	script.onreadystatechange = ajaxCallBack;
	script.onload = ajaxCallBack;
}

/* left&right ad */
function setBgGG(pageWidth,imgLink,imgWidth,imgHeight,topBlank){
		/* 参数说明
			pageWidth：网页宽度
			imgLink：背景广告链接
			imgWidth：背景广告单图宽度
			imgHeight：背景广告高度
			topBlank：背景广告上补边高度
			以上高度及宽度均必须使用整数值，例如38，不允许使用“38px”
		*/
		var isIE6 = navigator.appVersion.indexOf("MSIE 6") > -1;
		var ishtm = document.documentElement.clientHeight <= 0;
		var positionWidth = parseInt((document.body.scrollWidth - pageWidth) / 2 - imgWidth - 2);
		var blankWidth = null;
		if(isIE6 || ishtm)
			document.writeln("<style type=\"text/css\">#bg_divl,#bg_divr{position: absolute;botttom: auto;clear: both;top:expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop+" + topBlank + " : document.body.scrollTop+" + topBlank + ");cursor:pointer;height:" + imgHeight + "px;}#bg_divl{left:" + positionWidth + "px;}#bg_divr{right:" + positionWidth + "px;}</style>");
		else
			document.writeln("<style type=\"text/css\">#bg_divl,#bg_divr{position:fixed;height:" + imgHeight + "px; top:" + topBlank + "px;cursor:pointer; }#bg_divl{left:" + positionWidth + "px;}#bg_divr{right:" + positionWidth + "px;}</style>");
		document.writeln("<div id=\"bg_divl\"><\/div><div id=\"bg_divr\"><\/div>");
		var divl = document.getElementById("bg_divl");
		var divr = document.getElementById("bg_divr");
		divl.onclick = goLink;
		divr.onclick = goLink;
		var documentWidth = null;
		var clientDivHeight = null;
		function setPosition(){
			documentWidth = (ishtm) ? document.documentElement.scrollWidth : document.body.scrollWidth;
			blankWidth = parseInt(documentWidth - pageWidth) / 2;
			blankWidth = (ishtm) ? blankWidth - 8 : blankWidth;
			positionWidth = blankWidth - imgWidth - 2;
			if(blankWidth < 0){ blankWidth = 0; }
			if(blankWidth >= imgWidth){
				divl.style.width = imgWidth +"px";
				divr.style.width = imgWidth +"px";
				divr.style.right = positionWidth.toString() + "px";
				divl.style.left = positionWidth.toString() + "px";
			}
			else{
				divr.style.right = "0px";
				divl.style.left = "0px";
				divl.style.width = blankWidth.toString() + "px";
				divr.style.width = blankWidth.toString() + "px";
			}
			if(isIE6 || ishtm){
				clientDivHeight = (ishtm) ? document.body.clientHeight : document.documentElement.clientHeight;
				if(clientDivHeight < (imgHeight + topBlank)){
					clientDivHeight = (clientDivHeight - topBlank - 2) + "px";
					divl.style.height = clientDivHeight;
					divr.style.height = clientDivHeight;
				}
			}
		}
		window.onresize = setPosition;
		function goLink(){ window.open(imgLink); }
		setPosition();
	}
	





function Bgad() {
    var d = this;
    var l, f, b, h;
    var a = 1;
    var g = {
        id: "newbgad",
        width: "1002px",
        margin: "0 auto",
        position: "relative"
    };
    function e() {
        var o = document.createElement("div");
        o.id = g.id;
        o.style.width = g.width;
        o.style.position = g.position;
        o.style.margin = g.margin;
        return o
    }
    function m(q, p, o) {
        q.appendChild(p);
        q.appendChild(o);
        document.body.style.overflowX = "hidden";
        document.body.style.position = "relative";
        document.body.insertBefore(q, document.body.childNodes[0])
    }
    function n(o, p) {
        ad = document.createElement("div");
        ad.id = p;
        ad.style.position = "absolute";
        ad.style.cursor = "pointer";
        ad.style.backgroundImage = "url(" + b + ")";
        ad.style.backgroundRepeat = "no-repeat";
        ad.style.backgroundAttachment = "fixed";
        ad.onclick = function() {
            window.open(o)
        };
        return ad
    }
    function c(r, o) {
        var s, q, t, p;
        if (document.all) {
            s = Math.abs(document.body.clientWidth - 1002) / 2 - 4;
            q = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
            p = Math.max(document.body.scrollTop, document.documentElement.scrollTop)
        } else {
            s = Math.abs(document.documentElement.clientWidth - 1002) / 2 - 4;
            q = document.documentElement.clientHeight;
            p = document.documentElement.scrollTop
        }
        if (document.compatMode != "CSS1Compat") {
            q = document.body.clientHeight;
            p = document.body.scrollTop
        }
        t = document.body.scrollHeight;
		
		var topblank1=(p<h)?p-h:0;
		var top1=p-topblank1;
		
        r.style.top = top1+"px";
        r.style.width = s + "px";
        if (t == (p + q)) {
            t = (document.all && h == null) ? (t - 0) : (t - 0)
        }
		
        r.style.height = t - top1 + "px";
        r.style.left = "-" + s + "px";
        o.style.width = r.style.width;
        o.style.height = r.style.height;
        o.style.right = r.style.left;
        o.style.top = r.style.top;
        r.style.backgroundPosition = Math.ceil(s - 219 + 4) + "px " + ((p <= h) ? h-p+"px": "0");
        if (window.XMLHttpRequest) {
            o.style.backgroundPosition = r.style.backgroundPosition
        } else {
			r.style.backgroundPosition = Math.ceil(s - 219 + 4) + "px " + (-p)+"px" ;
            o.style.backgroundPosition = "-1222px " +  (-p)+"px" ;
        }
    }
    function k() {
        return window.screen.width > 1024 ? true: false
    }
    this.init = function(t, r, o, s) {
        l = t;
        f = r;
        b = o;
        h = s;
        if (!k()) {
            return
        }
        var u = e();
        var q = n(l, "leftad");
        var p = n(f, "rightad");
        m(u, q, p);
        if (document.all) {
            window.attachEvent("onload",
            function() {
                c(q, p)
            });
            if (window.XMLHttpRequest) {
                window.attachEvent("onscroll",
                function() {
                    c(q, p)
                })
            }
            window.attachEvent("onresize",
            function() {
                c(q, p)
            })
        } else {
            window.addEventListener("load",
            function() {
                c(q, p)
            },
            false);
            window.addEventListener("scroll",
            function() {
                c(q, p)
            },
            true);
            window.addEventListener("resize",
            function() {
                c(q, p)
            },
            true)
        }
    }
}
/* / left&right ad */



