/* from: http://labnol.blogspot.com/2006/01/add-to-favorites-ie-bookmark-firefox.html */
function CreateBookmarkLink(title, url) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
		return true; 
	} 
	else if ( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
		return true; 
	}
	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}

function showBox(sId) {
	document.getElementById(sId).style.display = 'block';
	var currentId = sId.replace(/sub/,'');
	document.getElementById('parent' + currentId).className += ' open';
}


function hideBox(sId) {
	document.getElementById(sId).style.display = 'none';
	var currentId = sId.replace(/sub/,'');
	var currentClass = document.getElementById('parent' + currentId).className;
	currentClass = currentClass.replace(/\s?open/,'');
	document.getElementById('parent' + currentId).className = currentClass;
}

function toggleSubMenu(sId,sLocation) {
	if (!document.getElementById(sId)) {
		location.href = sLocation;
		return;
	}
	else {
		if (document.getElementById(sId).style.display != 'block') {
			showBox(sId);
		}
		else {
			hideBox(sId);
		}
	}
}


function show(sId, display) {
	if (typeof(display) == 'undefined') {
		display = 'block'
	}
	document.getElementById(sId).style.display = display;
};

function hide(sId) {
	document.getElementById(sId).style.display = 'none';
};

function toggleDisplay(sId) {
	if (document.getElementById(sId).style.display != 'block') {
		document.getElementById(sId).style.display = 'block';
	}
	else {
		document.getElementById(sId).style.display = 'none';
	}
};


function slideOpen (sId, finalHeight) {
	var slidingElement = document.getElementById(sId);
	slidingElement.style.height = '1px';
	var actualHeight = 2;
	show (sId);
	var slideInt = setInterval(function () {
		while (actualHeight < finalHeight ) {
			slidingElement.style.height = actualHeight + 'px';
			actualHeight++;
		}
		clearInterval(slideInt);
	}, 500);
};

function slideClose (sId) {
	var slidingElement = document.getElementById(sId);
	var actualHeight = slidingElement.offsetHeight;
	var slideCloseInt = setInterval(function () {
		while (actualHeight >= 1 ) {
			slidingElement.style.height = actualHeight + 'px';
			actualHeight--;
		}
		hide (sId);
		clearInterval(slideCloseInt);
	}, 500);
};



function getInternetExplorerVersion() {
	/* Returns the version of Windows Internet Explorer or a -1
	(indicating the use of another browser).*/
	   var rv = -1; /* Return value assumes failure. (ml> A healthy assumption when dealing with MS) */
	   if (navigator.appName == 'Microsoft Internet Explorer')
	   {
	      var ua = navigator.userAgent;
	      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	      if (re.exec(ua) != null)
	         rv = parseFloat( RegExp.$1 );
	   }
	   return rv;
	}


function detectIe6 () {
	var agentVersion = getInternetExplorerVersion();
	if (agentVersion > -1) {
		isIE = true;
	}
	if (8.0 == agentVersion) {
		isIE8 = true;
	}
	if (7.0 == agentVersion) {
		isIE7 = true;
	}
	if (6.0 == agentVersion) {
		isIE6 = true;
		if(document.getElementById('ie6Detector')) {
			try {
				document.getElementById('ie6Detector').innerHTML = '<p><input type="button" id="closeIe6Detector" class="close" width="16px" height="16px" title="close" /><a href="http://www.microsoft.com/windows/internet-explorer/default.aspx" target="_blank">Internet Explorer is missing updates required to view this site. Click here to update... </a></p>';
				slideOpen('ie6Detector', 15);
			}
			catch (e) {
				alert(e);
			}
			document.getElementById('ie6Detector').onmouseover = function () {
				document.getElementById('closeIe6Detector').style.backgroundColor = '#3399ff';
				document.getElementById('ie6Detector').style.backgroundColor = '#3399ff';
				document.getElementById('ie6Detector').style.color = '#ffffff';
			}
			document.getElementById('ie6Detector').onmouseout = function () {
				document.getElementById('closeIe6Detector').style.backgroundColor = '#FFFFE1';
				document.getElementById('ie6Detector').style.backgroundColor = '#FFFFE1';
				document.getElementById('ie6Detector').style.color = '#000000';
			}
			document.getElementById('closeIe6Detector').onclick = function() {
				slideClose('ie6Detector');
			}
		}
		var images = document.getElementsByTagName('img');
		for (var i=0;i < images.length;i++) {
			images[i].src = images[i].src.replace(/png/i,'gif');
		}
	}
};