document.observe('dom:loaded',function(){
	if ($('panelContainer') != undefined) {
		var panelWidth = $('panelContainer').childElements().size() * parseInt($('content').getStyle('width'),10);
		$('panelContainer').setStyle({  
			width: panelWidth+'px'
		});
	}
	if ($$('.scrollPanel') != undefined) {
		$$('.scrollPanel a').invoke('observe','click',function(e) {
			$$('.scrollPanel li').invoke('removeClassName', 'current');
			this.up().addClassName('current');
			var pNum = this.up().previousSiblings().size();
			scrollPanel(pNum);
		});
	}
	if ($$('.more-link') != undefined) {
		$$('.more-link').invoke('observe','click',function(e) {
			Event.stop(e);
			this.up().next().show();
			if (this.up().next(1) != undefined) {
				this.up().next(1).show();
			}
			this.remove();
		});
	}
	if ($$('.popup') != undefined) {
		$$('.popup').invoke('observe','click',function(e) {
			Event.stop(e);
			var url = this.getAttribute('href');
			var w = "";
			var h = "";

			if (url == "compliancereports.shtml" || url == "analytics.shtml") {
				w = 500;
				h = 600;
			} else if (url == "detailreports.shtml") {
				w = 450;
				h = 500;
			} else if (url == "summaryreports.shtml") {
				w = 500;
				h = 500;
			} else if (url == "baselines.shtml") {
				w = 550;
				h = 580;
			} else if (url == "finaltests.shtml") {
				w = 550;
				h = 560;
			} else if (url == "checkpoints.shtml") {
				w = 500;
				h = 370;
			} else if (url == "frenchscreens.shtml") {
				w = 500;
				h = 350;
			} else if (url == "learningstyles.shtml") {
				w = 650;
				h = 450;
			} else if (url == "courselist.shtml") {
				w = 650;
				h = 575;
			}
			openPopup(url,w,h);
		});
	}
	if ($$('.newstemplate a') != undefined) {
		$$('.newstemplate a').invoke('observe','click',function(e) {
			Event.stop(e);
			window.location.href = "template.shtml?news="+this.getAttribute('href');
		});
	}
	if ($$('.faq_q') != undefined && $$('.faq_a') != undefined) {
		$$('.faq_a').invoke('hide');
		$$('.faq_q').invoke('observe','click',function() {
			//Effect.toggle(this.next(), 'blind', { duration: 0.5 });
			this.next().toggle();
		});
	}
	if (getIEVersion() == 6) {
		$$('img').each(function(i, index) {
			var tempimg = new Image();
			tempimg.setAttribute('src',i.getAttribute('src'));
			i.setStyle({'width': tempimg.width+'px', 'height': tempimg.height+'px'});		 
		});
		$('headerLogin').remove();
	}
});

function focusInput(inputel,inputval) {
	if(inputel.value == inputval) {
		inputel.value = '';
	}
}

function blurInput(inputel,inputval) {
	if(inputel.value == '') {
		inputel.value = inputval;
	}
}

function focusPass(inputel,inputval) {
	if(inputel.value == inputval) {
		var ie = getIEVersion();
		if (ie > -1 && ie < 9) {
			var newInput = document.createElement('input');
			newInput.setAttribute('type','password');    
			newInput.setAttribute('name',inputel.getAttribute('name'));
			newInput.setAttribute('id',inputel.getAttribute('id'));  
			new Insertion.After(inputel, newInput);
			inputel.remove();
			setTimeout(function() { newInput.focus(); }, 10);
		} else {
			inputel.setAttribute('type','password');
			inputel.value = "";
		        inputel.focus();
		}
	}
}

function blurPass(inputel,inputval) {
	if(inputel.value == '') {
		var ie = getIEVersion();
		if (ie > -1 && ie < 9) {
			var newInput = document.createElement('input');
			newInput.setAttribute('type','text');    
			newInput.setAttribute('name',inputel.getAttribute('name'));
			newInput.setAttribute('id',inputel.getAttribute('id')); 
			newInput.value = inputval;
			new Insertion.After(inputel, newInput);
			inputel.remove();
		} else {
			inputel.setAttribute('type','text');
			inputel.value = inputval;
		}
	}
}

function bannerAnimation(count){
	for(i = 1; i <= count; i++){ 
		if (i == 1) {
			new Effect.Appear('img'+i,{afterFinish:function(e){updateImg(e.element.getAttribute('id'));}});
		} else {
			var delayval = 0.5 * (i-1);
			new Effect.Appear('img'+i,{delay:delayval,afterFinish:function(e){updateImg(e.element.getAttribute('id'));}});
		}
	}			
}

function updateImg(img){
	var blockerId = 'blocker' + img.substr(3);	
	if ($(blockerId)){	
		$(blockerId).fade();
	}
}
	
function scrollPanel(pNum){
	var pos = 0;
	var panelWidth = parseInt($('content').getStyle('width'),10);
	if (pNum){
		pos = (pNum) * panelWidth; 
	}
	new Effect.Move('panelContainer', {	
		duration: 0.5, 
		x: -pos,
		y: 0,
		mode: 'absolute', 
		transition: Effect.Transitions.sinoidal
	});
}

function openPopup(url,w,h){
	if (!w || !h) {
		hs.htmlExpand(null, { 
			objectType: 'iframe', 
			src:url, 
			align:'center' 
		});
	} else {
		hs.htmlExpand(null, { 
			objectType: 'iframe', 
			width:w, 
			height:h, 
			src:url, 
			align:'center' 
		});
	}
} 

function validateRequired(form) {
	var bValid = true;
	var focusField = null;
	var i = 0;
	var fields = new Array();
	oRequired = new required();
	for (x in oRequired) {
		if ((form[oRequired[x][0]].type == 'text' || form[oRequired[x][0]].type == 'textarea' || form[oRequired[x][0]].type == 'select-one' || form[oRequired[x][0]].type == 'radio' || form[oRequired[x][0]].type == 'password') && form[oRequired[x][0]].value == '') {
			if (i == 0)
				focusField = form[oRequired[x][0]];
			fields[i++] = oRequired[x][1];
			bValid = false;
		}
	}
	if (fields.length > 0) {
		focusField.focus();
		alert(fields.join('\n'));
	}
	return bValid;
} 

function setCookie(name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var prefix = name + "="
	var start = document.cookie.indexOf(prefix)
	if (start==-1) {
		return null;
	}
	var end = document.cookie.indexOf(";", start+prefix.length)
	if (end==-1) {
		end=document.cookie.length;
	}
	var value=document.cookie.substring(start+prefix.length, end)
	return unescape(value);
}

function getIEVersion() {    
	var rv = -1; 
	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;
}
