//菜单切换
function switchMenu(id){
	$(id).toggleClass('switchMenu');
}
//子菜单切换
function switchSubMenu(id){
	$("div.menuButtonSub").addClass('switchMenu');
	$("div.lastMenuButtonSub").addClass('switchMenu');
	$(id).removeClass('switchMenu');
}
//高亮记录
function highlight(id){
	$(id).toggleClass('highlight');
}
//图片预览
function setImage(fileid,imgid) {
	var imgShow = document.getElementById(imgid);
	var imgFile = document.getElementById(fileid);
	imgShow.src=imgFile.value;
}
//关闭窗口
function closeWin(id) {
	var win = document.getElementById(id);
	win.style.display = "none";
}
//获取x轴位置
function getx(id){
	var e = document.getElementById(id);
	var l=e.offsetLeft;
	while(e=e.offsetParent){
		l+=e.offsetLeft;
	}
	return(l);
}
//获取y轴位置
function gety(id){
	var e = document.getElementById(id);
	var t=e.offsetTop;
	while(e=e.offsetParent){
		t+=e.offsetTop;
	}
	return(t);
}
//缩小图片适应指定宽高
function zoomImg(myPic,myWidth,myHeight){   
    var srcWidth = myPic.width; 
    var srcHeight = myPic.height;
    if(srcWidth>myWidth || srcHeight>myHeight){                 
	    var rateWidth = myWidth/srcWidth; 
	    var rateHeight = myHeight/srcHeight;      
		var rate;
		if(rateWidth < rateHeight) {
			rate = rateWidth;
		}else{
			rate = rateHeight;
		}
		myPic.width	 = srcWidth * rate;
		myPic.height = srcHeight * rate;
	}
	$(myPic).css("margin-left",(myWidth-myPic.width)/2+"px");
	$(myPic).css("margin-top",(myHeight-myPic.height)/2+"px");
}

//缩小图片适应指定宽高
function zoomImgIndex(myPic,myWidth,myHeight){   
    var srcWidth = myPic.width;
    var srcHeight = myPic.height;
    if(srcWidth>myWidth || srcHeight>myHeight){
	    var rateWidth = myWidth/srcWidth;
	    var rateHeight = myHeight/srcHeight;
		var rate;
		if(rateWidth < rateHeight) {
			rate = rateWidth;
		}else{
			rate = rateHeight;
		}
		myPic.width	 = srcWidth * rate;
		myPic.height = srcHeight * rate;
	}
	$(myPic).css("margin-left","1px");
	$(myPic).css("margin-top","1px");
}

//获取指定名称cookie
function getCookie(name){
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return "";
}

//设置指定名称cookie
function setCookie(name, value){
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    var expDay = (argc > 2) ? argv[2] : -1;
    try
    {
        expDay = parseInt(expDay);
    }
    catch(e)
    {
        expDay = -1;
    }
    if(expDay < 0) {
        setCookieVal(name, value);
    } else {
        var expDate = new Date();
        // The expDate is the date when the cookie should expire, we will keep it for a month
        expDate.setTime(expDate.getTime() + (expDay * 24 * 60 * 60 * 1000));
        setCookieVal(name, value, expDate);
    }
}
//删除指定名称cookie
function deleteCookie(name){
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    // This cookie is history
    var cval = getCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
//获取cookie值
function getCookieVal(offset){
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
//设置cookie值
function setCookieVal(name, value)
{
    var argv = setCookieVal.arguments;
    var argc = setCookieVal.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
                      ((expires == null || expires < 0) ? "" : ("; expires=" + expires.toGMTString())) +
                      ((path == null) ? "" : ("; path=" + path)) +
                      ((domain == null) ? "" : ("; domain=" + domain)) +
                      ((secure == true) ? "; secure" : "");
}





