// JavaScript Document

function pop_qm(id){
	window.open ("popup/qm.php?id="+id, "qmWindow", "height=550, width=500, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no")
}

function GetLength()
{
	// This functions shows that you can interact directly with the editor area
	// DOM. In this way you have the freedom to do anything you want with it.

	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

	// Get the Editor Area DOM (Document object).
	var oDOM = oEditor.EditorDocument ;

	var iLength ;

	// The are two diffent ways to get the text (without HTML markups).
	// It is browser specific.

	if ( document.all )		// If Internet Explorer.
	{
		iLength = oDOM.body.innerText.length ;
		if(oDOM.body.innerHTML.indexOf("img") !=-1 || oDOM.body.innerHTML.indexOf("IMG") !=-1){
			iLength ++;
		}
	}
	else					// If Gecko.
	{
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		iLength = r.toString().length ;
		if(r.toString().indexOf("img") !=-1 || r.toString().indexOf("IMG") !=-1){
			iLength ++;
		}
	}

	return iLength;
}

function ExecuteCommand( commandName )
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

	// Execute the command.
	oEditor.Commands.GetCommand( commandName ).Execute() ;
}

function OnSubmitDiaryComment(){
  if(document.pressed == 'Submit Comment')
  {
	ExecuteCommand('SelectAll');
	ExecuteCommand('Copy');
	alert("Your message has been copied to clipboard, if this action failed, you can paste it and try again.");
   document.frmPostComment.action ="add_diary_comment.php";
	document.frmPostComment.target ="_self";
  }
  else
  if(document.pressed == 'Preview')
  {
	ExecuteCommand('SelectAll');
	ExecuteCommand('Copy');
	alert("Your message has been copied to clipboard, if this action failed, you can paste it and try again.");
    document.frmPostComment.action ="diary_comment_preview.php";
	document.frmPostComment.target ="_blank";
  }
  return true;
}


function imgzoom(img,maxsize){
	var a=new Image();
	a.src=img.src
	if(a.width > maxsize)
	{
		img.style.width=maxsize;
		img.style.height=Math.round(maxsize*a.height / a.width);
	}
	return false;
}

function showMore(varA1, varB1) {
	var123 = ('varXYZ' + (varA1));
	varABC = ('varP' + (varA1));
	if ( document.getElementById ) {
		if ( document.getElementById(var123).style.display ) {
			if ( varB1 != 0 ) {
				document.getElementById(var123).style.display = "block";
				document.getElementById(varABC).style.display = "none";
			} else { 
				document.getElementById(var123).style.display = "none";
				document.getElementById(varABC).style.display = "block"; 
			}
		} else {
			location.href = varB1; return true;
		}
	} else {
		location.href = varB1; return true;
	}
}

function OnSubmitTopic(){
  if(document.pressed == '发表')
  {
	if(!document.frmPostTopic.topic_title.value){
		alert("请输入文章标题。");
		document.frmPostTopic.topic_title.focus();
		return false;
	}else if(!GetLength()){
		alert("请输入文章内容。");
		return false;
	}else{
		ExecuteCommand('SelectAll');
		ExecuteCommand('Copy');
		document.frmPostTopic.action ="post.php";
		document.frmPostTopic.target ="_self";
	  return true;
	}
  }
  else
 if(document.pressed == '编辑')
	  
  {
	if(!document.frmEditTopic.topic_title.value){
		alert("请输入文章标题e。");
		document.frmEditTopic.topic_title.focus();
		return false;
	}else if(!GetLength()){
		alert("请输入文章内容。");
		return false;
	}else{
		ExecuteCommand('SelectAll');
		ExecuteCommand('Copy');
		document.frmEditTopic.action ="post_edit_topic.php";
		document.frmEditTopic.target ="_self";
	  return true;
	}
  }
}

function OnSubmitReply(){
  if(document.pressed == '回复')
  {
	if(!GetLength()){
		alert("请输入文章内容。");
		return false;
	}else{
		ExecuteCommand('SelectAll');
		ExecuteCommand('Copy');
		document.frmPostReply.action ="post_reply.php";
		document.frmPostReply.target ="_self";
	    return true;
	}
  }
  else
  if(document.pressed == '编辑')
  {
	if(!GetLength()){
		alert("请输入文章内容。");
		return false;
	}else{
		ExecuteCommand('SelectAll');
		ExecuteCommand('Copy');
		document.frmEditReply.action ="post_edit_reply.php";
		document.frmEditReply.target ="_self";
		return true;
	}
  }
}

var QuoteCount=1;

function insertQuote(topicIndex, userName, topicDate )
{
	if (QuoteCount++>5)
	{
		alert("回帖引用不可以超过5次");
	}else{
	
		// Get the editor instance that we want to interact with.
		var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
		var topicID = ('topic_text' + (topicIndex));
		var quoteText;
		var quoteTextL = '<div class="quote_head">QUOTE: '+ userName +' posted in '+ topicDate +'</div><div class="quote_body">';

		if(document.all || document.getElementById){ 
			if(document.all){
				quoteText = quoteTextL+document.all[topicID].innerHTML+'</div>';
			}else{
				quoteText = quoteTextL+document.getElementById(topicID).innerHTML+'</div>';
			}

			quoteText = quoteText.replace(/onload/, "");
		}

		// Check the active editing mode.
		if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
		{
			// Insert the desired HTML.
			oEditor.InsertHtml( quoteText ) ;
		}
		else{
			alert( 'You must be on WYSIWYG mode!' ) ;
		}
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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_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_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];}
}

function showZone(menuNo) {
	var123 = ('zone' + (menuNo));
	if ( document.getElementById ) {
		if ( document.getElementById(var123).style.display ) {
			  for(var i=1;i<3;i++){
				 if(i!=menuNo){
				 	var varXYZ = ('zone' + (i));
					document.getElementById(varXYZ).style.display = "none";
				 }
			  }
			if ( document.getElementById(var123).style.display == "none" ) {
				document.getElementById(var123).style.display = "block";
			} else { 
				document.getElementById(var123).style.display = "none";
			}
		} 
	}
}

function showMore(varA1, imageName) {
	var123 = ('block' + (varA1));
	if ( document.getElementById ) {
		if ( document.getElementById(var123).style.display ) {
			if ( document.getElementById(var123).style.display == "none" ) {
				document.getElementById(var123).style.display = "block";
				MM_swapImage(imageName,'','../images/common/html/arrow_exp_a.gif',1);
			} else { 
				document.getElementById(var123).style.display = "none";
				MM_swapImage(imageName,'','../images/common/html/arrow_exp_b.gif',1);
			}
		} 
	}
}

function copy2blog(id){
	var id;
	window.open("copy2blog.php?id="+id,"copy2blog","resizable=no,menubar=no,directories=no,scrollbars=yes,status=no,location=no,width=400,height=150");
}

