function isNumeric(num){ if (num.match(/[^0-9]/g)) { return false; } return true; } 


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 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 spot_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 == 'Submit')
  {
	if(!document.frmPostTopic.topic_title.value){
		alert("请输入文章标题。");
		document.frmPostTopic.topic_title.focus();
		return false;
	}else{
		ExecuteCommand('SelectAll');
		ExecuteCommand('Copy');
		document.frmPostTopic.action ="post.php";
		document.frmPostTopic.target ="_self";
	  return true;
	}
  }
  else
 if(document.pressed == 'Edit')
	  
  {
	if(!document.frmEditTopic.topic_title.value){
		alert("请输入文章标题e。");
		document.frmEditTopic.topic_title.focus();
		return false;
	}else{
		ExecuteCommand('SelectAll');
		ExecuteCommand('Copy');
		document.frmEditTopic.action ="post_edit_topic.php";
		document.frmEditTopic.target ="_self";
	  return true;
	}
  }
  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.frmPostTopic.action ="topic_preview.php";
	document.frmPostTopic.target ="_blank";
  }
}

function OnSubmitReply(){
  if(document.pressed == 'Submit')
  {
	ExecuteCommand('SelectAll');
	ExecuteCommand('Copy');
	document.frmPostReply.action ="post_reply.php";
	document.frmPostReply.target ="_self";
  }
  else
  if(document.pressed == 'Edit')
  {
	ExecuteCommand('SelectAll');
	ExecuteCommand('Copy');
	document.frmEditReply.action ="post_edit_reply.php";
	document.frmEditReply.target ="_self";
  }
  else
  if(document.pressed == 'Preview')
  {
	ExecuteCommand('SelectAll');
	ExecuteCommand('Copy');
    document.frmPostTopic.action ="reply_preview.php";
	document.frmPostTopic.target ="_blank";
  }
  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<8;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/arrow_exp_a.gif',1);
			} else { 
				document.getElementById(var123).style.display = "none";
				MM_swapImage(imageName,'','../images/arrow_exp_b.gif',1);
			}
		} 
	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


function fCheck(theForm){

if(theForm.company_name.value.length == 0){

alert("请输入贵旅行社的名称");

    theForm.company_name.focus();

return false;}


if(theForm.company_post.value.length == 0){

alert("请输入贵旅行社的邮政编码");

    theForm.company_post.focus();

return false;}


if(theForm.company_add.value.length == ""){

alert("请输入贵旅行社的地址");

    theForm.company_add.focus();

return false;}


if(theForm.company_tel.value.length == ""){

alert("请输入贵旅行社的电话号码");

    theForm.company_tel.focus();

return false;}


if(theForm.company_licence_no.value.length == ""){

alert("请输入贵旅行社的许可证编号");

    theForm.company_licence_no.focus();

return false;}


if(theForm.company_contact_name.value.length == ""){

alert("请输入负责人姓名");

    theForm.company_contact_name.focus();

return false;}


if(!echeck(theForm.company_contact_email.value)){
	
alert("请输入合法的负责人联系电子邮箱");

    theForm.company_contact_email.focus();
return false;}


if(theForm.company_user_name.value.length == ""){

alert("请输入您希望注册用的用户名称");

    theForm.company_user_name.focus();

return false;}


if(theForm.company_user_name.value.length < 2 || theForm.company_user_name.value.length > 20){
	
alert("用户名称长度为2-20个半角英文字母或数字");

    theForm.company_user_name.focus();

return false;}


  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

  var checkStr = theForm.company_user_name.value;

  var allValid = true;

  for (i = 0;  i < checkStr.length;  i++)

  {ch = checkStr.charAt(i);

    for (j = 0;  j < checkOK.length;  j++)

      if (ch == checkOK.charAt(j))

        break;

    if (j == checkOK.length){

      allValid = false;

      break;}

  }

  if (!allValid)

  {alert("用户名称只能使用半角英文字母或数字");

    theForm.company_user_name.focus();

    return (false);}


if(!theForm.company_link.checked && !theForm.company_print.checked){
	
	alert("请至少选择一项");

    theForm.company_link.focus();

    return (false);}

	return true;
}


//有偿会员Form检查

function pCheck(theForm){

if(theForm.company_name.value.length == 0){

alert("请输入贵旅行社的名称");

    theForm.company_name.focus();

return false;}


if(theForm.company_post.value.length == 0){

alert("请输入贵旅行社的邮政编码");

    theForm.company_post.focus();

return false;}


if(theForm.company_add.value.length == ""){

alert("请输入贵旅行社的地址");

    theForm.company_add.focus();

return false;}


if(theForm.company_tel.value.length == ""){

alert("请输入贵旅行社的电话号码");

    theForm.company_tel.focus();

return false;}


if(theForm.company_licence_no.value.length == ""){

alert("请输入贵旅行社的许可证编号");

    theForm.company_licence_no.focus();

return false;}


if(theForm.company_contact_name.value.length == ""){

alert("请输入负责人姓名");

    theForm.company_contact_name.focus();

return false;}


if(!echeck(theForm.company_contact_email.value)){
	
alert("请输入合法的负责人联系电子邮箱");

    theForm.company_contact_email.focus();
return false;}


if(theForm.company_user_name.value.length == ""){

alert("请输入您希望注册用的用户名称");

    theForm.company_user_name.focus();

return false;}


if(theForm.company_user_name.value.length < 2 || theForm.company_user_name.value.length > 20){
	
alert("用户名称长度为2-20个半角英文字母或数字");

    theForm.company_user_name.focus();

return false;}


  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

  var checkStr = theForm.company_user_name.value;

  var allValid = true;

  for (i = 0;  i < checkStr.length;  i++)

  {ch = checkStr.charAt(i);

    for (j = 0;  j < checkOK.length;  j++)

      if (ch == checkOK.charAt(j))

        break;

    if (j == checkOK.length){

      allValid = false;

      break;}

  }

  if (!allValid)

  {alert("用户名称只能使用半角英文字母或数字");

    theForm.company_user_name.focus();

    return (false);}


	return true;
}




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 ;
	}
	else					// If Gecko.
	{
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		iLength = r.toString().length ;
	}

	return iLength;
}



function tcFInfoCheck(theForm){
	if(GetLength()>1000){
		alert("公司介绍文字共"+GetLength()+"字,超过了1000字的字数限制。");
		return false;
	}

	if(!echeck(theForm.tcEmail.value)){
		alert("请输入合法的联系电子邮箱");
		theForm.tcEmail.focus();
		return false;
	}
	
	return true;
}

function tcInfoCheck(theForm){
	if(!echeck(theForm.tcEmail.value)){
		alert("请输入合法的联系电子邮箱");
		theForm.tcEmail.focus();
		return false;
	}
	return true;
}

function tcRecCheck(theForm){
	if(theForm.tcRecTitle.value == ""){
		alert("请输入标题");
		theForm.tcRecTitle.focus();
		return false;
	}
	
	if(theForm.tcRecURL.value == "" || theForm.tcRecURL.value=="http://"){
		alert("请输入网址");
		theForm.tcRecURL.focus();
		return false;
	}
	return true;
}

function arraySizeCheck() {
	if (document.tcCrsFrm.elements['tsCrsClass[]'].length) {
		count = 0;
		for (var i=0;i<document.tcCrsFrm.elements['tsCrsClass[]'].length;i++){
			if ((document.tcCrsFrm.elements[i].name=="tsCrsClass[]") && (document.tcCrsFrm.elements[i].checked)) {
				count ++;
			}
		}
		return count; //

	} else {
		if (document.tcCrsFrm.elements['tsCrsClass[]'].checked) {
			return 1; //
		} else {
			return 0; //
		}
	}
}


function tcCrsCheck(theForm){

	if(theForm.tcCrsTitle.value == ""){
		alert("请输入标题");
		theForm.tcCrsTitle.focus();
		return false;
	}
	
	if(theForm.tcCrsIntro.value == ""){
		alert("请输入简介");
		theForm.tcCrsIntro.focus();
		return false;
	}
	
	if(theForm.tsCrsPhoto.value != ""){
		var myLength = theForm.tsCrsPhoto.value.length;
		var exten = theForm.tsCrsPhoto.value.substring(myLength-3, myLength);

		if(exten!="jpg" && exten!="JPG" && exten!="gif" && exten!="GIF"){
			alert("请使用Jpg, Gif格式的图片文件");
			theForm.tsCrsPhoto.focus();
			return false;
		}
	}
	
	if(!arraySizeCheck()){
		alert("请至少选择一项类别");
		return false;
	}

	if(theForm.tcCrsPrice.value == ""){
		alert("请输入价格");
		theForm.tcCrsPrice.focus();
		return false;
	}
	
	if(!isNumeric(theForm.tcCrsPrice.value)){
		alert("价格必须为半角数字");
		theForm.tcCrsPrice.focus();
		return false;
	}
	
	if(theForm.tcCrsContact.value == ""){
		alert("请输入联系人");
		theForm.tcCrsContact.focus();
		return false;
	}
	
	if(theForm.tcCrsTel.value == ""){
		alert("请输入联系电话");
		theForm.tcCrsTel.focus();
		return false;
	}
	
	if(GetLength() == 0){
		alert("请填写日程安排");
		return false;
	}

	return true;
}

function OnSubmitCnBLog(theForm){
	if(theForm.title.value == ""){
		alert("请输入博客名称");
		theForm.title.focus();
		return false;
	}
	
	if(theForm.url.value == "" || theForm.url.value == "http://"){
		alert("请输入博客地址");
		theForm.url.focus();
		return false;
	}
	
	if(theForm.author.value == ""){
		alert("请输入博客作者");
		theForm.author.focus();
		return false;
	}
	
	if(!echeck(theForm.email.value)){
		alert("请输入合法的电子邮箱");
		theForm.email.focus();
		return false;
	}
	
	if(theForm.agree.checked == false){
		alert("您必须同意《华人博客圈加入协议》才可以继续。");
		theForm.agree.focus();
		return false;
	}
	
	return true;
}

	function changeTab(objNum, MaxNum){
		for(var i=1; i<=MaxNum; i++ ){
			var tabName = 'tab'+i;
			var conName = 'tabCon'+i;
			var tabObj = document.getElementById(tabName);
			var conObj = document.getElementById(conName);
			if(i==objNum){
				tabObj.className = "active";
				conObj.style.display = "block";
			}else{
				tabObj.className = "normal";
				conObj.style.display = "none";
			}
		}
	}


