
var userid;	
function exit(){
	
	$.cookie('userid', null); 
	$.cookie('userAuth', null); 
	$.cookie('userEmail', null); 
	$.cookie('userMobilePhone', null); 
	$.cookie('userName', null); 
	$.cookie('userType', null); 
	location.href="index.html"
}

function valUser(){
	var userid = $.cookie('userid');
	var userAuth = $.cookie('userAuth');
	if(userid == undefined || userid.length==0 || userid == "null"  || userAuth == false){
		location.href="login.html";
	}
}

 function GetQueryString(name) { 
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 	
		var r = window.location.search.substr(1).match(reg);  //��ȡurl��"?"�����ַ�����ƥ��
	
		var context = ""; 
		if (r != null) 
			 context = r[2]; 
		reg = null; 
		r = null; 
		return context == null || context == "" || context == "undefined" ? "" : decodeURI(context); 
	}

/* function GetQueryString(name) { 
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
		var r = window.location.search.substr(1).match(reg);  //��ȡurl��"?"�����ַ�����ƥ��
		var context = ""; 
		if (r != null) 
			 context = r[2]; 
		reg = null; 
		r = null; 
		return context == null || context == "" || context == "undefined" ? "" : context; 
	}*/

function loginStatus(){
	userid = $.cookie('userid');
	if(userid && userid != "null" && userid!=null){
		$(".onlogin").show();
		$(".unlogin").hide();
 		$(".portrait-p").attr("src","/images/head/"+userid+"_m.jpg");
		$(".portrait-p").load(function(){//判断图片是否加载，加载不成功默认有默认的图像									
		})
		.error(function(){
			$(".portrait-p").attr("src","/images/default-photo.jpg");
		});
	}else{
		$(".onlogin").hide();
		$(".unlogin").show();
	}
	
	
//	if(userid && userid != "null" && userid!=null ){
//		$(".head-portrait").show();
//		$(".unlogin").hide();
//	}else{
//		$(".head-portrait").hide();
//		$(".unlogin").show();
//	}
}

//转换格式
function changeTime(dealtime){
	   var s = dealtime;
	   //console.log(s);
	   if(dealtime.length==8){
	   	var y = s.substr(0,4);
	   var m = s.substr(4,2);
	   var d = s.substr(6,2);			  
	   var formatTime = y+"-"+m+"-"+d;
		return formatTime;
	   }
	   else
	   {
	   	var y = s.substr(0,4);
	   var m = s.substr(4,2);
	   var d = s.substr(6,2);
	   var h = s.substr(8,2);
	   var minute = s.substr(10,2);
	   var formatTime = y+"-"+m+"-"+d+" "+h+":"+minute;
		return formatTime;
	   }
	   
	}
//******过滤特殊字符*******//
function replaceStr(s) 
{ 
	var pattern = new RegExp("-");
	var rs = ""; 
	for (var i = 0; i < s.length; i++) { 
		rs = rs+s.substr(i, 1).replace(pattern, ''); 
	} 
	return rs; 
} 	
//**********************//

//根据内容的多少获取高度给父级设置高度
function limitHeight(){
	var Length = $(".limitBox").length;
	for(var i=0; i<Length;i++){
		var limitheight = $(".limitwords").eq(i).height();
		console.log(limitheight);
		$(".limitBox").eq(i).css("height",limitheight);
	}
	
}


//根据用户输入的Email跳转到相应的电子邮箱首页  
var hash={  
    'qq.com': 'http://mail.qq.com',  
    'gmail.com': 'http://mail.google.com',  
    'sina.com': 'http://mail.sina.com.cn',  
    '163.com': 'http://mail.163.com',  
    '126.com': 'http://mail.126.com',  
    'yeah.net': 'http://www.yeah.net/',  
    'sohu.com': 'http://mail.sohu.com/',  
    'tom.com': 'http://mail.tom.com/',  
    'sogou.com': 'http://mail.sogou.com/',  
    '139.com': 'http://mail.10086.cn/',  
    'hotmail.com': 'http://www.hotmail.com',  
    'live.com': 'http://login.live.com/',  
    'live.cn': 'http://login.live.cn/',  
    'live.com.cn': 'http://login.live.com.cn',  
    '189.com': 'http://webmail16.189.cn/webmail/',  
    'yahoo.com.cn': 'http://mail.cn.yahoo.com/',  
    'yahoo.cn': 'http://mail.cn.yahoo.com/',  
    'eyou.com': 'http://www.eyou.com/',  
    '21cn.com': 'http://mail.21cn.com/',  
    '188.com': 'http://www.188.com/',  
    'foxmail.coom': 'http://www.foxmail.com'  
};


//评价字数限制
//字数限制函数
function limitTextCountFn(TextAreaId,countContainerId,count){
	var curLength=$(TextAreaId).val().length; 
	if(curLength > count){ 
		var num=$(TextAreaId).val().substr(0,count); 
		$(TextAreaId).val(num); 
		
	} 
	else { 
		$(countContainerId).text(count - $(TextAreaId).val().length); 
	} 
};

//咨询申请主题字数限制函数
function titleLimitFontCountFn(){
	var curLength= $("#consultTitle").val().length;

	if(curLength>20){
		var num = $("#consultTitle").val().substr(0,20); 
		$("#consultTitle").val(num);
	} 
	
};
//模拟下拉菜单
function selectThis(value){ 
	$("#div_select").text(value); 
	$("#li_show").css("display","none"); 
} 

function showmenu(){ 
  $("#li_show").css("display","block");  
} 

//咨询 专家信息接口函数
function concultProInfo(professorId){
	 $.ajax({
			url:"/ajax/professor/editBaseInfo/"+professorId,
			type:"get",
			data : {"id":professorId},
			contentType : "application/x-www-form-urlencoded",
			success:function(response){
				console.log(response);
				var myData = response["data"];
				
				$("#professorName").html(myData["name"]);
				$("#professorTitle").html(myData["title"]);
				$("#profDepartment").html(myData["department"]);
				$("#profOrganization").html(myData["orgName"]);
				$("#profAdress").html(myData["address"]);
				$("#byConsultConut").html(myData["consultCount"]);
				$("#sendConsultBtn").attr("proId",myData["id"]);
				
				//星级 
				var startConut = myData["starLevel"];
				for(var i = 0; i < startConut; i ++){
					$("#starLevel .evastar2").eq(i).addClass("addStar");
				}
				
				//是否认证
				if(myData["authentication"] == true){
					$("#proModify").removeClass("displayNone");
				}
				
				//没有头像
				if(myData["hasHeadImage"] == 0){
					$("#prohead").attr("src","images/default-photo.jpg");
				}
				//有头像
				else {
					$("#prohead").attr("src","images/head/"+myData["id"]+"_m.jpg");
				}
				
				
			},
			error:function(error){
				$.MsgBox.Alert("message","请求数据失败");
			}
		});
};

//发送咨询
function sendConsultHandler(professorId){

 	var professorId = professorId;
	var consult_type = $(".clicknow").text();//咨询类型
	var consult_title = $("#consultTitle").val();//咨询主题
	var consult_content = $("#consultcontent").val();//咨询内容
	var consultStr = {
			"consultType":consult_type,
			"consultTitle":consult_title,
			"consultContant":consult_content,
			"professorId":professorId,
			"consultantId":userid
	};
	
	if(consult_type == '' || consult_title == '' || consult_content == ''){
		$.MsgBox.Alert("message","请填写完整");
	};
	if(consult_type == ''){
		$.MsgBox.Alert("消息","请选择联系目的");
	}
	if(consult_title == ''){
		$.MsgBox.Alert("消息","请填写咨询目的");
	}
	if(consult_content == ''){
		$.MsgBox.Alert("消息","请填写咨询内容");
	}
	
	if(userid && userid != null && userid != "null" && consult_type != '' &&
			consult_title != '' && consult_content != ''
	){
		
		$.ajax({
			"url" :"/ajax/consult",
			"type" : "post",
			//传值：咨询类型、主题、内容、专家id、申请人id
			"data" : consultStr,				
			"contentType" : "application/x-www-form-urlencoded",
			"dataType" : "json",
			"success" : function(response) {
				console.log(response);
			},
			"error":function (){
				$.MsgBox.Alert("消息","咨询申请失败");
			},
			
			"complete":function(){
				//$(".consultapply").remove();
				$(".blackcover").remove();
				$("body").css("position","static");
				$.MsgBox.Alert("消息","咨询申请成功");
			},
		});
	}


};


