﻿
var question={version:'1.0.0',action:'/ask/question.aspx',method:'post',target:'iframeQuestion',validateUrl:'/controls/validatecode.ashx',loginUser:true,tagList:[],outputId:'question',broadcastId:0,validateForm:function(){var msg=[];if(this.loginUser){if(autoRadio.$('txtUsername').value.trim().length<2){msg[msg.length]='登陆名';}
if(autoRadio.$('txtPassword').value.trim().length<2){msg[msg.length]='密码';}}
if(autoRadio.$('txtAskTitle').value.trim().length<2){msg[msg.length]='问题标题';}
if(autoRadio.$('txtAskContent').value.trim().length<2){msg[msg.length]='问题描述';}
if(autoRadio.$('txtAskTags').value.trim().length<2){msg[msg.length]='标签';}
if(autoRadio.$('chkEmail').checked){var patrn=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;if(!patrn.exec(autoRadio.$('txtAskEmail').value)){alert('邮件地址格式不正确, 请检查!');return false;}}
if(autoRadio.$('txtValidate').value.trim().length<3){msg[msg.length]='验证码';}
if(msg.length>0){alert('请先填写 '+msg.join(', ')+' 等信息!');return false;}
return true;},submit:function(){if(this.validateForm()){document.forms[0].submit();}},reset:function(){document.forms[0].reset();this.validateCode();},guestLogin:function(checked){if(checked){autoRadio.$('pnlGuestUser').style.display='block';autoRadio.$('pnlLoginUser').style.display='none';autoRadio.$('chkGuestUser').value='0';}else{autoRadio.$('pnlGuestUser').style.display='none';autoRadio.$('pnlLoginUser').style.display='block';autoRadio.$('chkGuestUser').value='1';}
autoRadio.$('chkGuestUser').checked=true;autoRadio.$('chkLoginUser').checked=false;this.loginUser=!checked;},inputCount:function(maxCount){var input=autoRadio.getContent('txtAskContent');var count=500-input.length;if(count<0){alert('已经超过最大字数!');return;}
else{autoRadio.$('lblOverText').innerHTML=count;}},validateCode:function(){autoRadio.$('txtValidate').value='';autoRadio.$('imgValidate').src=this.validateUrl+'?'+Math.random();},selectTags:function(title){var tag=autoRadio.$('txtAskTags');if(tag.value.trim()==0){tag.value=title;}else if(tag.value.indexOf(title)<0){tag.value=tag.value.trim().replace("，",",")+','+title;}},initialForm:function(){autoRadio.insertObject(this.outputId,this.generateHtml());document.forms[0].method=this.method;document.forms[0].action=this.action;document.forms[0].target=this.target;},show:function(broadcast){this.broadcastId=broadcast;this.tagList=new Array('买车','养车','性价比','维修保养','经济','省油','耐用','二手车','自动挡','报价','优惠','按揭','异地提车','诊断故障','改装');this.initialForm();},searchQuetion:function(){var type=autoRadio.$('ddlSearchType').value;var keyword=autoRadio.$('txtKeyword').value;if(keyword.trim().length<2){alert('请输入搜索关键字!');return false;}else{window.location.href='/ask/search/'+type+'/1/'+keyword.trim()+'/';}},searchType:function(value){var tag=autoRadio.$('searchBox2').innerHTML;if(value=='date'&&tag=='text'){autoRadio.$('searchBox').innerHTML='<input class="input_text Wdate" type="text" id="txtKeyword" name="txtKeyword" onfocus="WdatePicker({isShowClear:false,readOnly:true})"  maxlength="15"/>';autoRadio.$('searchBox2').innerHTML='date';}
else if(value!='date'&&tag=='date'){autoRadio.$('searchBox').innerHTML='<input type="text" name="txtKeyword" id="txtKeyword"  maxlength="15"  class="input_text"/>';autoRadio.$('searchBox2').innerHTML='text';}},generateHtml:function(){var html='';var form=(document.forms[0]==undefined?true:false);if(form){html+='<form>';}
html+='<h4 class="ask">输入您的问题 轻松获得答案</h4>';html+='<ul class="ask_inputbox">';html+='<li id="pnlLoginUser">';html+='<label>';html+='登录名：</label><input id="txtUsername" name="txtUsername" type="text" class="w135px" maxlength="32" />';html+=' 密码：<input id="txtPassword" name="txtPassword" type="password" class="w135px" maxlength="32" />';html+='<input id="chkLoginUser" name="chkLoginUser" type="checkbox" onclick="question.guestLogin(true);"/> 匿名提问 <a href="http://my.bitauto.com/GetYourPassword.aspx" target="_blank">找回密码</a> <a href="http://my.bitauto.com/register.aspx" target="_blank">注册</a>';html+='</li>';html+='<li id="pnlGuestUser" style="display: none;">';html+='<label>';html+='昵称：</label><input id="txtAskName" name="txtAskName" type="text" class="w135px" maxlength="32" />';html+='<input id="chkGuestUser" name="chkGuestUser" type="checkbox" onclick="question.guestLogin(false);"  value="1" checked="checked" /> 匿名提问 </li>';html+='<li>';html+='<label>';html+='* 您的问题：</label><input id="txtAskTitle" name="txtAskTitle" type="text" class="w322px"  maxlength="256" />';html+='</li>';html+='<li>';html+='<label>';html+='* 问题描述：</label>';html+='<textarea name="txtAskContent" id="txtAskContent" cols="45" rows="5" class="w322px" onkeyup="question.inputCount(500);" ></textarea>';html+='<input type="hidden" name="txtBroadcastId" id="txtBroadcastId" value="'+this.broadcastId+'" /> ';html+='<span>还可输入<span class="hl" id="lblOverText">500</span>字</span> </li>';html+='<li>';html+='<label>';html+='* 标签：</label>';html+='<input id="txtAskTags" name="txtAskTags" type="text" class="w322px" maxlength="256" /><span class="small">（多个标签用逗号空格分离）</span>';html+='</li>';html+='<li class="othertag">';html+='<label>';html+='别人常用的：</label>';html+='<ul>';if(this.tagList.length>0){for(var index in this.tagList){html+='<li><a href="javascript:void(0);" ';if(index%3==0){html+='class="hl" ';}
html+='onclick="question.selectTags(this.title);" title="'+this.tagList[index]+'">'+this.tagList[index]+'</a> </li>';}}
html+='</ul>';html+='</li>';html+='<li>';html+='<input id="chkEmail" name="chkEmail" type="checkbox" value="1" />';html+=' 当有人回答该问题时,发邮件提醒我';html+=' <input id="txtAskEmail" name="txtAskEmail" type="text" value="" />';html+='</li>';html+='<li>';html+='<label>';html+='* 验证码：</label><input id="txtValidate" name="txtValidate" type="text" class="w60px" />';html+=' <img id="imgValidate" src="/Controls/ValidateCode.ashx" width="45" height="20" align="absmiddle" alt="验证码" />';html+=' <a href="javascript:void(0);" onclick="question.validateCode()">看不清</a> </li>';html+='<li class="submit"><a href="javascript:void(0);" class="button" onclick="question.submit()">我要提问</a></li>';html+='</ul>';html+='<iframe name="'+this.target+'" id="'+this.target+'" width="0px" height="0px" scrolling="no" src=""></iframe>';if(form){html+='</form>';}
return html;}}
