var page = 1;

function hide(id)
{
    if (document.getElementById(id).style.display == 'none') 
    	current = 'block' 
    else 
    	current = 'none';
    document.getElementById(id).style.display = current;
}

function PreviewCountry (flag, path)
{
	document.getElementById('CountryImg').src = path+'img/flags/'+flag+'.gif'; 
}

function addfckeditor(id, title, text, path) {
	
	var table = document.getElementById(id);

	var sBasePath = path + 'fckeditor/';
	var oFCKeditor = new FCKeditor('content[' + page + ']') ;
	
	oFCKeditor.Config["CustomConfigurationsPath"] = path + 'newseditor.js' ;
	oFCKeditor.BasePath	= sBasePath ;
	oFCKeditor.Height	= 500 ;
	oFCKeditor.Value	= text;
	
	var row1 = document.createElement('tr');
	var row2 = document.createElement('tr');
	
	var col1 = document.createElement('td');
	var col2 = document.createElement('td');
	var col3 = document.createElement('td');

	var input1 = document.createElement('input');
	var button1 = document.createElement('input');
	
	var text1 = document.createTextNode('Page - ' + page + ' - Title : ');
	
	input1.setAttribute('type', 'text');
	input1.setAttribute('name', 'title[' + page + ']');
	input1.setAttribute('value', title);
	
	button1.setAttribute('type', 'button');
	button1.setAttribute('value', 'Supprimer page');
	button1.setAttribute('onclick', 'removefckeditor(\'fckcontents\')');
	
	col1.style.width = '150px';
	
	col1.appendChild(text1);
	col2.appendChild(input1);
	col3.innerHTML = oFCKeditor.Create();
	
	col3.setAttribute('colSpan', 2);
	
	row1.appendChild(col1);
	row1.appendChild(col2);
	row2.appendChild(col3);
	
	table.appendChild(row1);
	table.appendChild(row2);

	page++;
}

function InsertHTML(value, type)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance('content[' + (page - 1) + ']') ;

	// Check the active editing mode.
	if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
	{
		switch(type) {
			case 'flag':
				value = '<img src="/img/flags/' + value + '.gif" alt="' + value + '" />'
				break;
		}
		// Insert the desired HTML.
		oEditor.InsertHtml(value) ;
	}
	else
		alert( 'You must be on WYSIWYG mode!' ) ;
}

function removefckeditor(id) {
	if(page > 1) {
		var table = document.getElementById(id);
		
		table.removeChild(table.lastChild);
		table.removeChild(table.lastChild);
		table.removeChild(table.lastChild);
	}
	page--;
}


function openWindow(url, w, h) {
	var options = "width=" + w + ",height=" + h + ",";
	options += "resizable=yes,scrollbars=yes,status=yes,";
	options += "menubar=no,toolbar=no,location=no,directories=no";
	var newWin = window.open(url, 'newWin', options);
	newWin.focus();
}