//
function deleteCookie(name) {
    var date = new Date();
    date.setTime(date.getTime() - 10000); 
    document.cookie = name + "=删除无效" + "; expires=" + date.toUTCString();
    document.getElementById('history').innerHTML='<li>暂无浏览记录</li>';
}

//
function getCookieVal(offset){ 
    var endstr = document.cookie.indexOf (";", offset); 
    if (endstr == -1) endstr = document.cookie.length; 
    return unescape(document.cookie.substring(offset, endstr)); 
} 

//
function setCookie(name,value){ 
    var exp = new Date(); 
    exp.setTime (exp.getTime()+3600000000); 
    document.cookie = name + "=" + escape(value) + "; expires=" + exp.toGMTString(); 
}

//
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 unescape(getCookieVal (j)); 
        i = document.cookie.indexOf(" ", i) + 1; 
        if (i == 0) break; 
    } 
    return null; 
} 
//
function intShow(src){
	var imgbox=document.getElementById("imgbox");
	imgbox.style.display='block';
	document.getElementById('imgviewBox').src=src;
}

//
function ShowImg(obj,e){
	var obj=document.getElementById(obj);
	var browerHeight=document.body.clientHeight;
	var browerWidth=document.body.clientWidth; 
	var mouseY=e.clientY; 
	var mouseX=e.clientX; 
	var scrollTop=document.body.scrollTop; 
	var scrollLeft=document.body.scrollLeft 
	if (mouseY+ obj.height + 20 <= browerHeight) var height = true; 
	if (browerWidth-mouseX > mouseX) var width = true; 
	if(height)
		y=scrollTop+mouseY+20;
	else
		y=scrollTop + browerHeight-obj.top * 2 - 20;
	if(width)
		x=scrollLeft+mouseX+20;
	else
		x=scrollLeft+mouseX-obj.left * 2 -20;
	document.getElementById("imgbox").style.left=x + "px";
	document.getElementById("imgbox").style.top=y + "px";
}

//
function ShowBox(){
	document.getElementById("imgbox").style.display="none";
}

//
function HiddenShow(){
	document.getElementById("imgbox").style.display="none";
	}

//
function saveLastView(name,html,imgsrc){
	if(name==null || html==null) return false;
	var saved = getCookie("LastView");
	if(saved==null) saved ="Begin";
	if(saved.indexOf(name)<1 &&saved.indexOf(imgsrc)){
		setCookie("LastView",saved + "{f}" + name + "{e}" + html + "{e}" + imgsrc);
		}
}

//
function showLastView(){
	var saved = getCookie("LastView");
	var Output ="";
	if(saved!="Begin" && saved.indexOf('{f}')>0){
		var viewarg = saved.split("{f}");
		var i;
		var l;
		if(viewarg.length>10){l=viewarg.length-10;}else{l=1;}
		for(i=viewarg.length-1;i>=l;i--){
			var e_view = viewarg[i].split("{e}");
			Output+="<li><a href='"+ e_view[1] +"' onMouseOver=intShow('"+e_view[2]+"') onMouseMove=ShowImg('imgviewBox',event) onMouseOut=HiddenShow()>" + e_view[0] + "</a></li>";
			}
		Output+="<li><a href='javascript:void(0);' Onclick=javascript:deleteCookie('LastView')>清除浏览记录</a></li>";		
	}else{Output='您还没有浏览记录';}
	document.getElementById("history").innerHTML=Output;
	} 
