/** 公共变量定义*/
var HTTP_PREFIX = "/drain_news";

/** 登陆用户实例*/ 
function USER(){
	this.hostId = "";
	this.utype = "";
	this.uname ="";
	this.pwd = "";
	this.nick = "";
	this.head = "";
	this.province = "";
	this.city = "";
	this.strict = "";
}

$(function(){

	fetchUSER = function(){
		var user=new USER();

		user.hostId = localStorage.hostId; 
		user.utype = localStorage.utype; 
		user.uname = localStorage.uname; 
		user.pwd  = localStorage.pwd; 
		user.nick = localStorage.nick; 
		user.head = localStorage.head; 
		user.province = localStorage.province; 
		user.city = localStorage.city; 
		user.strict=localStorage.strict; 

		return user;
	};

	logout = function(){ // 退出登录
		$.confirm("确认退出当前账户？", function(){
			localStorage.hostId = '0';
			localStorage.utype = '';
			localStorage.pwd='';
			window.location.href = HTTP_PREFIX+'/protal/login.html';
		});
	};

	gotoLogin = function(){
		$.confirm("您还未登录，现在登陆？", function(){
			window.location.href = HTTP_PREFIX+'/protal/login.html';
		});
	};

	/**
	 * 重新构建请求路径
	 */
	buildHTTP = function(_path){
		if(_path.indexOf(".shtml?")!=-1){
			return HTTP_PREFIX+_path +"&uname="+localStorage.uname+"&pwd="+localStorage.pwd;
		}else{
			return HTTP_PREFIX+_path +"?uname="+localStorage.uname+"&pwd="+localStorage.pwd;
		}
	}

	String.prototype.len = function(){     
		return this.replace(/[^\x00-\xff]/g, "xx").length;  
	}


	getURLParameter = function (name) {// 获取URL请求参数
		return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
	};



	configTitle =function(_site){ // 修改网页标题  
		if($.trim($(document).attr("title"))==''){
			$(document).attr("title",_site);
		}else{
			var title = _site +"|"+ $(document).attr("title");
			$(document).attr("title",title);
		}
	}

	fetchConfig = function(type){ // 站点配置等
		var _path=HTTP_PREFIX+"/protal/fetch.shtml";
		$.ajax({
			url: _path, 
			type: "get", 
			dataType: "json",
			contentType:"application/json",
			success: function(data) {
				var config = data.content;
				if(type=='1'){ // 初始化站点名称
					configTitle(config.siteName);
				}
				else if(type=='2'){
					$("#serv_phone").html(config.tel);
					$("#serv_wx").html(config.wxcode);
					$("#serv_email").html(config.email);
				}else{

				}
			}
		});
	};

	fetchConfig('1'); // 设置站点名称

	$(".page").addClass("theme-green"); // 更换主题样式

});