var booInit = true;
var objPageContent = null;
var intCurrentRowId = 0;
var booModeEdit = false;

function admin_login()
{
	var strMail = document.getElementById("mail").value;
	var strPassword = document.getElementById("password").value;
	loadData("admin", "content", "action=login&mail="+encodeURIComponent(strMail)+"&password="+encodeURIComponent(strPassword));
}

function admin_update_config_generale()
{
	var strSiteTitle = document.getElementById("site_title").value;
	var strSiteDescription = document.getElementById("site_description").value;
	var strSiteKeyword = document.getElementById("site_keyword").value;
	loadData("admin", "content", "action=update_config_generale&site_title="+encodeURIComponent(strSiteTitle)+"&site_description="+encodeURIComponent(strSiteDescription)+"&site_keyword="+encodeURIComponent(strSiteKeyword));
}

function admin_update_config_page()
{
	var intPageId = document.getElementById("page_id").value;
	var strPageTitle = document.getElementById("page_title").value;
	objPageContent = tinyMCE.get(document.getElementsByName("page_content")[0].id);
	objPageContent.setProgressState(1);
	loadData("admin", "content", "action=update_config_page&id="+encodeURIComponent(intPageId)+"&page_title="+encodeURIComponent(strPageTitle)+"&page_content="+encodeURIComponent(objPageContent.getContent()));
	objPageContent.setProgressState(0);
}

function showArea(){
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "template_list.js",
		external_link_list_url : "link_list.js",
		external_image_list_url : "image_list.js",
		media_external_list_url : "media_list.js",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
}

function showHeaderUploader(strSid)
{
	document.getElementById("upload_file").style.display = 'block';
	var so = new SWFObject("./data/swf/upload_header.swf", "upload_header", "550", "400", "8");
	so.addParam ('FlashVars','sid='+encodeURIComponent(strSid));
	so.write("upload_file");
	document.getElementById("upload_activate").style.display = 'none';
}

function showAudioUploader()
{
	document.getElementById("upload_file").style.display = 'block';
	var so = new SWFObject("./data/swf/upload_audio.swf", "upload_audio", "550", "400", "8");
	so.addParam ('FlashVars','varget=dossierup%3Dtests');
	so.write("upload_file");
	document.getElementById("upload_activate").style.display = 'none';
}

function rowHover(intRowId)
{
	if(booModeEdit == false)
	{
		intCurrentRowId = intRowId;
		var intId = document.getElementById("rank_id_"+intRowId).innerHTML;
		document.getElementById("header_viewer").src = './data/img/header/'+intId+'.jpg';
		var trCount = document.getElementById('header_picture').getElementsByTagName('tr').length;
		for(i=1; i<trCount; i++)
		{
			if(i == intRowId)
				document.getElementById("row_"+i).style.backgroundColor = '#CCCCCC';
			else
				document.getElementById("row_"+i).style.backgroundColor = '#FFFFFF';
		}
	}
}

function nameClick(intRowId)
{
	if(document.getElementById("name_"+intRowId).innerHTML.substr(0, 1) != '<' && booModeEdit == false)
	{
		booModeEdit = true;
		document.getElementById("name_"+intRowId).innerHTML = '<input id=\"input_name_'+intRowId+'\" class=\"col_21_input\" value="'+document.getElementById("name_"+intRowId).innerHTML+'" /><p><a href="#" onClick="nameCancel('+intRowId+'); return false;">Annuler</a> <a href="#" onClick="nameValid('+intRowId+'); return false;">Valider</a></p>';
		document.getElementById("input_name_"+intRowId).focus();
	}
}

function nameCancel(intRowId)
{
	if(intCurrentRowId == intRowId)
	{
		document.getElementById("name_"+intRowId).innerHTML = document.getElementById("input_name_"+intRowId).value;
		booModeEdit = false;
	}
}

function nameValid(intRowId)
{
	if(intCurrentRowId == intRowId)
	{ 
		var intId = document.getElementById("rank_id_"+intRowId).innerHTML;
		var strName = document.getElementById("input_name_"+intRowId).value;
		document.getElementById("name_"+intRowId).innerHTML = strName;
		loadData('admin', 'content', 'action=set_header_name&id='+encodeURIComponent(intId)+'&header_name='+encodeURIComponent(strName));
		booModeEdit = false;
	}
}

function rankClick(intRowId)
{
	if(document.getElementById("rank_"+intRowId).innerHTML.substr(0, 1) != '<' && booModeEdit == false)
	{
		booModeEdit = true;
		document.getElementById("rank_"+intRowId).innerHTML = '<input id=\"input_row_'+intRowId+'\" class=\"col_22_input\" value="'+document.getElementById("rank_"+intRowId).innerHTML+'" /><p><a href="#" onClick="rankCancel('+intRowId+'); return false;">Annuler</a> <a href="#" onClick="rankValid('+intRowId+'); return false;">Valider</a></p>';
		document.getElementById("input_row_"+intRowId).focus();
		document.getElementById("rank_"+intRowId).backgroundColor = '#CCCCCC';
	}
}

function rankCancel(intRowId)
{
	if(intCurrentRowId == intRowId)
	{
		document.getElementById("rank_"+intRowId).innerHTML = document.getElementById("input_row_"+intRowId).value;
		booModeEdit = false;
	}
}

function rankValid(intRowId)
{
	if(intCurrentRowId == intRowId)
	{ 
		var intId = document.getElementById("rank_id_"+intRowId).innerHTML;
		var intRank = document.getElementById("input_row_"+intRowId).value;
		document.getElementById("rank_"+intRowId).innerHTML = intRank;
		loadData('admin', 'content', 'action=set_header_rank&id='+encodeURIComponent(intId)+'&header_rank='+encodeURIComponent(intRank));
		booModeEdit = false;
	}
}

function statusClick(intRowId)
{
	if(booModeEdit == false)
	{
		var intId = document.getElementById("rank_id_"+intRowId).innerHTML;
		if(document.getElementById("status_"+intRowId).className == 'en_ligne')
			loadData('admin', 'content', 'action=set_header_status&id='+encodeURIComponent(intId)+'&header_status=0');
		else
			loadData('admin', 'content', 'action=set_header_status&id='+encodeURIComponent(intId)+'&header_status=1');
	}
}

function delClick(intRowId)
{
	var intId = document.getElementById("rank_id_"+intRowId).innerHTML;
	loadData('admin', 'content', 'action=delete_header&id='+encodeURIComponent(intId));
}