window.addEvent('domready', function() {

	// Main navigation submenu
/*

	var links = $$('li.heading');
	var contents = $$('ul.sub-menu-links');
	var contentsOn = $$('ul.sub-menu-links-on');
	var activeItemIndex = false;	
	for ( var i = 0; i < links.length; i++  )
			if (links[i].className == 'heading on')
				activeItemIndex = i;
				


	contents.set('slide',{
		duration:500,
		transition:Fx.Transitions.Back.easeOut
	});

	contentsOn.set('slide',{
		duration:500,
		transition:Fx.Transitions.Back.easeOut
	});

	contents.slide('hide');

	if ($('main-menu-holder'))
		$('main-menu-holder').style.display='block';

	if ($('sub-menu'))
		$('sub-menu').style.display='block';

	contentsOn.slide('show');
	contentsOn.set('tween', {duration: 500, transition: 'back:in'}).tween('opacity', 0, 1);
	contents.set('tween', {duration: 900, transition: 'back:in'}).tween('opacity', 0, 1);
 
 	links.addEvent('mouseout',function(e){

		e.stop();		
		var index = links.indexOf(this);

		if (activeItemIndex !== false && index != activeItemIndex)
			{
				links[activeItemIndex].className = "heading on";
			}
		
	});
	
	var selectedItem = false;
	
	links.addEvent('mouseover',function(e){
		
		e.stop();
		
		var index = links.indexOf(this);
		selectedItem = index;
		
		if (activeItemIndex !== false && index != activeItemIndex)
			{
				links[activeItemIndex].className = "heading off";
			}
			

		if(!contents.some(function(content,i){
		
			var slide = content.get('slide');
			if(slide.open && i != index){
				slide.slideOut().chain(function(){contents[index].slide('in')});
				return true;
			} else if(i != index) {
				slide.slideOut();
		}
		
		})){
			var slide = contents[index].get('slide');
			contents[index].slide((slide.open && index != activeItemIndex) ? 'out' : 'in');						
		}

	});

	
 	$$('div.sub-menu').addEvent('mouseover',function(e){
		if (selectedItem  !== false && selectedItem!=activeItemIndex )
		{
			links[selectedItem].className = "heading on";
			
			if (activeItemIndex !== false)
				links[activeItemIndex].className = "heading off";
		}
	});

 	$$('div.sub-menu').addEvent('mouseout',function(e){
		if (selectedItem !== false)
			links[selectedItem].className = "heading off";
		if (activeItemIndex !== false)
			links[activeItemIndex].className = "heading on";
					
	});

*/		
			
	if ($('accordion'))
	{
		//create our Accordion instance
		var myAccordion = new Accordion($('accordion'), $$('.toggler'), $$('.element'), {
			opacity: false,
			onActive: function(toggler, element){
				toggler.setStyle('color', '#41464D');
			},
			onBackground: function(toggler, element){
				toggler.setStyle('color', '#0099CC');
			}
		});
		
		if($('question-page'))
			myAccordion.display(3);
		
		if($('commission-page'))
		{
			myAccordion.display(-1);
		}
	}
	
	
	if($('question'))

	if($('help_box'))
	{
		if ($('help_box_toggle'))
			var helpSlide = new Fx.Slide('help_box').hide();
		
		if ($('help_box_toggle'))
		{
			$('help_box_toggle').addEvent('click', function(e){
				document.getElementById('help_box_holder').style.visibility = "visible";
				e.stop();
				helpSlide.toggle();
			});
		}
	}
	
});

function checkMouseOver(element)   {
   var el = $$(element);
   
   el.mouseIsOver = false;
   
   el.onmouseover = function()   {
      this.mouseIsOver = true;
   };
   
   el.onmouseout = function()   {
      this.mouseIsOver = false;
   }
   
   return el.mouseIsOver;
   
}



function writeResponseToDiv(strURL, node, showLoader) {
	if ( showLoader != 0 ) 
		showLoading(node);

	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('GET', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			writeToDiv(self.xmlHttpReq.responseText, node);
			document.getElementById(node).style.display='';
		}
	}
	self.xmlHttpReq.send(strURL);
}

function showLoading(node) {
	if(document.getElementById(node))
		document.getElementById(node).innerHTML = "<div class='loader'>Loading...</div>";
}

function writeToDiv(str, node){
	if(document.getElementById(node))
		document.getElementById(node).innerHTML = str;
}

var rowClicked1 = '';
var rowOpened1 = '';
var picClicked1 = '';
var picOpened1 = '';

var rowClicked2 = '';
var rowOpened2 = '';
var picClicked2 = '';
var picOpened2 = '';

function closeOpened( id ){
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'none';
	}
}

function openClosed(id){
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = '';
	}
}

function switchPicIcon(id, icon){
	if (document.getElementById(id)) 
	document.getElementById(id).src = icon;
}

function displayTrDetails(url, trid, divid, id, icon_close, icon_open, child){
		
		eval('rowClicked'+child + '= "' +  trid + '"');
		eval('picClicked'+child + '= "folder_' +  id + '"');
		
		var rowClicked = eval('rowClicked'+child);
		var rowOpened = eval('rowOpened'+child);
		var picClicked = eval('picClicked'+child);
		var picOpened = eval('picOpened'+child);
		 
		closeOpened(rowOpened); 
		switchPicIcon(picOpened, icon_close); 
		
		if ( rowClicked != rowOpened ) {
			openClosed(rowClicked); 
			eval('rowOpened'+child + '= "' +  rowClicked + '"');
			//rowOpened = rowClicked;
			switchPicIcon(picClicked, icon_open); 
			eval('picOpened'+child + '= "' +  picClicked + '"');
			//picOpened = picClicked;
			
		} else {
			closeOpened(rowClicked); 
			//rowOpened = '';	
			eval('rowOpened'+child + '= ""');
			switchPicIcon(picClicked, icon_close); 
			//picOpened = '';	
			eval('picOpened'+child + '= ""');
		}
		
		writeResponseToDiv(url,divid);
}

function hideNode(id) 
{
	document.getElementById(id).style.display = 'none';
}

function hideElement(ids)
{

	if (ids!=''){
		var id_array = ids.split(",");
		for ( var i = 0; i < id_array.length; i++  )
			document.getElementById(id_array[i]).style.display = 'none';
	}

}

function validateEmail(str) {
		var err = 0;
		var at="@"
		var dot="."	
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var errorMessage = "Please enter a valid e-mail address"; 
		
		var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.-_";
		var temp;
		for (var i=0; i< str.length; i++) {
			temp = "" + str.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") {
			err = 10;
			}
		}
		
		//check if blank spaces between periods and '-'s
		chunks = str.split(".");
		for(i=0;i < chunks.length; i++){
			if(chunks[i].length <1){
				err=20;
			}
		}
		
		chunks = str.split("-");
		if (chunks.length > 3){
			err=23;
		}
		for(i=0;i < chunks.length; i++){
			if(chunks[i].length <1){
				err=25;
			}
		}
	
		chunks = str.split("@");
		if (chunks.length != 2){
			//alert (errorMessage + " - must contain an'@'.");
			return false
		}
		
		periods = chunks[1].split("."); // if split after the '@' contains more than one period then error
		if (periods.length >3){
			err = 30;
		}
		
		periods = chunks[0].split("."); // if split before the '@' contains more than two periods then error
		if (periods.length>5){
			err = 40;
		}
		
		finalPeriod = str.lastIndexOf(".")
		if (finalPeriod >= (parseInt(str.length) - 2) || finalPeriod < (parseInt(str.length) - 10)){
			err = 50;
		}
		
		if (lstr < 7){
		    err = 60;
		}
		
		if (str.indexOf(at)==-1){
		   err = 70;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)>(lstr-5)){
		   err = 80;
		}

		
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0){
		   err = 90;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    err = 100;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   err = 110;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){ // cannot have a period immediately after the '@' symbol
		    err = 120;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    err = 130;
		 }
		
		if (err > 0){
			//alert(errorMessage);
		   //alert(errorMessage + err)
			return false
		}else{
 			return true
		}					
	}
