﻿// JavaScript Document
var sUserAgent = navigator.userAgent;
var isIE = sUserAgent.indexOf("compatible") > -1&& sUserAgent.indexOf("MSIE") > -1
var isMinIE4 = isMinIE5 = isMinIE5_5 = isMinIE6= isIE6 = false;
if (isIE) {
    var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
    var retemp= sUserAgent.match(reIE);
    var fIEVersion = parseFloat(retemp[1]);
    isMinIE4 = fIEVersion >= 4;
    isMinIE5 = fIEVersion >= 5;
    isMinIE5_5 = fIEVersion >= 5.5;
    isMinIE6 = fIEVersion >= 6.0;
	isIE6 = fIEVersion == 6.0;
}

var CNReg=/^[\s\n\r\t]*$/;

var Box=new Object()
Box.CheckNull=function(str)
{	return CNReg.test(str);}
Box.LightBox=function(width,height,argument)
{
	var jchan=argument;
	this.gen=null;
	this.height=height?height:300;
	this.Identity={User:Box.Model.User};
	if(jchan&&jchan.IsGetUserInfo==true){Box.LightBox.UserValidate();}
	Box.LightBox.init.call(this,width);
}
Box.Model={User:{ UserID:"",Tel:"",Contact:"",Email:""},LiuYan:{WhoID:""}}
Box.LightBox.UserValidate=function(){    
    var tUser = Box.Model.User;
	$.post("/User/Ajax/DialogUserValidate.aspx",{},function(data){
		if(data.flag==1)
		{
			Box.Model.User.UserID=data.UserInfo.UserID;	Box.Model.User.Tel=data.UserInfo.Tel;Box.Model.User.Contact=data.UserInfo.Contact;Box.Model.User.Email=data.UserInfo.Email;
		}
	},"json");
}

Box.LightBox.init=function(width)
{
	if(!document.getElementById("dialogcss"))
	{
		var head=document.documentElement.firstChild,createcss=document.createElement("link");
		createcss.setAttribute("rel","stylesheet");
		createcss.setAttribute("type","text/css");
		createcss.setAttribute("href", "/JScript/CustomDialog.css");
		createcss.setAttribute("id","dialogcss");
		head.appendChild(createcss);
	}
	if(!document.getElementById("operames"))
	{	boxhtml='';
		boxhtml=boxhtml+'  <iframe frameborder="0" class="zhedang"></iframe>';
		boxhtml=boxhtml+'  <div class="operadiv">';
		boxhtml=boxhtml+'	<h4>操作名称</h4>';
		boxhtml=boxhtml+'	<a title="关闭此窗口" href="javascript:void(0)" class="opclose">关闭</a>';
		boxhtml=boxhtml+'	<div class="opcontent">';
		boxhtml=boxhtml+'    </div>';
		boxhtml=boxhtml+'    <p class="ajaxload">';
		boxhtml=boxhtml+'    	请稍等，正在处理中。';
		boxhtml=boxhtml+'    </p>';
		boxhtml=boxhtml+'    <p class="errorinfo hide">';
		boxhtml=boxhtml+'    	错误!';
		boxhtml=boxhtml+'    </p>';
		boxhtml=boxhtml+'    <p class="successinfo hide">';
		boxhtml=boxhtml+'    	成功!';
		boxhtml=boxhtml+'    </p>';
		boxhtml=boxhtml+'    </div>';
		var operames=document.createElement("div");
		operames.setAttribute("id","operames");
		operames.setAttribute("class","hide");
		if(width)
		{operames.style.width=width+"px";operames.style.marginLeft="-"+Math.floor(width/2)+"px";}
		operames.className="hide";
		operames.innerHTML=boxhtml;
		document.body.appendChild(operames);
		this.gen=operames;
		var loader=this;
		$(operames).find(".opclose").click(function(){
			loader.Close();
		});
	}
	else{this.gen=document.getElementById("operames");}
}
Box.LightBox.prototype.Width=function(width)
{if(width)
	{var width=width
	this.gen.style.width=width+"px";this.gen.style.marginLeft="-"+Math.floor(width/2)+"px";}
}
Box.LightBox.prototype.Depicted=function()
{	var $Content=$(this.gen).find("div.opcontent");
	$Content.height("auto");
	if($Content.height()>this.height)
	{$Content.height(this.height);}
	var BrowserH=window.innerHeight||document.documentElement.offsetHeight;//+document.documentElement.scrollTop+"px"
	if(!isIE6)
	{  $(this.gen).css("top",(BrowserH-$(this.gen).outerHeight())*100/(2*BrowserH)+"%");}
}
Box.LightBox.prototype.Html=function(strMess,strHtml)
{	
	$(this.gen).removeClass("hide").find("h4").html(strMess).end().find("div.opcontent").removeClass("hide").html(strHtml).siblings("p").addClass("hide");
	this.Depicted();
}
Box.LightBox.prototype.Append=function(strMess,strHtml)
{	
	$(this.gen).removeClass("hide").find("h4").html(strMess).end().find("div.opcontent").removeClass("hide").find(">div").addClass("hide").end().append(strHtml).siblings("p").addClass("hide");
	this.Depicted();
}
//关闭窗口
Box.LightBox.prototype.Close=function()
{
	$(this.gen).addClass("hide").find(".opcontent>div").addClass("hide");
}
Box.LightBox.prototype.Opcontent=function(){return $(this.gen).find("div.opcontent");}
//显示ajaxload
Box.LightBox.prototype.AjaxLoad=function(strT,strA)
{	if(!strA||strA==""){strA="请稍等，正在处理中。";}
	Box.LightBox.opMessage.call(this,".ajaxload",strT,strA);}
//错误提示
Box.LightBox.prototype.Error=function(strTitle,strError)
{Box.LightBox.opMessage.call(this,".errorinfo",strTitle,strError);}
Box.LightBox.prototype.Success=function(strTitle,strS)
{Box.LightBox.opMessage.call(this,".successinfo",strTitle,strS);}
Box.LightBox.opMessage=function(className,strTitle,strMess)
{
	$(this.gen).removeClass("hide").find("h4").html(strTitle).end().find("p"+className).html(strMess).removeClass("hide").siblings("p").addClass("hide").end().siblings(".opcontent").addClass("hide").find(">div").addClass("hide");
}
Box.LightBox.prototype.$=function(obj)
{return $(this.gen).find(obj);}
Box.LightBox.prototype.ChildShow=function(strMess,obj)
{ 	$(this.gen).removeClass("hide").find("h4").html(strMess).end().find("div.opcontent").removeClass("hide").find(obj).removeClass("hide").siblings().addClass("hide").end().end().siblings("p").addClass("hide");
	this.Depicted();
}
Box.LightBox.prototype.HasElement=function(obj)
{dd=(this.$(obj).length>0)?true:false; 
return dd; }

Box.LightBox.prototype.AjaxLogin=function(methodname,callback)
{
  loader=this;
  var huiDiao
  if(typeof methodname=="function")	//如果methodname这个参数类型为方法的话，则把这个当作回调函数
  {huiDiao=methodname}
  else{huiDiao =callback;} 
  if(!huiDiao){huiDiao=function(){}}
  if(!loader.HasElement("#oplogin")){
 	 var strLogin="";
	 strLogin= strLogin+'<div id="oplogin">';
	 strLogin= strLogin+'  <label><span>用户名：</span><input type="text" name="UserName"  /></label>';
	 strLogin= strLogin+'  <label><span>密码：</span><input type="password" name="password" /></label>';
	 strLogin= strLogin+'  <p><input type="submit" value="登陆" />&nbsp;&nbsp;&nbsp;还不是会员？&nbsp;请<a href="/zhuce/register.asp" style="font-weight:700; font-size:14px; color:#f00;">注册</a></p>';
	 strLogin= strLogin+'</div>';
	  loader.Append("请登陆",strLogin);
	  loader.$("#oplogin :submit").click(function(){
	  var pUserName=loader.$("#oplogin :input[name=UserName]").val();
	  var pPassWord=loader.$("#oplogin :input[name=password]").val()
	  if(Box.CheckNull(pUserName)||Box.CheckNull(pPassWord))
	  {alert("请填写用户名和密码");return false;}
	  loader.AjaxLoad("登陆中..");
	  loader.$("#oplogin label :input").val("");
	  $.post("/User/Ajax/Login.ashx", { UserName: pUserName, password: pPassWord, isnocode: 'isnocode' }, function (data) {
		 if(data.flag==0)
		 {loader.Error("登陆失败",data.message+"<input type='button' value='重新登录' onclick=loader.ChildShow('请登陆','#oplogin') />")}
		 else
		 {loader.Close();
			if(typeof methodname=="string")	//如果methodname参数为字符串，则代表是要触发某个事件，兼容以前的老方法
			 {eval(methodname);}
		 }
		 huiDiao(data);
	  },"json");
	 })
   }else{loader.ChildShow("请登陆","#oplogin");}
}
/* 
chanshu.UserID 发送给谁的留言
chanshu.Data 提交附加的数据,json格式
chanshu.Data.XiaoXiType 消息类型
chanshu.Data.AlternateID  备用字段
chanshu.Title 弹出框标题
chanshu.Title.Init 初始化标题
chanshu.Title.Success 成功标题
chanshu.Title.Error   失败标题
*/
Box.LightBox.prototype.AjaxLiuYan=function(chanshu,callback)
{
	if(!chanshu.UserID||isNaN(chanshu.UserID))
	{alert("留言缺少参数!");return false;}
	Box.Model.LiuYan.WhoID=chanshu.UserID;
		
	var TitleInit="在线留言",TitleSuccess="留言成功",TitleError="留言失败";
	if(chanshu.Title)
	{
		if(chanshu.Title.Init){ TitleInit=chanshu.Title.Init;}
		if(chanshu.Title.Success){ TitleSuccess=chanshu.Title.Success;}
		if(chanshu.Title.Error){ TitleError=chanshu.Title.Error;}
	}
	
	loader=this;
	if(!callback){callback=function(){}}
		
	if(!loader.HasElement("#opliuyan"))
	{
		 var strLiu="";
		 strLiu= strLiu+'<div id="opliuyan">';
		 strLiu= strLiu+' <form id="opliuyanform">';
		 strLiu= strLiu+'  <label><span>标题：</span><input name="Title" type="text"  maxlength="60" /> <em>*不能超过50个字</em></label>';
		 strLiu= strLiu+'  <label><span>电话或手机：</span><input name="Tel" type="text" value="'+loader.Identity.User.Tel+'" maxlength="20" /> <em>*</em></label>';
		 strLiu= strLiu+'  <label><span>联系人：</span><input name="lx_ren" type="text" value="'+loader.Identity.User.Contact+'" maxlength="16" /></label>';
		 strLiu= strLiu+'  <label><span>Email：</span><input name="Email" type="text" value="'+loader.Identity.User.Email+'" maxlength="36" /></label>';
		 strLiu= strLiu+'  <label><span>内容：</span><textarea name="Content" style="width:98%; height:80px;"></textarea><em style="display:block;">*内容不能超过500个字</em></label>';
		 strLiu= strLiu+'  <p><input type="button" name="optijiao" value="提交" /><input type="reset" value="重置" /></p></form>';
		 strLiu= strLiu+'</div>';
 
		 loader.Append(TitleInit,strLiu);	  
		
	}else{Box1.ChildShow(TitleInit,"#opliuyan");$("#opliuyanform")[0].reset();}
	
	 var $liuForm=loader.$("#opliuyanform");
	 $liuForm.find(":input[type=button][name='optijiao']").unbind("click").click(function(){
		var d_l_title=loader.$("#opliuyan :input[name=Title]").val();
		var d_l_content=loader.$("#opliuyan textarea").val();
		var d_l_tel=loader.$("#opliuyan :input[name=Tel]").val();
		if(Box.CheckNull(d_l_title)||Box.CheckNull(d_l_content)||Box.CheckNull(d_l_tel))
		{alert("标题、电话和内容不能为空!");return false;}
		
		var d_l_lx_ren=loader.$("#opliuyan :input[name=lx_ren]").val();
		var d_l_email=loader.$("#opliuyan :input[name=Email]").val();
		
		loader.AjaxLoad(TitleInit);
		
		var jLiuYan={
				Title:d_l_title,
				Content:d_l_content,
				Email:d_l_email,
				lx_ren:d_l_lx_ren,
				Tel:d_l_tel,
				User_ID:Box.Model.LiuYan.WhoID
			}
		if(chanshu.Data)
		{
			for(var jt in chanshu.Data)
			{
				jLiuYan[jt]=chanshu.Data[jt];
			}
}

		$.post("/user/ajax/LiuYanAdd.aspx",jLiuYan,function(data){
			if(data.flag==1)
			{loader.Success(TitleSuccess,data.message);$liuForm[0].reset();}
			else{loader.Error(TitleError,data.message);}
			callback(data);
		},"json");
	 }) 
}
