

function ctlent(event) {
	if(postSubmited == false && (event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83)) {
		if(this.document.input.pmsubmit) {
			postSubmited = true;
			this.document.input.pmsubmit.disabled = true;
			this.document.input.submit();
		} else if(validate(this.document.input)) {
			postSubmited = true;
			if(this.document.input.topicsubmit) this.document.input.topicsubmit.disabled = true;
			if(this.document.input.replysubmit) this.document.input.replysubmit.disabled = true;
			if(this.document.input.editsubmit) this.document.input.editsubmit.disabled = true;
			this.document.input.submit();
		}
	}
}

function checkall(form, prefix, checkall) {
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
			e.checked = form.elements(checkall).checked;;
		}
	}
}

function findobj(n, d) {
	var p, i, x;
	if(!d) d = document;
	if((p = n.indexOf("?"))>0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if(x != d[n] && d.all) x = d.all[n];
	for(i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for(i = 0; !x && d.layers && i < d.layers.length; i++) x = findobj(n, d.layers[i].document);
	if(!x && document.getElementById) x = document.getElementById(n);
	return x;
}


function copycode(obj) {
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.scrollIntoView();
	rng.select();
	rng.execCommand("Copy");
	rng.collapse(false);
}

function toggle_collapse(objname) {
	obj = findobj(objname);
	img = findobj(objname+"_img");
	collapsed = getcookie("discuz_collapse");
	cookie_start = collapsed ? collapsed.indexOf(objname) : -1;
	cookie_end = cookie_start + objname.length + 1;

	if(obj.style.display == "none") {
		obj.style.display = "";
		img_re = new RegExp("_yes\\.gif$");
		img.src = img.src.replace(img_re, '_no.gif');
		if(cookie_start != -1) collapsed = collapsed.substring(0, cookie_start) + collapsed.substring(cookie_end, collapsed.length);
	} else {
		obj.style.display = "none";
		img_re = new RegExp("_no\\.gif$");
		img.src = img.src.replace(img_re, '_yes.gif');
		if(cookie_start == -1) collapsed = collapsed + objname + " ";
	}

	expires = new Date();
	expires.setTime(expires.getTime() + (collapsed ? 86400 * 30 : -(86400 * 30 * 1000)));
	document.cookie = "discuz_collapse=" + escape(collapsed) + "; expires=" + expires.toGMTString() + "; path=/";
}

function imgzoom(o) {
	if(event.ctrlKey) {
		var zoom = parseInt(o.style.zoom, 10) || 100;
		zoom -= event.wheelDelta / 12;
		if(zoom > 0) {
			o.style.zoom = zoom + '%';
		}
		return false;
	} else {
		return true;
	}
}

function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

/** 
 * Create a cookie with the given name and value and other optional parameters. 
 * 
 * @example $.cookie('the_cookie', 'the_value'); 
 * @desc Set the value of a cookie. 
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); 
 * @desc Create a cookie with all available options. 
 * @example $.cookie('the_cookie', 'the_value'); 
 * @desc Create a session cookie. 
 * @example $.cookie('the_cookie', null); 
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain 
 *       used when the cookie was set. 
 * 
 * @param String name The name of the cookie. 
 * @param String value The value of the cookie. 
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. 
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. 
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted. 
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained 
 *                             when the the browser exits. 
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). 
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). 
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will 
 *                        require a secure protocol (like HTTPS). 
 * @type undefined 
 * 
 * @name $.cookie 
 * @cat Plugins/Cookie 
 * @author Klaus Hartl/klaus.hartl@stilbuero.de 
 * Get the value of a cookie with the given name. 
 * 
 * @example $.cookie('the_cookie'); 
 * @desc Get the value of a cookie. 
 * 
 * @param String name The name of the cookie. 
 * @return The value of the cookie. 
 * @type String 
 * 
 * @name $.cookie 
 * @cat Plugins/Cookie 
 * @author Klaus Hartl/klaus.hartl@stilbuero.de 
 */ 
jQuery.cookie = function(name, value, options) { 
    if (typeof value != 'undefined') { // name and value given, set cookie 
        options = options || {}; 
        if (value === null) { 
            value = ''; 
            options.expires = -1; 
        } 
        var expires = ''; 
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 
            var date; 
            if (typeof options.expires == 'number') { 
                date = new Date(); 
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 
            } else { 
                date = options.expires; 
            } 
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 
        } 
        // CAUTION: Needed to parenthesize options.path and options.domain 
        // in the following expressions, otherwise they evaluate to undefined 
        // in the packed version for some reason... 
        var path = options.path ? '; path=' + (options.path) : ''; 
        var domain = options.domain ? '; domain=' + (options.domain) : ''; 
        var secure = options.secure ? '; secure' : ''; 
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 
    } else { // only name given, get cookie 
        var cookieValue = null; 
        if (document.cookie && document.cookie != '') { 
            var cookies = document.cookie.split(';'); 
            for (var i = 0; i < cookies.length; i++) { 
                var cookie = jQuery.trim(cookies[i]); 
                // Does this cookie string begin with the name we want? 
                if (cookie.substring(0, name.length + 1) == (name + '=')) { 
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 
                    break; 
                } 
            } 
        } 
        return cookieValue; 
    } 
}; 

function getDomainName(a){
if (a) //只要有参数就包含长域名，否则就仅仅处理短域名
var arydomain = new Array(".com",".cn",".net",".cc",".org",".info",".biz",".tv"); 
else
var arydomain = new Array(".com.cn",".net.cn",".org.cn",".gov.cn",".com",".cn",".net",".cc",".org",".info",".biz",".tv"); 

var domain = document.domain;
var tmpdomain = ""; 
for(var i=0;i<arydomain.length; i++) 
{ 
tmpdomain = arydomain[i]; 
if(domain.indexOf(tmpdomain) != -1) 
{ 
domain = domain.replace(tmpdomain,""); 
domain = domain.substring(domain.lastIndexOf(".")+1,domain.length); 
domain = domain + tmpdomain; 
break; 
} 
} 
return domain;} 

function site_main_css(setid){
if (setid=='0'||setid)
 $('#site_main_css').attr('href','/sys/css_'+setid+'.css');
else{
 var cookievalue = $.cookie('lmx_color');
 if (cookievalue != null){
 	 $('#site_main_css').attr('href','/sys/css_'+cookievalue+'.css');
 	 return 1;
 }else{
 	var now=new Date(); 
  var number = now.getMilliseconds().toString();
  var setid = number.charAt(0);
 	$('#site_main_css').attr('href','/sys/css_'+setid+'.css');
 }
}
var domainstr = getDomainName();
$.cookie('lmx_color',setid, { expires: 2, path: '/', domain: '.'+domainstr, secure: false })
}

site_main_css();
