//common.js
//2009-7-25 下午十四点三十八分
//http://www.14pc.com/
//QQ:312709349
//by stri

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);

function $(id) {
    return document.getElementById(id);
}
function closed_open(id) {
    $(id).style.display = ($(id).style.display == 'none') ? ($(id).style.display = 'block') : ($(id).style.display = 'none');
}
function text_copy(text, te) {
    if (is_ie) {
        clipboardData.setData('text', text);
        alert(te);
    } else if (prompt('非常抱歉!\n您需要手动复制(请用ctrl+c实现复制).\n(Sorry!You must shoudong copy!)', text)) {
        alert(te);
    }
}

//Cookie
function setCookie(sName, sValue, iExpireDays) {
    if (iExpireDays) {
        var dExpire = new Date();
        dExpire.setTime(dExpire.getTime() + parseInt(iExpireDays * 24 * 60 * 60 * 1000));
        document.cookie = sName + "=" + escape(sValue) + "; expires=" + dExpire.toGMTString();
    }
    else {
        document.cookie = sName + "=" + escape(sValue);
    }
}

function getCookie(sName) {

    var arr = document.cookie.match(new RegExp("(^| )" + sName + "=([^;]*)(;|$)"));
    if (arr != null) {
        return unescape(arr[2])
    };
    return null;

}


//引用代码
function c_o_code(ob) {
    var obj = ob.parentNode.nextSibling;
    var obj_a = ob.parentNode.childNodes[0];
    obj_a.style.display = (obj.style.display == "block") ? "none": "block";
    obj.style.display = (obj.style.display == "block") ? "none": "block";

    ob.className = (obj.style.display == "block") ? "code_o": "code_c";
}

function get(id) {
    return document.getElementById(id);
}

//把运行框变大
function reset_big(obj) {
    obj.style.height = "150px";
    obj.style.overflowY = "auto";
    obj.style.borderTop = "1px solid #ccc";
}

//去掉a边框线
function clear_a() {
    var a;
    for (var i = 0;
    (a = document.getElementsByTagName("a")[i]); i++) {
        if (a.getAttribute("onfocus") == null) {
            a.setAttribute("onfocus", "this.blur();");
        } else {
            a.setAttribute("onfoucs", a.getAttribute("onfocus") + ";this.blur();");
        }
        a.setAttribute("hideFocus", "hidefocus");

    }
}

//消除留言框
function clear_form() {

    $("liuyan_textarea").value = "";

}
var backTop=function (btnId){
	var btn=document.getElementById(btnId);
	var d=document.documentElement;
	window.onscroll=set;
	btn.onclick=function (){
	
		window.onscroll=null;
		this.timer=setInterval(function(){
			d.scrollTop-=Math.ceil(d.scrollTop*0.1);
			if(d.scrollTop==0) clearInterval(btn.timer,window.onscroll=set);
		},10);
	};
	function set(){btn.style.display="block";}
};
//运行代码
function runCode(obj) {
    var winname = window.open('', "_blank", '');
    winname.document.open('text/html', 'replace');
    winname.opener = null; // 防止代码对论谈页面修改
    winname.document.write(obj.parentNode.childNodes[0].value);
    winname.document.close();
}

//拷贝代码
function copyCode_code(obj) {
    var code = obj.parentNode.parentNode.childNodes[1];

    if (is_ie) {
        var rng = document.body.createTextRange();
        rng.moveToElementText(code);
        rng.scrollIntoView();
        rng.select();
        rng.execCommand("Copy");
        rng.collapse(false);
    }
    else {
        alert("你的游览器不支持此功能,你需要手动复制!^^")
    }
}
//复制引用代码
function copyCode(obj) {
    var code = obj.parentNode.childNodes[0];

    if (is_ie) {
        var rng = document.body.createTextRange();
        rng.moveToElementText(code);
        rng.scrollIntoView();
        rng.select();
        rng.execCommand("Copy");
        rng.collapse(false);

    }
    else {
        code.select();
        prompt('友情提醒:请用ctrl+c实现复制', code.value);

    }
}
window.onresize = function() {
	var obj="divId_no_click";
	if($(obj)){
  Class.res("divId_no_click","wrap");}
}

function rss_aa(id){
	divcenter(id);
  Class.bint("divId_no_click");}
  function c_f(){
	popo.remove("divId_no_click","rss_div");
	}
function send_f(){
	
	popo.remove("divId_no_click","send_wrong");}

Array.prototype.indexOf = function(v, b, s) {
    for (var i = +b || 0, l = this.length; i < l; i++) {
        if (this[i] === v || s && this[i] == v) {
            return i;
        }
    }
    return - 1;
};
if (typeof Array.prototype.push === 'undefined') {
    Array.prototype.push = function() {
        for (var i = 0, b = this.length, a = arguments, l = a.length; i < l; i++) {
            this[b + i] = a[i];
        }
        return this.length;
    };
}

Array.prototype.unique = function(b) {
    var a = [],
    i,
    l = this.length;
    for (i = 0; i < l; i++) {
        if (a.indexOf(this[i], 0, b) < 0) {
            a.push(this[i]);
        }
    }
    return a;
};

function isNodes(xmldoc, s) {
    var d;
    var str = [];
    d = (typeof s == 'undefined') ? true: s;
    for (var i = 0; i < xmldoc.childNodes.length; i++) {
        if (xmldoc.childNodes[i].hasChildNodes()) {
            str = str.concat(xmldoc.childNodes[i].tagName);
        }
    }
    str = (d) ? str: str.unique();
    return str;
}

function isNumber(String) {

    var Letters = "1234567890";
    var c;
    for (var i = 0; i < String.length; i++) {
        c = String.charAt(i);
        if (Letters.indexOf(c) < 0) return false;
    }
    return true;
}

//添加事件
function addEvent(elem, evtType, func, capture) {
    capture = (capture) ? capture: false;
    if (elem.addEventListener) {
        elem.addEventListener(evtType, func, capture);
    }
    else if (elem.attachEvent) {
        elem.attachEvent("on" + evtType, func);
    } else {
        elem["on" + evtType] = func;
    }
}

//添加多项onload事件,这得很重要,和加密
function addOnLoadEvent(func) {
    if (window.addEventListener || window.attachEvent) {
        addEvent(window, "load", func, false);
    }
    else {
        var oldQueue = (window.onload) ? window.onload: function() {};
        window.onload = function() {
            oldQueue();
            func();
        }
    }
}
function addOnClickEvent(id, func) {
    if ($(id).addEventListener || $(id).attachEvent) {
        addEvent($(id), "click", func, true);
    }
    else {
        var oldQueue = ($(id).onclick) ? $(id).onlcik: function() {};
        $(id).onlcik = function() {
            oldQueue();
            func();
        }
    }
}

function go_to_liuyan_page(id) {
    var p = id + 1;
}

function remove_node(id) {

    for (var i = 0; i < $(id).childNodes.length; i++) {
        $(id).removeChild($(id).childNodes[i]);
    }
}
function getFormValue(form) {
    var str = '',
    ft, fv;

    for (var i = 0; i < form.elements.length; i++) {
        fv = form.elements[i];
        ft = fv.type.toLowerCase();

        switch (ft) {
        case 'select-one':
            str += fv.name + '=' + escape(fv.value) + '&';
            break;
        case 'radio':
            if (fv.checked) {
                str += fv.name + '=' + escape(fv.value) + '&';
            }
            break;
        case 'checkbox':
            if (fv.checked) {
                str += fv.name + '=' + escape(fv.value) + '&';
            }
            break;
        case 'text':
            str += fv.name + '=' + escape(fv.value.replace(/\+/g, "%2B")) + '&';
            break;
        case 'password':
            str += fv.name + '=' + escape(fv.value) + '&';
            break;
        case 'hidden':
            str += fv.name + '=' + escape(fv.value) + '&';
            break;
        case 'textarea':
            str += fv.name + '=' + escape(fv.value.replace(/\+/g, "%2B")) + '&';
            break;
        default:
            break;
        }
    }

    return str.split(/\s/).join('')
}
String.prototype.trim = function() {
    return this.replace(/(^[\s]*)|([\s]*$)/g, "");
}
var RegUrl = /^http:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/;
var RegMail = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
