
document.domain = "tiexue.net";

if (typeof(TopPanel)!='function'){
	
}

//频道ID
var froumid=0;


	//创建对话框
	function CreateInfo()
	{
		if (TxCustomDlg==null) TxCustomDlg = new CustomDlg("TxCustomDiv","TxMsgDialog_h");

		var inputBoxHeight=20;
		if (xmlns1999) inputBoxHeight = 15;
		
		//提问对话框网页脚本数据
		var inputstyle = "";
		var temp = "<style>";
		temp += '.inputInfo{BORDER-LEFT: #84a1bd 1px solid;BORDER-TOP:#84a1bd 1px solid;BORDER-RIGHT:#84a1bd 1px solid;BORDER-BOTTOM: #84a1bd 1px solid;FONT-SIZE:12px;PADDING-LEFT:2px;PADDING-TOP:2px;PADDING-RIGHT:2px;PADDING-BOTTOM:0px;text-valign: middle;}\r\n';
		temp += '#helpContent{';
		temp += 'font-size:10pt;SCROLLBAR-HIGHLIGHT-COLOR: #ffffff; SCROLLBAR-SHADOW-COLOR: #cccccc; COLOR: #000000; SCROLLBAR-3DLIGHT-COLOR: #cccccc;SCROLLBAR-FACE-COLOR: #ffffff;SCROLLBAR-ARROW-COLOR: #666666;SCROLLBAR-TRACK-COLOR: #ffffff;SCROLLBAR-DARKSHADOW-COLOR: #fff; FONT-FAMILY: 宋体;';
		temp += 'BORDER-RIGHT: #333 1px dashed; PADDING-RIGHT: 6px; BORDER-TOP: #333 1px dashed; PADDING-LEFT: 6px; PADDING-BOTTOM: 6px; BORDER-LEFT: #333 1px dashed; PADDING-TOP: 6px; BORDER-BOTTOM: #333 1px dashed';
		temp += '}';
		temp += '</style>';
			
		
		temp += '<form id="thishelpForm" name="thishelpForm" method="post" action="return false">';	
		temp += '<table cellSpacing="0" cellPadding="0" width="97%" height="100%" border="0" align="center">';
		


        temp+='<tr>';
		temp+='<td align="left" colspan="3" style="color:red;">为了方便我们与你联系，请填写你的联系方式(需填一种，方便与您联系)</td>';
		temp += '</tr>';
        
		temp += '<tr height="3"><td colspan="3"></td></tr>';
		

        temp += '<tr>';
		temp += '	<td noWrap align="left">电子邮箱: <input title="邮箱" id="Email" style="WIDTH:210px;HEIGHT:' + inputBoxHeight + 'px;" maxLength="80" NAME="Email" class="inputInfo"></td>';
		temp += '</tr>';
		
		
		temp += '<tr height="3"><td colspan="3"></td></tr>';
		
		temp += '<tr>';
		temp += '	<td noWrap align="left">联系电话: <input title="联系电话" id="Tel" style="WIDTH:210px;HEIGHT:' + inputBoxHeight + 'px;" maxLength="80" NAME="Tel" class="inputInfo"></td>';
		temp += '</tr>';
		
//		temp += '<tr height="5" ><td colspan="3" align="left">-------------------------------------------------------------------------------</td></tr>';
		
		temp += '<tr height="5"><td colspan="3"></td></tr>';

		
		
		temp+='<tr >';
		temp+='<td align="left" width="300">问题所属类别:';
		temp += '		<select  ID="GroupList" NAME="GroupList" class="inputInfo" onChange="Selgid(this.options[this.options.selectedIndex].value)">';
		temp += '		</select>';
		temp += '	</td>';
		temp += '</tr>';
		
        temp += '<tr height="3"><td colspan="3"></td></tr>';
		
		
		
		temp += '<tr><td colspan="3"></td></tr>';
		temp += '<tr>';
		temp += '	<td noWrap align="left">问题标题: <input title="问题标题" id="Title" style="WIDTH:210px;HEIGHT:' + inputBoxHeight + 'px;" maxLength="80" NAME="Title" class="inputInfo"><font color=red>（务必填写）</font></td>';
		temp += '</tr>';
		
		
	    temp += '<tr height="3"><td colspan="3"></td></tr>';

		
		temp+='<tr><td colspan="3" align="left">问题详细描述: </td></tr>';
		
		temp += '<tr>';
		temp += '	<td align="center" colspan="3" id="HelpContentTD">';
		
		temp += '</td>';
		temp += '</tr>';
		
		temp += '<tr height="5"><td colspan="3"></td></tr>';
		
		
		
		
		
		temp += '<tr><td colSpan="3" align="left"><b>文本要求</b>：&nbsp;&nbsp;标题最多<b>50</b>个字符，内容最多<b>500</b>个字符</td></tr>';
		
		temp += '<tr height="5"><td colspan="3"></td></tr>';
		
		temp += '<tr>';
		temp += '	<td vAlign="middle" align="center" colSpan="3">';
		temp += '		<INPUT id="SendHelpBt" type="button" value="  提  交  " onClick="SendSubmit1();" class="inputInfo">&nbsp;';		
		temp += '	</td>';
		temp += '</tr>';
		temp += '</table>';
		temp += '</form>';

		TxCustomDlg.YUIShow("我要提问题",temp);
	
		YAHOO.util.Event.onContentReady ("HelpContentTD",function(){
					document.getElementById("HelpContentTD").innerHTML = '<textarea title="键入短信文本内容" style="WIDTH:97%;height:180px;" name="helpContent" rows="12" cols="60" ID="helpContent"></textarea>';
				});
		

		
		//YAHOO.util.Event.onAvailable("MsgCodeImage1",function(){document.getElementById("MsgCodeImage1").src = MsgConfig.ValidateUrl + '?tmp=' + Math.random();});
	
	    
	    //获取频道信息
	    //YAHOO.util.Event.onAvailable("GroupList",SendMsgExecute0);
	    
	    
	}
	
	
	



 //填充频道信息
function FillGroupList(value)
{
   
   var groupid,groupname;
	if (value!=""){
		var tempArr;
		var arr=value.split(";");
		try{
		with(thishelpForm){
		//加载频道
			while(GroupList.options.length>0) GroupList.remove(0);
			//GroupList.options.add(new Option("--选择论坛--",-1));
			for (var i=0;i<arr.length;i++){
				tempArr=arr[i].split(",");
				groupid=tempArr[0];
				groupname=tempArr[1];
				GroupList.options.add(new Option(groupname,groupid));
			}
					
		//判断是哪个频道以便设置默认值，取频道的ID	
        if(window.location.href.indexOf("pic.tiexue.net")!=-1)
         {
            GroupList.options[4].selected=true;
            GroupList.options[GroupList.selectedIndex].value=7;
            
            froumid= GroupList.options[GroupList.selectedIndex].value;
          }
        else if(window.location.href.indexOf("book.tiexue.net")!=-1)
         {
            GroupList.options[1].selected=true;
            GroupList.options[GroupList.selectedIndex].value=2;
            froumid= GroupList.options[GroupList.selectedIndex].value;
         }
        else if(window.location.href.indexOf("pay.tiexue.net")!=-1)
        {
           GroupList.options[0].selected=true;
           GroupList.options[GroupList.selectedIndex].value=1;
           froumid= GroupList.options[GroupList.selectedIndex].value;
        }
        else
        {
            GroupList.options[2].selected=true;
            GroupList.options[GroupList.selectedIndex].value=3;
            
            froumid= GroupList.options[GroupList.selectedIndex].value;
        }
        
		}
		}catch(e){}
	}
	
}

//获取select选项改变后的值
function Selgid (groupvalue)
{
   if(groupvalue>=0)
   {
      froumid=groupvalue;
   }
}








//判断内容是否为空及相关输入格式是否正确
function SendSubmit1(){
	with(thishelpForm){
	    if(Email.value==""&&Tel.value==""){
	       TxAlert("联系方式请至少填写一项");
	       return;
	    }
	    
	    if(Email.value!=""){
	    if(!ValidateEmail(document.getElementById("Email")))
	    {
	       
	       TxAlert("电子邮箱格式不正确");
	       
	       return;
	    }
	    }
	    
	    if(Tel.value!=""){
	    if(!ValidateText(document.getElementById("Tel")))
	    {
	       TxAlert("联系电话格式不正确");
	       
	       return;
	    }
	    }
	    
	    
		if (Title.value == ""){
			TxAlert('标题不能为空值!');
			return;
		}
		
		
		SendMsgExecute1(Title.value,Email.value,helpContent.value,Tel.value,froumid);
	}
}

//获取板块信息
function SendMsgExecute0(){
	var SendMsgCallback =
	{
		success:function(o){
			TxProcessHide();
			if(o.responseText !== undefined){
				if (o.status==200){
					var temp = o.responseText;
					FillGroupList(temp);
				}
			}
		},
		failure:function(o){
			TxProcessHide();
			if(o.responseText !== undefined){
				TxAlert(o.statusText);
			}
		}
	};
    var sUrl="agent.aspx?desturl=" + encodeURIComponent("http://help.tiexue.net/GroupList.aspx");
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, SendMsgCallback,"");

}


//发送提问执行过程
function SendMsgExecute1(Title,Email,Content,Tel,froumid){
	var SendMsgCallback =
	{
	    
		success:function(o){
		    //alert(1);
			TxProcessHide();
			if(o.responseText !== undefined){
				if (o.status==200){
					var returnText = o.responseText;
					if(returnText != ""){
					var temp = returnText.split('|');
					if(temp[0]=="true"){  //成功
					   CloseHelpWindow();
					   TxAlert(temp[2]);
					}
					else if (temp[0]=="false"){ //未成功
						TxAlert(temp[2]);
					}
				    }
				}
			}
		},
		failure:function(o){
			TxProcessHide();
			if(o.responseText !== undefined){
				TxAlert(o.statusText);
			}
		}
	};
	var sUrl = "agent.aspx?desturl=" + encodeURIComponent("http://help.tiexue.net/SaveQuestion.aspx");
	var postData = "Tel=" + encodeURIComponent(Tel);
	postData += "&Email=" + encodeURIComponent(Email);
	postData += "&froumid=" + froumid;
	postData +="&Title=" + encodeURIComponent(Title);
	postData += "&Content=" + encodeURIComponent(Content);
	

	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, SendMsgCallback, postData);
	TxProcessShow("发送中,请等待...",true);
}

//点击打开对话框
function OpenSendDlgOne(){
    SendMsgExecute0();
	CreateInfo();
}

function CloseHelpWindow()
{
   if (TxCustomDlg!=null) TxCustomDlg.Close();
}


/************ 站内搜索 **************/
function SearchPostByForum()
{
	var strkeywords = document.getElementById("textfield2").value;
	if (strkeywords == "" || strkeywords == undefined)
	{
		alert("搜索的内容不能为空！");
		return;
	}
	var Url = "http://so.tiexue.net/Search.aspx?Query=" + strkeywords;
	window.open(Url);
}

//验证Email格式是否正确
function ValidateEmail(mail){
        
		var helpMail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
		if(helpMail.test(mail.value)){
		   
			return true;	
		}
	
}

//验证联系电话格式是否正确
function ValidateText(obj){
	if(obj.value.length > 0){
		switch(obj.id)
		{
			case "Tel":
			var telhelp = /\d{11}|\d{13}/;
			if(telhelp.test(obj.value))
			{
				return true;
			}
			break;
			default:return true;
		}
	}
	return false;	
}