﻿// JavaScript Document
function getCurrentTime(){//获取当前时间
	var dateObj = new Date();
	var tempDate=dateObj.getFullYear()+"-"+(dateObj.getMonth()+1)+"-"+dateObj.getDay()+" "+dateObj.getHours()+":"+dateObj.getMinutes()+":"+dateObj.getSeconds();
	return tempDate;
}

//读取cookie的值
function getCookie(name){
	var strCookie=document.cookie;
	var arrCookie=strCookie.split("; "); /* 将多cookie切割为多个名/值对*/
	for(var i=0;i<arrCookie.length;i++){ // 遍历cookie数组，处理每个cookie对
		var arr=arrCookie[i].split("="); // 找到名称为userId的cookie，并返回它的值
		if(arr[0]==name)return arr[1];
	}
}

//设定cookie
function setCookie(cookieName,cookievalue,expirationDate){
	var expirationDateObj = new Date();
	//expirationDateObj.setDate(expirationDateObj.getDate()  + expirationDate );
	expirationDateObj.setHours(expirationDateObj.getHours()  + expirationDate*24 );
	document.cookie = cookieName + '=' + escape(cookievalue) + ';expires=' + expirationDateObj.toGMTString();
}


//去掉空格
String.prototype.Trim = function()
{
    return this.replace(/^\s+/g,"").replace(/\s+$/g,"");
}

//javascript 操作cookie类 
function JSCookie()
{
    //过期时间设定（小时）
    this.SetExpireHour = function(expireHour)
    {
        var expirationDateObj = new Date();
	    expirationDateObj.setHours(expirationDateObj.getHours()  + expireHour );
	    return expirationDateObj;
    };
    //获取Cookies
    this.GetCookie = function(key)
    {
        var cookie = document.cookie;
        var cookieArray = cookie.split(';');
        var getvalue;
        for(var i = 0;i<cookieArray.length;i++)
        {
            if(cookieArray[i].Trim().substr(0,key.length) == key)
            {
                getvalue = cookieArray[i].Trim().substr(key.length + 1);
                break;
            }
        }
        if(getvalue!=null) return unescape(getvalue);
    };
    //获取子键值
    this.GetChild = function(cookieKey,childKey)
    {
        var getvalue;
        var child = this.GetCookie(cookieKey);
        if(child!=null && child!="") {
            var childs = child.split('&');
            for(var i = 0;i < childs.length;i++)
            {
                if(childs[i].Trim().substr(0,childKey.length) == childKey)
                {
                    getvalue = childs[i].Trim().substr(childKey.length + 1);
                    break;
                }
            }
        }
        return getvalue;
    };
    //设定Cookies
    this.SetCookie = function(key,value,expire,domain,path)
    {
        var cookie = "";
        if(key != null && value != null) cookie += key + "=" + escape(value) + ";";
        if(expire != null) cookie += "expires=" + this.SetExpireHour(expire).toGMTString() + ";";
        if(domain != null) cookie += "domain=" + domain + ";";
        if(path != null) cookie += "path=" + path + ";";
        document.cookie = cookie;
    };
    //设定Cookies子键值
    this.SetChild = function(cookieKey,childKey,childValue,expire,domain,path)
    {
        if(cookieKey != null && childKey != null && childValue != null)
        {
            var cookieValue = this.GetCookie(cookieKey);
            if(cookieValue != null){
                //去掉最后的分号
                //cookieValue = cookieValue.Trim().substr(0,cookieValue.length - 1)
                var childCookie = this.GetChild(cookieKey,childKey);
                if(childCookie != null){
                    var childs = cookieValue.split('&');
                    for(var i = 0;i < childs.length;i++){
                        if(childs[i].Trim().substr(0,childKey.length) == childKey){
                            childs[i] = childKey + "=" + childValue;
                        }
                        if(i==0){
                            cookieValue = childs[i];
                        }else{
                            cookieValue += "&" + childs[i];
                        }
                    }
                    //cookieValue += ";";
                }else{
                    cookieValue += "&" + childKey + "=" + childValue;
                }
            }else{
                cookieValue = childKey + "=" + childValue;
            }
            this.SetCookie(cookieKey,cookieValue,expire,domain,path);
        }
    };
    
    //使Cookie过期删除
    this.Expire = function(key)
    {
         expire_time = new Date();
         expire_time.setFullYear(expire_time.getFullYear() - 1);
         var cookie = " " + key + "=e;expires=" + expire_time.toGMTString() + ";"
         document.cookie = cookie;
    };
}

/*检查用户是否第一次登陆本网站，跳转到导航页面*/
function CheckVisiter(_App){
	if((getCookie("homeLat")==null)||(getCookie("homeLng")==null)){
		window.location.href="firstNav.aspx?resetPosition=reset";
	}else if(_App!=null){
		load(_App);
	}else{
		window.location.href="main.aspx";
	}
}

/*检查屏幕尺寸，让页面适应不同的分辨率*/
function CheckScreen(){
	if(window.screen.height>=1024){
	}else{
		document.getElementById("left_business_list").style.height=(window.screen.height-340)+"px";
		document.getElementById("map2").style.height=(window.screen.height-300)+"px";
		if(window.screen.height>=768){
		//document.getElementById("left_business_list").style.height="430px";
		//document.getElementById("map2").style.height="470px";
		}else{
			if(window.screen.height>=600){
			
			}
		}
	}
}
