﻿var lang = new Array();
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var is_mac = userAgent.indexOf('mac') != -1;
var ajaxdebug = 0;
var ls = {};
ls.loaded = new Array();
ls.LoadCss=function(src) {
	if(!this.loaded[src]) {
		css = document.createElement('link');
		css.type = 'text/css';
		css.rel = 'stylesheet';
		css.href = src;
		var headNode = document.getElementsByTagName("head")[0];
		headNode.appendChild(css);
		this.loaded[src] =true;
	}
}
ls.LoadScript = function(id, src) {
   if(!this.loaded[src]) {
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.href = src;
		script.attributes["id"]=id;
		var headNode = document.getElementsByTagName("head")[0];
		headNode.appendChild(script);
		this.loaded[src] =true;
	}
}
ls.SelectOption = function(e, value) {
    if (typeof (e) == "string") { e = document.getElementById(e); } else { }
    if (!e) { return; }
    for (var i = 0; i < e.options.length; i++) {
        if (e.options[i].value+"" == value+"") {
            e.selectedIndex = i;
            return;
        }
    }
}
ls.CheckRadioCheckBox = function(e, value) {
    var e = document.getElementsByName(e);
    if (e.length < 1) { return; }
    for (var i = 0; i < e.length; i++) {
        if (e[i].value == value) {
            e[i].checked = true;
            return;
        }
    }
}
function doane(event) {
    e = event ? event : window.event;
    if (is_ie) {
        e.returnValue = false;
        e.cancelBubble = true;
    } else if (e) {
        e.stopPropagation();
        e.preventDefault();
    }
}
ls.FillSelectFromArray = function(e, array, value, text, defaultValue) {
    if (array.length == 0) { return; }
    if (typeof (e) != Object) {
        e = document.getElementById(e);
    }
    if (!e) { return; }
    for (var i = 0; i < array.length; i++) {
        e.options[i] = new Option(array[i][text], array[i][value]);
    }
}
ls.$ = function(e) {
    if (typeof (e) == "string") { return document.getElementById(e); }
    return e;
}
ls.setCookie = function(key, value) {
    document.cookie = key + "=" + encodeURI(value);
}
ls.getCookie=function(str){
	 var tmp,reg=new RegExp("(^| )"+str+"=([^;]*)(;|$)","gi");
	 if(tmp=reg.exec(unescape(document.cookie)))return(tmp[2]);
	 return "";
}
ls.ReadCookie = function(str1, str3) {
    try {
        var cookie = ls.getCookie(str1).split("&");
        for (i = 0; i <= cookie.length; i++) {
            if (cookie[i].split("=")[0] == str3) { return cookie[i].split("=")[1] }
        }
    }
    catch (e) {
        return "";
    }
    return cookie;
}
ls.Area = function(p, c, pv, cv) {
    p = ls.$(p); c = ls.$(c);
    for (var i = 0; i < state.length; i++) {
        p.options[i] = new Option(state[i][1], state[i][0]);
    }
    p.options[p.options.length] = new Option("请选择省份", "");
    p.selectedIndex = p.options.length - 1;
    ls.SelectOption(p, pv);
    p.onchange = function() {
        c.options.length = 0;
        if (p.value == "") { c.options[0] = new Option("请先选择省份", ""); return; }
        else { c.options[0] = new Option("所有城市", "");  }
        for (var i = 0; i < city.length; i++) {
            if (city[i][2] == p.value) {
                c.options[c.options.length] = new Option(city[i][1], city[i][0]);
            }
        }
    }
    if (pv) {
        p.onchange();
        ls.SelectOption(c, cv);
    }
}
ls.CheckForm = function(e) {
    
}
ls.CheckInput = function(e, popstr) {
    e = ls.$(e);
    if (e.value == "") {
        alert(popstr);
        e.focus();
        return false;
    }
    return true;
}
ls.ReplaceAll = function(str, sptr, sptr1) {
    while (str.indexOf(sptr) >= 0) {
        str = str.replace(sptr, sptr1);
    }
    return str;
}
var changestyle=function() {
    try {
        $(".nav_color").find("a").click(function() {
            var color = $(this).attr("href").split('#')[1];
            var host = location.host.replace(location.host.split('.')[0] + ".", "");
            document.cookie = "skin=" + color + ";path=/;domain=" + host;
            $("#mainStyle").attr("href", "http://www." + host + "/style/" + color + "/" + color + ".css");
            return false;
        });
    } catch (e) { }
}
setTimeout("changestyle()", 1000);