
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// --------------- UTILS-------------
var Browser = {};

Browser.isIE = function(){
	return (document.all && window.ActiveXObject) ? true : false;
};
Browser.isIE5Up = function(){
	return (Browser.isIE() && document.getElementById) ? true : false;
};
Browser.isIE7 = function(){
	return (Browser.isIE() && window.navigator.userAgent.indexOf( "MSIE 7" )>0) ? true : false;
};
Browser.isFirefox = function(){
	return (document.implementation && document.implementation.createDocument && !window.opera) ? true : false;
};
Browser.isOpera = function(){
	return (window.opera) ? true : false;
};

function getStrActualLen(sChars){
	return sChars.replace(/[^\x00-\xff]/g,"xx").length;
}
function getEvent(){ 
    if(Browser.isIE()) return window.event;  
	//FireFox
    func=getEvent.caller; 
    while(func!=null){ 
        arg0=func.arguments[0]; 
		if(arg0){
			if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
				|| (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){
				return arg0; 
			} 
		}
        func=func.caller; 
    } 
    return null; 
} 

	function sltAll(frmName,chkName){
		var li_rowmax = frmName.elements.length;
		var li_checked = 0;
		var li_num = 0;
		for(var li_row=0;li_row<li_rowmax;li_row++) {
			if (frmName.elements[li_row].name==chkName){
				if (frmName.elements[li_row].checked == true) {
					li_checked++;
				}
				li_num++;
			}
		}
		for(li_row=0;li_row<li_rowmax;li_row++) {
			if (frmName.elements[li_row].name==chkName) {
				if (li_checked!=li_num)
					frmName.elements[li_row].checked = true;
				else
					frmName.elements[li_row].checked = false;
			}
		}
	}


	function sltItem(frmName,chkName,val){
		var li_rowmax = frmName.elements.length;
		for(var li_row=0;li_row<li_rowmax;li_row++) {
			if (frmName.elements[li_row].name==chkName){
				if (frmName.elements[li_row].value == val) 
					frmName.elements[li_row].checked=true;
				else
					frmName.elements[li_row].checked=false;
			}
		}
	}
	function getCheckboxValue( frmName,checkboxname ) {
		var ret = "";
		var num = frmName.elements.length;
		for(var i=0;i<num;i++) {
			obj = frmName.elements[i];
			if (obj.name==checkboxname && obj.checked){
				v = obj.value+",";
				if( ret.indexOf( v ) <0 )
					ret += v;
			}
		}
		if( ret.length > 0 )
			ret = ret.substring(0, ret.length-1);
		return ret;
	}


function genSelectItem(chkName) {
  var selectId = "";
  var obj_id = document.all.item(chkName);
  if (obj_id == null) {
    return selectId;
  }
  if (obj_id.length == null) {
    if (obj_id.checked) {
      selectId = obj_id.value;
    }
  } else {
    for (i = 0; i < obj_id.length; i++) {
      if (obj_id[i].checked) {
        if (selectId.length > 0) {
          selectId = selectId + ",";
        }
        selectId = selectId + obj_id[i].value;
      }
    }
  }
  return selectId;
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
};

String.prototype.stripScripts=function() {
    return this.replace(new RegExp( '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 'img'), '');
};
String.prototype.unfixHTML=function(){
	var chars = this.replace(/<br>/ig, (Browser.isFirefox() ? "\n" : "\r\n"));
	chars = chars.replace(/&lt;/g, "<");
	chars = chars.replace(/&gt;/g, ">");
	chars = chars.replace(/&quot;/g, "\"");
	chars = chars.replace(/&#039;/g, "'");
	chars = chars.replace(/&amp;/g, "&");
	return chars;
};
String.prototype.fixHTML = function (){
	html= this.replace(/&(?!#\d+;|[a-zA-Z]+;)/g, "&amp;");
	html = html.replace(/</g, "&lt;");
	html = html.replace(/>/g, "&gt;");
	html = html.replace(/"/g, "&quot;");
	html = html.replace(/'/g, "&#039;");
	html = html.replace((Browser.isFirefox() ? /\n/g : /\r\n/g), "<br>");
	return html;
};

function $(s){   
	return document.getElementById(s);
}
function $C(tagName){
	return document.createElement(tagName);
}
function $A(child,parentObj){
	if( !child ) return false;
	return parentObj?parentObj.appendChild(child):document.body.appendChild(child);
}
function $R(child,parentObj){
	if( !child ) return false;
	return parentObj?parentObj.removeChild(child):document.body.removeChild(child);
}
function getPosition(o){
	var p={x:0,y:0};
	p.w=o.offsetWidth;
	p.h=o.offsetHeight;
	while(!!o){
		p.x+=o.offsetLeft;
		p.y+=o.offsetTop;
		o=o.offsetParent;
	}
	return p;
}
function getCookie(name){
	var search = name + "=";
	var offset = document.cookie.indexOf(search);
	if (offset != -1) {
		offset += search.length;
		var end = document.cookie.indexOf(";", offset);
		if (end == -1){
			end = document.cookie.length;
		}
		return unescape(document.cookie.substring(offset, end));
	}
	return "";
} 
function setCookie(name,value,hours){
	if(arguments.length>2){
		var expireDate=new Date(new Date().getTime()+hours*3600000);
		document.cookie = name + "=" + escape(value) + "; path=/; domain="+pathMap["ROOT_PATH"]+"; expires=" + expireDate.toGMTString();
	}
	else{
		document.cookie = name + "=" + escape(value) + "; path=/; domain="+pathMap["ROOT_PATH"]; 
	}
}
function getParameter(name){
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r!=null){return unescape(r[2]).replace(/\D*/g,'');}
	return null;
}
function replaceScript(s) {
	if(typeof(s)=='string'){
		s=s.replace(/&#(\d+);?/g,function(a,b){return String.fromCharCode(b)}).replace(/&#x(\d+);?/ig,function(a,b){return String.fromCharCode(parseInt(b,16))}).replace(/(\Won)(\w+\s*=)/ig,"$1<wbr>$2").replace(/(\Wexpres)(sion\()/ig,"$1<wbr>$2").replace(/(\Wbehav)(ior\s*:)/ig,"$1<wbr>$2").replace(/(obj)(ect)/ig,"$1<wbr>$2").replace(/(scr)(ipt)/ig,"$1<wbr>$2").replace(/(emb)(ed)/ig,"$1<wbr>$2").replace(/\r\n/g,"bbrr").replace(/\t/g," &nbsp; &nbsp;");
	}
	return s;
}
function replaceHtmlTag(s){
	if(typeof(s)=="string"){
		s=s.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");
	}
	return s;
}
function getWindowSize(){
	return {w:Math.max(document.body.scrollWidth,document.documentElement.clientWidth),
		h:Math.max(document.body.scrollHeight,document.documentElement.clientHeight),
		x:Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
		y:Math.max(document.documentElement.scrollTop, document.body.scrollTop)};
}
function setStyle(obj,css){
	var arr1=css.split(";"),l=arr1.length,o=obj.style,arr2=[];
	for(var i=0;i<l;i++){
		arr2 = arr1[i].split(":");
		o[arr2[0]] = arr2[1];
	}
}
	function showFloat(obj){
		f = $("maskAll");
		if( !f ){
			f =$C("div");
			f.setAttribute("id","maskAll");
			$A(f);
		}
		s = getWindowSize();
		css = "display:;position:absolute;z-index:"+(obj.style.zIndex -1)+";left:0px;top:0px;width:"+s.w+"px;height:"+s.h+"px;filter:alpha(opacity=35);-moz-opacity:0.35;opacity:0.35;background:#999;";
		f.style.cssText = css;
	}
	function closeFloat(){
		$R($("maskAll"));
	}

	function show( s, flag ){
		obj = $(s);
		if( obj.style.display == "none" || flag==1 )
			obj.style.display = "";
		else
			obj.style.display = "none";
	}
	function copyUrlToFriend(){
		var u=window.location.toString();
		clipboardData.setData('Text',u);
		alert("地址已经复制到粘贴板，请按Ctrl+V粘贴");
	}
	function copySelect(code,msg){
		var t = $(code);
		t.select();
		t.createTextRange().execCommand('Copy');
		alert(msg);
	}
