var Info={F:null,IsNewUser:false,IsNewInfo:true,Calendar:null,Init:function(f)
{with(this)
{F=f;IsNewUser=(f.iUser!=null);IsNewInfo=f.iID.value==0;Calendar=new CalendarEntity(null,_acceptDate,{id:"Calendar",className:"Calendar"},true);this.Uploader.Init();with(this.F)
{if(this.IsNewUser)
{for(var i=0;i<iUser.length;i++)
iUser[i].onclick=Info.ToggleUserPanel;Info.ToggleUserPanel();}
if(this.IsNewUser)
{var z="系统默认情况下会用电话号码作为用户名为您注册用户，<br />如果没有填写电话号码则选择联系信息内的某一项作为用户名";Hinter.Reg(iContact,Hinter.FOCUS,z);Hinter.Reg(iContactTel,Hinter.FOCUS,z);Hinter.Reg(iContactEMail,Hinter.FOCUS,z);Hinter.Reg(iContactQQMSN,Hinter.FOCUS,z);Hinter.Reg(iTags,Hinter.FOCUS,"添加标签可以让您的信息更容易被搜索到");Hinter.Reg(iRegisterUserName,Hinter.FOCUS,"点击右面的按钮可以从联系方式中自动选择可以使用的名字，您也可以手动填写。<br />"+Validator.UserNameMessage);LMGR.Reg(iRegisterPassword,LMGR.BLUR,Info.ComparePasswords,null);LMGR.Reg(iRegisterPassword2,LMGR.BLUR,Info.ComparePasswords,null);LMGR.Reg(iRegisterUserName,LMGR.BLUR,function(e){var n=Info.F.iRegisterUserName.value.Trim();if(n.IsBlank())return;if(Validator.ValidateUserName(n))Validator.ValidateRegisterUserName(n,Info.OnRegisterUserNameValidated,false);},null);}
Hinter.Reg(iExpireDateUI,Hinter.FOCUS,"如果不选择过期时间则默认为一周后过期");InfoTagHelper.Init(iTags,Info.OpenTagList);iTagsButton.onclick=function(e){InfoTagHelper.ExtractTags(Info.F.iContent);}
LMGR.Reg(iExpireDateUI,LMGR.FOCUS,InfoTagHelper.CloseTagList);LMGR.Reg(iContent,LMGR.FOCUS,InfoTagHelper.CloseTagList);LMGR.Reg(iContactEMail,LMGR.BLUR,Info.ValidateEMail);LMGR.Reg(iExpireDateUI,LMGR.FOCUS,Info.OpenCalendar);LMGR.Reg(iExpireDateUI,LMGR.CLICK,Info.OpenCalendar);LMGR.Reg(iTags,LMGR.FOCUS,Info.CloseCalendar);LMGR.Reg(iImage,LMGR.FOCUS,Info.CloseCalendar);LMGR.Reg(document,LMGR.CLICK,Info.CloseCalendar,null,[this.F.iExpireDateUI,this.Calendar.Body]);iImage.onclick=function(e){Info.Uploader.Open("FlashCom/Uploader/Uploader.swf?web=1");};LMGR.Reg(iImageClear,LMGR.FOCUS,Info.Uploader.Close);LMGR.Reg(iExpireDateUI,LMGR.FOCUS,Info.Uploader.Close);LMGR.Reg(document,LMGR.CLICK,Info.Uploader.Close,null,[this.F.iImage,this.Uploader.Panel]);iImageClear.onclick=function(e){Info.Uploader.Update(null);}
F.iExpireDateSpan.value=F.iExpireDateSpanReserved.value;}
_updateExpireDateUI(true);EnhanceCalendar(Calendar);F.onsubmit=IsNewUser?ValidateUser:ValidateAll;}},_pC:null,OpenTagList:function(e)
{with(Info)
{if(_pC!=F.iSubCategory.value)
{var cv=F.iSubCategory.value?F.iSubCategory.value:F.iRootCategory.value;InfoTagHelper.OpenTagList(e,[["category",cv]]);_pC=Info.F.iSubCategory.value;}
else
{InfoTagHelper.OpenTagList(e);}}},Uploader:{Panel:null,TPanel:null,Init:function()
{with(Info.Uploader)
{if(!Panel)
{with(Info.F.iImageUI)
{onclick=ShowImage;onmouseover=ShowImageThumbnail;onmouseout=HideImageThumbnail;}
Panel=BuildPanel("_imgPanel",570,360);}
Update(Info.F.iImageID.value);}},GetImageID:function()
{return Info.F.iImageID.value;},ShowImage:function(e)
{var id=Info.Uploader.GetImageID();if(id)
window.open("/IImg/"+id+".jpg");},ShowImageThumbnail:function(e)
{with(Info.Uploader)
{var id=GetImageID();if(id)
{if(!TPanel)
{TPanel=$C("div");TPanel.className="Calendar";with(TPanel.style)
{position="absolute";zIndex="50";padding="5px";display="none";}
document.body.appendChild(TPanel);}
TPanel.innerHTML="<img src='/IImg/T/"+id+".jpg' />";$XY(TPanel,Info.F.iImageUI,0,Info.F.iImageUI.clientHeight);TPanel.style.display="";Info.CloseCalendar();}}},HideImageThumbnail:function(e)
{with(Info.Uploader)
{if(TPanel)
TPanel.style.display="none";}},BuildPanel:function(_id,w,h)
{var i=$C("div");i.id=_id;with(i.style)
{position="absolute";display="none";width=w+"px";height=h+"px";}
document.body.appendChild(i);return i;},Open:function(src)
{with(Info.Uploader)
{if(Panel.innerHTML.IsBlank())
{var so=new SWFObject(src+"&"+Math.random(),"Cam","100%","100%","10","#ffffff");so.addParam("wmode","transparent");so.addParam("quality","high");so.addParam("swliveconnect","true");so.useExpressInstall("expressinstall.swf");so.write(Panel.id);}
var t=Info.F.iImageUI;$XY(Panel,t,-7,t.clientHeight-5);Panel.style.display="";}},Close:function(e)
{if(Info.Uploader.Panel)
Info.Uploader.Panel.style.display="none";},Update:function(imgid)
{with(Info)
{F.iImageID.value=imgid?imgid:"";F.iImageUI.value=imgid?("上传的图片 #"+imgid):"";F.iImageUI.title=imgid?"查看图片":"";}}},ToggleUserPanel:function(e)
{var a=Info.F.iUser[0].checked==true;document.getElementById("PUserLogin").style.display=a?"":"none";document.getElementById("PUserRegister").style.display=a?"none":"";},EnhanceCalendar:function(c)
{var z=$C("div",{id:"Ex"});var a;var ds=[3,7,15,30];for(var i=0;i<ds.length;i++)
{a=$C("a",{href:"#",innerHTML:ds[i]+"天"});eval("a.onclick = function() { Info.F.iExpireDateSpan.value = "+ds[i]+"; Info._updateExpireDateUI(); return false; }");z.appendChild(a);}
a=$C("div",{className:"Sep "});z.appendChild(a);a=$C("a",{href:"#",innerHTML:"转到当月"});eval("a.onclick = function() { CalendarHelper.GetCalendar(\""+c.ID+"\").Refresh(new Date()); return false; }");z.appendChild(a);c.Body.insertBefore(z,c.Body.firstChild);},OpenCalendar:function(e)
{var t=$E_T(e);Info.Calendar.Open($X(t),$Y(t)+t.offsetHeight);},CloseCalendar:function(e)
{if(Info.Calendar)
Info.Calendar.Close();},_acceptDate:function(d,donotvalidate)
{with(Info)
{var t=_getApproxDate();var dspan=Math.floor((d-t)/86400000);if(dspan<1&&!donotvalidate)
{Notice.SetLabel(F.iExpireDateUI,true,"有效期不应该是过去的某个日期",true);return;}
if(!donotvalidate)
F.iDate.value=(t.getMonth()+1)+"/"+t.getDate()+"/"+t.getFullYear();F.iExpireDateUI.value=_getDateString(d);F.iExpireDateSpan.value=dspan;Notice.SetLabel(F.iExpireDateUI,false,null,true);CloseCalendar();}},_updateExpireDateUI:function(donotvalidate)
{var dspan=parseInt(Info.F.iExpireDateSpan.value);if(isNaN(dspan))
dspan=Info.F.iExpireDateSpan.value=7;this._acceptDate(new Date(Date.parse(this.F.iDate.value).valueOf()+dspan*86400000),donotvalidate);},_getDateString:function(d)
{return d.getFullYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日";},_getApproxDate:function()
{var t=new Date();return new Date(t.getFullYear(),t.getMonth(),t.getDate());},ValidateUser:function(e)
{with(Info.F)
{var OK=true;var iL=iUser[0].checked;if(iL)
{OK=Notice.SetLabel(iLoginUserName,iLoginUserName.value.IsBlank(),"需要填写用户名",true)&&OK;OK=Notice.SetLabel(iLoginPassword,iLoginPassword.value.IsBlank(),"需要填写密码",true)&&OK;if(Info.ValidateAll())
submit();}
else
{OK=Info.ValidateAll()&&OK;OK=Notice.SetLabel(iRegisterUserName,iRegisterUserName.value.IsBlank(),"需要填写用户名",true)&&OK;OK=Notice.SetLabel(iRegisterPassword,iRegisterPassword.value.IsBlank(),"需要填写密码",true)&&OK;OK=Notice.SetLabel(iRegisterPassword2,iRegisterPassword2.value.IsBlank(),"需要填写密码",true)&&OK;OK=Notice.SetLabel(iRegisterUserName,!Validator.ValidateUserName(iRegisterUserName.value),Validator.UserNameMessage,true)&&OK;if(!OK)
return false;if(!Info.ComparePasswords())
return false;Validator.ValidateRegisterUserName(iRegisterUserName.value.Trim(),Info.OnRegisterUserNameValidated,true);}}
return false;},DecideUserName:function(e)
{with(Info.F)
{var n=[];if(iContactTel.value.Trim().length>2)
n.push(iContactTel.value.Trim());if(iContactEMail.value.Trim().length>2)
n.push(iContactEMail.value.Trim());if(iContactQQMSN.value.Trim().length>2)
n.push(iContactQQMSN.value.Trim());if(iContact.value.Trim().length>2)
n.push(iContact.value.Trim());if(n.length>0)
{var a="";for(var i=0;i<n.length;i++)
a+="&name="+encodeURIComponent(n[i]);AJAX.Load("AJAX_User.aspx?type=DecideUserName"+a,"GET",null,Info.OnUserNameDecided);}
else
{Notice.Alert("在联系方式中没有找到适合使用的用户名",Notice.OK|Notice.CANCELABLE);}}},OnUserNameDecided:function(msg)
{if(/^OK/i.test(msg))
{Info.F.iRegisterUserName.value=msg.substr(3);}
else if(/^AlreadyRegistered/i.test(msg))
{Notice.Alert("下列用户名已被注册:<br />"+msg.substr(msg.indexOf("\n")+1).replace(/\u000a/g,"<br />"),Notice.OK|Notice.CANCELABLE);}
else if(/^NoValid/i.test(msg))
{Notice.Alert("未找到合适的用户名:<br />"+msg.substr(msg.indexOf("\n")+1).replace(/\u000a/g,"<br />")+"<br />请手动填写",Notice.OK|Notice.CANCELABLE);}},ComparePasswords:function(e)
{with(Info.F)
{if(iUser[0].checked)
return true;var match=iRegisterPassword.value==iRegisterPassword2.value;Notice.SetLabel(iRegisterPassword,!match,"两次填写的密码不一致",true);Notice.SetLabel(iRegisterPassword2,!match,"两次填写的密码不一致",true);return match;}},OnRegisterUserNameValidated:function(nameok,dosubmit)
{Notice.SetLabel(Info.F.iRegisterUserName,true,nameok?"用户名可以使用":"用户名已被注册",!nameok);if(nameok&&dosubmit)
Info.F.submit();},ValidateEMail:function(e)
{with(Info.F)
{var iv=Validator.ValidateEMail(iContactEMail.value);Notice.SetLabel(iContactEMail,!iv,Validator.EMailMessage,true);return iv;}},ValidateExpireDate:function(e)
{with(Info)
{_updateExpireDateUI();var iv=parseInt(Info.F.iExpireDateSpan.value)>0;Notice.SetLabel(F.iExpireDateUI,!iv,"有效期不应该是过去的某个日期",true);return iv;}},ValidateAll:function(e)
{with(Info)
{var m=[];var iv=Info.ValidateEMail()&&Info.ValidateExpireDate();if(F.iTitle.value.IsBlank()||F.iContent.value.IsBlank())
{iv=false;m.push("请填写标题和内容");}
if(InfoHelper.RootCategorySelect.value==""||InfoHelper.SubCategorySelect.value==""||InfoHelper.TypeSelect.value=="")
{iv=false;m.push("请选择信息分类和类型");}
if(F.iContactTel.value.IsBlank()&&F.iContactEMail.value.IsBlank()&&F.iContactQQMSN.value.IsBlank()&&F.iContactAddress.value.IsBlank())
{iv=false;m.push("至少要填写一种联系方式");}
if(m.length>0)
Notice.Alert(m,Notice.OK|Notice.CANCELABLE);return iv;}}}