﻿//发贴提交
var subN=0 ;
function mysubmit(submitvalue,vlvalue)
{
	var sv = submitvalue;
	var vv = vlvalue;
	var message = wysiwyg ? html2bbcode(getEditorContents()) : $("message").value;
	var msglen = message.length;
	
	if(form1.title.value=="" || form1.title.value=="请输入标题"){
		alert("标题不能为空！也不能为默认值！");
		form1.title.focus();
		return(false);
	}
	if(msglen<2){
		alert("贴子内容不能为空！");
		checkFocus();
		return(false);
	}
	
	if(vv=="y") {
		if(form1.vl_code.value==""){
		alert("请输入验证码！");
		form1.vl_code.focus();
		return(false);
	}
	}
	if (sv=="y")
	{

		if(form1.subclass.value==0){
		alert("请选择分类！");
		form1.subclass.focus();
		return(false);
	}
	}

	if(subN==0)
	{subN=1;
	}
	else
	{return(false);
   }

	if(wysiwyg==0) document.getElementById("context").value=$("posteditor_textarea").value;
	else document.getElementById("context").value=html2bbcode(getEditorContents());

	CopyText(document.form1.context);
	document.getElementById("postbtn").disabled=true;
	document.all.waiting.style.pixelTop = (document.body.offsetHeight - 	document.all.waiting.clientHeight) / 2 - 100 + document.body.scrollTop;
	document.all.waiting.style.pixelLeft = (document.body.offsetWidth - 	document.all.waiting.clientWidth) / 2 + document.body.scrollLeft;
	document.all.waiting.style.visibility = "visible";
	document.all.form1.submit();
}


//搜索提交
function mysubmitsearch()
{
	if(search.userid.value=="" && search.keyword=="" && search.postcontent==""){
		alert("搜索项目不能全为空！");
		search.keyword.focus();
		return(false);
	}

document.all.waiting2.style.pixelTop = (document.body.offsetHeight - document.all.waiting2.clientHeight) / 2 - 100 + document.body.scrollTop;
document.all.waiting2.style.pixelLeft = (document.body.offsetWidth - document.all.waiting2.clientWidth) / 2 + document.body.scrollLeft;
document.all.waiting2.style.visibility = "visible";
document.all.search.submit();
}

//注册窗口
function openreg()
{
	var x,y;
	x=(screen.width-640)/3;
	y=(screen.height-480)/3;
	window.open("register.asp","regwindow","toolbar=no,resizable=no,directories=no,status=yes,scrollbars=auto,menubar=no,width=310,height=280,left="+x+",top="+y);
}

//会员信息
function memberinfo(id)
{
	var x,y;
	x=(screen.width-640)/3;
	y=(screen.height-480)/3;
	window.open("memberinfo.asp?id="+id+"Z","memberwindow","toolbar=no,resizable=no,directories=no,status=yes,scrollbars=auto,menubar=no,width=360,height=305,left="+x+",top="+y);
}

function memberinfo2(id)
{
	var x,y;
	x=(screen.width-640)/3;
	y=(screen.height-480)/3;
	window.open("../memberinfo.asp?id="+id+"Z","memberwindow","toolbar=no,resizable=no,directories=no,status=yes,scrollbars=auto,menubar=no,width=360,height=305,left="+x+",top="+y);
}


//关于信息
function openabout(id)
{
	var x,y;
	x=(screen.width-640)/3;
	y=(screen.height-480)/3;
	window.open("about.asp","aboutwindow","toolbar=no,resizable=no,directories=no,status=yes,scrollbars=auto,menubar=no,width=320,height=240,left="+x+",top="+y);
}

//WAP
function openwap(id)
{
	var x,y;
	x=(screen.width-640)/3;
	y=(screen.height-480)/3;
	window.open("http://win.uucun.com/frame.jsp?url=http%3A%2F%2Fwww.learn365.cn%2Fwap%2Fwap.asp&frameheight=440&submit.x=14&submit.y=8","aboutwindow","toolbar=no,resizable=no,directories=no,status=yes,scrollbars=auto,menubar=no,width=260,height=400,left="+x+",top="+y);
}

//标题类别
function DoTitle(addTitle) { 
var revisedTitle; 
var currentTitle = document.form1.title.value; 
addTitle="["+addTitle+"]"
revisedTitle = addTitle+String.fromCharCode(32)+currentTitle; 
document.form1.title.value=revisedTitle; 
document.form1.title.focus();
return; 
}

//重设回复标题
function setReplyTitle(title,idnum) {
var newtitle;
newtitle="回复"+idnum+"楼:"+title
if (idnum==0)
{
newtitle="回复楼主:"+title;
}
document.form1.title.value=newtitle;
checkFocus();
return;
}

//表情插入
function insertemot(emotCode) {
	if (emotCode<10) {emotCode="0"+emotCode;}
	var emotCode2=emotCode;
	emotCode = ' [emot' + emotCode + '] ';
	emotCode2='images/emot/'+emotCode2+'.gif'
	checkFocus();
	if(wysiwyg)	{
		applyFormat('insertimage', false,emotCode2);
		checkFocus();
	}
	else 
	{
	var txtarea = document.form1.message;
	emotCode = ' ' + emotCode + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
	var caretPos = txtarea.caretPos;
	caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? emotCode + ' ' : emotCode;
	txtarea.focus();
	} else {
	txtarea.value  += emotCode;
	txtarea.focus();
	}
	}
}

//错误图片处理
function errpic(thepic){
thepic.src="images/showerr.gif" 
}

//发贴内容缓存
function CopyText(obj) {
	ie = (document.all)? true:false
	if (ie){
		var rng = document.body.createTextRange();
		rng.moveToElementText(obj);
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
	}
}

//页面关键字搜索
function searchkey(objname,num){
	var myfontsize,a,i;
	var tempText,Text;
	for (i=1;i<=num ;i++ )
	{
	 a=objname+i;
	 //document.write(a);
	Text=document.getElementById(a).innerText;
	tempText=Text;
	h="<font class=keyword>";
	f="</font>";
	keyset=new Array();
	key=document.all.keys.value;
	if (key==""){
		alert("请输入搜索关键字!");
			return;
		}
		else{
		keyset[0]=tempText.indexOf(key,0);
			if (keyset[0]<0){
					return;
			}else
				temp=tempText.substring(0,keyset[0]);
				temp=temp+h+key+f;
				temp2=tempText.substring(keyset[0]+key.length,tempText.length);
				for (i=1;i<tempText.length;i++)	{
					keyset[i]=tempText.indexOf(key,keyset[i-1]+key.length);
					if(keyset[i]<0){
					temp=temp+tempText.substring(keyset[i-1]+key.length,tempText.length);
					break;
					}else{
					temp=temp+tempText.substring(keyset[i-1]+key.length,keyset[i])+h+key+f;
					}
				}
					a.innerHTML = temp;
			}
	}
	}


/*引用*/
function quoteit(objname) {
		if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		if(wysiwyg)	
			{editdoc.body.innerHTML+="[quote][link="+objname+"][/link][color=gray]" + document.getElementById(objname).innerText + "[/color]<br/>===============================================<br/>" + range.text + "[/quote]\n";
			}
		else 
			{$('message').value +="[quote][link="+objname+"][/link][color=gray]" + document.getElementById(objname).innerText + "[/color]\n===============================================\n" + range.text + "[/quote]\n";
				}
		alert("引用内容已成功复制到发贴区！");
		checkFocus();	
		} else {  
        alert("请先用鼠标拖动选择要引用的内容!");
        }
}

/*读写Cookie*/

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
  
}	

//清空表单
function FormReset() {
     if(wysiwyg==0)$("posteditor_textarea").value="";
	 else editdoc.body.innerHTML="";
	 if (document.getElementById("context").value!=""){
		if(wysiwyg==0)$("posteditor_textarea").value=document.getElementById("context").value;
		else editdoc.body.innerHTML=bbcode2html(document.getElementById("context").value);
	 }
}
