var adtimeout;
function flashadbox(w,h,th,arrp,arrl,arrt,adplace){
	var stop_time=5000; //图片停顿时间，单位为秒，为0则停止自动切换
	var focus_width=w;
	var focus_height=h;
	var text_height=0;
	var text_align="center" //标题文字对齐方式(left、center、right)
	var txtcolor="000000"; //文字色
	var bgcolor="DDDDDD"; //背景色
	var button_pos=4; //按扭位置 1左 2右 3上 4下
	var swf_height=focus_height+text_height; //相加之和最好是偶数,否则数字会出现模糊失真的问题
	var pics=arrp.join('|');
	var links=arrl.join('|');
	var texts=arrt.join('|');
	var flash='<object id="swf'+adplace+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">';
	flash+='<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/pic/index/focus.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#F0F0F0">';
	flash+='<param name="menu" value="false"><param name=wmode value="opaque">';
	flash+='<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+focus_width+'&pic_height='+focus_height+'&show_text='+text_height+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">';
	flash+='<embed src="/pic/index/focus.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+focus_width+'&pic_height='+focus_height+'&show_text='+text_height+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" menu="false" bgcolor="#F0F0F0" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	flash+='</object>';
	return flash;
}
function printAd(adPlace,adUrl,adLink,adTitle,adtype,adWidth,adHeight,mmax,mmin){
	//adtype 0 img 1 flash
	if(!$(adPlace)){return false;}
	if(adtype==2 && typeof adUrl!='string'){
		AdChange(adPlace,adUrl,adLink,mmax,mmin);
		return true;
	}
	aadWidth=adWidth;
	aadHeight=adHeight
	adWidth = adWidth?" width='"+adWidth+"'":'';
	adHeight = adHeight?" height='"+adHeight+"'":'';
	aadLink = adLink?" href='"+adLink+"'":'';
	if(adtype==1 || adtype==0){//随机一条 ||  固定一条
		if(adUrl.substr(adUrl.length-4,adUrl.length-1).toUpperCase=='SWF'){
			
			printAd(adPlace,adUrl,adLink,adTitle,3,adWidth,adHeight,mmax,mmin);
			return true;
		}
		adHtml = "<a"+aadLink+" target='_blank'><img border=0 "+adWidth+adHeight+" src='"+adUrl+"' /></a>";
	}
	if(adtype==5){
		adHtml = "<a"+aadLink+" target='_blank'>"+adUrl+"</a>";
		}
	if(adtype==3){
		/*if(adUrl.substr(adUrl.length-3,3).toUpperCase!='SWF'){
			printAd(adPlace,adUrl,adLink,adTitle,1,adWidth,adHeight,mmax,mmin);
			return true;
		}*/
		adHtml = "<a"+aadLink+" target='_blank'><object id='swf"+adPlace+"'  classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' "+adWidth+adHeight+"><param name='movie' value='"+adUrl+"' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='"+adUrl+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'"+adWidth+adHeight+"></embed></object></a>";
	}
	if(adtype==4){
		adHtml = flashadbox(aadWidth,aadHeight,24,adUrl,adLink,adTitle,adPlace);
	}
	if($(adPlace)){
	
		$(adPlace).innerHTML = adHtml;
		if($(adPlace).innerHTML=='')
			adtimeout = setTimeout(function(){printAd(adPlace,adUrl,adLink,adtype,mmax,mmin,adWidth,adHeight)},5000);
		//clearTimeout(adtimeout);
	}
}
function AdChange(adPlace,adUrl,adLink,mmax,mmin,oldkey){
		m = Math.random()*100+1;
		
		for(key in mmax){
			if(m<mmax[key] && m>mmin[key])
				break;
		}
		if(m<mmax[key] && m>mmin[key])
		if($(adPlace)){
			if(key!=oldkey)
				$(adPlace).innerHTML =  "<a href='"+adLink[key]+"'><img src='"+adUrl[key]+"' /></a>";
			setTimeout(function(){AdChange(adPlace,adUrl,adLink,mmax,mmin,key)},3000);
		}
	}
function $(){
	var elements=new Array();
	for(var i=0;i<arguments.length;i++){
		var element=arguments[i];
		if(typeof element=='string')element=document.getElementById(element);
		if(arguments.length==1)return element;elements.push(element);
	}
	return elements;
}
function getCodeImage(id){
	$(id+'show').innerHTML = "<img src=\"index.php?controller=BoLogin&action=imgcode\" onclick=\"this.src='index.php?controller=BoLogin&action=imgcode'\" alt=\"验证码看不清楚?请点击刷新验证码\">";
	setTimeout(function(){},60000)
}
function jump(url,name){
		 document.location.href = url+'&page='+(document.getElementById(name).value-1);
	}
function alertWin(title, msg, w, h, buttonText){
	var dbody = document.body;
	if(!dbody){setTimeout(function(){alertWin(title, msg, w, h, buttonText)},10);return false;} 
	
	var s=document.getElementsByTagName("select"); //--------------把所有select标签捉住
	for(var j=0;j<s.length;j++){s[j].style.display="none";} //--------------设为不显示，再进行下面操作
	var titleh = 22;
	var titleheight =  titleh+"px"; // 提示窗口标题高度 
	var bordercolor = "#666699"; // 提示窗口的边框颜色 
	var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色 
	var titlebgcolor = "#666699"; // 提示窗口的标题背景色
	var bgcolor = "#FFFFFF"; // 提示内容的背景色
	document.documentElement.style.overflow = "hidden";
	document.documentElement.scrollTop = 0;
	var iWidth = document.documentElement.clientWidth+document.documentElement.scrollLeft; 
	var iHeight = document.documentElement.clientHeight+document.documentElement.scrollTop; 
	var bgObj = document.createElement("div"); 
	bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;";
	document.body.appendChild(bgObj); 
	
	var msgObj=document.createElement("div");
	msgObj.style.cssText = "position:absolute;font:11px '宋体';top:"+(iHeight-h)/2+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:102;";
	document.body.appendChild(msgObj);
	
	var table = document.createElement("table");
	msgObj.appendChild(table);
	table.style.cssText = "margin:0px;border:0px;padding:0px;";
	table.cellSpacing = 0;
	var tr = table.insertRow(-1);
	var titleBar = tr.insertCell(-1);
	titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:"+titlecolor+";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor;
	titleBar.style.paddingLeft = "10px";
	titleBar.innerHTML = title;
	var moveX = 0;
	var moveY = 0;
	var moveTop = 0;
	var moveLeft = 0;
	var moveable = false;
	var docMouseMoveEvent = document.onmousemove;
	var docMouseUpEvent = document.onmouseup;
	titleBar.onmousedown = function() {
		var evt = getEvent();
		moveable = true; 
		moveX = evt.clientX;
		moveY = evt.clientY;
		moveTop = parseInt(msgObj.style.top);
		moveLeft = parseInt(msgObj.style.left);
		
		document.onmousemove = function() {
			if (moveable) {
				var evt = getEvent();
				var x = moveLeft + evt.clientX - moveX;
				var y = moveTop + evt.clientY - moveY;
				if ( x > document.documentElement.scrollLeft &&( x + w < iWidth+document.documentElement.scrollLeft) && y > document.documentElement.scrollTop && (y + h < iHeight+document.documentElement.scrollTop) ) {
					msgObj.style.left = x + "px";
					msgObj.style.top = y + "px";
				}
			}	
		};
		document.onmouseup = function () { 
			if (moveable) { 
				document.onmousemove = docMouseMoveEvent;
				document.onmouseup = docMouseUpEvent;
				moveable = false; 
				moveX = 0;
				moveY = 0;
				moveTop = 0;
				moveLeft = 0;
			} 
		};
	}
	
	var closeBtn = tr.insertCell(-1);
	closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
	closeBtn.innerHTML = "<span style='font-size:15pt; color:"+titlecolor+";'>×</span>";
	closeBtn.onclick = function(){ 
		for(var j=0;j<s.length;j++){s[j].style.display="";} //--------------再给select显出来
		document.body.removeChild(bgObj); 
		document.body.removeChild(msgObj); 
		document.documentElement.style.overflow = "auto";
		if(msg.innerHTML){msg.innerHTML=msgBox.innerHTML;}
		if(msg.value){msg.value = msgBox.innerHTML;}
	} 
		var msgBox = table.insertRow(-1).insertCell(-1);
		msgBox.style.cssText = "font:10pt '宋体';padding-top:"+(h/2-16-titleh)+"px";
		msgBox.colSpan  = 2;
	if(msg)msgBox.innerHTML = msg;
	if(msg.innerHTML){
		msgBox.innerHTML = msg.innerHTML;
		msg.innerHTML = '1';
	}
	if(msg.value){
		msgBox.innerHTML = msg.value;
		msg.value = '1';
	}
	
	var buttonTB = document.createElement('TABLE');
	buttonTB.style.cssText = "color:"+titlecolor+";margin:0px;border:1px;padding:0px; position:absolute;font:9pt '宋体';top:"+(h-16)+"px;left:1px;width:"+w+"px;text-align:left;background-color:" + titlebgcolor;
	buttonTB.cellSpacing = 0;
	var td = buttonTB.insertRow(-1).insertCell(-1);
	td.innerHTML = buttonText;
	msgObj.appendChild(buttonTB);
	
    // 获得事件Event对象，用于兼容IE和FireFox
    function getEvent() {
	    return window.event || arguments.callee.caller.arguments[0];
    }
}
function scrollImg(x,y,obj){
	var w = obj.width;
	var h = obj.height;
	
	var maxP = Math.min(x/obj.width,y/obj.height);
	if(maxP>1){return true;}
	
	obj.width = w*maxP;
	obj.height = h*maxP;
	return true;

}

function copyToClipBoard(clipBoardContent){

	if (window.clipboardData){//IE
		window.clipboardData.setData("Text",clipBoardContent);
	}
	else if (window.netscape) //firefox etc.
	{ 
		try{
            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
            var clip = Components.classes['@mozilla.org/widget/clipboard;1']
            .createInstance(Components.interfaces.nsIClipboard);
            if (!clip) return;

            var trans = Components.classes['@mozilla.org/widget/transferable;1']
            .createInstance(Components.interfaces.nsITransferable);
            if (!trans) return;

            trans.addDataFlavor('text/unicode');

            var str = new Object();
            var len = new Object();

            var str = Components.classes["@mozilla.org/supports-string;1"]
            .createInstance(Components.interfaces.nsISupportsString);

            var copytext=clipBoardContent;
            str.data=copytext;
            trans.setTransferData("text/unicode",str,copytext.length*2);

            var clipid=Components.interfaces.nsIClipboard;
            if (!clip) return false;
            clip.setData(trans,null,clipid.kGlobalClipboard);
        }
        catch(e)
        {
            alert('对不起，您的浏览器不支持自动复制功能，请手动复制链接地址');
           return false;
        }
	}
	alert("复制成功，请粘贴到您的Email/MSN/QQ上推荐给您的好友");
}
function clickEmotions(event) {
    var eventSource = event.srcElement ? event.srcElement : event.target;
    var  src = eventSource.src;
	var index = src.lastIndexOf("/");
	var elem = document.getElementById("content");
	elem.value = elem.value + " [e0575:" +  src.substring(index+1).split(".")[0]+"] ";
}
function trim(str){
	return str.replace(/(^s*)|(s*$)/g,'');
}

function sharprim(str){
	return str.replace(/(^s*)|(s*$)/g,'#');
}

function checkNum(tagID,tagCNName){
    var tagValue = document.getElementById(tagID).value;
    if(isNaN(trim(tagValue))){
    	alert(tagCNName + '必须为数字！');
        tagObj.value = '';
        tagObj.focus();
        return false;
    }        
    return true;
}

function checkReplyForm(){    
    var form = document.form1;   
    if(trim(form.qtext.value) == ""){   
        window.alert("回复内容不能为空！");   
        form.qtext.select();
        return false;   
    }     
	return true;
  }  
  
function checkForm(){    
    var form = document.thisForm;   
       
    if(trim(form.title.value) == ""){   
        window.alert("请输入标题!");   
        form.title.select();
        return false;   
    }     
    if(trim(form.content.value) == ""){   
        window.alert("请输入内容!");   
        form.content.select();   
        return false;   
    }   
    if(trim(form.poster.value) == ""){   
        window.alert("请输入发布者!");   
        form.poster.select();   
        return false;   
    }
	return true;
  }  

/**
 * HashMap构造函数
 */
function HashMap()
{
    this.length = 0;
    this.prefix = "hashmap_prefix__";
}
/**
 * 向HashMap中添加键值对
 */
HashMap.prototype.put = function (key, value)
{
    this[this.prefix + key] = value;
    this.length ++;
}
/**
 * 从HashMap中获取value值
 */
HashMap.prototype.get = function(key)
{
    return typeof this[this.prefix + key] == "undefined" 
            ? null : this[this.prefix + key];
}
/**
 * 从HashMap中获取所有key的集合，以数组形式返回
 */
HashMap.prototype.keySet = function()
{
    var arrKeySet = new Array();
    var index = 0;
    for(var strKey in this)
    {
        if(strKey.substring(0,this.prefix.length) == this.prefix)
            arrKeySet[index ++] = strKey.substring(this.prefix.length);
    }
    return arrKeySet.length == 0 ? null : arrKeySet;
}
/**
 * 从HashMap中获取value的集合，以数组形式返回
 */
HashMap.prototype.values = function()
{
    var arrValues = new Array();
    var index = 0;
    for(var strKey in this)
    {
        if(strKey.substring(0,this.prefix.length) == this.prefix)
            arrValues[index ++] = this[strKey];
    }
    return arrValues.length == 0 ? null : arrValues;
}
/**
 * 获取HashMap的value值数量
 */
HashMap.prototype.size = function()
{
    return this.length;
}
/**
 * 删除指定的值
 */
HashMap.prototype.remove = function(key)
{
    delete this[this.prefix + key];
    this.length --;
}
/**
 * 清空HashMap
 */
HashMap.prototype.clear = function()
{
    for(var strKey in this)
    {
        if(strKey.substring(0,this.prefix.length) == this.prefix)
            delete this[strKey];   
    }
    this.length = 0;
}
/**
 * 判断HashMap是否为空
 */
HashMap.prototype.isEmpty = function()
{
    return this.length == 0;
}
/**
 * 判断HashMap是否存在某个key
 */
HashMap.prototype.containsKey = function(key)
{
    for(var strKey in this)
    {
       if(strKey == this.prefix + key)
          return true;  
    }
    return false;
}
/**
 * 判断HashMap是否存在某个value
 */
HashMap.prototype.containsValue = function(value)
{
    for(var strKey in this)
    {
       if(this[strKey] == value)
          return true;  
    }
    return false;
}
/**
 * 把一个HashMap的值加入到另一个HashMap中，参数必须是HashMap
 */
HashMap.prototype.putAll = function(map)
{
    if(map == null)
        return;
    if(map.constructor != HashMap)
        return;
    var arrKey = map.keySet();
    var arrValue = map.values();
    for(var i in arrKey)
       this.put(arrKey[i],arrValue[i]);
}
//toString
HashMap.prototype.toString = function()
{
    var str = "";
    for(var strKey in this)
    {
        if(strKey.substring(0,this.prefix.length) == this.prefix)
              str += strKey.substring(this.prefix.length) 
                  + " : " + this[strKey] + "\r\n";
    }
    return str;
}

function sortNumber(a,b){
    return a - b;
}

function reloadGradesColorDelay(i){
    var t=setTimeout("reloadGradesColor()",i)
}

function getElementsByName(tag, name){
    var returns = document.getElementsByName(name);
    if(returns.length > 0) return returns;
    returns = new Array();
    var e = document.getElementsByTagName(tag);
    for(var i = 0; i < e.length; i++){
        if(e[i].getAttribute("name") == name){
            returns[returns.length] = e[i];
        }
    }
    return returns;
}
var mouseCssActionMap =  new HashMap();
function mouseOverAction(tagID){
    var tagIDObj = document.getElementById(tagID);
    var tagIDObjCss =  tagIDObj.className;
    mouseCssActionMap.put(tagID,tagIDObjCss);
    tagIDObj.className = "dd_blue2";
}

function mouseOutAction(tagID){
    var tagIDObj = document.getElementById(tagID);
    var tagIDObjCss = mouseCssActionMap.get(tagID);
    tagIDObj.className = tagIDObjCss;
}

function reloadGradesColor(){
	var upGradesArray = new Array(); 
	var upGradesPointsArray = new Array();
	var upGradesDivIDsArray = new Array();
	var pointsGradesIDsPair = new HashMap();
	upGradesArray = getElementsByName("div","upGrades");
	for(var i = 0; i < upGradesArray.length; i++){
		var divObjs = upGradesArray[i];
		var spanObj = divObjs.getElementsByTagName("span").item(0);
		var spanID = "ID_"+spanObj.id;
		var point = spanObj.innerHTML;
		upGradesPointsArray[i] = point;
		upGradesDivIDsArray[i] = spanID;
		if(pointsGradesIDsPair.containsKey(point)){
            var oldValue = pointsGradesIDsPair.get(point);
            pointsGradesIDsPair.put(point,(oldValue+","+spanID));
        }else{
            pointsGradesIDsPair.put(point,spanID); 
        } 
	} 
	if(upGradesPointsArray.length > 0){
		upGradesPointsArray.sort(sortNumber);
		var minPoint = upGradesPointsArray[0];
		var maxPoint = upGradesPointsArray[upGradesPointsArray.length -1];
		var maxPointGradesIDs = pointsGradesIDsPair.get(maxPoint);
		var maxPointGradesIDsArray = maxPointGradesIDs.split(",");
		for(var j =0;j<upGradesDivIDsArray.length;j++){
			document.getElementById(upGradesDivIDsArray[j]).className = "dd_blue3";
		}
		if(minPoint != maxPoint || upGradesPointsArray.length == 1){
			for(var k =0;k<maxPointGradesIDsArray.length;k++){
				document.getElementById(maxPointGradesIDsArray[k]).className = "dd_blue1";
			}
		}
	}
	
}

function addBookmark(title) {
                     var url=parent.location.href;
                     if (window.sidebar) { 
                            window.sidebar.addPanel(title, url,""); 
                     } else if( document.all ) {
                     window.external.AddFavorite( url, title);
                     } else if( window.opera && window.print ) {
                     return true;
                     }
       }
       
function IsSeleRadio(bname)
{
    
    var bn = document.getElementsByName(bname);
    var k = 0;
    for(i=0;i<bn.length;i++)
    {
        if(!bn[i].checked)
        {
            k++;
        }
    }
    if(k == bn.length)
    {
        return false;
    }
    else
    {
        return true;
    }
}

