/**
 * Test the user-agent's cookie support
 */
SetCookie( 'PoweredByAdaptOne', '1', null, '/'); var _isCookieSet;var _cookieWarn='';
if(GetCookie('PoweredByAdaptOne')){_isCookieSet=true;DelCookie('PoweredByAdaptOne', '/', '');
}else{_isCookieSet=false;_cookieWarn='<font style="color:red;">Your browser appears to be configured to block cookies. Please enable cookie support, then try navigating to the site again.</font>';}

/**
 * Utility functions used by templates/naviations/SessionTimeout.vm
 *
 */
function showContentTable() {
   var contenttbl = $('contenttable');
   if (contenttbl) {
    var main_body = contenttbl.parentNode;
    if ($("_session_timeout_div").style.display!='block') {
	 contenttbl.style.display = 'block';
	}
    var bigempty = $('bigempty');
    main_body.removeChild(bigempty);
   }
}

function hideContentTable() {
   var contenttbl = $('contenttable');
// style.visibility does not work because the inside block element could
// still be visible. here simply set the container table to display:none.
   if (contenttbl) {
     contenttbl.style.display = 'none';
// Create a big empty div to replace the content table
     var main_body = contenttbl.parentNode;
     if (document.getElementById){
        var bigempty = $('bigempty');
        if (bigempty) main_body.removeChild(bigempty);
		bigempty = document.createElement('div');
		bigempty.id = 'bigempty';
		bigempty.style.display = 'block';
		main_body.insertBefore(bigempty, contenttbl);
	 }
   }
}

function _refresh()
{
    //For js version 1.0/1.1
    //var sURL = unescape(window.location.pathname);
	//window.location.replace( sURL );
    //window.location.href=sURL;
    //For JavaScript version 1.2

    var sURL = window.location.href;
    if (sURL) {
        // Turbine has this action specific url, need to remove that to prevent form resubmit.
        // e.g.
        // /rfx%2Cadmin%2CRfxDoc.vm/action/rfx.SectionAction/eventsubmit_dodeletesection/doDeletesection/rfxdocid/1060
    	sURL = sURL.replace(/\/action\/[0-9a-zA-Z.]*/gi, '');
    	sURL = sURL.replace(/\/eventsubmit_do[0-9a-zA-Z]+\/do[A-Z][0-9a-zA-Z]*/gi, '');
    }
	if ($('_session_timeout_public_page').value != "")
		sURL = $('_session_timeout_public_page').value;
    // window.location.reload( true );
    // This doesn't work for js version 1.0.
	window.location.replace(sURL);
}

function onTimeoutHandler(e, key, targetUrl, targetElmts) {
   var f = e.form; var onC = function(responseText, responseXML){
        var resp = new Function("return " + responseText + ";")();
	    // reset timeout
	    clearTimeout(_preventTimeoutId); clearTimeout(_showTimeoutId);
		if (null == resp || "" == resp) {
           showContentTable();
		   _showTimeoutId = setTimeout( 'ShowTimeoutWarning();', _timeOut);
		   _preventTimeoutId = setTimeout( 'PreventTimeoutWarning();', _preTimeOut);
		}
		else {
		  setFieldValues(f, resp);
   	      var divTag = document.getElementById("_session_timeout_div");
		  if (e.value != "") {
		    divTag.style.display="block";
		    hideContentTable();
		  }
		  else {
		    showContentTable();
		    _showTimeoutId = setTimeout( 'ShowTimeoutWarning();', _timeOut);
			_preventTimeoutId = setTimeout( 'PreventTimeoutWarning();', _preTimeOut);
		  }
	    }
	}
	var myReqObj = new XmlHttpReqObj();
	myReqObj.onComplete = onC;
    var url = targetUrl;
    url += "?" + key + "=" + escape(e.value) + "&";
	if (targetElmts && targetElmts.length > 0) {
	   for (var i=0; i<targetElmts.length;i++) {
	     url += "id" + i + "=" + escape(targetElmts[i]) + "&";
	   }
	}
    myReqObj.submit(url);
}


function ShowTimeoutWarning ()
{
document._session_timeout_form._session_timeout_msg.onblur();
}

function addWindowOnload(fn) {
    var oldOnLoad = window.onload;
    if (typeof window.onload != 'function') {
       window.onload = function() {
				fn();
	       };
    } else {       
            window.onload = function() {
              oldOnLoad();
		      fn();
            };
    }	
}
