//Hover function ie

var siteBaseUrl = '/';
var onloadEvents = new Array();

//Hover function ie
sfHover = function() {
	//Trigger only for IE
	if (document.all && !window.opera){		
		
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		if (sfEls){
			for (var i=0; i<sfEls.length; i++) {
				
				sfEls[i].style.filter = 'alpha(opacity=80)';
				
				sfEls[i].onmouseover=function() {
					this.className += " sfhover";
				}
				sfEls[i].onmouseout=function() {
					this.className = this.className.replace(new RegExp(" sfhover\\b"), "");					
				}
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function addToOnload(event){
	onloadEvents.push(event);
	window.onload = function() { 
		for (var x = 0; x < onloadEvents.length; x ++) {
			eval(onloadEvents[x]);
		}
	}
}


function setBaseUrl(baseUrl){
	siteBaseUrl = baseUrl;
}

//Generic select option url jump
function jumpTo(s){
    var url = s.value;
	if (url !='') loadUrl(url);    
}

function loadUrl(url){ window.location.href = url;}

function disableField(element){ document.getElementById(element).style.display = 'none';}


function closePopup() {
	e = document.getElementById('imgPopup');
	if (e){
		e.parentNode.removeChild(e);
	} 
}

function popupKeyListener() {document.onkeypress = processKeyPress; }

function processKeyPress(e){
	var e = window.event  || e;
	try {
		var key = e.keyCode || e.which;
	} catch (e){
		var key = 0;
	}
	//Esc or x (lowercase)
	if (key == 27 || key == 120) closePopup();
}

function attachOnClickImage(id, imgPath , altText, imgWidth, imgHeight){
	element = document.getElementById(id);
	element.style.cursor = 'pointer';
	var imageText = altText || '';		
	var imgWidth = Number(imgWidth);
	var imgHeight = Number(imgHeight);		
	element.removeAttribute("href");
	element.onclick = function (){
		//check if this element exists.
		e = document.getElementById('imgPopup');
		if (!e){
			popupKeyListener();
			var myDiv = document.createElement("DIV");
			myDiv.id = "imgPopup";
			myIframe = document.createElement('iframe');
			myIframe.src = siteBaseUrl+'blank.php?image='+encodeURIComponent(imgPath)+'&altText='+encodeURIComponent(imageText);			
			myIframe.scrolling = 'no';
			myIframe.width = imgWidth;
			myIframe.height = imgHeight+45;					
			myIframe.frameBorder = "0";
			//Append
			myDiv.appendChild(myIframe);
			myDimensions = getWindowDimensions();
			myWidth = myDimensions[0];
			myDiv.style.width = imgWidth;
			myDiv.style.left = (myWidth / 2) - (imgWidth / 2) + "px";
			document.body.appendChild(myDiv);
		}
		return false;
	}
}
function getWindowDimensions(){
	
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth, myHeight];
}

