// JavaScript Document
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}


function deleteitem(id, url, type, message, attach){
	if(window.confirm(message)){
		location= url+'?'+type+'='+id+attach;
	}
}

function loadPageManager(){
	//new Ajax.Updater('navcontent', 'includes/nav/pagemanagernav.php', {onComplete:function(){ new Effect.Appear('navcontent');},asynchronous:true, evalScripts:true});
	new Ajax.Updater('pagecontent', 'includes/pagemanager.php', {onComplete:function(){ new Effect.Appear('pagecontent');},asynchronous:true, evalScripts:true});
	
	
}

function changePicture(id,otherid){
	//new Effect.Puff(otherid);
	new Effect.Appear('picture');
	getData('scripts/php/fetchsketch.php?id='+id, 'picture');
}


function showEventEditor(id,editor,forms,editorbox){
	var editor = document.getElementById(editor);
	var forms = document.getElementById(forms);
	var editorbox = document.getElementById(editorbox);
	forms.style.display = "none";
	//alert(obj2.innerHTML);
	editor.style.display="block";
	editorbox.style.display="block";
		//string = string.replace("&","&amp;");
		//string = string.replace("<","&lt;");
		//string = string.replace(">","&gt;");
		//alert(string);
		oEdit1.putHTML(string);
	
	
	//new Ajax.Updater(obj2, file, {asynchronous:true, evalScripts:true});
	//var x = obj2.innerHTML;
	//obj3.text = x;
	//eval(editor_string);
}


function showEditor(id,editor,editable,forms,editorbox){
	var editor = document.getElementById(editor);
	var idholder = document.getElementById('txt');
	var editable = document.getElementById(editable);
	var forms = document.getElementById(forms);
	var editorbox = document.getElementById(editorbox);
	idholder.innerHTML = id;
	forms.style.display = "none";
	//alert(obj2.innerHTML);
	var string = editable.innerHTML
	editor.style.display="block";
	editorbox.style.display="block";
		//string = string.replace("&","&amp;");
		//string = string.replace("<","&lt;");
		//string = string.replace(">","&gt;");
		//alert(string);
		oEdit1.putHTML(string);
	
	
	//new Ajax.Updater(obj2, file, {asynchronous:true, evalScripts:true});
	//var x = obj2.innerHTML;
	//obj3.text = x;
	//eval(editor_string);
}


function showPageForm(id,editor,forms,editorbox,file){
	var editor = document.getElementById(editor);
	var forms = document.getElementById(forms);
	var editorbox = document.getElementById(editorbox);
	editorbox.style.display = "none";
	//alert(obj2.innerHTML);
	editor.style.display="block";
	forms.style.display="block";
	new Ajax.Updater(forms, file, {asynchronous:true, evalScripts:true});
	//var x = obj2.innerHTML;
	//obj3.text = x;
	//eval(editor_string);
}


function updateContent(){
	var obj = document.getElementById('editablecontent');
	var obj2 = document.getElementById('txt');
	var string = oEdit1.getHTMLBody();
	var id = obj2.innerHTML;
	obj.innerHTML = string;
	var obj3 = document.getElementById('editor');
	new Ajax.Request('scripts/php/updatepage.php', {method:'post', postBody:'id='+id+'&content='+string+''});
	new Effect.Fade(obj3 , {duration: 1.0});
	
}

function changePage(id,filename){
	new Ajax.Updater('page', '../'+filename+'?editable=go', {onComplete:function(){ new Effect.Appear('page');},asynchronous:true, evalScripts:true});
}

function setCover(id){
	var obj = document.getElementById('picture');
	obj.style.display = 'none';
	new Effect.Appear('picture');
	getData('scripts/php/fetchcover.php?cover='+id, 'picture');
}


function getGroupOrder(display) {
		var sections = document.getElementsByClassName('sortabledemo');
		var alerttext = '';
		sections.each(function(section) {
			var sectionID = section.id;
			var order = Sortable.serialize(sectionID);
			alerttext += sectionID + ': ' + Sortable.sequence(section) + '\n';
		});
		var obj = document.getElementById(display);
		obj.innerHTML=alerttext;
		//return false;
	}
	
	///animation
	
function doWidthChangeMem(elem,startWidth,endWidth,steps,intervals,powr) { 
//Width changer with Memory by www.hesido.com
    if (elem.widthChangeMemInt)
	window.clearInterval(elem.widthChangeMemInt);
    var actStep = 0;
    elem.widthChangeMemInt = window.setInterval(
	function() { 
	  elem.currentWidth = easeInOut(startWidth,endWidth,steps,actStep,powr);
	  elem.style.width = elem.currentWidth + "px"; 
	  actStep++;
	  if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
	} 
	,intervals)
}



function widthChange(elem) { 
	var elem = document.getElementById(elem);
    if (!elem.currentWidth) elem.currentWidth = 150; 
	//if no memory is set, set it first; 
    doWidthChangeMem(elem,elem.currentWidth,300,10,10,0.5); 
    } 
function widthRestore(elem) { 
	var elem = document.getElementById(elem);
    if (!elem.currentWidth) return; 
    doWidthChangeMem(elem,elem.currentWidth,150,10,10,0.5); 
    }
	
	function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) { 
//Generic Animation Step Value Generator By www.hesido.com 
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta); 
    return Math.ceil(stepp) 
    } 
	
function buttonOver(obj){
	document.getElementById(obj).className='button_on';
 }
 
 function buttonOut(obj){
	 document.getElementById(obj).className='button.';
 }

