var pham = document.cookie; 

function getCookie(name) { 
	name += "="; // append '=' to name string 
	var i = 0; // index of first name=value pair 
	while (i < pham.length) { 
		var offset = i + name.length; // end of section to compare with name string 
		if (pham.substring(i, offset) == name) { // if string matches 
			var endstr = pham.indexOf(";", offset); // locate end of name=value pair 
			if (endstr == -1) endstr = pham.length; 
				return unescape(pham.substring(offset, endstr)); // return cookie value section 
		} 
		i = pham.indexOf(" ", i) + 1; // move i to next name=value pair 
		if (i == 0) break; // no more values in cookie string 
	} 
	return null; // cookie not found 
} 

var today = new Date(); 
var expiry = new Date(today.getTime() + 24 * 60 * 20 * 1000);

var CrazyAD = getCookie("CrazyAD") || 1; 

if (CrazyAD == 1)
{
	ShowCrazyAD();//change greeting as required
    document.cookie = "CrazyAD=" + (++CrazyAD) + "; expires=" + expiry.toGMTString(); 
}

var viewportwidth; 
var viewportheight; 

function ShowCrazyAD()
{
	//d=document.all("CrazyADDiv");	
	d = document.getElementById("CrazyADDiv"); 
	nwidth = 789;
	nheight= 528;

	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight 

	if (typeof window.innerWidth != 'undefined') 
	{ 
		viewportwidth = window.innerWidth, 
	    viewportheight = window.innerHeight 
	} 

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) 

	else if (typeof document.documentElement != 'undefined'  && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) 
	{ 
       viewportwidth = document.documentElement.clientWidth, 
       viewportheight = document.documentElement.clientHeight 
	} 

	// older versions of IE 

	else 
	{ 
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth, 
       viewportheight = document.getElementsByTagName('body')[0].clientHeight 
	} 

	// 置中
	//ytop = (viewportheight - nheight) /2;
	//yleft = (viewportwidth - nwidth) / 2;
	//ytop = ytop - 100;
	//yleft = yleft - 230;
    ytop = 50;
    yleft = -12;
	d.style.top = ytop + "px";
	d.style.left = yleft + "px";
	d.style.display="block";

	//setTimeout('CrazyADStop()',15000);	 //15秒後執行結束函數
}

function CrazyADStop()
{
	end = document.getElementById("CrazyADDiv"); 
	end.style.display="none";
	
	CrazyADInit();
}

function CrazyADInit()
{
	start = document.getElementById("CrazyADDiv"); 
	start.style.display="none";
}