/* IE FIX FOR BUG IN CACHING BACKGROUND IMAGES */
/*@cc_on
   /*@if (@_win32)
     {document.execCommand("BackgroundImageCache",false,true);}
   /*@end 
@*/

function stripHTML(oldString){
	newString = oldString.replace(/<\S[^><]*>/g, "");
  return newString;
}

function trim(val){
	return val.replace(/^\s*/, "").replace(/\s*$/, "");
}

function confirmAction(msg,action) {
   if (confirm(msg)){       
		document.location = action;
   }
}

function displayWindow(name,url, width, height) {
  var top = screen.height/2 - height/2;
  var left = screen.width/2 - width/2;
  var Win = window.open(url, name, 'top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', resizable=1, scrollbars=1, menubar=0, status=0' );
}

function displayWindowNoScroll(name,url, width, height) {
  var top = screen.height/2 - height/2;
  var left = screen.width/2 - width/2;
  var Win = window.open(url, name, 'top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', resizable=1, scrollbars=0, menubar=0, status=0' );
}
function isUndefined( f ) {
	return (typeof(f)=='undefined');
}

function checkAll( field, check ) {
var i;
	if (isUndefined(field))
		return;
	if (isUndefined(field.length)) {
		field.checked = check;
	} else {
		for(i=0; i<field.length; i++)
			field[i].checked = check;
	}
}

function isChecked( field ) {
var i;
	if (isUndefined(field.length)) {
		return field.checked;
	} else {
		for(i=0; i<field.length; i++) {
			if (field[i].checked)
				return true;
		}
		return false;
	}
}

function isSelected( f, i ) {
	if (isUndefined(i))
		i = 0;
	try {
		return f.options[i].selected;
	} catch(e) {
	}
	return false;
}

//---------------------------------------------------------------------------
/**
 * Functions to cookie management
 */
function createCookie(name,value,days) {
	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 readCookie(name) {
	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 eraseCookie(name) {
	createCookie(name,"",-1);
}

//---------------------------------------------------------------------------
/**
 * Functions to manage option panels Open/Close/SetPanelStatus/GetPanelStatus
 */
function showPanel(panel_id,panel_img,panel_status,lbl_open,lbl_close,img_scr_down,img_src_up){
  element = document.getElementById(panel_id);
  if(panel_status==0){
		new Effect.BlindUp(element, { duration: 0.4 });
		document.getElementById(panel_img).src=img_scr_down;
		document.getElementById(panel_img).alt=lbl_open;
		document.getElementById(panel_img).title=lbl_open;
		if(document.getElementById(panel_id+'_close')){
			document.getElementById(panel_id+'_close').style.display = 'none';
		}
		if(document.getElementById(panel_id+'_open')){
			document.getElementById(panel_id+'_open').style.display = 'inline';
	 	}
		if(document.getElementById(panel_id+'_top_close')){
			document.getElementById(panel_id+'_top_close').style.display = 'none';
		}
		if(document.getElementById(panel_id+'_top_open')){
			document.getElementById(panel_id+'_top_open').style.display = 'inline';
	 	}
		panel_status = 1;
		setPanelStatus(panel_id,'close');
	} else {
		new Effect.BlindDown(element, { duration: 0.4 });
		document.getElementById(panel_img).src=img_src_up;
		document.getElementById(panel_img).alt=lbl_close;
		document.getElementById(panel_img).title=lbl_close;
		if(document.getElementById(panel_id+'_close')){
			document.getElementById(panel_id+'_close').style.display = 'inline';
		}
		if(document.getElementById(panel_id+'_open')){
			document.getElementById(panel_id+'_open').style.display = 'none';
	 	}
		if(document.getElementById(panel_id+'_top_close')){
			document.getElementById(panel_id+'_top_close').style.display = 'inline';
		}
		if(document.getElementById(panel_id+'_top_open')){
			document.getElementById(panel_id+'_top_open').style.display = 'none';
	 	}
		panel_status = 0;
		setPanelStatus(panel_id,'open');
	}
	return panel_status;
}

function initPanel(panel_id,panel_img,panel_status,lbl_open,lbl_close,img_scr_down,img_src_up,remember_state){
	if(remember_state==1){
		if(readCookie(panel_id+'_st')=='open'){
			document.getElementById(panel_id).style.display = 'inline';
			document.getElementById(panel_img).src=img_src_up;
			document.getElementById(panel_img).alt=lbl_close;
			document.getElementById(panel_img).title=lbl_close;
			if(document.getElementById(panel_id+'_close')){
				document.getElementById(panel_id+'_close').style.display = 'inline';
			}
			if(document.getElementById(panel_id+'_top_close')){
				document.getElementById(panel_id+'_top_close').style.display = 'inline';
			}
			return 0;
		} else {
			document.getElementById(panel_id).style.display = 'none';
			document.getElementById(panel_img).src=img_scr_down;
			document.getElementById(panel_img).alt=lbl_open;
			document.getElementById(panel_img).title=lbl_open;
			if(document.getElementById(panel_id+'_open')){
				document.getElementById(panel_id+'_open').style.display = 'inline';
			}
			if(document.getElementById(panel_id+'_top_open')){
				document.getElementById(panel_id+'_top_open').style.display = 'inline';
			}
			return 1;
		}
	} else {
		if(document.getElementById(panel_id)!=null)
			document.getElementById(panel_id).style.display = 'none';
		if(document.getElementById(panel_img)!=null)
		{
	    	document.getElementById(panel_img).src=img_scr_down;
			document.getElementById(panel_img).alt=lbl_open;
			document.getElementById(panel_img).title=lbl_open;
		}
		if(document.getElementById(panel_id+'_open')){
			document.getElementById(panel_id+'_open').style.display = 'inline';
	 	}
		if(document.getElementById(panel_id+'_top_open')){
			document.getElementById(panel_id+'_top_open').style.display = 'inline';
	 	}
		return 1;
	}
}

function setPanelStatus(panel_id,panel_status){
	createCookie(panel_id+'_st',panel_status,31);
}

var switch_panel_mode = 0;
function switchPanel(panel_id_1,panel_id_2,panel_id_3){
	p1 = document.getElementById(panel_id_1);
	a1 = document.getElementById(panel_id_2);
	d1 = document.getElementById(panel_id_3);

	if(switch_panel_mode==0){
		new Effect.DropOut(p1, { duration: 0.5 });
		switch_panel_mode = 1;
		a1.innerHTML = '&raquo;';
		d1.style.display = 'inline';
	} else {
		new Effect.Appear(p1, { duration: 0.5 });
		switch_panel_mode = 0;
		a1.innerHTML = '&laquo;';
		d1.style.display = 'none';
	}
}

//---------------------------------------------------------------------------
/**
 * Functions to manage one active tab panels
 */

var menu_home_active_tab;
var src_img_up = '/images/home/arrow_up.gif'
var src_img_down = '/images/home/arrow_down.gif'

function menuPanel_init(menu_home_name){
	menu_home_active_tab = readCookie(menu_home_name);
	if(isNaN(parseInt(menu_home_active_tab))){
		menu_home_active_tab = '1';
	}
	if($(menu_home_name+'_'+menu_home_active_tab)==null){
		for(i=0;i<=3;i++){
			if($(menu_home_name+'_'+i)!=null){
				menu_home_active_tab = i;
				break;
			}
		}
	}
	if($(menu_home_name+'_'+menu_home_active_tab)==null){
		menu_home_active_tab = '-1';
	}
	// Show active panel
	if($(menu_home_name+'_'+menu_home_active_tab)!=null){
		$(menu_home_name+'_'+menu_home_active_tab).style.display = 'block';
		$(menu_home_name+'_img_'+menu_home_active_tab).src = src_img_up;
	}
}

function menuPanel_switch(menu_home_name,id){
	if(parseInt(menu_home_active_tab)!=parseInt(id)){
		if(!isNaN(parseInt(menu_home_active_tab))){
			// Hide old active panel
			if($(menu_home_name+'_img_'+menu_home_active_tab)){
				$(menu_home_name+'_img_'+menu_home_active_tab).src = src_img_down;
				new Effect.SlideUp($(menu_home_name+'_'+menu_home_active_tab), { queue: { position: 'front', scope: 'leftmenuscope',limit: 2 }, duration: 0.5 });
			}
		}
		// Show new active panel
		menu_home_active_tab = id;
		createCookie(menu_home_name,menu_home_active_tab,31);
		$(menu_home_name+'_img_'+menu_home_active_tab).src = src_img_up;
		new Effect.SlideDown($(menu_home_name+'_'+menu_home_active_tab), { queue: { position: 'end', scope: 'leftmenuscope',limit: 2 }, duration: 0.5 });
	} else {
		// Hide old active panel
		$(menu_home_name+'_img_'+menu_home_active_tab).src = src_img_down;
		new Effect.SlideUp($(menu_home_name+'_'+menu_home_active_tab), { queue: { position: 'front', scope: 'leftmenuscope',limit: 1 }, duration: 0.5 });
		menu_home_active_tab = undefined;
		createCookie(menu_home_name,menu_home_active_tab,31);
	}
}

//---------------------------------------------------------------------------
/**
 * Form functions
 */

function set_all_checkboxes(FormName, FieldName, CheckValue){
	if(!document.forms[FormName])	return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes) return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes){
		objCheckBoxes.checked = CheckValue;
	} else {
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++){
			objCheckBoxes[i].checked = CheckValue;
		}
	}
}

function submit_rate_form(Rate,CanRate,RateMsg){
	if(CanRate==''){
		alert(RateMsg);
		return;
	}
	if(!document.forms['rate_form']) return;
	document.forms['rate_form'].rate.value = Rate;
	document.forms['rate_form'].submit();
}

function isEmail(value) {
	var apos = value.indexOf('@');
	var dpos = value.lastIndexOf('.');
	
	if (value.indexOf(' ') >= 0 || apos < 1 || dpos - apos < 2) {
		return false;
	}
	return true;
}

//---------------------------------------------------------------------------
/**
 * SCORM
 */
function exportScorm() {
	document.getElementById('export_form').submit();
}

//---------------------------------------------------------------------------
/**
 * OFFLINE
 */
function downloadOffline() {
	document.getElementById('offline_form').submit();
}

//---------------------------------------------------------------------------

// top menu
function myyteach (event,id1,id2) {	
	//var el = Event.element(event);	
	var el = $(id2).parentNode;
	if (event.type == 'mouseover') {		
		$(id1).setStyle({display:'block'});		
		$(id2).childNodes[0].style.background = 'transparent url(/images/head-nav-item-a-on.gif) bottom left no-repeat';
		$(id2).childNodes[1].style.background = 'transparent url(/images/head-nav-item-span-on.gif) bottom right no-repeat';
		$(id2).setStyle({color:'#006FAF'});
	} else {
		$(id1).setStyle({display:'none'});		
		if (el.getAttribute('class') == 'on' || el.getAttribute('classname') == 'on')
			$(id2).setStyle({color:'#006FAF'});
		else {
			$(id2).setStyle({color:'white'});
			$(id2).childNodes[0].style.background = '';
			$(id2).childNodes[1].style.background = '';
		}
			
	}
}

function setBg(el,val){
	if(val=='on'){
		//el.setStyle({backgroundColor:'#d6edf8'}); //doesn't work on MSIE
		el.style.backgroundColor = '#d6edf8';
	} else {
		//el.setStyle({backgroundColor:'#ffffff'});
		el.style.backgroundColor = '#ffffff';
	}
}

	function showHint (event,el, wx, wy) {
		var obj = $('hint_'+el);
		var x = Event.pointerX(event) + wx/2;
		var y = Event.pointerY(event) + wy;


		if (el == 'cheque') {
			$('hint_transfer').style.display = 'none';
			$('hint_card').style.display = 'none';
		} else if (el == 'transfer') {
			$('hint_cheque').style.display = 'none';
			$('hint_card').style.display = 'none';
		} else if (el == 'card') {
			$('hint_transfer').style.display = 'none';
			$('hint_cheque').style.display = 'none';			
		}
		if (!obj.style.display || obj.style.display=='none') {
			with (obj.style) {
				left = x+'px';
				top = y+'px';
				display = 'block';
			}
			obj.setOpacity(0);
			Effect.Appear('hint_'+el,{duration: 0.5, from: 0, to: 0.95});			
		} else {
			obj.style.display = 'none';
		}
	}
