

var isIE = /msie/i.test(navigator.userAgent);
var isDTD = /CSS1Compat/i.test(document.compatMode);
String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g,"");
}
Array.prototype.deleteItem = function(item){
	var i,count = this.length;
	for(i = 0;i < count;i++){
		if(this[i] == item){
			this.splice(i,1);
			i--;
			count--;
		}
	}
}
Array.prototype.addItem = function(item){
	for(var i = 0;i < this.length;i++){
		if(this[i] == item)
			return;
	}
	this.push(item);
}
Array.prototype.indexOf = function(_value){
	for(var i = 0;i < this.length;i++)
		if(this[i] == _value) return i;
	return -1;
};
Array.prototype.lastIndexOf = function(_value){
	for(var i = this.length - 1;i >= 0;i--)
		if(this[i] == _value) return i;
return -1;
};
Array.prototype.contains = function(_value){return this.indexOf(_value)!= -1;};
if(!isIE){
	window.constructor.prototype.__defineGetter__("event",function(){
		var func = arguments.callee.caller;
		while(func != null){
			var arg0 = func.arguments[0];
			if(arg0 && (arg0.constructor==Event || arg0.constructor ==MouseEvent)){
				return arg0;
			}
			func = func.caller;
		}
    	return null;
	});
	Event.prototype.__defineSetter__("returnValue",function(b){
		if(!b)this.preventDefault();
		return b;
	});
	Event.prototype.__defineGetter__("srcElement",function(){
		var node=this.target;
		while(node.nodeType != 1)node=node.parentNode;
		return node;
	});
	Event.prototype.__defineGetter__("fromElement",function(){// 返回鼠标移出的源节点
        var node;
        if(this.type == "mouseover")
            node = this.relatedTarget;
        else if(this.type == "mouseout")
            node = this.target;
        if(!node)return;
        while(node.nodeType != 1)node=node.parentNode;
        return node;
        });
    Event.prototype.__defineGetter__("toElement",function(){// 返回鼠标移入的源节点
        var node;
        if(this.type == "mouseout")
            node = this.relatedTarget;
        else if(this.type == "mouseover")
            node = this.target;
        if(!node)return;
        while(node.nodeType != 1)node=node.parentNode;
        return node;
        });
	Event.prototype.__defineGetter__("offsetX",function(){
			return this.layerX;
	});
	Event.prototype.__defineGetter__("offsetY",function(){
		return this.layerY;
	});
	HTMLElement.prototype.attachEvent = function(sType,foo){
		this.addEventListener(sType.slice(2),foo,false);
	}
	HTMLElement.prototype.detachEvent = function(sType,foo){
		this.removeEventListener(sType.slice(2),foo,false);
	}
	HTMLDocument.prototype.attachEvent = function(sType,foo){
		this.addEventListener(sType.slice(2),foo,false);
	}
	HTMLDocument.prototype.detachEvent = function(sType,foo){
		this.removeEventListener(sType.slice(2),foo,false);
	}
	HTMLElement.prototype.__defineGetter__("innerText",function(){
		return this.textContent;
	});
	HTMLElement.prototype.__defineSetter__("innerText",function(str){
		this.textContent = str;
	});
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode){
		switch(where){
			case "beforeBegin":
                this.parentNode.insertBefore(parsedNode,this);
                break;
            case "afterBegin":
                this.insertBefore(parsedNode,this.firstChild);
                break;
            case "beforeEnd":
                this.appendChild(parsedNode);
                break;
            case "afterEnd":
                if(this.nextSibling)
                    this.parentNode.insertBefore(parsedNode,this.nextSibling);
                else
                    this.parentNode.appendChild(parsedNode);
                break;
		}
	}
    HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr){
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var parsedHTML = r.createContextualFragment(htmlStr);
        this.insertAdjacentElement(where,parsedHTML);
	}
	HTMLElement.prototype.contains = function(Node){// 是否包含某节点
        do if(Node == this)return true;
        while(Node = Node.parentNode);
        return false;
        }
}
else document.execCommand("BackgroundImageCache",false,true);
function $(id){return (typeof id == "string" ? document.getElementById(id) : id);}
function $N(name){return document.getElementsByName(name);}
function $TN(name,root){return root ? $(root).getElementsByTagName(name) : document.getElementsByTagName(name);}
function $F(id){return exist(id) ? $(id).value.trim() : null;}
function $IH(id,s){$(id).innerHTML = s;}
function $IT(id,s){$(id).innerText = s;}
function $iF(id,s){$(id).value = s;}
function $DC(name){return document.createElement(name);}
function isEmpty(str){return str.replace(/(?:null)|(?:undefined)/i,"").length == 0;}
function exist(id){return $(id)!= null;}
function hide(){
	for(var i = 0; i < arguments.length; i++){
		if(exist(arguments[i])){
			if($(arguments[i]).style.visibility) $(arguments[i]).style.visibility = "hidden";
			else $(arguments[i]).style.display = "none";
		}
	}
}
function show(){
	for(var i = 0; i < arguments.length; i++){
		if(exist(arguments[i])){
			if($(arguments[i]).style.visibility) $(arguments[i]).style.visibility="visible";
			else $(arguments[i]).style.display = "";
		}
	}
}
function $previousSibling(id){
	return (($(id).previousSibling.nodeName == "#text" && !/^\S$/g.test($(id).previousSibling.nodeValue)) ? $(id).previousSibling.previousSibling : $(id).previousSibling);
}
function $nextSibling(id){
	return (($(id).nextSibling.nodeName == "#text" && !/^\S$/g.test($(id).nextSibling.nodeValue)) ? $(id).nextSibling.nextSibling : $(id).nextSibling);
}
function $removeNode(id){
	if(exist(id)){
		$(id).parentNode.removeChild($(id));
	}
}


function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}



/*
===========================================
//是否是有效的身份证(中国)
===========================================
*/

String.prototype.isIDCard = function()
{
        var iSum=0;
        var info="";
        var sId = this;

        var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"};

        if(!/^\d{17}(\d|x)$/i.test(sId))
        {
                return false;
        }
        sId=sId.replace(/x$/i,"a");
        //非法地区
        if(aCity[parseInt(sId.substr(0,2))]==null)
        {
                return false;
        }

        var sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));

        var d=new Date(sBirthday.replace(/-/g,"/"))
        
        //非法生日
        if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))
        {
                return false;
        }
        for(var i = 17;i>=0;i--) 
        {
                iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11);
        }

        if(iSum%11!=1)
        {
                return false;
        }
        return true;

}

/**
 * 是否是数字
 */
function is_int(val){
	var Ret=true;	
	var NumStr="0123456789";	
	var chr;	
	if(val.length==0)
	{
		Ret=false;		
	}
	for(i=0;i<val.length;++i){
		chr=val.charAt(i);		
		if(NumStr.indexOf(chr,0)==-1){
			Ret=false;			
		}
	}
	return (Ret);	
}

//去掉两边空格
function trim(his)
{
	//找到字符串开始位置
	Pos_Start=-1;	
	for(var i=0;i<his.length;i++){
		if(his.charAt(i)!=" "){
			Pos_Start=i;			
			break;
		}
	}
	//找到字符串结束位置
	Pos_End=-1;	
	for(var i=his.length-1;i>=0;i--){
		if(his.charAt(i)!=" "){
			Pos_End=i;
			break;
		}
	}
	//返回的字符串
	Str_Return=""
	if(Pos_Start!=-1&&Pos_End!=-1){
		for(var i=Pos_Start;i<=Pos_End;i++){
			Str_Return=Str_Return+his.charAt(i);
		}
	}
	return Str_Return;	
}

function setCookie(name,value)
{
	var Days = 60;   
    var exp  = new Date();  
    exp.setTime(exp.getTime() + Days*24*60*60*1000);  
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name){
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null)
	{
  		return unescape(arr[2]); 
	}
    return null;

} 

function delCookie(name){
    var exp = new Date(); 
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) 
	    document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

/**
 * show faq
 * @param num
 * @return
 */
function faq_show(num){
//	var chk = document.getElementsByClassName("faq_a");   
//	alert(chk);
    for(var i=0;i < 4;i++)   
     {   
    	
    	if(num==i){
    		if($('faq_a_'+num).style.display=='block'){
    			$('faq_a_'+num).style.display='none';
    		}else{
    			$('faq_a_'+num).style.display="block";
    		}
    	}else{
    		$('faq_a_'+i).style.display='none';
    	}
     }  
}