/* CONFIGURATION AREA */
/*
	browsers:
		IE - Microsoft Internet Explorer
		FF - FireFox
		Safari - Safari browser
		Opera - Opera browser
		all - includes IE, FF, Opera and Safari
		
	parentId:
		any existing Id attribute 
	tagName:
		any valid tag name
	tagPosition:
		all - all inner elements 
		children - first level children only
	className:
		any valid class name
*/

var browsers = 'all';
var config = {
	hovers: new Array(
		{
			parentId:'menu',
			tagName:'li',
			tagPosition:'children',
			className:'hover'
		}
	)
};



/* CODE AREA */

/* hovers */

var initHovers = function()
{
	for (var index in config.hovers){
		var conf = config.hovers[index];
		var topLevelElement = document.getElementById(conf.parentId);
		if (topLevelElement){
			var subElements = topLevelElement.getElementsByTagName(conf.tagName);
			for (var i = 0; i < subElements.length; i++){
				if (conf.tagPosition == 'all' || (conf.tagPosition == 'children' && subElements[i].parentNode.id == conf.parentId))
				{
					subElements[i].configIndex = index;
					subElements[i].onmouseover = function(){
						this.className += ' ' + config.hovers[this.configIndex].className;
					};
					subElements[i].onmouseout = function(){
						this.className = this.className.replace(config.hovers[this.configIndex].className,'');
					};
				}
			}
		}
	}
}

/* common */

var currentState = {};

var opera = window.opera;
var safari = navigator.appVersion.indexOf("Safari") != -1;
var ie = document.all && !window.opera;
var ff = navigator.userAgent.indexOf("Firefox") != -1;

var addEvent = function(browsers,event,initMethod)
{
	if (opera && (browsers.match(/Opera/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (safari && (browsers.match(/Safari/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (ie && (browsers.match(/IE/) || browsers.match(/all/))) {
		window.attachEvent("on" + event, initMethod);
	} else if (ff && (browsers.match(/FF/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (!ie && !ff && !safari && !opera) {
		if (window.addEventListener){
			window.addEventListener(event, initMethod, false);
		}
		else if (window.attachEvent){
			window.attachEvent("on" + event, initMethod);
		}
	} 
}

function goToPage(id)
{						
	document.getElementById("htxtPage").value=id;
	if(document.getElementById("htxtPage").value!="" )
		{	
			if(fnisInteger(document.getElementById("htxtPage").value)==true)				
			{
				try
				{	
				__doPostBack("lnkPages","");
				}
				catch(Exception)
				{}
			}
		}
}

function fnisInteger(s)
{
	var i;
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}


var i;
var banner = "visual$"
var previousbanner;
function Timer()
{
	if (previousbanner)
		previousbanner.style.display = 'none';
	
	var objbanner;
	i = Math.floor(Math.random()*7);
	if (i == 0)
		i = 1;
	objbanner = document.getElementById(banner.replace("$",i));
	$(objbanner).fadeIn(2000);
	previousbanner = objbanner;
	window.setTimeout("Timer()",20000)
}

function OpenEmailWindow(companyID, pageTitle, referer)
{
	var encodedResource = encodeURIComponent(referer)
	window.open('EmailForm.aspx?CompanyID='+companyID+'&PageTitle='+pageTitle+'&referer='+encodedResource,'','width=420,resizable=1,height=320,top=10,left=10,scrollbars=no');
}	

function openWindow(url, windowName, featureString) 
{
	if (featureString == "")
	{
		featureString = "width=780,height=580,status=yes,scrollbars=yes,minimize=yes,top=10,left=10,resizable=1,toolbar=1,location=1,menubar=1";
	}

	winname = open (url, windowName, featureString);
	if (!winname) {
		alert("The window could not be opened. Please check if you have a popup blocker installed that may be preventing the window from opening. Try holding down the Ctrl key on your keyboard while clicking on the link.");
	}else 
	{
		winname.focus();
	}				
}

function submitPage(e, textbox)
{
	var key_enter= 13; // 13 = Enter
	var evt = (window.event==null) ? e : window.event;
	var code = evt.which ? evt.which : evt.keyCode
	
	if (key_enter==code)
	{
		location.href = 'SiteSearch.aspx?txtSearch=' + textbox.value;
		return false;		
	}
}
	


addEvent(browsers,'load',initHovers);