/**
 * Read the JavaScript cookies tutorial at:
 *   http://www.netspade.com/articles/javascript/cookies.xml
 */

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


var newWinCook = getCookie("tintuc_newwin");
var newWin = (newWinCook == "yes");
var openopt = getCookie("openopt");
var expDate = new Date(2006,12,30);


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function setStatus(status)
{	
	newWin = status; 
	if (newWin)
	{
		setCookie("tintuc_newwin", "yes", expDate);
	} else 
	{
		setCookie("tintuc_newwin", "no", expDate);
	}
	updateOption();
}

function updateOption()
{
	var cell1 = document.getElementById("opt1");
	var cell2 = document.getElementById("opt2");
	if (newWin) 
	{
		cell2.style.backgroundColor = '#FF6600';
		cell1.style.backgroundColor = '';		
	} else 
	{
		cell1.style.backgroundColor = '#FF6600';
		cell2.style.backgroundColor = '';
	}
}


function highlightoop()
{
	var ptr = document.getElementById("ptrdv");
	ptr.style.left = ''+((openopt-1)*23)+'px';
	ptr.style.top = '4px';
	//alert(ptrdv.style.top);

	/*
	var cell = new Array(3);
	cell[0] = document.getElementById("oop1");
	cell[1] = document.getElementById("oop2");
	cell[2] = document.getElementById("oop3");
	cell[3] = document.getElementById("oop4");
	var i;
	
	for (i=0;i<4;i++)
	{
		if (openopt-1==i)
		{
			cell[i].style.backgroundColor = '#FFdd99';
		} else 
		{
			cell[i].style.backgroundColor = '';
		}
	}
	*/
}

function setopenopt(x)
{
	if (x == openopt)
	   return;
	openopt = x;
	setCookie("openopt", x, expDate);	
	highlightoop();
}


function initopenopt()
{
	if (openopt == null || openopt <= 0 || openopt > 4)
	   openopt = 4; //open in frame
	highlightoop();
}


function encodeHtml(s) {
	var a = escape(s);
	a = a.replace(/\//g,"%2F");
	a = a.replace(/\?/g,"%3F");
	a = a.replace(/=/g,"%3D");
	a = a.replace(/&/g,"%26");
	a = a.replace(/@/g,"%40");
	return a;	
}
function decodeHtml(s) {
	return unescape(s);
}


function openLink(lnk, it)
{
	//sendreport(itemid);
	if (openopt == 2) 
	{				
		lnk.target = "_blank";
		return true;
	} 
	if (openopt == 3) 
	{	
	    if (window.name != "tgtopencontent") 
			lnk.target = "tgtopencontent"; 
		else 
			lnk.target = "tgtopencontent2"; 
		return true;
	} 
	if (openopt == 4) 
	{		
		lnk.href = "open.jsp?u="+encodeHtml(lnk.href)+"&r="+encodeHtml(window.document.location.toString())+"&it="+it;
		lnk.target = "_self";
		return true;	
	} 
	lnk.target = "_self";
	
	return true;
	
}




function showtooltip(event, headline, text)
{
    var pv_x, pv_y;

    pv_x = tt_EvX(event);
    pv_y = tt_EvY(event);

    //alert("event at " + pv_x + ", " + pv_y);
    tt_go(event, headline, text, pv_x, pv_y);
}

function hidetooltip()
{
	tt_Hide();
}


function rg(it, st)
{
	var url = "report.jsp?i="+it+"&s="+st;
	var req;
	if (window.XMLHttpRequest) {
        req  = new XMLHttpRequest();
        req.onreadystatechange = donothing;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = donothing;
            req.open("GET", url, true);
            req.send();
        }
    }
}


function donothing()
{
}

function rf()
{	
}



