function getSectionName(text, id, method){
	
	var http=false; //Clear our fetching variable
	try {
			http = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object?
	} catch (e) {
			try {
					http = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			http = false;
					}
	}
	if (!http && typeof XMLHttpRequest!='undefined') {
			http = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}
	
	
	var url = '_includes/get_section_name.php';
	var params = 'text=' + text + "&id=" + id + "&method=" + method;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('updateDiv').innerHTML=http.responseText;
		}
	}
}


function getTopMenu(){
	
	var http=false; //Clear our fetching variable
	try {
			http = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object?
	} catch (e) {
			try {
					http = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			http = false;
					}
	}
	if (!http && typeof XMLHttpRequest!='undefined') {
			http = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}
	
	
	var url = '_includes/get_section_top_menu.php';
	var params = '';
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('topMenuDiv').innerHTML=http.responseText;
		}
	}
}
function moveSection(section_id, method, group_id){

	var http=false; //Clear our fetching variable
	try {
			http = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object?
	} catch (e) {
			try {
					http = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			http = false;
					}
	}
	if (!http && typeof XMLHttpRequest!='undefined') {
			http = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}
	
	
	var url = '_includes/get_section_move.php';
	var params = "method=" + method + "&section_id=" + section_id + "&group_id=" + group_id;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('topMenuUpdateDiv').innerHTML=http.responseText;
		}
	}

}

function deleteSection(section_id){

	var http=false; //Clear our fetching variable
	try {
			http = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object?
	} catch (e) {
			try {
					http = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			http = false;
					}
	}
	if (!http && typeof XMLHttpRequest!='undefined') {
			http = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}
	
	
	var url = '_includes/get_section_delete.php';
	var params = "section_id=" + section_id;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('updateDiv').innerHTML=http.responseText;
		}
	}

}


function moveArticle(articleId, method, section_id, where){

	var http=false; //Clear our fetching variable
	try {
			http = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object?
	} catch (e) {
			try {
					http = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			http = false;
					}
	}
	if (!http && typeof XMLHttpRequest!='undefined') {
			http = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}
	
	
	var url = '_includes/get_article_move.php';
	var params = "article_id=" + articleId + "&method=" + method + "&section_id=" + section_id + "&where=" + where;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('articleMenuDiv').innerHTML=http.responseText;
		}
	}

}


function moveGallery(galleryId, method, section_id, where){

	var http=false; //Clear our fetching variable
	try {
			http = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object?
	} catch (e) {
			try {
					http = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			http = false;
					}
	}
	if (!http && typeof XMLHttpRequest!='undefined') {
			http = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}
	
	
	var url = '_includes/get_gallery_move.php';
	var params = "gallery_id=" + galleryId + "&method=" + method + "&section_id=" + section_id + "&where=" + where;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('galleryMenuDiv').innerHTML=http.responseText;
		}
	}

}

function saveEmbed(section_id, id, method){
	
	if(method=="edit"){
		var text = escape(document.getElementById('embedTextarea'+id).value);
	}
	
	var http=false; //Clear our fetching variable
	try {
			http = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object?
	} catch (e) {
			try {
					http = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			http = false;
					}
	}
	if (!http && typeof XMLHttpRequest!='undefined') {
			http = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}
	
	
	var url = '_includes/get_section_embed.php';
	var params = "section_id=" + section_id + "&id=" + id + "&text=" + text + "&method=" + method;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('embedDiv'+id).innerHTML=http.responseText;
		}
	}

}


function checkSectionName(id, method){
	var nameLength = document.getElementById("sectionName"+id).value.length;
	
	if(nameLength>0){
		
		getSectionName(document.getElementById("sectionName"+id).value, id, method);
		if(id<1){
			restoreField('sectionName'+id, '');
			toggleDiv("addNewSectionDiv"+id, "addNewSectionButtonDiv"+id);
		} else{
			toggleDiv("sectionNameEditDiv"+id, '');	
		}
		
	} else{
		document.getElementById("sectionNameErrorDiv"+id).style.visibility='visible'; 
		document.getElementById("sectionNameErrorDiv"+id).style.zIndex='3';
		document.getElementById("sectionNameErrorDiv"+id).style.position='static';
	}
	
	
}


function checkSubSectionName(id, groupId, fieldId, method){
	
	var nameLength = document.getElementById(fieldId).value.length;
	
	if(nameLength>0){
		
		if(method=="add_sub_topic"){
			getSectionName(document.getElementById(fieldId).value, groupId, method);	
		} else if(method=="edit_sub_topic"){
			getSectionName(document.getElementById(fieldId).value, id, method);
		}
		
		if(id<1){
			restoreField('sectionName'+id, '');
			toggleDiv("addNewSectionDiv"+id, "addNewSectionButtonDiv"+id);
		} else{
			restoreField('sectionName'+id, '');
			toggleDiv("sectionNameEditDiv"+id, '');	
		}
		
		
	} else{
		document.getElementById("sectionNameErrorDiv"+id).style.visibility='visible'; 
		document.getElementById("sectionNameErrorDiv"+id).style.zIndex='3';
		document.getElementById("sectionNameErrorDiv"+id).style.position='static';
	}
	
}


function getGroupTopics(section_id){
	
	var http=false; //Clear our fetching variable
	try {
			http = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object?
	} catch (e) {
			try {
					http = new
					ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
		} catch (E) {
			http = false;
					}
	}
	if (!http && typeof XMLHttpRequest!='undefined') {
			http = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
	}
	
	
	var url = '_includes/get_section_group_topics.php';
	var params = 'section_id=' + section_id;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('groupTopicsDiv').innerHTML=http.responseText;
		}
	}
}



function checkBannerImage(){
	
	var bannerImage = document.getElementById('bannerImage').value;
	var bannerLength = bannerImage.length;
	
	if(bannerLength<1){
		//document.getElementById('bannerErrorDiv').innerHTML = "You must upload an image.";
		document.getElementById('bannerSubmit').disabled=false;
	} else{
		if(bannerImage.substring(bannerLength-3, bannerLength)=="jpg" || bannerImage.substring(bannerLength-3, bannerLength)=="gif"){
			document.getElementById('bannerSubmit').disabled=false;
		} else{
			//document.getElementById('bannerErrorDiv').innerHTML = "Your image must be in jpg or gif format.";
			//document.getElementById('bannerImage').value='';
			document.getElementById('bannerSubmit').disabled=true;
		}
	}

}

var oldContentx="";
function updateBannerType(method, value){
if(method!="move"){
	document.getElementById('bannerTypeDiv').innerHTML="loading...";
}
var xmlhttp=false; //Clear our fetching variable
		try {
				xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
		} catch (e) {
				try {
						xmlhttp = new
						ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
			} catch (E) {
				xmlhttp = false;
						}
		}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
				xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
		}
		var file = '_includes/get_banner_type.php?method=' + method + "&value=" + value; //This is the path to the file we just finished making *
	xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) { //Check if it is ready to receive data
				var content = xmlhttp.responseText; //The content data which has been retrieved ***
				
				if( content ){ //Make sure there is something in the content variable
					  
					  if(content!=oldContentx){
						document.getElementById('bannerTypeUpdateDiv').innerHTML=content;
					
					}
					  oldContentx=content;
				}
		}
	}
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	
}

function checkBannerType(type){
	
	var buttonArray = new Array("bannerTypeMoveUp", "bannerTypeMoveDown", "bannerTypeMoveLeft", "bannerTypeMoveRight", "bannerTypeLargerButton", "bannerTypeSmallerButton");
	var x=0;
	
	var buttonCount=buttonArray.length;
	
	if(type.length>0){
		
		while(x<buttonCount){
			document.getElementById(buttonArray[x]).style.cursor="pointer";
			document.getElementById(buttonArray[x]).style.opacity="1";
			document.getElementById(buttonArray[x]).style.filter="alpha(opacity=100)";
			x++;
		}
		
		var bannerWidth=document.getElementById('mainBannerDiv').offsetWidth;
		var bannerHeight=document.getElementById('mainBannerDiv').offsetHeight;
		
		var bannerTypeWidth=document.getElementById('bannerTypeDiv').offsetWidth;
		var bannerTypeHeight=document.getElementById('bannerTypeDiv').offsetHeight;
		
		var bannerTypeX=document.getElementById('bannerTypeDiv').style.left;
		var bannerTypeY=document.getElementById('bannerTypeDiv').style.top;
		
					
		if(bannerTypeX<1){
			document.getElementById("bannerTypeMoveLeft").style.cursor="no-drop";
			document.getElementById("bannerTypeMoveLeft").style.opacity=".4";
			document.getElementById("bannerTypeMoveLeft").style.filter="alpha(opacity=40)";
		}
		
		if(bannerTypeY<1){
			document.getElementById("bannerTypeMoveUp").style.cursor="no-drop";
			document.getElementById("bannerTypeMoveUp").style.opacity=".4";
			document.getElementById("bannerTypeMoveUp").style.filter="alpha(opacity=40)";
		}
		
		if((parseInt(bannerTypeX)+parseInt(bannerTypeWidth))==parseInt(bannerWidth)){
			document.getElementById("bannerTypeMoveRight").style.cursor="no-drop";
			document.getElementById("bannerTypeMoveRight").style.opacity=".4";
			document.getElementById("bannerTypeMoveRight").style.filter="alpha(opacity=40)";
		}
		
		if((parseInt(bannerTypeY)+parseInt(bannerTypeHeight))==parseInt(bannerHeight)){
			document.getElementById("bannerTypeMoveDown").style.cursor="no-drop";
			document.getElementById("bannerTypeMoveDown").style.opacity=".4";
			document.getElementById("bannerTypeMoveDown").style.filter="alpha(opacity=40)";
		}
		
		
	} else{
		
		while(x<buttonCount){
			document.getElementById(buttonArray[x]).style.cursor="no-drop";
			document.getElementById(buttonArray[x]).style.opacity=".4";
			document.getElementById(buttonArray[x]).style.filter="alpha(opacity=40)";
			x++;
		}
	}

}




function displayTypeColors(){

	document.getElementById('bannerTypeColorSelectDiv').style.visibility="visible";
	document.getElementById('bannerTypeColorSelectDiv').style.zIndex="4";
	document.getElementById('bannerTypeColorArrowDiv').innerHTML="<img onclick=\"hideTypeColors();\" onmouseover=\"this.style.backgroundColor='#a43e31';\" onmouseout=\"this.style.backgroundColor='#D3D3D3';\" style=\"background-color: #D3D3D3; cursor: pointer;\" id=\"bannerTypeColorButton\" src=\"_images/i-edit_banner_color.gif\" border=\"0\" />";
	

}

function hideTypeColors(){
	document.getElementById('bannerTypeColorSelectDiv').style.visibility="hidden";
	document.getElementById('bannerTypeColorSelectDiv').style.zIndex="-1";
	document.getElementById('bannerTypeColorArrowDiv').innerHTML="<img onclick=\"displayTypeColors();\" onmouseover=\"this.style.backgroundColor='#a43e31';\" onmouseout=\"this.style.backgroundColor='#D3D3D3';\" style=\"background-color: #D3D3D3; cursor: pointer;\" id=\"bannerTypeColorButton\" src=\"_images/i-edit_banner_color.gif\" border=\"0\" />";
	
}


function toggleDiv(hide, show){
	
	if(hide.length>0){
		document.getElementById(hide).style.visibility="hidden";
		document.getElementById(hide).style.zIndex="-1";
		document.getElementById(hide).style.position="absolute";
	}
	if(show.length>0){
		document.getElementById(show).style.visibility="visible";
		document.getElementById(show).style.zIndex="3";
		document.getElementById(show).style.position="static";
	}
}

function restoreField(id, restoreText){
	document.getElementById(id).value=restoreText;
}

function openDiv(divId){
	document.getElementById(divId).style.visibility="visible";
	document.getElementById(divId).style.zIndex="3";
}

function closeDiv(divId){
	document.getElementById(divId).style.visibility="hidden";
	document.getElementById(divId).style.zIndex='-1';
}

function hide(divId){
	document.getElementById(divId).style.visibility='hidden';
	document.getElementById(divId).style.position='absolute';
	document.getElementById(divId).style.zIndex='-1';
}
function reveal(divId){
	document.getElementById(divId).style.visibility='visible';
	document.getElementById(divId).style.position='static';
	document.getElementById(divId).style.zIndex='3';
}
