//Rollovers for submenus	
//*************************************************************************
	
function subNav(which){
	document.getElementById('dSub'+which).style.backgroundColor = '#999';
	document.getElementById('dSub'+which).style.color = '#fff';
	
	//get the left position of the menu based on it's parent
	var menuLeft = document.getElementById('dSub'+which).offsetLeft;
	
	//get the width of this element so that we can right align the submenu if left alignment will push the position over the 728px boundary
	var menuWidth = document.getElementById('dSub'+which).offsetWidth;
	
	//if the last menu will stretch beyond the end of the left column, we will force back a little
	var subWidth = 213; //the width in pixels of the menus
	//calculate the left position
	if(menuLeft + subWidth > 728){menuLeft = eval(menuLeft + menuWidth - subWidth);}
	
	
	//set the left position by applying that calculation
	document.getElementById('compSub'+which).style.left = menuLeft + 'px';
	
//ADDED FOR SYNDICATED CONTENT***********************************
	//get the offset top of the subNav div to calculate top position of the sub menus
	var actualTop = document.getElementById('leftCol').offsetTop;
	//alert(actualTop);
	var stdTop = 128; //CONSTANT - the base offset
	var diffTop = actualTop - stdTop;
	//now set the top position - base position is 379px
	var newSubTop = 379 + diffTop;
	document.getElementById('compSub'+which).style.top = newSubTop + 'px';
	
//END ADDED FOR SYNDICATED CONTENT*******************************
}
function subNavOut(which){
	document.getElementById('dSub'+which).style.backgroundColor = '#fff';
	document.getElementById('dSub'+which).style.color = '#888';

}

//**SUBMENU from SQUIDFINGERS*********************************************/

subMenu = {timer : null, current : null};
subMenu.getStyle = function(name){
	if(document.getElementById) return document.getElementById(name).style;
	else if(document.all) return document.all[name].style;
	else if(document.layers) return document.layers[name];
}
subMenu.show = function(name){
	if(this.timer) clearTimeout(this.timer);
	this.getStyle(name).display = "block";
	this.current = name;
}
subMenu.hide = function(){
	this.timer = setTimeout("subMenu.doHide()",50);
}
subMenu.doHide = function(){
	if(this.current){
		this.getStyle(this.current).display = "none";
		this.current = null;
	}
}


/********************************************************************
this function is used to create the rollover state of the global nav.
It needs to be initialised with each page
********************************************************************/
function globNav(){
 
var globList = new Array();
var g;
var i=0;
var lis = document.getElementsByTagName ("li");
for(i = 0; i < lis.length; i++){
g=lis[i];
if(g.className == "glob"){
//g.onmouseover = function(){this.style.color = '#50aed4'; this.style.cursor = 'pointer';}
//g.onmouseout = function(){this.style.color = '#999'; this.style.cursor = 'default';}
}
}
}


//***Jump Menu********************************************************/
function jumpMenu(which){
var page = document.getElementById(which).value;
if(page!="") window.location = page;
}
//********************************************************************/

//***Category Tabs********************************************************/

	function tabsNav(){
		var t;
		var tabs = document.getElementsByTagName('li');
		for(var i=0; i<tabs.length; i++){
		if(tabs[i].className == 'tabNav'){
		t = tabs[i];
		t.onmouseover = function(){this.className='tabNavOn';} 
		t.onmouseout = function(){this.className='tabNav';} 

		}
		}
		
}
//***EMAIL POP-UP************************************************************/

	function emailPop(title,contentURL){
		var title= 'title='+title;
		//alert(title);
		var content ='&contentURL='+contentURL;
	//	alert(content);
		var t = '/E01.php?'+title+content;   
		window.open( t, 'EMAIL', 'width=400, height=590, scrollbars=yes, toolbars=no, locationbar=no, personalbar=no');		
	}

//**SHOP MENU from SQUIDFINGERS*********************************************/

Menu = {timer : null, current : null};
Menu.getStyle = function(name){
	if(document.getElementById) return document.getElementById(name).style;
	else if(document.all) return document.all[name].style;
	else if(document.layers) return document.layers[name];
}
Menu.show = function(name){
	if(this.timer) clearTimeout(this.timer);
	this.getStyle(name).display = "block";
	this.current = name;
}
Menu.hide = function(){
	this.timer = setTimeout("Menu.doHide()",50);
}
Menu.doHide = function(){
	if(this.current){
		this.getStyle(this.current).display = "none";
		this.current = null;
	}
}



	
//**GLOBAL NAV SUBMENUS****************************************************************/



//detect for GECKO browsers
var browserName = window.navigator.product;
if(window.navigator.oscpu){var os = window.navigator.oscpu;}else{var os='pc';}
var moz;
var mac;

if(os.indexOf("Mac") == -1){mac = false;}else{mac = true;}
if(browserName == 'Gecko'){moz = true;}else{moz = false;}
//end detect




//displays the submenu for the active tab
function showMenu(which){

//ADDED FOR SYNDICATED CONTENT***********************************
	//get the offset top of the global nav to calculate top position of the menus
	var actualTop = document.getElementById('globalNav').offsetTop;
	//var stdTop = 69; //CONSTANT - the base offset
	var stdTop = 90; //Edited by Fanny Surjana
	var diffTop = actualTop - stdTop;
	//now set the top position - base position is 379px
	var newSubTop = 126 + diffTop;
	//var newSubTop = 105 + diffTop; // Edited by Fanny Surjana
	document.getElementById(globs[which]).style.top = newSubTop + 'px';
	
//END ADDED FOR SYNDICATED CONTENT*******************************

//build array of the Submenu IDs
//TR1**var globs = new Array('menu1', 'menu2', 'menu3', 'menu4', 'menu5', 'menu6', 'menu7', 'menu8');

//set the path to the global nav image directory
var basePath = '';

//build an array of global nav images, first OFF, then ON
//TR1**var globOff = new Array('nav_off_01.gif', 'nav_off_02.gif', 'nav_off_03.gif', 'nav_off_04.gif', 'nav_off_05.gif', 'nav_off_06.gif', 'nav_off_07.gif', 'nav_off_08.gif');
//TR1**var globOn = new Array('nav_on_01.gif', 'nav_on_02.gif', 'nav_on_03.gif', 'nav_on_04.gif', 'nav_on_05.gif', 'nav_on_06.gif', 'nav_on_07.gif', 'nav_on_08.gif');

//this builds a string for reference to the active tab (so that we can change the colour while the menu is being used
var actTab = 'globImg'+which;

//testing for non-gecko browser or macintosh OS
if(!moz || mac){

//make sure that no other submenus are still displaying and change he active tab colour
for(var i=0; i< globs.length; i++){
document.getElementById(globs[i]).style.display = 'none';

}

//now that we can be sure that all other submenus are hidden, display the correct one
document.getElementById(globs[which]).style.display = 'block';

}//end MOZ

//active tab properties
document.getElementById(actTab).style.color = '#50aed4';
document.getElementById(actTab).style.cursor = 'pointer';

//replaced for images 
document.getElementById(actTab).src = basePath+globOn[which];

}

function hideMenu(which){
//build array of the Submenu IDs
//var globs = new Array('menu1', 'menu2', 'menu3', 'menu4', 'menu5', 'menu6', 'menu7', 'menu8'); 

//set the path to the global nav image directory
var basePath = '';

//build an array of global nav images, first OFF, then ON
//TR1**var globOff = new Array('nav_off_01.gif', 'nav_off_02.gif', 'nav_off_03.gif', 'nav_off_04.gif', 'nav_off_05.gif', 'nav_off_06.gif', 'nav_off_07.gif', 'nav_off_08.gif');
//TR1**var globOn = new Array('nav_on_01.gif', 'nav_on_02.gif', 'nav_on_03.gif', 'nav_on_04.gif', 'nav_on_05.gif', 'nav_on_06.gif', 'nav_on_07.gif', 'nav_on_08.gif');

//this builds a string for reference to the active tab (so that we can change the colour while the menu is being used
var actTab = 'globImg'+which;

//testing for non-gecko browser or macintosh OS
if(!moz || mac){

//hide all menus
for(var i=0; i< globs.length; i++){
document.getElementById(globs[i]).style.display = 'none';

}//end MOZ

//active tab properties
document.getElementById(actTab).style.color = '#666';
document.getElementById(actTab).style.cursor = 'default';


}
//rules to switch to OFF state. If the tab is acting as a breadcrumb, dont switch it back
if(document.getElementById(actTab).className != 'activePage'){
document.getElementById(actTab).src = basePath+globOff[which];
}
}


//****************************************************************************//
//  POLL MODULE

function pollVote(){
	//array to put our failures in
	var ans = new Array();
	//look for any checked radio buttons
	for(var i = 0; i< document.pollModule.pollA.length; i++){
		//we found one, now show results
		//this will need to submit to DB 
		if(document.pollModule.pollA[i].checked){
			showPollResult();
		}else{
		//each that isnt checked is put into the ans array
		ans[i] = 'false';
		}
	}
	//check that array to see how many failures we got
	//if it is the same as the length of the buttons array, none passed
	if(ans.length >= document.pollModule.pollA.length){
	//show error message
	document.getElementById('pollError').style.display = 'block';
	}
	

}
//show results
function showPollResult(){
document.getElementById('pollError').style.display = 'none';
document.getElementById('pollAns').style.display = 'block';
document.getElementById('pollQuest').style.display = 'none';
}


//****************************************************************************//
//  EMAIL VALIDATION

function validateMail(formName){
	if(formName == 'sendToFriend'){
		
		var err = new Array('One or more errors have been identified in your form. See below for more information.', '', '', '', '', '');
		var i = 0;

		//email section
		if(document.sendToFriend.senderEmail.value != ''){ //there is something in there
			//regex for an email address
			var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
			var result = re.test(document.sendToFriend.senderEmail.value);
			if(!result){
				i++
				err[1] = "Please enter a valid email address";
			}
		}else{ //field is empty
			i++
			err[2] = "This field is required.";
		}
	
		//email section
		if(document.sendToFriend.friendEmail.value != ''){ //there is something in there
			//regex for an email address
			var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
			var result = re.test(document.sendToFriend.friendEmail.value);
			if(!result){
				i++
				err[3] = "Please enter a valid email address";
			}
		}else{ //field is empty
			if(document.sendToFriend.friendPool.value == ''){
			i++
			err[4] = "This field is required.";
			}
		}
		
		//email section
		if(document.sendToFriend.friendPool.value != ''){ //there is something in there
			nameList = new Array();
			nameList = document.sendToFriend.friendPool.value.split(';');
			var nlLen = nameList.length;
			for(var k = 0; k < nlLen; k++){
				//regex for an email address
				var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
				var result = re.test(nameList[k]);
				if(!result){
					if(nameList[k] != ''){ //the last position will be empty, because all entries add the separator at the end. we will not try to validate empty positions 
						i++
						err[5] = "Please enter a valid email address";
					}
				}
			}
		}
		
		//end of email
		//Check for any errors. 'i' iterates at each error instance, so if it is equal to zero, there were no errors
		if(i == 0){
		document.sendToFriend.submit();
		}else{
		//create error messages
		document.getElementById('err0').style.display = 'block';
		document.getElementById('error0').innerHTML = err[0];
		
		
			//loop through all error message array positions 
			for (j=1; j< 6; j++)
			{
				//clear out the previous messages
				document.getElementById('err' + j ).style.display = 'none';
				//see if this error is not empty
				if(err[j] != ''){
					//display the associated arror message block
					document.getElementById('err' + j).style.display = 'block';
					document.getElementById('error' + j).innerHTML = err[j];
					//since error 1&2 and 3&4 cannnot be displayed simultaneously, we get either hide the array position before or after the current one
					//using the modulos will tell us whether to subtract or add (eg. 4 has mod=0, 3 has mod = 1)
					a = j % 2;
					//if we are on an odd number, add 1 and hide that. 
					if(a == 1){d = j+a;}else{d = j-1;}
					document.getElementById('err' + d ).style.display = 'none';
				}
				
			}//end of for
		 
		}//end of ELSE

	}//end formName IF


}//end function

//****************************************************************************//
//  ADD A FRIEND

function addFriend(){
	if(document.sendToFriend.friendEmail.value != ''){
	//make sure that the textarea is shown
	document.getElementById('addFriend').style.display = 'block';
	
	//move the email address to the "pool"
	document.sendToFriend.friendPool.value += document.sendToFriend.friendEmail.value + ';';
	document.sendToFriend.friendEmail.value = '';
	}
}


//****************************************************************************//
// BLACK LINE HEIGHT
function blackLine(){
//	alert("hi");
	if(document.getElementById('leftCol') && document.getElementById('rightCol')){ //see if the leftCol is in this page
		//get the heights of the left and right Columns
		var leftHeight = document.getElementById('leftCol').offsetHeight; 
		var rightHeight = document.getElementById('rightCol').offsetHeight;
			if(leftHeight < rightHeight){//if the right Column is taller than the left...
				document.getElementById('leftCol').style.height = rightHeight+'px'; //make the left column the same height as the right Column
			}
	}
}


//****************************************************************************//
function goTab(url){
// alert("Hi");
 window.location =url;

}

//****************************************************************************//
//	CreateBookmarkLink
//	Will create bookmark for both firefox & IE
//	param:	none
//	return:	none
//****************************************************************************//
function CreateBookmarkLink() {
        title=document.title; 
        url=location.href;
        if (window.sidebar) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(title, url,"");
        } else if( window.external ) { // IE Favorite
            window.external.AddFavorite( url, title); }
        else if(window.opera && window.print) { // Opera Hotlist
            return true; 
		}
}