﻿//判断cookie是否开启 
function CookieEnabled() {
addCookie("CookieEnabled","1",1);
if(getCookie("CookieEnabled")=="") return false;
else return true;
} 
//设置添加cookie，expireDays是设置保存cookie的时间，单位：天
function addCookie(name,value,expireDays){
	var cookieString=name+"="+escape(value);
	if(expireDays>0){
		var date=new Date();
		date.setTime(date.getTime()+expireDays*24*3600*1000);
		cookieString=cookieString+"; expires="+date.toGMTString();
	}
	document.cookie=cookieString;
}
//查询名为name的cookie中的内容,找不到则返回空字符
function getCookie(name){
    var strCookie=document.cookie;
	var arrCookie=strCookie.split("; ");
	for(var i=0;i<arrCookie.length;i++){
		var arr=arrCookie[i].split("=");
		if(arr[0]==name)return unescape(arr[1]);
	}
	return "";
}
//删除cookie中名为name的记录,若存在记录，则删除并返回true,否则不操作并返回false
function deleteCookie(name){
    if(getCookie(name)!=""){
	var date=new Date();
	date.setTime(date.getTime()-1);
        document.cookie=name+"=; expires="+date.toGMTString();
        return true;
    }else{ return false; }
}
//启动本地安装易信通，能够启动返回true,否则返false
function execEETong(EEID){
	if(EEID!=null&&EEID!=0){
		window.oldOnError = window.onerror;   
		window._command = command;   
		window.onerror = function(err){   
		if(err.indexOf("utomation")!=-1){   
			alert("请更改您的IE的安全级别,以启用易信通进行通信（开始->设置->控制面板->Internet选项->安全->自定义级别->对没有标记为安全的ActiveX控件进行初始化和脚本运行->启用）；您也可以不进行安全设置而使用易信通网页即时通讯工具进行即时通讯");     
			return false;   
			}
		} 
		try{
			var wsh = new ActiveXObject('WScript.Shell');
			if (wsh) wsh.Run("ee.exe "+EEID,1,true);
			window.onerror  =  window.oldOnError;
			return true;
		}catch(e){
			return false;
		} 
	}else{
		alert("不存在EE号");
		return true;
	}
}
function getLocationValue(name){
	var valuetmp = "";
	var pairs = "";
	if(window.parent.location.href.indexOf("?")>-1)
	    pairs = window.parent.location.href.substring(window.parent.location.href.indexOf("?")+1).split("&");
	else if(window.parent.location.href.indexOf("@")>-1)
	    pairs = window.parent.location.href.substring(window.parent.location.href.indexOf("?")+1).split("&");
	for(var i=0; i<pairs.length; i++){
		if(pairs[i].indexOf(name) != -1){
			valuetmp = pairs[i].substring(name.length+1);
			break;
		}
	}
	return valuetmp;
}
//设为主页
function setHP(obj){
	try{obj.style.behavior='url(#default#homepage)';obj.setHomePage(window.parent.location.href);}
	catch(e){alert("您的浏览器不支持该功能!");return true;}
}
//添加收藏夹
function addBookmark(title,url) {
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}
/**
 *重设图片，将其按比例缩放
 */
function ImageReset(targetPicture){
    var tempImg = document.createElement("img");
    tempImg.src = targetPicture.src;
    var height = tempImg.height;
    var width = tempImg.width;
    if(height>targetPicture.height || width > targetPicture.width){
        var hTmp = height/targetPicture.height;
        var wTmp = width/targetPicture.width;
        if( hTmp>wTmp ) wTmp = hTmp;
        height = height/wTmp;
        width = width/wTmp;
    }
    if(height > 0 && width > 0)
    {
        targetPicture.width = width;
        targetPicture.height = height;
    }   
 }
 
//获取当前页主机地址及端口(类似的方法分布于common.js、showcitybox.js、HeaderSearch.html)
function getUrl(){
var tmptest = "\/EE56.WebSite\/";//注:开发测试期所用到的文件夹，正式应用之后要删除该变量
//var tmptest = "\/";
var url = "http:\/\/"+window.location.hostname;
if(window.location.port!="")url = url+":"+window.location.port;
return (url+tmptest);

}

//提交留言
var companyId = 0;
var toEeid = "";
function showMessageBox(eeid){//,id
    //companyId=id;
    toEeid=eeid;
    $.getScript("js/ajaxform.js",function(){
        if(document.getElementById("background")==null||document.getElementById("messageBox")==null){
            $("body").append("<div style='filter:alpha(opacity=30);opacity:0.40;background-color:#000000;position:absolute;left:0;top:0;z-index:160' id='background'></div><div style='display:block;top:300px;left:"+($(document).width()-350)/2+"px;border:#C85B00 solid 1px;width:500px;font-size:12px;background-color:#FFFFFF;color:#666666;text-align:left;position:absolute;z-index:170;' id='messageBox'><div style='background-color:#FF7400;line-height:25px;height:25px;color:#FFFFFF;'><div style='float:left;font-size:14px;font-weight:bold;text-indent:5px'>留言板</div><div style='float:right; width:35px;'><a href='javascript:void(0);' onclick='hideMessageBox()' style='color:#FFFFFF'>关闭</a></div><div style='clear:both'></div></div><div style='line-height:22px;'><div style='border-top:#FF6600 dashed 1px;padding:10px; background-color:#FFFDFB'><form id='submitMessage' style='padding:0;margin:0;width:475px;' onSubmit='return submitMessage();'><table width='100%' border='0' cellspacing='0' cellpadding='0' style='margin-top:10px'><tr><td width='14%' height='27'>您的尊称：</td><td width='86%'><input type='text' name='message_name' id='message_name' class='message_input'/></td></tr><tr><td height='28'>您的邮箱：</td><td><input type='text' name='message_email' id='message_email' class='message_input'/></td></tr><tr><td height='28'>联系电话：</td><td><input type='text' name='message_phone' id='message_phone' class='message_input'/></td></tr><tr><td height='68' valign='top'>您的留言：</td><td><textarea name='message_content' cols='40' rows='5' id='message_content' class='message_input'></textarea></td></tr><tr><td>验证码：</td><td><input type='text' id='validateNum' runat='server' size='7'/>&nbsp;&nbsp;<img src='' id='validateNumImage' onload=this.style.display='' onerror=this.style.display='none' onclick='changeValidateNum()' alt='点击切换验证码' style='margin-bottom:-3px;height:23px;'/></td></tr><tr><td colspan='2' align='center' height='35'><input type='submit' id='messageButton' value='提交留言'/></td></tr></table></form></div></div></div>");
            $("#background").width($(document).width()).height($(document).height());
            $(window).resize(function(){$("#background").width($(document).width()).height($(document).height());$("#messageBox").css("left",($(document).width()-350)/2+"px")}); 
            changeValidateNum();
        }else{
            $("#background").show();
            $("#messageBox").show();
        }
    });
}
function showExtMessageBox(eeid){//,id
    //companyId=id;
    toEeid=eeid;
    $.getScript("../js/ajaxform.js",function(){
        if(document.getElementById("background")==null||document.getElementById("messageBox")==null){
            $("body").append("<div style='filter:alpha(opacity=30);opacity:0.40;background-color:#000000;position:absolute;left:0;top:0;z-index:160' id='background'></div><div style='display:block;top:300px;left:"+($(document).width()-350)/2+"px;border:#C85B00 solid 1px;width:500px;font-size:12px;background-color:#FFFFFF;color:#666666;text-align:left;position:absolute;z-index:170;' id='messageBox'><div style='background-color:#FF7400;line-height:25px;height:25px;color:#FFFFFF;'><div style='float:left;font-size:14px;font-weight:bold;text-indent:5px'>留言板</div><div style='float:right; width:35px;'><a href='javascript:void(0);' onclick='hideMessageBox()' style='color:#FFFFFF'>关闭</a></div><div style='clear:both'></div></div><div style='line-height:22px;'><div style='border-top:#FF6600 dashed 1px;padding:10px; background-color:#FFFDFB'><form id='submitMessage' style='padding:0;margin:0;width:475px;' onSubmit='return submitMessage();'><table width='100%' border='0' cellspacing='0' cellpadding='0' style='margin-top:10px'><tr><td width='14%' height='27'>您的尊称：</td><td width='86%'><input type='text' name='message_name' id='message_name' class='message_input'/></td></tr><tr><td height='28'>您的邮箱：</td><td><input type='text' name='message_email' id='message_email' class='message_input'/></td></tr><tr><td height='28'>联系电话：</td><td><input type='text' name='message_phone' id='message_phone' class='message_input'/></td></tr><tr><td height='68' valign='top'>您的留言：</td><td><textarea name='message_content' cols='40' rows='5' id='message_content' class='message_input'></textarea></td></tr><tr><td>验证码：</td><td><input type='text' id='validateNum' runat='server' size='7'/>&nbsp;&nbsp;<img src='' id='validateNumImage' onload=this.style.display='' onerror=this.style.display='none' onclick='changeExtValidateNum()' alt='点击切换验证码' style='margin-bottom:-3px;height:23px;'/></td></tr><tr><td colspan='2' align='center' height='35'><input type='submit' id='messageButton' value='提交留言'/></td></tr></table></form></div></div></div>");
            $("#background").width($(document).width()).height($(document).height());
            $(window).resize(function(){$("#background").width($(document).width()).height($(document).height());$("#messageBox").css("left",($(document).width()-350)/2+"px")}); 
            changeExtValidateNum();
        }else{
            $("#background").show();
            $("#messageBox").show();
        }
    });
}

function hideMessageBox(){
    $("#background").hide();
    $("#messageBox").hide();
}
function submitMessage(){
    $("#submitMessage").ajaxSubmit({ 
        beforeSubmit:validateForm,
        success:showResponse,
        url:"Ajax/GuestMessage.aspx?toEeid="+toEeid,//+"&companyId="+companyId
        type:"post",
        clearForm: true
    }); 
    return false; 
}
//测试EE号是否在线
function checkEEOnLine(eeid){
    var html = $.ajax({
  		url: "Ajax/CheckEEOnLine.aspx?eeid="+eeid,
  		async: false
 	}).responseText; 
	return html;
}
function validateForm() {
    if(toEeid==""){
        alert("无参数!请重试...");return false;
    }else if($.trim($("#message_name").val())==""){
        alert("抱歉！请输入您的姓名");return false;
    }else if(!/^[\w-]+@[\w-]+(\.(\w)+)*(\.(\w){2,3})$/.test($.trim($("#message_email").val()))){
        alert("抱歉！您的邮箱地址不正确！请重新输入...");return false;
    }else if($.trim($("#message_phone").val())==""||$.trim($("#message_phone").val()).length>15||$.trim($("#message_phone").val()).length<7||!(/^[0-9]*[1-9][0-9]*$/.test($("#message_phone").val()))){
        alert("抱歉！请正确输入您的联系电话");return false;
    }else if($.trim($("#message_content").val()).length<5){
        alert("抱歉！您的留言字数最少不能少于5个");return false;
    }else if($.trim($("#validateNum").val())==""){
        alert("请输入验证码");return false;   
    }else if(isPass()=="false"){
        alert("验证码不正确，请重新输入");changeValidateNum();return false;
    }else{
        $("#messageButton").attr("disabled",true);
        return true;
    }
} 
function showResponse(responseText, statusText) {
    $("#messageButton").attr("disabled",false);
    if(responseText=="true"){alert("提交成功！");hideMessageBox();}
    else alert("抱歉！提交过程中遇到异常未能正常提交...请稍候重试");
} 

//检查验证码
 function isPass(){
	var html = $.ajax({
  		url: "UserControls/validatenumber.aspx?n="+$("#validateNum").val()+"&"+Math.random(),
  		async: false
 	}).responseText; 
	return html;
}
//刷新验证码
function changeValidateNum(){
	$("#validateNumImage").attr("src","UserControls/validatenumber.aspx?"+Math.random());
}
function changeExtValidateNum(){
	$("#validateNumImage").attr("src","../UserControls/validatenumber.aspx?"+Math.random());
}
//获取安心指数
function getSecureIndex(id,memberType,secureIndex,transportHeft,safetyFactor){
    var num_SecureIndex = 0; //指数
    var num_display = 0; //显示数
    var showCode = "";
   // showCode += "<img  src='Webs/TransportationIndex/images/s_member_"+memberType+".gif' alt='' style='padding:0; margin:0;' />";
    if(memberType == 3){
        num_SecureIndex = secureIndex+transportHeft+safetyFactor;
    
        if (num_SecureIndex>0 && num_SecureIndex<=20)
        {
            num_display = 1;
        }
        else if(num_SecureIndex>20 && num_SecureIndex<90)
        {
            num_display = 2;
        }
        else if(num_SecureIndex>=90 && num_SecureIndex<=200)
        {
            num_display = 3;
        }
        else if(num_SecureIndex>200 && num_SecureIndex<450)
        {
            num_display = 4;
        }
        else if (num_SecureIndex >= 450)
        {
            num_display = 5;
        }
        else
        {
            num_display = 0;
        }
        //showCode += "<br />";
        for(var i=0;i<5;i++,num_display--){
            if(num_display > 0){
                showCode += "<a href='http://www.ee56.com/Webs/TransportationIndex/LogisticCenter/SecureIndex/index.html' target='_blank'><img src='../../../images/shop/lineTeamVIP/s_heart_a.jpg' border='0' alt='从2009年3月1日起&#10放心度：20&#10安全率：100%' style='margin-top:7px;'/></a>";
            } else {
                showCode += "<a href='http://www.ee56.com/Webs/TransportationIndex/LogisticCenter/SecureIndex/index.html' target='_blank'><img src='../../../images/shop/lineTeamVIP/s_heart.jpg' border='0' style='margin-top:7px;'/></a>";
            }
        }
        
    }
    $("#s_"+id).html(showCode); 
}

//获取安心指数(搜索页面)
function getSecureIndex_search(id,memberType,secureIndex,transportHeft,safetyFactor,ebtDate){
    var num_SecureIndex = 0; //指数
    var num_display = 0; //显示数
    var showCode = "";
    if(ebtDate!=""){
        ebtDate = "从"+ebtDate+"起";
    }
    if(memberType == 3){
        num_SecureIndex = secureIndex+transportHeft+safetyFactor;
    
//        if (num_SecureIndex>0 && num_SecureIndex<=20)
//        {
//            num_display = 1;
//        }
//        else if(num_SecureIndex>20 && num_SecureIndex<90)
//        {
//            num_display = 2;
//        }
//        else if(num_SecureIndex>=90 && num_SecureIndex<=200)
//        {
//            num_display = 3;
//        }
//        else if(num_SecureIndex>200 && num_SecureIndex<450)
//        {
//            num_display = 4;
//        }
//        else if (num_SecureIndex >= 450)
//        {
//            num_display = 5;
//        }
//        else
//        {
//            num_display = 0;
//        }
//        for(var i=0;i<5;i++,num_display--){
//            if(num_display > 0){
//                showCode += "<a href='http://www.ee56.com/Webs/TransportationIndex/LogisticCenter/SecureIndex/index.html' target='_blank'><img src='images/s_heart_a.gif' border='0' title='"+ebtDate+"&#10放心度："+num_SecureIndex+"&#10安全率：100%' style='margin-top:10px;'/></a>";
//            } else {
//                showCode += "<a href='http://www.ee56.com/Webs/TransportationIndex/LogisticCenter/SecureIndex/index.html' target='_blank'><img src='images/s_heart.gif' border='0' style='margin-top:10px;'/></a>";
//            }
//        }
        showCode += "<a href='http://www.ee56.com/Webs/TransportationIndex/LogisticCenter/SecureIndex/index.html' target='_blank'><img src='images/s_heart_a.gif' border='0' title='"+ebtDate+"&#10放心度："+num_SecureIndex+"&#10安全率：100%' style='margin-top:10px;'/></a>";
        showCode += "<span style='color:red;font-size:16px; font-weight:bold; margin-left:5px;'>"+num_SecureIndex+"</span>";
        
    }
    $("#d_"+id).html(showCode); 
}

//修改搜索文本框文字
function changeText(){
    if(($.trim($("#searchText").val()).indexOf("(请输入到达目的地城市)")>= 0 || $.trim($("#searchText").val())=="")&& $("#searchTagId").val()==0)
        $("#searchText").val(newText); 
   else if(($.trim($("#searchText").val())=="请输入公司名称" || $.trim($("#searchText").val())=="") && $("#searchTagId").val()==2)
        $("#searchText").val("");
        
   //光标停止文本最后
    var e = event.srcElement; 
    var r =e.createTextRange(); 
    r.moveStart('character',e.value.length); 
    r.collapse(true); 
    r.select();  
}
function checkText(){
    if(($.trim($("#searchText").val()).indexOf("(请输入到达目的地城市)")>=0 || $.trim($("#searchText").val())=="") && $("#searchTagId").val()==0){
       alert("请输入要搜索的线路");
       return false;
    } else if(($.trim($("#searchText").val())=="请输入公司名称" || $.trim($("#searchText").val())=="") && $("#searchTagId").val()==2){
       alert("请输入要搜索的公司名称");
       return false;
    }
    else if($("#searchTagId").val()==1)
    {
        return false;
    }
}

//验证体验搜索
function checkText_tmp(){
    if($.trim($("#startCity").val())==""){
       alert("请输入起始城市名称！如：广州");
       $("#startCity").focus();
       return false;
    } else if($.trim($("#endCity").val())==""){
       alert("请输入目的城市名称！如：上海");
       $("#endCity").focus();
       return false;
    }
}

//搜索公司无结果
function changeText2(){
    if(($.trim($("#searchText2").val())=="请输入公司名称" || $.trim($("#searchText2").val())==""))
        $("#searchText2").val("");
        
   //光标停止文本最后
    var e = event.srcElement; 
    var r =e.createTextRange(); 
    r.moveStart('character',e.value.length); 
    r.collapse(true); 
    r.select();  
}
function checkText2(){
    if(($.trim($("#searchText2").val())=="请输入公司名称" || $.trim($("#searchText2").val())=="")){
       alert("请输入要搜索的公司名称");
       return false;
    }
    else{
        $("#searchText").val($.trim($("#searchText2").val()));
    }
}


//文本框回车键事件
var ie = (document.all)? true:false   
if (ie){   
function ctlent(eventobject){if(window.event.keyCode==13){$("#searchCompany").focus();$("#searchCompany").click();}}   
function ctlent2(eventobject){if(window.event.keyCode==13){$("#searchCompany2").focus();$("#searchCompany2").click();}} 
}  

//搜索框切换
function searchTag(hover){
$("#IndexSearch ul li a").each(function(ahober){
			if(ahober==hover){
				$(this).attr("class","ahover")
				$("#searchTagId").val(hover);
				if($("#searchTagId").val()==0){
				    $("#searchText").val(newText+endName+" (请输入到达目的地城市)");
				    $("#searchText").attr("disabled","");
				}else if($("#searchTagId").val()==2){
				    $("#searchText").val("请输入公司名称");
				    $("#searchText").attr("disabled","");
				}else if($("#searchTagId").val()==1){
				    $("#searchText").val("");
				    $("#searchText").attr("disabled","disabled");
				}
			}else{
				$(this).attr("class","")			
			}
	})
}

//设置首页Cookie
function resetCookie(FeightStationId,province,city){
    if(CookieEnabled()){
	    deleteCookie("FeightStationId");
	    addCookie("FeightStationId",FeightStationId,7);
	    deleteCookie("province");
	    addCookie("province",province,7);
	    deleteCookie("city");
	    addCookie("city",city,7);
    }
}

//设置登录Cookie
function resetLoginCookie(memberId,memberName,companyId,memberRight){
    if(CookieEnabled()){
	    deleteCookie("memberId");
	    addCookie("memberId",memberId,7);
	    deleteCookie("memberName");
	    addCookie("memberName",memberName,7);
	    deleteCookie("companyId");
	    addCookie("companyId",companyId,7);
	    deleteCookie("memberRight");
	    addCookie("memberRight",memberRight,7);
    }
}
