var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

function getBrowserInfo() {
	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser 	= "Safari"
	else if (checkIt('omniweb')) browser 	= "OmniWeb"
	else if (checkIt('opera')) browser 		= "Opera"
	else if (checkIt('webtv')) browser 		= "WebTV";
	else if (checkIt('icab')) browser 		= "iCab"
	else if (checkIt('msie')) browser 		= "Internet Explorer"
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS) {
		if (checkIt('linux')) OS 		= "Linux";
		else if (checkIt('x11')) OS 	= "Unix";
		else if (checkIt('mac')) OS 	= "Mac"
		else if (checkIt('win')) OS 	= "Windows"
		else OS = "an unknown operating system";
	}
}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


function toggleSelectBoxes(status) {
	if (window.top.browser == 'Internet Explorer') {
		selects = top.document.getElementsByTagName('select');
		for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = status;
		}
	}
}
/* shd be moved to javascript.js */
if(window.top.document.getElementById('pop_iframe'))
	window.close = close_popup;

function close_popup()
{
	if(this.window.name=='pop_iframe')
		logged_in_val = is_logged_in;
	else
		logged_in_val = pop_iframe.is_logged_in;
	
	if(window.top.is_logged_in != logged_in_val) {
		window.top.location = window.top.location;
	}
	else {
		if(window.top.document.getElementById('pop_iframe')) {
			//show_selectBoxes('show');
			toggleSelectBoxes('');
			window.top.document.getElementById('myoverlay').style.display='none';
			window.top.document.getElementById('popLbContent').style.display='none';
			window.top.document.getElementById('pop_iframe').style.display='none';
			//return true;
		}
		else {
			//window.releaseCapture();//window.releaseEvents("window.close");
			window.close();
		}
	}
	document.onkeydown = '';
}

var xScroll;
var yScroll;
var rScroll;

function PageSize()
{
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
		rScroll = yScroll;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
		rScroll = yScroll+20;
	}
}

function open_popup(filename, h, w, extra) 
{
	//if(!w) w = 494; if(!h) h = 435; else h = h-50;
	w =494;
	h = 350;
	PageSize();
	getBrowserInfo();
	toggleSelectBoxes('hidden');
	
	popIframe = document.getElementById('pop_iframe');
	popIframe.src=filename;
	popIframe.style.width = w+'px';
	popIframe.style.height = h+'px';
	popIframe.style.display = 'block';
	
	if(extra)
		popIframe.style.scrollbars='yes';
	//	extra = ",resizable=no,scrollbars=no,status=yes";

	overlayDiv = document.getElementById('myoverlay');
	overlayDiv.style.width = xScroll+'px';
	overlayDiv.style.height = yScroll+'px';
	overlayDiv.style.display = 'block';
	
	document.getElementById('popLbContent').style.display="block";
	
	tempY = document.documentElement.scrollTop;
	tempY=tempY + 150;
	document.getElementById('popLbContent').style.top= tempY+'px';
  
	overlayDiv.style.display="block";
	
	document.onkeydown = function(event)
	{
		e = event || window.event;
		key = String.fromCharCode(e.keyCode).toLowerCase();
		if(key == "w" && e.ctrlKey) {
			//window.close();
			close_popup();
			return false;
		}
		else
			return true;
	}
}

var iframeHt;
var iframeHtcurr;

function ad_height()
{
	popIframe = top.document.getElementById('pop_iframe'); 
	if(popIframe)
	{
		if(!iframeHt)
		{
			//if(docRoot) if(!window.opener)
				changecss('.tableclass','visibility','hidden');
				// shortcut dont change the possition of the .tableclass in popup.css
			iframeHt = parseInt(popIframe.style.height); //iframe height
			iframeHtcurr = iframeHt;
		}
		
		inc = rScroll - iframeHtcurr
		if(Math.abs(inc) >  20)
		{
			if(inc>20)
				iframeHtcurr = iframeHtcurr+20;
			else
				iframeHtcurr = iframeHtcurr-20;
			popIframe.style.height = iframeHtcurr+'px';
			setTimeout("ad_height()",50);
		}
		else if(iframeHtcurr)
		{
			popIframe.style.height = iframeHtcurr+inc+'px';
			changecss('.tableclass','visibility','visible');
			// focus on the first elelment of the popup form
			if(document.forms[0]) {
				e = document.forms[0].elements;
				for(i=0; i < e.length; i++) {
					if(e[i].type != 'hidden') {
						e[i].focus();
						break;
					}
				}
			}
		}
	}
}

// this function can be used to change any property of the any class defined in either style or page
function changecss(theClass,element,value) {
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	S=0;
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    document.styleSheets[S][cssRules][R].style[element] = value;
	   }
	  }
}
