<!--

/*
function fadeBackground(revert) {

    grayOut(!revert);

	op = 0.3
	if (revert) op = 1;
	oDiv = parent.document.getElementById("fader");
	oDiv.style.KHTMLOpacity = op; // Safari<1.2, Konqueror
	oDiv.style.MozOpacity = op; // Older Mozilla and Firefox
	oDiv.style.opacity = op; // Safari 1.2, newer Firefox and Mozilla, CSS3
	oDiv.style.color = "#000000";
	op = op*100
	oDiv.style.filter = "alpha(opacity:" + op +")"; // IE/Win
}
*/

function fadeBackground( grayScreen ) {
    // Pass true to gray out screen, false to ungray
    // options are optional.  This is a JSON object with the following (optional) properties
    // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
    // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
    // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
    // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
    var zindex = 50;
    var opacity = 50;
    var opaque = (opacity / 100);
    var bgcolor = '#000000';
    var dark=document.getElementById('darkenScreenObject');
    
    if ( !dark ) {
        // The dark layer doesn't exist, it's never been created.  So we'll create it here and apply some basic styles.
        // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
        var tbody = document.getElementsByTagName("body")[0];
        var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
        tbody.appendChild(tnode);                            // Add it to the web page
        dark=document.getElementById('darkenScreenObject');  // Get the object.
    }
    
    if ( grayScreen ) {
        // Calculate the page width and height 
        if ( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
            var pageWidth = document.body.scrollWidth+'px';
            var pageHeight = document.body.scrollHeight+'px';
        } else if( document.body.offsetWidth ) {
            var pageWidth = document.body.offsetWidth+'px';
            var pageHeight = document.body.offsetHeight+'px';
        } else {
            var pageWidth='100%';
            var pageHeight='100%';
        }   
        //set the shader to cover the entire page and make it visible.
        dark.style.opacity=opaque;                      
        dark.style.MozOpacity=opaque;                   
        dark.style.filter='alpha(opacity='+opacity+')'; 
        dark.style.zIndex=zindex;        
        dark.style.backgroundColor=bgcolor;  
        dark.style.width= pageWidth;
        dark.style.height= pageHeight;
        dark.style.display='block';                          
    } else {
        dark.style.display='none';
    }
}


// start an ajax request
function ajaxRequest(url,func,obj) {
    //alert("test message 2");
	if (window.XMLHttpRequest) {var req = new XMLHttpRequest();}
	else if (window.ActiveXObject) {try {req = new ActiveXObject("Msxml2.XMLHTTP");}catch(e) {req = new ActiveXObject("Microsoft.XMLHTTP");}}
	if (func) {
		req.onreadystatechange = function() 
			{
				func(req,obj);
			}
	}
	req.open('GET',url,true);
	req.setRequestHeader('X-Requested-With','XMLHttpRequest');
	req.setRequestHeader('If-Modified-Since','Wed, 15 Nov 1995 00:00:00 GMT');
	req.send(null);
	return false;
}

function getContentsReq(req, obj) {
	if (req.readyState == 4) {
		obj.innerHTML = req.responseText;
		if (document.getElementById("user-name")) document.getElementById("user-name").focus();
	}
}

function getContentsViaAjax(url, obj) {
	ajaxRequest(url, getContentsReq, obj);
}

function freezeScreenPopup(revert, tpl_name) {

	fadeBackground( !revert );

	if ( !revert ) {
		var oDiv = document.createElement('div');
		oDiv.setAttribute('id','popup');
		oDiv.setAttribute('align','center');
		oBody = document.getElementById('wrap');
		oBody.appendChild( oDiv );
		
		// Create two child divs that will be placed within the main popup div. The top will include the window content and a bottom div to include the close window link
		var divContent = document.createElement('div');
		oDiv.appendChild( divContent );
		
		divContent.innerHTML = "<br><br><br><div id=\"cancel\" align=\"center\"><img src=\"pictures/loading.gif\"></div><br><br><br>";
		
		var divClosePopupLink = document.createElement('div');
		divClosePopupLink.setAttribute('align','center');
		oDiv.appendChild( divClosePopupLink );		
		divClosePopupLink.innerHTML = "<div id=\"cancel\" align=\"center\" style=\"margin-top:20px; font-size:7.5pt;\">- <a href=\"javascript:freezeScreenPopup(true)\" tabindex=\"-1\" class=\"screenshot_hover\">close window</a> -</div>";
		
		getContentsViaAjax('templates/popup/' + tpl_name + '.tpl', divContent);
		
	} else {
		oDiv = document.getElementById("popup")
		document.getElementById('wrap').removeChild(oDiv)
	}
}

function freezeScreenPicturePopup(revert, picture_name) {
	 
	fadeBackground(revert);
	
	if (!revert) {
		var oDiv = parent.document.createElement('div');
		oDiv.setAttribute('id','popupScreenCapture');
		oDiv.setAttribute('align','center');
		
		oPic = document.createElement('img');
		oPic.setAttribute('src', picture_name);

		//var doc_width = document.all ? Math.min(truebody().scrollLeft, truebody().clientWidth) : Math.min(parent.window.innerWidth);
		//var doc_height = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(parent.window.innerHeight);
		var doc_width = document.all ? truebody().clientWidth : parent.window.innerWidth; // parent.document.body.offsetWidth;
		var doc_height = document.all ? truebody().clientHeight : parent.window.innerHeight; // parent.document.body.offsetHeight;

		var left_pos = (doc_width - oPic.width - 40)/2;
		var top_pos = ((doc_height - oPic.height)/2) - 65 + f_scrollTop();

		var style = 'margin: 0 auto; position:absolute; width:' + oPic.width + 'px; top:' + top_pos + 'px; left:' + left_pos + 'px; padding:20px; margin-left:0px; text-align: center; z-index:100; background:#fff; border:solid 1px #000000;';

		//oDiv.setAttribute('style', style); // Doesn't work on IE!! therefore we use the following line instead
		oDiv.style.cssText = style;
		
		oBody = parent.document.getElementById('wrap');
		oBody.appendChild(oDiv);
		
		oDiv.innerHTML = '<table>' +
							 '<tr>' +
								'<td class="app_top_description">' +
									'<img src="' + picture_name + '" width="936">' +
									'<div id="cancel" align="center" style="margin-top:20px; font-size:7.5pt;">- <a href="javascript:freezeScreenPicturePopup(true)" tabindex="-1" class="screenshot_hover">close window</a> -</div>' +
								'</td>' +
							 '</tr>' +
					     '</table>';
	} else {
		oDiv = parent.document.getElementById("popupScreenCapture")
		parent.document.getElementById('wrap').removeChild(oDiv)
	}
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		parent.document.documentElement ? parent.document.documentElement.scrollTop : 0,
		parent.document.body ? parent.document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}



function truebody(){
	return (!window.opera && parent.document.compatMode && parent.document.compatMode!="BackCompat")? parent.document.documentElement : parent.document.body
}

-->