//Examine the browser
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_mac    = (userAgent.indexOf('mac') != -1);

//Show/Hide a DIV
function showhidediv(id){
  try{
    var panel=document.getElementById(id);
    if(panel){
      if(panel.style.display=='none'){
        panel.style.display='block';
      }else{
        panel.style.display='none';
      }
    }
  }catch(e){}
}

function addhtml (id, htmlcode, uniqueid) {
	var panel=document.getElementById(id);
	var hiddenpannel=document.getElementById(uniqueid);
	if(panel){
		hiddenpannel.value='';
		hiddenpannel.value=panel.innerHTML;
		panel.innerHTML=hiddenpannel.value+htmlcode;
		hiddenpannel.value+=htmlcode;
	}
}

function showadminreply (divid) {
	var cleanid=divid.replace('com_', '');
	var inputcontent="<form action='admin.php?go=reply_addadminreply_"+cleanid+"' method='post'>";
	inputcontent+="回复: <br/><textarea cols='66' rows='3' name='adminreplycontent'></textarea><br/>";
	inputcontent+="<input type='submit' value='提交'/> <input type='reset' value='清空'/> <input type='button' value='取消' onclick=\"hideadminreply('"+divid+"');\"/></form>";
	document.getElementById(divid).innerHTML=inputcontent;
	document.getElementById(divid).style.display='block';
}

function showadminreplyformessage (divid) {
	var cleanid=divid.replace('com_', '');
	var inputcontent="<form action='admin.php?go=message_addadminreply_"+cleanid+"' method='post'>";
	inputcontent+="回复: <br/><textarea cols='66' rows='3' name='adminreplycontent'></textarea><br/>";
	inputcontent+="<input type='submit' value='提交'/> <input type='reset' value='清空'/> <input type='button' value='取消' onclick=\"hideadminreply('"+divid+"');\"/></form>";
	document.getElementById(divid).innerHTML=inputcontent;
	document.getElementById(divid).style.display='block';
}

function hideadminreply (divid) {
	document.getElementById(divid).innerHTML='';
	document.getElementById(divid).style.display='none';
}

function showdelblog(blogid) {
	var urldel="admin.php?go=entry_deleteblog_"+blogid+'';
	if(confirm("确定删除对这篇日志吗？包括回复和引用在内的一切都将被删除且不可恢复！")){
		window.location=urldel;
	}
	else {
		return;
	}
}

function comfirmurl(urldel) {
	if(confirm("确定执行删除操作吗？这步操作不可恢复！")){
		window.location=urldel;
	}
	else {
		return;
	}
}

function showdeladminreply(repid) {
	var urldel="admin.php?go=reply_deladminreply_"+repid+'';
	if(confirm("确定删除对这条评论的回复吗？这步操作不可恢复！")){
		window.location=urldel;
	}
	else {
		return;
	}
}

function showdeladminreplyformessage(repid) {
	var urldel="admin.php?go=message_deladminreply_"+repid+'';
	if(confirm("确定删除对这条留言的回复吗？这步操作不可恢复！")){
		window.location=urldel;
	}
	else {
		return;
	}
}

function showdelreply(repid, blogid) {
	var urldel="admin.php?go=reply_delreply_"+repid+'-'+blogid;
	if(confirm("确定删除这条评论吗？这步操作不可恢复！")){
		window.location=urldel;
	}
	else {
		return;
	}
}

function showdelreplyformessage(repid) {
	var urldel="admin.php?go=message_delreply_"+repid;
	if(confirm("确定删除这条留言吗？这步操作不可恢复！")){
		window.location=urldel;
	}
	else {
		return;
	}
}

//Submit Check and AJAX functionality
function ajax_submit (job) {
	var stat_html = document.getElementById('stat_html').checked ? 1 : 0;
	var stat_ubb = document.getElementById('stat_ubb').checked ? 1 : 0;
	var stat_emot = document.getElementById('stat_emot').checked ? 1 : 0;
	var stat_property = document.getElementById('stat_property').checked ? 1 : 0;
	var v_replier = document.getElementById('v_replier').value;
	var v_repurl = document.getElementById('v_repurl').value;
	var v_repemail = document.getElementById('v_repemail').value;
	var v_content = document.getElementById('v_content').value;
	//v_content = v_content.replace("\r","<n>");
	//v_content = v_content.replace("\n","<n>"); //Convert line changing character
	var v_id = document.getElementById('v_id').value;
	if (document.getElementById('v_security')) {
		var v_security = document.getElementById('v_security').value;
		if (v_security=='') {
			alert('请填写验证码！');
			return false;
		}
	} else {
		var v_security;
	}
	if (v_replier=='' || v_content=='') {
		alert('请填写昵称或内容！');
		return false;
	}
	document.getElementById('btnSubmit').value='正在提交，请稍候';
	document.getElementById('btnSubmit').disabled='disabled';
	if (shutajax==0 && (is_ie || is_moz || is_saf || is_opera)) { //Currently for IE, Safari, Mozilla and Opera
		xajax_addreply(job, stat_html, stat_ubb, stat_emot, stat_property, v_replier, v_repurl, v_repemail, v_content, v_id, v_security);
		window.location="#topreply";
	} else {
		document.getElementById('visitorinput').submit();
	}
}


//Avatar Selection
function changeavatar (slname, area) {
	var current=document.getElementById(slname);
	var realvalue=current.options[current.selectedIndex].value;
	var areashow=document.getElementById(area);
	if (areashow) {
		if (realvalue!='' && realvalue!=null) {
			areashow.innerHTML="<img src='images/avatars/"+realvalue+"' alt=''/>";
		}
		else {
			areashow.innerHTML="无头像";
		}
	}
}

//Insert Emots
function insertemot (emotcode) {
	var current=document.getElementById('v_content');
	var emot="[emot]"+emotcode+"[/emot]";
	if (current) {
		if (current.value!='' && current.value!=null) {
			current.value+=emot;
		}
		else {
			current.value=emot;
		}
	}
}

// Show/Hide Sidebar
function showHideSidebar(){
  try{
    var objSidebar=document.getElementById("sidebar");
    var objContent=document.getElementById("content");
    if(objSidebar.className!="sidebar-hide"){
      objSidebar.className="sidebar-hide";
      objSidebar.style.display="none";
      objContent.className="content-wide";
    }else{
      objSidebar.className="sidebar";
      objSidebar.style.display="block";
      objContent.className="content";
    }
  }catch(e){}
}

//Media Link
function playmedia(strID,strType,strURL,intWidth,intHeight) {
	var objDiv=document.getElementById(strID);
	if (!objDiv) return false;
	if (objDiv.style.display!='none') {
		objDiv.innerHTML='';
		objDiv.style.display='none';
	} else {
		objDiv.innerHTML=makemedia(strType,strURL,intWidth,intHeight);
		objDiv.style.display='block';
	}
}

//Media Build
function makemedia (strType,strURL,intWidth,intHeight) {
	var strHtml;
	switch(strType) {
		case 'wmp':
			strHtml="<object width='"+intWidth+"' height='"+intHeight+"' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param name='url' value='"+strURL+"'/><embed width='"+intWidth+"' height='"+intHeight+"' type='application/x-mplayer2' src='"+strURL+"'></embed></object>";
			break;
		case 'swf':
			strHtml="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='"+intWidth+"' height='"+intHeight+"'><param name='movie' value='"+strURL+"'/><param name='quality' value='high' /><embed src='"+strURL+"' quality='high' type='application/x-shockwave-flash' width='"+intWidth+"' height='"+intHeight+"'></embed></object>";
			break;
		case 'real':
			strHtml="<object classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width='"+intWidth+"' height='"+intHeight+"'><param name='src' value='inc/realplay.php?link="+strURL+"' /><param name='controls' value='Imagewindow' /><param name='console' value='clip1' /><param name='autostart' value='true' /><embed src='inc/realplay.php?link="+strURL+"' type='audio/x-pn-realaudio-plugin' autostart='true' console='clip1' controls='Imagewindow' width='"+intWidth+"' height='"+intHeight+"'></embed></object><br/><object classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width='"+intWidth+"' height='44'><param name='src' value='inc/realplay.php?link="+strURL+"' /><param name='controls' value='ControlPanel' /><param name='console' value='clip1' /><param name='autostart' value='true' /><embed src='inc/realplay.php?link="+strURL+"' type='audio/x-pn-realaudio-plugin' autostart='true' console='clip1' controls='ControlPanel' width='"+intWidth+"' height='44'></embed></object>";
			break;
	}
	return strHtml;
}

//Font size control
function doZoom(size) {
	document.getElementById('zoomtext').style.fontSize=size+'px';
}

//Starring
function dostar(blogid) {
	gourl="admin.php?go=star&blogid="+blogid;
	window.location=gourl;
}