function Init() {
          __dlg_init();
          var param = window.dialogArguments;
          if (param) {
              document.getElementById("f_url").value = param["f_url"];
          }
        };

function onOK(url) {
          // pass data back to the calling window
          var param = new Object();
          param["f_url"] = url;
          __dlg_close(param);
          return false;
        };
function onCancel() {
          __dlg_close(null);
          return false;
        };       
function setEntryToTop(entry_id){
	if (window.confirm("是否确定置顶文章？"))
    {
    	window.location.href="set_entry_to_top.jspa?entry_id="+entry_id;
    }
}
function unsetEntryToTop(entry_id){
 	if (window.confirm("是否确定取消置顶文章？"))
   	{
   		window.location.href="set_entry_to_top!unset.jspa?entry_id="+entry_id;
   	}
}        
function delEntry(entry_id) {
		if (window.confirm("是否确定删除文章？")) {
			window.location.href="del_entry.jspa?entry_id="+entry_id;
		}
	}
function vote(option,pollId,objectId)
	{
		var action = "/ajaxVote.jspa";
		var pars ="pollId="+pollId+"&option="+option+"&objectId="+objectId;		
		var myAjax = new Ajax.Request(action,{method: 'post', parameters: pars, onComplete: updatePage} );
	}	
function isClicked() {
    if (!clicked) { clicked = true; return true; }
    return false;
}
function NewWin(newURL,wth,hgh) {
			window.open(newURL,'','width='+wth+',height='+hgh+',left=70,top=130,scrollbars=yes');
		}
function winOpen(url){
		    window.open(url,'newwindow','height=800,width=700,scrollbars=yes');
		    return false;
		}
function selectCategory(catID, forumID) {
				window.location.replace('FORUM_LIST_'+catID+'_'+forumID+'_0_0.HTM');
		  }	
function resetForum(obj){
			var topic =obj.options[obj.selectedIndex].text;
			if(topic.indexOf("---")==-1)
				obj.options[obj.selectedIndex+1].selected=true;
			else
				obj.options[obj.selectedIndex].selected=true;
		}		
function doInsertAddress(el, targetEl) {
    // Look for an address book redirect
    if (el.value == '***') {
        location.href='addressbook.jspa';
    }

    // If the username is blank, return
    var username = el.value;
    if (username == '') {
        return;
    }
    // turn the current list of usernames into an array, check if the
    // specified username is already in the username list.
    var currentVal = targetEl.value;
    var usernames = currentVal.split(",");
    for (var i=0; i<usernames.length; i++) {
        if (usernames[i] == '') {
            usernames.splice(i,1);
            i--;
        }
        else {
            if (username == usernames[i].trim()) {
                return;
            }
        }
    }
    // At this point, the username was not found so add
    // the usename to the list of usernames:
    var newUsernames = username;
    for (var i=0; i<usernames.length; i++) {
        newUsernames += ", ";
        newUsernames += usernames[i];
    }
    targetEl.value = newUsernames;
    el.selectedIndex = 0;
}
function gotoeditab() {
    location.href = 'addressbook.jspa';
}	
function checkForm(frm,max,min) {
	if (frm.body.value.length>500){
		alert(max);
		frm.body.focus();
		return false;
	}else if(frm.body.value.length == 0){
		alert(min);
		frm.body.focus();
		return false;
	}
	return true;			
}
function delConfirm(url) {
			if (window.confirm(document.forms[1].confirmdelete.value)) {
				window.location=url+"";
			}
		}
function doSubmit(val) {
			document.forms[1].approve.value = val;
			document.forms[1].submit();
		}
function doScript(url) {
    window.location = url;
    return;
}	
function saveProperty(threadId) {
	var styleClass=document.getElementById('titleColor').value
	var  bold="";
	if(document.getElementById("boldfaced").checked == true)
	{
		bold="Y";
	}
	window.location.href="EditStyle.jspa?styleContent="+styleClass+"&threadId="+threadId+"&bold="+bold;
}
function setTabShow(showTab,tabNames,showTd,tdNames){
	for(var i=0;i<tabNames.length;i++){
		if(tabNames[i]==showTab){
			document.getElementById(tabNames[i]).style.display="";
		}else{
			document.getElementById(tabNames[i]).style.display="none";
		}
	}	
	for(var i=0;i<tdNames.length;i++){
		if(tdNames[i]==showTd){
			document.getElementById(tdNames[i]).className="tabon";
		}else{
			document.getElementById(tdNames[i]).className="taboff";
		}
	}
}	

function doDeletePostSubmit(form){			
if(window.confirm("are you sure delete?")){				
		form.action="approve!delThread.jspa";
		form.submit();							
 }
} 
			
function doDeleteMessageSubmit(form,targetMessageID){
	if(window.confirm("are you sure delete?")){
		form.action="approve!delMessage.jspa";
		var   targetMessageID   =   document.getElementsByName(targetMessageID);
		var delMessage = "";	
      	for( var i=0;i<targetMessageID.length;i++){       
		  if(targetMessageID[i].checked == true){  
	               delMessage += targetMessageID[i].value+":";  
	       }   
	  	}
		form.delMessage.value=delMessage;			
		form.submit();
	}
}

function checkthisPost(frm,message){
	if(frm.body01.value==""){
		alert(message);
		return false;
	}
	var content = frm.body01.value.replace(/\r\n/g,"<br/>");
	content = content.replace(/\n/g,"<br/>");
	frm.body.value = content;
}			

var docEle = function() {
  return document.getElementById(arguments[0]) || false;
}

function openPop(_id) {
	var m = "mask";
	var newMask = document.createElement("div");
	newMask.id = m;
	newMask.style.position = "absolute";
	newMask.style.zIndex = "999";
	_scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
	_scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
	newMask.style.width = _scrollWidth + "px";
	newMask.style.height = _scrollHeight + "px";
	newMask.style.top = "0px";
	newMask.style.left = "0px";
	newMask.style.background = "#999999";
	newMask.style.filter = "alpha(opacity=50)";
	newMask.style.opacity = "0.50";
	document.body.appendChild(newMask);
	document.getElementById(_id).style.display="block";
	
	var endHeight = window.screen.availHeight - document.getElementById(_id).offsetHeight;
	document.getElementById(_id).style.top = (document.documentElement.scrollTop+(endHeight/2))+"px";
	var endWidth = window.screen.availWidth - document.getElementById(_id).offsetWidth;
	document.getElementById(_id).style.left = (endWidth/2)+"px";
}
		
function closePop(_id) {
	document.getElementById(_id).style.display="none";
	document.body.removeChild(docEle("mask"));
	return false;
}		

function fsubmit(obj){
	obj.submit();
}

function freset(obj){
	obj.reset();
}

var timeClose = 30;
var timeCer;
function player(id){
	clearTimeout(timeCer);
	var id=document.getElementById(id)
	id.style.display="block";
}

function clocer(id){
	this.xid = id;
	var self = this;
	timeCer = setTimeout(function(){
		var idx=document.getElementById(self.xid)
		idx.style.display="none";
	},timeClose);
}

String.prototype.replaceAll  = function(s1,s2){
	return this.replace(new RegExp(s1,"gm"),s2);
}

function $E(b){
	var a=typeof b=="string"?document.getElementById(b):b;
	if(a!=null){return a}else{}return null
}

function inputCounter(objectid, msgId, isEditor, maxLength){
	var expectLength = maxLength;

	if(isEditor=="true"){
		var body = editor.getData();
			body = body.replaceAll("\t","");
			body = body.replaceAll("\n","");
			body = body.replaceAll("\r","");

		expectLength = maxLength - body.length;
	}else{
		var body = $E(objectid).value;
			body = body.replaceAll("\t","");
			body = body.replaceAll("\n","");
			body = body.replaceAll("\r","");
			var len = body.length;
			
			expectLength = maxLength - len;
	}

	//show the message
	var messageBox = $E(msgId);
	if(expectLength>=0){
		messageBox.innerHTML = "你还可以输入<span>" + expectLength + "</span>个中文字";
	}else{
		messageBox.innerHTML = "对不起，讯息内容不能超过<span>" + maxLength + "</span>个中文字";
	}
}

