var responseText = '';


function $(el){
	if(document.getElementById(el)){
		var el2 = document.getElementById(el);
		return el2;
	}else{
		return false;
	}
}


function showHide(target){
	var obj = document.getElementById(target);
	
	if(obj.style.display=="block" || obj.style.display==""){
		obj.style.display="none";
	}else{
		obj.style.display="block";
	}//end else	

}//end function


function popupOpen(type, param_1, param_2, param_3){	
	
	var currentTime = new Date();
	var anticaching = currentTime.getTime();
	
	switch(type){
		case "login":
			//Call up the login form.
			TA_showBox('lightbox', '554', '', prepend+'pop-ups/inc.login.php?time='+anticaching, 0, '200',"focusLoginField()");
		break;
		
		case "paypal_showme":
			TA_showBox('lightbox', '554', '', prepend+'pop-ups/inc.paypal_showme.php', 0, '200');
		break;
				
		case "selectMe":			
			TA_showBox('selectMe', '600', 'Title='+param_1+"&divName="+param_2+"&inputName="+param_3, prepend+'pop-ups/inc.select_box.php', 0, '200');
		break;
		
		case "inviteMe":
			TA_showBox('selectMe', '600', 'type=invites&Title='+param_1+"&divName="+param_2+"&inputName="+param_3, prepend+'pop-ups/inc.select_box.php', 0, '230');
		break;
		
		case "report":
			TA_showBox('lightbox', '600', 'To='+param_1+"&From="+param_2, prepend+'pop-ups/inc.user_report.php', 0, '200');		
		break;
		
		case "syllabus":
			TA_showBox('lightbox', '600', '', prepend+'pop-ups/inc.new_syllabus.php', 0, '200');		
		break;
		
		case "addCourse":
			TA_showBox('lightbox', '200', 'Course_ID='+param_1, prepend+'pop-ups/inc.wishlist-frame.php', 0, '150');
		break;	
	}
}

//Sets the focus to the username login field on the login form.
//Called by popupOpen('login')
//Requires the inc.login.php box to be loaded already
function focusLoginField(){
	document.getElementById('username').focus();
}//end function


function popupClose(type){
	switch(type){
		case "login":
			//document.getElementById('overlay').style.display = "none";
			TA_hideDiv();	
		break;
		
		case "report":
			//document.getElementById('overlay').style.display = "none";
			TA_hideDiv();	
		break;

		case "syllabus":
			//document.getElementById('overlay').style.display = "none";
			TA_hideDiv();	
		break;
		
		case "invites":
			setTimeout("sendInvites()", 1000);
			TA_hideDiv();
		break;
		
		default:
			if(document.getElementById('overlay')){
				document.getElementById('overlay').style.display = "none";
			}
			TA_hideDiv();
		break;			
	}
}


//////////////////////////////////////////////////////////////////////////////	
//updateDiv
//
//Desc: Calls a special version of updateContentArea just for use with
//run.php
//////////////////////////////////////////////////////////////////////////////
function updateDiv(divName,funct_name,param1,param2,param3,param4){
	
	var vars = "function_name="+funct_name+"&param[1]="+param1+"&param[2]="+param2+"&param[3]="+param3+"&param[4]="+param4;	
	updateContentArea(divName,vars, prepend+'php/run.php');
	
	
	
}//end function

//This is meant to be put onclick on an image. The image must pass
//itself to the function so that it can be changed out
function toggleSection(sectionName,imageObject){

	//check for dev environment
	if(location.href.indexOf("www.ecampuswide.com")===true){	
		var up_image = "http://www.ecampuswide.com/images/arrow_up.png";
		var down_image = "http://www.ecampuswide.com/images/arrow_down.png";
	}else{			
		var up_image = "http://www.ecampuswide.com/images/arrow_up.png";
		var down_image = "http://www.ecampuswide.com/images/arrow_down.png";
	}
	
	//which image are we dealing with? up arrow or down arrow?
	var src = imageObject.src;
	
	if(src.indexOf('down')>0){
		//User clicked on a down arrow. So hide contents and swap to an up arrow
		var section = document.getElementById(sectionName);
		section.style.display = "none";
		imageObject.src = up_image;
	}else if(src==up_image){
		//User clicked on an up arrow. So show contents and swap to a down arrow
		var section = document.getElementById(sectionName);
		section.style.display = "block";
		imageObject.src = down_image;
	}//end else

}//end function

function refreshPage(){
	
	history.go(0);
}


function submitSearch(){

	var searchPage = document.getElementById('search_page').value;
	var searchWords = document.getElementById('search_words').value;	
	location.href = searchPage+"?search="+searchWords;
} 


//Used by the news box on groups and events.
function saveNews(Type,ID){

	var news = document.getElementById('news').value;
	
	news = news.replace(/\n/g,"<br/>");
	
	news = escape(news);
	
	if(Type=="Group"){
		updateDiv('newsContent','saveGroupNews',ID,news);
	}else if(Type=="Event"){
		updateDiv('newsContent','saveEventNews',ID,news);
	}else if(Type=='User'){
		updateDiv('newsContent','saveUserNews',ID,news);
	}



}//end function





//Used by profile-me.php. Controls Tabs on the main infobox (if there are any)
function switchTabs(newTab){

	var tab 	= newTab+"Tab";
	var section	= newTab+"Section";

	//get and hide all sections, and off state all tabs
	$('generalSection').style.display 	= 'none';
	$('contactSection').style.display 	= 'none';
	$('personalSection').style.display 	= 'none';
	
	$('generalTab').className 			= '';
	$('contactTab').className 			= '';
	$('personalTab').className 			= '';
	
	$(tab).className 					= "on";
	$(section).style.display			= "block";
		
}//end function