/**
 * common.js
 */

var whitespace=" \t\n\r";var mobilephonestand=/^[_0-9]{0,11}$/;var phonestand=/^[-0-9]{0,40}$/;var charstand=/^[1-9a-zA-Z]{0,20}$/;var moneystand=/^[0-9]{0,5}[\.]{0,1}[0-9]{0,2}$/;function IsEmpty(s)
{return((s==null)||(s.length==0));}
function IsWhitespace(s)
{var i;if(IsEmpty(s))return true;for(i=0;i<s.length;i++)
{var c=s.charAt(i);if(whitespace.indexOf(c)==-1)return false;}
return true;}
function ForceLength(val,vallength,msg)
{var strInput=new String(val.value);if(strInput.length>vallength)
{alert(msg);return false;}
else
return true;}
function CheckEntry(val)
{var strInput=new String(val.value);if(IsWhitespace(strInput))
{return false;}
else{return true;}}
function ForceEntry(val,msg)
{var strInput=new String(val.value);if(IsWhitespace(strInput))
{alert(msg);return false;}
else
return true;}
function IsDigit(fData)
{return((fData>="0")&&(fData<="9"))}
function isNumber(str)
{var ch,temp;var strSource="0123456789";for(var i=0;i<str.length;i++)
{ch=str.charAt(i);temp=strSource.indexOf(ch);if(temp==-1)
{return false;}}
if(strSource.indexOf(ch)==-1)
{return false;}
else
{return true;}}
function IsInteger(fData)
{if(IsEmpty(fData))
return true
if((isNaN(fData))||(fData.indexOf(".")!=-1)||(fData.indexOf("-")!=-1))
return false
return true}
function IsPlusNumeric(fData)
{if(IsEmpty(fData))
return true
if((isNaN(fData))||(fData.indexOf("-")!=-1))
return false
return true}
function DataLength(fData)
{var intLength=0
for(var i=0;i<fData.length;i++)
{if((fData.charCodeAt(i)<0)||(fData.charCodeAt(i)>255))
intLength=intLength+2
else
intLength=intLength+1}
return intLength}
function IsIntegerInRange(fInput,fLower,fHigh)
{if(fLower==null)
return(fInput<=fHigh)
else if(fHigh==null)
return(fInput>=fLower)
else
return((fInput>=fLower)&&(fInput<=fHigh))}
function DaysInFebruary(fYear)
{return((((fYear%4==0)&&(!(fYear%100==0)))||(fYear%400==0))?29:28);}
function IsYear(fYear)
{if(!(IsInteger(fYear)))
return false
if(DataLength(fYear)!=4)
return false
if(IsIntegerInRange(fYear,1900,3000)==false)
return false
return true}
function IsMonth(fMonth)
{if(!(IsInteger(fMonth)))
return false
if(IsIntegerInRange(fMonth,1,12)==false)
return false
return true}
function IsDay(fDay)
{if(!(IsInteger(fDay)))
return false
if(!(IsIntegerInRange(fDay,1,31)))
return false
return true}
function IsDate(fDate)
{var arrDaysInMonth=new Array(12);arrDaysInMonth[1]=31;arrDaysInMonth[2]=29;arrDaysInMonth[3]=31;arrDaysInMonth[4]=30;arrDaysInMonth[5]=31;arrDaysInMonth[6]=30;arrDaysInMonth[7]=31;arrDaysInMonth[8]=31;arrDaysInMonth[9]=30;arrDaysInMonth[10]=31;arrDaysInMonth[11]=30;arrDaysInMonth[12]=31;if(IsEmpty(fDate))
return true
var NameList=fDate.split("-");if(NameList.length!=3)
return false
if(!(IsYear(NameList[0])&&IsMonth(NameList[1])&&IsDay(NameList[2])))
return false
if(NameList[1]>arrDaysInMonth[NameList[1]])
return false
if((NameList[1]==2)&&(NameList[2]>DaysInFebruary(NameList[0])))
return false
return true}
function isEmail(strEmail){if(strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1)
return true;else
return false;}
function isPhone(strPhone){if(strPhone.search(phonestand)!=-1)
return true;else
return false;}
function htmlDecode(html){if(null!=html){return html.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');}else{return null;}}
function htmlEncode(html){if(null!=html){return html.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');}else{return null;}}
/**
 *cookie.js
 */
function setCookie(name,value,expires){var hostname=window.location.hostname;var domain="";if(!(/^\w+$/.test(hostname)||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname))){var f=hostname.split(".");domain="."+f[f.length-2]+"."+f[f.length-1];}if(expires){var exp=new Date();exp.setTime(exp.getTime()+expires);if(domain.length)document.cookie=name+"="+escape(value)+";domain="+domain+";path=/;expires="+exp.toGMTString();else
document.cookie=name+"="+escape(value)+";path=/;expires="+exp.toGMTString();}else{if(domain.length)document.cookie=name+"="+escape(value)+";domain="+domain+";path=/";else
document.cookie=name+"="+escape(value)+";path=/";}}function getCookie(name){var value=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));return value?unescape(value[2]):null}function delCookie(name){var exp=new Date();exp.setTime(exp.getTime()-1);var value=escape(getCookie(name));var hostname=window.location.hostname;var domain="";if(/^\w+$/.test(hostname)||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname)){domain=hostname;}else{var f=hostname.split(".");domain="."+f[f.length-2]+"."+f[f.length-1];}if(value!=null)document.cookie=name+"="+value+";domain="+domain+";path=/;expires="+exp.toGMTString();}

/**
 * login.js
 */
(function(a){a.fn.wBox=function(o){var f={wBoxURL:"wbox/",opacity:0.5,callBack:null,noTitle:false,show:false,timeout:0,target:null,requestType:null,title:"wBox Title",drag:true,iframeWH:{width:400,height:300},html:""},j=this;this.YQ=a.extend(f,o);var n='<div id="wBox"><div class="wBox_popup"><table><tbody><tr><td class="wBox_tl"/><td class="wBox_b"/><td class="wBox_tr"/></tr><tr><td class="wBox_b"><div style="width:10px;">&nbsp;</div></td><td><div class="wBox_body">'+(j.YQ.noTitle?"":'<table class="wBox_title"><tr><td class="wBox_dragTitle"><div class="wBox_itemTitle">'+j.YQ.title+'</div></td><td width="20px" title="\u5173\u95ed"><div class="wBox_close"></div></td></tr></table> ')+'<div class="wBox_content" id="wBoxContent"></div></div></td><td class="wBox_b"><div style="width:10px;">&nbsp;</div></td></tr><tr><td class="wBox_bl"/><td class="wBox_b"/><td class="wBox_br"/></tr></tbody></table></div></div>',c=null,b=null,d=a(window),g=a(this);this.showBox=function(){a("#wBox_overlay").remove();a("#wBox").remove();c=a("<div id='wBox_overlay' class='wBox_hide'></div>").hide().addClass("wBox_overlayBG").css("opacity",j.YQ.opacity).dblclick(function(){j.close()}).appendTo("body").fadeIn(300);b=a(n).appendTo("body");i()};function i(){var p=b.find("#wBoxContent");if(j.YQ.requestType&&a.inArray(j.YQ.requestType,["iframe","ajax","img"])!=-1){p.html("<div class='wBox_load'><div id='wBox_loading'><img src='/images/wbox/loading.gif' /></div></div>");if(j.YQ.requestType==="img"){var q=a("<img />");q.attr("src",j.YQ.target);q.load(function(){q.appendTo(p.empty());m()})}else{if(j.YQ.requestType==="ajax"){a.get(j.YQ.target,function(r){p.html(r);b.find(".wBox_close").click(j.close);m()})}else{ifr=a("<iframe name='wBoxIframe' style='width:"+j.YQ.iframeWH.width+"px;height:"+j.YQ.iframeWH.height+"px;' scrolling='auto' frameborder='0' src='"+j.YQ.target+"'></iframe>");ifr.appendTo(p.empty());ifr.load(function(){try{$it=a(this).contents();$it.find(".wBox_close").click(j.close);fH=$it.height();fW=$it.width();w=d;newW=Math.min(w.width()-40,fW);newH=w.height()-25-(j.YQ.noTitle?0:30);newH=Math.min(newH,fH);if(!newH){return}var r=k(newW);b.css({left:r[0],top:r[1]});a(this).css({height:newH,width:newW})}catch(s){}})}}}else{if(j.YQ.target){a(j.YQ.target).clone(true).show().appendTo(p.empty())}else{if(j.YQ.html){p.html(j.YQ.html)}else{g.clone(true).show().appendTo(p.empty())}}}e()}function e(){m();b.show().find(".wBox_close").click(j.close).hover(function(){a(this).addClass("on")},function(){a(this).removeClass("on")});a(document).unbind("keydown.wBox").bind("keydown.wBox",function(p){if(p.keyCode===27){j.close()}return true});typeof j.YQ.callBack==="function"?j.YQ.callBack():null;!j.YQ.noTitle&&j.YQ.drag?h():null;if(j.YQ.timeout){setTimeout(j.close,j.YQ.timeout)}}function m(){if(!b){return false}var u=b.width(),r=k(u);b.css({left:r[0],top:r[1]});var q=a("body").height(),p=d.height(),s=a("html").height();q=Math.max(q,p);c.height(q).width(d.width())}function k(p){l=(d.width()-p)/2;t=d.scrollTop()+d.height()/4;return[l,t]}function h(){var u,r,s;var x=b.find(".wBox_dragTitle").css("cursor","move");x.bind("selectstart",function(){return false});x.mousedown(function(y){u=y.clientX-parseInt(b.css("left"));r=y.clientY-parseInt(b.css("top"));b.mousemove(q).mouseout(v).css("opacity",0.8);x.mouseup(p)});function q(y){s=false;if(y.clientX-u<0){l=0}else{if(y.clientX-u>d.width()-b.width()){l=d.width()-b.width()}else{l=y.clientX-u}}b.css({left:l,top:y.clientY-r})}function v(y){s=true;setTimeout(function(){s&&p(y)},10)}function p(y){b.unbind("mousemove",q).unbind("mouseout",v).css("opacity",1);x.unbind("mouseup",p)}}this.close=function(){if(b){c.remove();b.stop().fadeOut(300,function(){b.remove()})}};d.resize(function(){m()});j.YQ.show?j.showBox():g.click(function(){j.showBox();return false});return this}})(jQuery);
var reqUrl;function login_box(){var template='<form onsubmit="return box_login_submit();"><table width="400" border="0" cellpadding="0" cellspacing="0">'+'<tr style="height:30px;"><td colspan="2"><div style="display: none;" class="load_error" id="box_message_txt"></div></td></tr>'+'<tr style="height:40px;"><td width="111" align="right" style="font-weight:bold;font-size:14px;">Email地址：</td><td width="273"><input name="box_username" id="box_username" class="i_text" style="height:auto;width:210px;"  maxlength="40" type="text" /></td></tr>'+'<tr style="height:40px;"><td align="right" style="font-weight:bold;font-size:14px;">密码：</td><td><input name="box_password" id="box_password" class="i_text" style="height:auto;width:210px;" maxlength="20" type="password" /></td></tr>'+'<tr style="height:50px;"><td>&nbsp;</td><td>'+'<input id="box_login_btn" style="margin-left:20px;" type="image" src="'+reqUrl+'/images/common/icon25.jpg" onmouseover="this.src=\''+reqUrl+'/images/common/icon21.jpg\'" onmouseout="this.src=\''+reqUrl+'/images/common/icon25.jpg\'">'+'<a style="margin-left:90px;" href="'+reqUrl+'/reg.html">马上去注册>>></a>'+'</td></tr></table></form>';$('#setPos').wBox({html:template,show:true,title:"登陆九月网"});}
function box_login_submit(){
	$error=$('#box_message_txt');
	$username=$('#box_username');
	$password=$('#box_password');
	if(!isEmail($username.val())){
		$error.show().html('Email地址不符合规范,请检查后重新输入!');
		$username.focus();
	}else if(IsWhitespace($password.val())){
	$error.show().html('密码不能为空,请检查后重新输入!');
	$password.focus();
	}else{
	$btn=$('#box_login_btn');
	$.ajax({
		type:"post",dataType:"xml",data:"lactiontype=login&user_name="+
		$username.val()+"&password="+$password.val(),
		url:reqUrl+"/login.html",
		beforeSend:function(){
			$btn.hide();
			$error.show().css('color','#66CC66').html('正在登陆....');
		},success:function(xml){
				var msg=$(xml).find("root > msg").text();
				if(msg=='unpass'){
					$error.show().css('color','#F02E2E').html("Email地址或密码错误,请检查后重新输入!");
					$btn.show();
				}else if(msg=='invalid'){
					$error.show().css('color','#F02E2E').html("帐号还未生效,请联系客服!");
					$btn.show();
				}else if(msg=='locked'){
					$error.show().css('color','#F02E2E').html("帐号被锁,请联系客服!");
					$btn.show();
				}else if(msg=='pass'){
					var nickname=$(xml).find("root > nickname").text();
					login_content(nickname);
					$('.wBox_close').click();
				}
			}
		});
	}
	return false;
}
function login_content(nickname){
	$('#wellcome').html('<p class="wl">您好，'+
	nickname+'&nbsp;欢迎来到九月网！<a href="'+
	reqUrl+'/user/onlinepay.html" class="first">充值</a><a href="javaScript:logout();">注销</a></p>');
}

function top_login_submit(){
	$top_user_name=$('#top_user_name');
	$top_password=$('#top_password');
	if(IsWhitespace($top_user_name.val())){
		alert("请输入用户名！");
		$top_user_name.focus();
		return false;
	}
	/*else if(!isEmail($top_user_name.val())){
		alert('Email地址不符合规范,请检查后重新输入!(例如：shuchong@xhbs.com)');
		$top_user_name.focus();
		return false;
	}*/
	else if(IsWhitespace($top_password.val())){
		alert("请输入密码！");
		$top_password.focus();
		return false;
	}else{
		$.ajax({
			type:"post",dataType:"xml",data:"lactiontype=login&user_name="+
			$top_user_name.val()+"&password="+$top_password.val(),
			url:reqUrl+"/login.html",success:function(xml){
				var msg=$(xml).find("root > msg").text();
				if(msg=='unpass'){
					alert("Email地址或密码错误,请检查后重新输入!");
				}
				else if(msg=='invalid'){
					alert("帐号还未生效,请联系客服!");
				}
				else if(msg=='locked'){
					alert("帐号被锁,请联系客服!");
				}else if(msg=='pass' || msg=='invalid'){
					var nickname=$(xml).find("root > nickname").text();
					login_content(nickname);
				}
			}
		});
		return false;
	}
	return false;
}

function logout(){delCookie('__user');delCookie('__username');window.location.href=reqUrl+'/';}
