
function windowOpener(winURL,winName,winX,winY,Scroll) {
	winPos = (screen.width / 2) - (winX / 2);
	winTop = (screen.height / 2) - (winY / 2);
	if(winTop < 0) { 
		winTop = 0;
	}
	
	window.open(winURL,winName,"width=" + winX + ",height=" + winY + ",left=" + winPos + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + Scroll + ",resizable=0");
}

function validate(frm) {
	if(frm.search.value == '') {
		flashBG(frm.search.name,frm.search.style.backgroundColor,'#CCCCCC',6);
		return false;
	}
	else {
		return true;
	}
}

function setTextSize(size) {
	if(size != null) {
		document.body.style.fontSize = size + "%";
		setCookie('textSize',size,364)
	}
}

function flashBG(theName,theColor,theFlash,theTimes) {
	theField = document.getElementById(theName)
	theField.style.backgroundColor = theFlash;
	theTimes = theTimes - 1;
	if (theTimes > 0){
		setTimeout("flashBG('" + theName + "','" + theFlash + "','" + theColor + "'," + theTimes + ")",100);
	}
}

function setTabs(strURL) {
	var arrURL = strURL.split("/");
	var strFileName = arrURL[arrURL.length-1].split(".")[0];	
	try
	{
		document.getElementById(strFileName).className = "current"
	}
	catch(err)
	{
		//Do nothing!
	}	
}


function showTab(names) {
	// Shows namegiven tab(s) (e.g. "Basket")
	arrNames = names.split(',');
	var theTab = document.getElementById('tab' + arrNames[0])
	if(theTab != null) {
		var theTabs = theTab.parentNode.getElementsByTagName('li')
		for(i = 0;i < theTabs.length;i++) {
			if(theTabs[i].className != 'tabTitle') {
				theTabs[i].className = '';
			}
		}
				
		var thePanel = document.getElementById('pnl' + arrNames[0])
		var thePanels = theTab.parentNode.parentNode.parentNode.getElementsByTagName('div')
		for(i = 0;i < thePanels.length;i++) {
			if(thePanels[i].className.indexOf('panel') != -1) {
				thePanels[i].style.display = 'none';
			}
		}
		
		theTab.className = 'tabActive';
		theTab.getElementsByTagName('a')[0].blur();
		
		for(i = 0;i < arrNames.length;i++) {
			thePanel = document.getElementById('pnl' + arrNames[i])
			if(thePanel != null) {
				thePanel.style.display = 'block';
			}
		}
	}
	return false;
}


//function showTab(theTab,thePanel) {
//	try {
//		var theTabs = theTab.parentNode.parentNode.getElementsByTagName('td')
//		for(i = 0;i < theTabs.length;i++) {
//			if(theTabs[i].className != 'tabTitle') {
//				theTabs[i].className = '';
//			}
//		}
//		
//		var thePanels = theTab.parentNode.parentNode.parentNode.getElementsByTagName('tr')
//		for(i = 0;i < thePanels.length;i++) {
//			if(thePanels[i].className.indexOf('rowHeader') == -1) {
//				thePanels[i].style.display = 'none';
//			}
//			else {
//			var strDisplayAs = thePanels[i].style.display
//			}
//		}
//		
//		theTab.parentNode.className = 'tabActive';
//		thePanel.style.display = strDisplayAs;
//		return false;
//	} catch(err)
//	{
//		//Do nothing!
//	}		
//}

//used for setting buttons to single click mode 
function setSingleClick(theLink) {
	theLink.href = '#'
	theLink.parentNode.className = 'btnNo'
	return false;
}


function getElementsByClassName(strTagName, strClassName){
	// Needs no further introduction I think...
	var arrElements = (strTagName == "*" && document.all)? document.all : document.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];      
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}   
	}
	return (arrReturnElements)
}

/*
	Minor improvement, based on http://ejohn.org/blog/getelementsbyclassname-speed-comparison/
	-Allows getElementsByClass within an elenment (rather than defaulting to document scope)
	-Can pass in a callback function to avoid looping over elements twice
*/
function foreachElementsByClass(searchClass, tag, node, callback) {
	if ( node == null ) {
		node = document;
	}
	if ( tag == null ) {	
		tag = '*';
	}
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  var retEls = new Array();
	for (i = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			retEls.push(els[i]);
			if (callback != null) {
				callback(els[i]);
			}
    }
  }    
  return retEls;
}

function setOpacity(obj,opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	if (typeof(obj) == 'object' && obj.style) {
		if (obj.style.MozOpacity!=null) {  
			obj.style.MozOpacity = (opacity/100) - .001;
		} 
		else if (obj.style.opacity!=null) {
			obj.style.opacity = (opacity/100) - .001;
		} 
		else if (obj.style.filter!=null) {
			obj.style.filter = "alpha(opacity="+opacity+")";
		}
	}
}
	
function getOpacity(obj) {
	var opactiy = 100;
	if (typeof(obj) == 'object' && obj.style) {
		if (obj.style.MozOpacity!=null) {  
			opactiy = parseInt((obj.style.MozOpacity*100) + .001);
		} 
		else if (obj.style.opacity!=null) {
			opactiy = parseInt((obj.style.opacity*100) + .001);
		} 
		else if (obj.style.filter!=null) {
			opactiy = obj.filters.item("alpha").opacity;
		}
	}
	return opactiy;
}

function setCookie(name,value,days) {
	// Needs no further introduction I think...
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	// Needs no further introduction I think...
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function delCookie(name) {
	// Needs no further introduction I think...
	setCookie(name,"",-1);
}

function showToolTip(tooltip,location,left,top,pos, forceShow) {
	// Displays the specified tooltip at the specified object's location (adjusted with left & top)
	if((forceShow || getCookie(tooltip) != 0) && document.getElementById(location) && document.getElementById(tooltip)) {
		var objLocation = document.getElementById(location);
		var objTooltip = document.getElementById(tooltip);
		var arrPos = getPosition(objLocation);
		objTooltip.style.display = 'block';
		if(pos == 'R' || pos == 'BR' || pos == 'TR') {
			objTooltip.style.left = arrPos[0] + (objLocation.offsetWidth + left) + 'px';
		}
		if(pos == 'L' || pos == 'BL' || pos == 'TL') {
			objTooltip.style.left = arrPos[0] - (objTooltip.offsetWidth - left) + 'px';
		}
		if(pos == 'T' || pos == 'TR' || pos == 'TL') {
			objTooltip.style.top = arrPos[1] - (objTooltip.offsetHeight + top) + 'px';
		}
		if(pos == 'B' || pos == 'BR' || pos == 'BL') {
			objTooltip.style.top = arrPos[1] + (objLocation.offsetHeight + top) + 'px';
		}
		if(getScrollPos() > arrPos[1] - objTooltip.offsetHeight) {
			window.scrollTo(0,arrPos[1] - objTooltip.offsetHeight)
		}
	}
}

function closeTooltip(tooltip) {
	if(document.getElementById(tooltip)) {
		document.getElementById(tooltip).style.display = 'none';
		setCookie(tooltip,0);
	}
}

function addClassName(objElement, strClass, blnMayAlreadyExist) {
	// Adds a class to the class attribute of a DOM element
	if (objElement.className ) {
		var arrList = objElement.className.split(' ');
		if (blnMayAlreadyExist ) {
			var strClassUpper = strClass.toUpperCase();
			for (var i = 0; i < arrList.length; i++ ) {
				if (arrList[i].toUpperCase() == strClassUpper ) {
					arrList.splice(i, 1);
					i--;
				}
			}
		}
		arrList[arrList.length] = strClass;
		objElement.className = arrList.join(' ');
	}
	else {   
		objElement.className = strClass;
	}
}

function remClassName(objElement,strClass) {
	// Removes a class from the class attribute of a DOM element
	if (objElement.className ) {
		var arrList = objElement.className.split(' ');
		var strClassUpper = strClass.toUpperCase();
		for (var i = 0; i < arrList.length; i++ ) {
			if (arrList[i].toUpperCase() == strClassUpper ) {
				arrList.splice(i, 1);
				i--;
			}
		}
	objElement.className = arrList.join(' ');
	}
}
