startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav_items");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;	

function edit_section(section_id){

	document.getElementById('page_edit_title').value 	= '';	
	
	var handlerFunc = function(t) {
		var vals = new Array();
		vals = t.responseText.split('-=.|.=-');
		
		update_mce_content(vals[0],vals[2]);
		
		document.getElementById('page_edit_title').value 	= vals[1];	
	}

	var errFunc = function(t) {
    	alert('Error ' + t.status + ' -- ' + t.statusText);
	}
	q = new Ajax.Request('inplace.php', {method: 'post',postBody:'action=get_page_info&section_id='+section_id, onSuccess:handlerFunc, onFailure:errFunc});
	document.getElementById('edit_page').style.display="block";
}
function edit_user(user_id){
	document.getElementById('user_perms').innerHTML = '';
	var handlerFunc = function(t) {
		document.getElementById('user_perms').innerHTML = t.responseText;		
	}

	var errFunc = function(t) {
    	alert('Error ' + t.status + ' -- ' + t.statusText);
	}

	q = new Ajax.Request('inplace.php', {method: 'post',postBody:'action=get_user_info&user_id='+user_id, onSuccess:handlerFunc, onFailure:errFunc});
}
////////////////////////////////////////////////////////////
function go(loc){
	switch(loc){
		case 'home':
			window.location = 'http://bclta.invokemedia.com';			
		break;
	}
}
function set_flash_focus(){
	document.getElementById('flash_module').focus();
}
////////////////////////////////////////////////////////////
function reg(){
	//==============================
	var username 	= document.getElementById('register_username').value;
	var passwd_1 	= document.getElementById('register_passwd_1').value;
	var passwd	 	= document.getElementById('register_passwd_confirm').value;	
	var fname	 	= document.getElementById('register_fname').value;
	var lname	 	= document.getElementById('register_lname').value;		
	var email 		= document.getElementById('register_email').value;
	var error_check	= new Array();
	var error_messages = 0;	//errors
	//********===========================================================********
		document.getElementById('register_username').style.backgroundColor	='#fff';
		document.getElementById('register_passwd_1').style.backgroundColor	='#fff';
		document.getElementById('register_passwd_confirm').style.backgroundColor	='#fff';
		document.getElementById('register_fname').style.backgroundColor		='#fff';
		document.getElementById('register_lname').style.backgroundColor		='#fff';
		document.getElementById('register_email').style.backgroundColor		='#fff';
		document.getElementById('error').innerHTML='';		
	//********===========================================================********	
	
	//==============================
	var handlerFunc = function(t) {
		
		if(t.responseText.length > 2){
			document.getElementById('hidden_errors').value = "errors";
			document.getElementById('error').innerHTML += t.responseText;
			document.getElementById('error').style.display = 'block;'	
			new Effect.ScrollTo('error');
			error_messages = 1;
			return false;		
		}else{
			document.getElementById('register_reference').submit();
			return true;
		}
	}	
	var errFunc = function(t) {
    	alert('Error ' + t.status + ' -- ' + t.statusText);
	}
	q = new Ajax.Request('inplace.php', {method: 'post',postBody:'action=registration&username='+username+'&email='+email, onSuccess:handlerFunc, onFailure:errFunc});

	//////////////////////////////////////////////****************************
		if(username == ''){
			error_check.push('You must input a valid username<br />~register_username');
		}
		if(passwd_1 != passwd){
			error_check.push('Your passwords must match<br />~register_passwd_1');
		}
		if(passwd_1 == ''){
			error_check.push('You may not enter an empty password<br />~register_passwd_1');
		}
		if(passwd == ''){
			error_check.push('You may not enter an empty password (Second Password Field)<br />~register_passwd_confirm');
		}
		if(fname == ''){
			error_check.push('You must input a valid first name<br />~register_fname');
		}
		if(lname == ''){
			error_check.push('You must input a valid last name<br />~register_lname');
		}
		if(email == ''){
			error_check.push('You must input a valid email to recieve your account activation<br />~register_email');
		}
		//////////////////////////////////////////////****************************		
		if(error_check.length > 1){
			for(var i = 0;i < error_check.length;i++){
				var error_set = new Array();
				if(error_check[i].length > 1){
					error_set = error_check[i].split("~");
					document.getElementById(error_set[1]).style.backgroundColor="#ffd0dc";
					document.getElementById('error').innerHTML += error_set[0];
					document.getElementById('error').style.display = 'block;'				
					Element.scrollTo('error',{duration:1.0})				
				}
			}
			error_messages = 1;
		}else{
			error_messages = 0;
			document.getElementById('register_reference').submit();			
		}
		return false;
}

function log_movie_entry(uid,module_id,access_key){
	q = new Ajax.Request('inplace.php', {method: 'post',postBody:'action=log_movie_entry&user_id='+uid+'&module_id='+module_id+'&access_key='+access_key});
}

function submit_comment(user_id,module_id){
	Effect.toggle('submit_post','appear');
	var content	= document.getElementById('comment_textarea').value;
	var handlerFunc = function(t) {
		if(t.responseText.length > 2){
			document.getElementById('comments').innerHTML 			= t.responseText;
			document.getElementById('comment_notice').innerHTML		= 'Your comment has been recieved';				
			Effect.toggle('comment_notice','appear');
			var timer = setTimeout("Effect.toggle('comment_notice','appear');",5000)			
			return true;
		}
	}

	var errFunc = function(t) {
    	alert('Error ' + t.status + ' -- ' + t.statusText);
	}

	q = new Ajax.Request('inplace.php', {method: 'post',postBody:'action=comment_add&user_id='+user_id+'&module_id='+module_id+'&content='+content, onSuccess:handlerFunc, onFailure:errFunc});
	if(handlerFunc == true){
		return true;	
	}else{
		return false;
	}		
}
function delete_section(section_id){
	var conf = confirm('Are you sure you want to delete this section?');
	if(conf == true){
		var sid = section_id;
		var handlerFunc = function(t,section_id) {
			if(t.responseText == 'child'){
				alert('This section has child pages, please delete them first.');						
				return false;			
			}else{
				Element.remove('section_'+sid);			
				return true;
			}
		}
		var errFunc = function(t) {
    		alert('Error ' + t.status + ' -- ' + t.statusText);
		}	
		q = new Ajax.Request('inplace.php', {method: 'post',postBody:'action=delete_section&section_id='+section_id, onSuccess:handlerFunc, onFailure:errFunc,asynchronous:false});	
		window.location = window.location;
	}
}
function delete_comment(comment_id,element_id){

	q = new Ajax.Request('inplace.php', {method: 'post',postBody:'action=delete_comment&comment_id='+comment_id+'&',onFailure:errFunc,on404:cant_find});
	Effect.Fade(element_id);
	//new Effect.ScrollTo(element_id);
				
	var cant_find = function(){
		alert('404');
	}
	var errFunc	= function(){
		alert(t.responseText)
		alert('hmmm');		
	}	
}
function update_section(obj,movie_id){
	o = obj.options[obj.selectedIndex].value;	
	q = new Ajax.Request('inplace.php?action=update_movie_section&movie_id='+movie_id+'&section_id='+o+'&', {onFailure:errFunc,on404:cant_find});
	
	document.getElementById('edit_notice').innerHTML = 'The movie module has been updated';					
	Effect.toggle('edit_notice','appear');
	var timer = setTimeout("Effect.toggle('edit_notice','appear');",4000)				
	var cant_find = function(){
		alert('404');
	}
	var errFunc	= function(){
		alert(t.responseText)
	}	
}
function delete_module(module_id){
	var delete_confirm = confirm('Are you sure you want to delete this movie? It cannot be undone.');
	if(delete_confirm){
		q = new Ajax.Request('inplace.php', {method: 'post',postBody:'action=delete_module&module_id='+module_id+'&',onFailure:errFunc,on404:cant_find});
		Element.remove('delete_'+module_id);
		//new Effect.ScrollTo(element_id);
	
	}
				
	var cant_find = function(){
		alert('404');
	}
	var errFunc	= function(){
		alert(t.responseText)
		alert('hmmm');		
	}	
}
function log_module_time(){
	q = new Ajax.Request('inplace.php', {method: 'post',postBody:'action=delete_module&module_id='+module_id+'&',onFailure:errFunc,on404:cant_find});
	//new Effect.ScrollTo(element_id);
				
	var cant_find = function(){
		alert('404');
	}
	var errFunc	= function(){
		alert(t.responseText)
		alert('hmmm');		
	}	
}
function delete_user(user_id){
	var agree = confirm('Are you sure you want to delete this user?');
	if(agree){
		q = new Ajax.Request('inplace.php?action=delete_user&user_id='+user_id);
		Element.remove('delete_'+user_id);
		
	}
}
function check_state(state_bool,form_set){
	var f_object = document.getElementById(form_set);
	if(state_bool == 1){
		for (var i=0;i<f_object.elements.length;i++) {
	    	var e = f_object.elements[i];
    		if ((e.type=='checkbox') && (e.name=='user_module_perms[]') && (e.disabled)) {
				e.disabled = false;
			}
    	}
	}else{
		for (var i=0;i<f_object.elements.length;i++) {
	    	var e = f_object.elements[i];
    		if ((e.type=='checkbox') && (e.name=='user_module_perms[]') && (!e.disabled)) {
				e.disabled = true;
			}
    	}	
	}
}