/*************************************************************
* USER SELECT FUNCTIONS
*************************************************************/
function chooseSelectMe(name){
	$('select_friends').className = "group";
	$('select_groups').className = "group";
	$('select_classmates').className = "group";
	$('select_all').className = "group";
	
	document.getElementById(name).className = "group all";
}	
			

/******************************************************************
* COMMENTS FUNCTIONS
******************************************************************/

//UPDATES THE LIST OF COMMENTS ON THE BLOG PROFILE PAGE
function updateComments(Type, ID){
	updateContentArea('comments_list', 'function_name=&param[1]='+Type+'&ID='+ID, "../php/run.php");
	}

//SUBMITS A NEW COMMENT REPLY
function submitCommentReply(Type, ID){	
	var form_vars= TA_readForm('comments_form');
	updateContentArea("comments_list", "function_name=&"+form_vars, "../php/run.php", "updateComments('"+Type+"','"+ID+"')");
	}

//OPENS A NEW COMMENT REPLY BOX
function addCommentReply(Element,vars){
	TA_attachBox(Element,'', vars, "../pop-ups/inc.comment-reply.php");
}//end function
	
	
	

/******************************************************************
* BOOKSWAP FUNCTIONS
******************************************************************/
function ISBNSearch(searchType){

	var bsTitle 	= 	$('bs_title').value;
	var bsAuthor 	= 	$('bs_author').value;
	var bsISBN 		= 	$('bs_isbn').value;

	var thisdate = new Date();
	var inSeconds = thisdate.getSeconds();

	updateDiv('isbn_search','isbnSearch',searchType,bsAuthor,bsISBN,bsTitle);
}

function classSearch(){

	if($('Class_ID')){
		var bsClass	= 	$('Class_ID').value;
		updateDiv('isbn_search','bookSearch',bsClass);
	}else{
		window.alert("You must select a class first");
	}
}


function changeSearch(ID){
	$('search_1').style.display = "none";
	$('search_2').style.display = "none";
	$('search_3').style.display = "none";		

	$('search_1_tab').className = '';
	$('search_2_tab').className = '';
	$('search_3_tab').className = '';
	
	$('search_'+ID).style.display =	'block';
	$('search_'+ID+'_tab').className =	'on';
}

//performs the correct action when hitting enter on the book search form
function executeSearch(bs_event){
	if(bs_event.keyCode == 13){
		if($('search_1').style.display == 'block'){
			ISBNSearch('combined');
			return;
		}
		
		if($('search_2').style.display == 'block'){
			ISBNSearch('isbn');
			return;
		}
		
		if($('search_3').style.display == 'block'){
			classSearch();
		}
	}	
}//end function

/******************************************************************
* MESSAGES FUNCTIONS
******************************************************************/
function checkMessage(elName){
	
	var error_message = '';
	var error = false;
	
	if($(elName)){
		var recipients = $(elName).value;
		if(recipients.length<1){
			error = true;
			error_message += "You must select at least one recipient";
		}
	}else{
		error = true;
		error_message += "You must select at least one recipient";	
	}
	
	if(error){
		$('error_box').style.display = 'block';
		$('error_box').innerHTML = error_message;
	}else{
		document.new_email.submit();
	}	
}


/******************************************************************
* BLOG FUNCTIONS
******************************************************************/
function richText(elName){
	var config = new HTMLArea.Config();
	config.width = '600px';
	config.height = '400px';
				
	if(document.getElementById(elName)){
		HTMLArea.replace(elName, config);
	}
}


function adjustBlogSubscription(Blog_ID){
	updateDiv('subscribe_button', 'adjustBlogSubscription', Blog_ID);
	}


/******************************************************************
* NOTICE / INFOFEED FUNCTIONS
******************************************************************/
function friendRequest(To_ID){
	updateDiv('', 'submitFriendRequest', To_ID);
	window.alert('Your request has been submitted');
	refreshPage();
	}

/******************************************************************
* Path Functions
******************************************************************/	
	
//This is activated by changing the Choose a department pulldown
//It updates the course number selectors with course numbers for that Dept
function updateNumberSelectors(department_code){
	
	//We have to chain ajax calls to do this
	var vars = "function_name=printDeptNumbers&param[0]="+department_code;
	var url = "../php/run.php";
	var callback = "updateRangeSelectors('"+department_code+"')";
	updateContentArea("specific_number",vars,url,callback);
	
}//end function

//This is the callback function activated by updateNumberSelectors. This 
//uses ajax to update the from and to pulldowns which allow a range of
//class numbers to be used.
function updateRangeSelectors(department_code){
		
	var vars = "function_name=printRangeSelectors&param[0]="+department_code;
	var url = "../php/run.php";
	updateContentArea("number_range",vars,url);
	
}//end function

//Changes which option a select currently points to.
//index is a numerical index that has nothing to do with <option value=''>
//The first option is index=0, the second is index=1, etc...
function setSelect(elName,index){

	var selector = $(elName);
	selector.selectedIndex = index;

}//end function

//This makes sure that the user has selected a department, a number/range, and a pathway
function validatePathForm(){

	//Get the values of all the fields
	var dept = $('dept_code');
//	var specific_selector = $('specific_number_select');
//	var min_range_selector = $('min_range');
//	var max_range_selector = $('max_range');
//	var specific_selector = document.getElementById('specific_number_select');
	var min_range_selector = document.getElementById('min_range');
	var max_range_selector = document.getElementById('max_range');
	var pathway = $('pathway');
	
	//Has a deptartment been selected?
	if(dept.value.length==1){
		//nope
		alert("Error: You must select a department first.");
		return;
	}//end if
	
	//Has a number or range been selected?
	if(min_range_selector.value==0 && max_range_selector.value==0){
		//Nope
		alert("Error: Please select either a specific course number or a range of course numbers");
		return;	
	}//end if
	
	//Has a pathway been selected?
	if(!pathway.value>0){
		//Nope
		alert("Error: Please select a search path");
		return;
	}//end if
	
	//Getting this far is success
	//Submit via GET
	var vars = "?Prefix="+dept.value+"&Min_Number="+min_range_selector.value;
	vars += "&Max_Number="+max_range_selector.value+"&Path_ID="+pathway.value+"&Tab=Path";
	
	var url = "courses.php"+vars;
	location.href=url;
		
}//end function



