var Browser = new function(){//判断浏览器与操作系统
var ua = navigator.userAgent.toLowerCase();
var isStrict = document.compatMode == "CSS1Compat";
    this.isOpera = ua.indexOf("opera") > -1;
    this.isSafari = (/webkit|khtml/).test(ua);
    this.isIE = !this.isOpera && ua.indexOf("msie") > -1;
    this.isIE7 = !this.isOpera && ua.indexOf("msie 7") > -1;
    this.isIE8 = !this.isOpera && ua.indexOf("msie 8") > -1;
    this.isGecko = !this.isSafari && ua.indexOf("gecko") > -1;
    this.isBorderBox = this.isIE && !isStrict;
    this.isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1);
    this.isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1);
    this.isLinux = (ua.indexOf("linux") != -1);
    this.isSecure = window.location.href.toLowerCase().indexOf("https") === 0;
}

/* Example event
var obj = window.event || arguments.callee.caller.arguments[0];   
	obj = Browser.isIE?obj.srcElement:obj.target;
*/

var $ = function $(id){
	return  document.getElementById(id);
}

var $BN = function $BN(name){
	return document.getElementsByName(name);
}

var $BTN = function $BTN(name){
	return document.getElementsByTagName(name);
}

function IsElement(id){
	return $(id)!=null ? true : false;
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function $F(id,mode){//得到节点的,value,innerHTML,
    if(mode==1){       return $(id).value;         //Form only
		}else if(mode==2){	return $(id).innerHTML; //Node only
		}else if(mode==3){ return $(id).innerText; //IE only
	}
}
function $FI(id,content){
	$(id).innerHTML = content;
}


function $CE(tagName){//创建一个节点
    return document.createElement(tagName);
}

function $CT(text){//创建一个文本节点
	return document.createTextNode(text);
}

function $AC(son,father){//把son节点->加到fatherId节点最后
	if(typeof(father)=='object' && typeof(son)=='object'){
		return father.appendChild(son);
	}else{
		return $(father).appendChild($(son));
	}
}

function $IB(id,newChild,refChild){//在Element的refChild节点前加newChild节点
	 return $(id).insertBefore(newChild,$(refChild));
}
function $CN(which,deep){//克隆which节点
	return $(which).cloneNode(deep);
}

function $RC(father,son){//删除指定节点的子节点
	return $(father).removeChild($(son)); 
}

function $RN(id,deep){//删除指定节点
	//$(id).removeNode(deep);//IE only
	$(id).parentNode.removeChild($(id));
}

function $RP(id,newChild,refChild){//用节点替换指定节点的某个节点
	$(id).replaceChild(newChild,$(refChild));
}

String.prototype.trim=function() { //过虑空格
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function redirect(url)
{
	window.location.replace(url);
}
function confirmurl(url,message)
{
	if(confirm(message)) location.href = url;
}

//文件名不包含.js
function load_js(file)
{
	document.write('<scri'+'pt language="javascript" src="'+site_root+'skins/js/'+file+'.js"></scri'+'pt>');
}
//////////////////////////////////////////////////////////////////


function get_ext(path)
{
	return path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
}

function in_array(str,arr)
{
	for(var i=0;i<arr.length;i++)	if(str==arr[i])	return true;
	return false;
}

function is_image(ext)
{
	return in_array(ext,['jpg','gif','png','bmp','jpeg']);
}

/*获取Cookie值*/
function getcookie(c_name){
if(document.cookie.length>0){
    c_start=document.cookie.indexOf(c_name + "=")
    if(c_start!=-1){
       c_start=c_start + c_name.length+1
       c_end=document.cookie.indexOf(";",c_start)
       if(c_end==-1) c_end=document.cookie.length
       return unescape(document.cookie.substring(c_start,c_end))
    }
}
return ""
}
/*设置Cookie值*/
function setcookie(c_name,value,expiredays){
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

var tID=0;
function show_tabs(ID,class1,class2)
{
	var ttab_title=$("tab_title"+tID);
	var ttabs=$("tabs"+tID);
	var tab_title=$("tab_title"+ID);
	var tabs=$("tabs"+ID);
	if(ID!=tID)
	{
		ttab_title.className = class1 ? class1 : class2;
		tab_title.className = class2 ? class2 : class1;
		ttabs.style.display = 'none';
		tabs.style.display = '';
		tID=ID;
	}
}
function check_all(form)
{
	for(var i = 0;i < form.elements.length; i++) 
	{
		var e = form.elements[i];
		if(e.type=='checkbox' && e.name != 'chkall' && e.disabled != true) e.checked = form.chkall.checked;
	}
}

function preg_quote(str)
{
	str = str.replace(/[ ]+/g,'\\s*');
	return str.replace(/([\\\:\.\-\+\!\]\[\}\{\(\)\?\'\"])/,'\\$1');
}

function get_tip_div(e) {
	if($('message'))	divElement = $('message');
	else
	{
		var divElement = $CE('DIV');
		divElement.id = 'message';
		document.body.appendChild(divElement);
	}
	divElement.style.width = '400px';
	divElement.style.tip = "width:396px;";
		
	var offX = 4;
	var offY = 4;
	var width = 0;
	var height = 0;
	var scrollX = 0;
	var scrollY = 0;  
	var x = 0;
	var y = 0;
		
	if (window.innerWidth) width = window.innerWidth - 18;
	else if (document.documentElement && document.documentElement.clientWidth) 
		width = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth) 
		width = document.body.clientWidth;
		
	
	if (window.innerHeight) height = window.innerHeight - 18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		height = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		height = document.body.clientHeight;
	

	if (typeof window.pageXOffset == "number") scrollX = window.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft)
		scrollX = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scrollX = document.body.scrollLeft; 
	else if (window.scrollX) scrollX = window.scrollX;
				
	  
	if (typeof window.pageYOffset == "number") scrollY = window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		scrollY = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scrollY = document.body.scrollTop; 
	else if (window.scrollY) scrollY = window.scrollY;
		
	x=e.pageX?e.pageX:e.clientX+scrollX;
	y=e.pageY?e.pageY:e.clientY+scrollY;

	if(x+divElement.offsetWidth+offX>width+scrollX){
		x=x-divElement.offsetWidth-offX;
		if(x<0)x=0;
	}else x=x+offX;
	if(y+divElement.offsetHeight+offY>height+scrollY){
		y=y-divElement.offsetHeight-offY;
		if(y<scrollY)y=height+scrollY-divElement.offsetHeight;
	}else y=y+offY;

	divElement.style.left = x+"px";
	divElement.style.top = y+"px";
}

function preview(src,str,w)
{
	$('message').style.display = (src || str) ? '' : 'none';
	$('message').innerHTML = '';
	if(!w)	var w=400;
	if(src)	$('message').innerHTML += insert_img(decodeURIComponent(src),w);
	if(str)
	{
		$('message').innerHTML += '<p Style="width:400px;overflow:hidden;text-align:left;line-height:18px">'+str+'</p>';
	}
}

function show_hide(id)
{
	return $(id).style.display = ($(id).style.display == 'none') ? '' : 'none';
}




//首页轮换 a:当前id b:轮换总数 c:区别使用该函数
function swap_tab(a,b,c){
	for(var i=1;i<=b;i++){
		if(a==i){
			$("tab"+c+"_"+i).style.display="block";
			$("tab"+c+"_t"+i).className="active"
		}else{
			$("tab"+c+"_"+i).style.display="none";
			$("tab"+c+"_t"+i).className="normal"
		}
	}
} 

