/* **************************************************************************************************************/
/* Administration function */
/* **************************************************************************************************************/


//---------------------------------
// Access Control Functions
//---------------------------------

function display_c(start){
	window.start = parseFloat(start);
	var end = 0;
	var refresh=1000;
	if(window.start > end ){
		mytime = setTimeout('display_ct()',refresh)
	} else if(window.start === end){
		window.location = "login.php";
	}
}
        
function display_ct() {
	var days = Math.floor(window.start / 86400);
	var hours = Math.floor((window.start - (days * 86400 ))/3600);
	var minutes = Math.floor((window.start - (days * 86400 ) - (hours *3600 ))/60);
	var seconds = Math.floor((window.start - (days * 86400 ) - (hours *3600 ) - (minutes*60)));
	if(days < 10){ var days = "0"+days; }
	if(hours < 10){ var hours = "0"+hours; }
	if(minutes < 10){ var minutes = "0"+minutes; }
	if(seconds < 10){ var seconds = "0"+seconds; }
	var x = minutes+" : "+seconds;
	document.getElementById('ct').innerHTML = x;
	window.start= window.start- 1;
	tt=display_c(window.start);
}
		
function switchpassword(q){ 
	if (q){ 
		document.getElementById('passwordtext').style.display="none"; 
		document.getElementById('password').style.display="inline"; 
		document.getElementById('password').focus(); 
	} else { 
		document.getElementById('password').style.display="none"; 
		document.getElementById('passwordtext').style.display="inline"; 
	} 
} 
function switchusername(q){ 
	if (q){ 
		document.getElementById('usernametext').style.display="none"; 
		document.getElementById('username').style.display="inline"; 
		document.getElementById('username').focus(); 
	} else { 
		document.getElementById('username').style.display="none"; 
		document.getElementById('usernametext').style.display="inline"; 
	} 
} 
//---------------------------------
// End Access Control Functions
//---------------------------------

function openMenu(menu){	
	document.getElementById(menu).style.display="inline-block";
	document.getElementById(menu).style.top=clientHeight;
}

function closeMenu(menu){
	document.getElementById(menu).style.display="none";
	document.getElementById(menu).style.top=clientHeight;

}

//=================================================================
// TEXT FORMATTING
//=================================================================
function formatText(el,tag){
	var selectedText = document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd);// IE:Moz
	if (selectedText == "") {return false}
	switch(tag){
		case "page_heading": 
			var newText='<p class='+tag+'>'+selectedText+'</p>'; 
			break;
		case "page_subheading": 
			var newText='<p class='+tag+'>'+selectedText+'</p>'; 
			break;
		default : 
			var newText='<'+tag+'>'+selectedText+'</'+tag+'>'; 
			break;
	}
	
	if(document.selection){    //IE
		document.selection.createRange().text=newText;
	} else{   //Moz
		el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value.length);
	}
}
//=================================================================
// END TEXT FORMATTING
//=================================================================

//=================================================================
// INSERT BLANK ROW AT CURSOR
//=================================================================
function insertAtCursor(el, tag) {
	//IE support
	if (document.selection) {
		el.focus();
		sel = document.selection.createRange();
		sel.text = tag+"\r\n";
	}
	//MOZILLA/NETSCAPE support
	else if (el.selectionStart || el.selectionStart == '0') {
		var startPos = el.selectionStart;
		var endPos = el.selectionEnd;
		el.value = el.value.substring(0, startPos)
		+ tag + "\n\n"
		+ el.value.substring(endPos, el.value.length);
	} else {
		el.value += tag;
	}
}
//=================================================================
// INSERT BLANK ROW AT CURSOR
//=================================================================
	
//=================================================================
// TEXT PREVIEW UPDATE
//=================================================================
function updatePreview(){
	var text = document.getElementById('new_content').value;
	
	document.body.style.overflow='hidden';
	document.getElementById('newContentPreview').innerHTML = text;
	document.getElementById('newContentPreviewDiv').style.display='inline-block'; 
}
//=================================================================
// END TEXT PREVIEW UPDATE
//=================================================================

