function redirectJS(url) {
	window.location=url;
	}
function updateGalery(galeryId) {
	new Ajax.Updater("gal"+galeryId, "/_inc/afjm/galery.php", {parameters:{galid:galeryId},evalScripts:'true', method:'post'});
	P7_LSMop('p7LSM_'+galeryId,3,0,100,500,1,1,1,1,0,1,5,1,1,1,0,0,0,100,1);
}
function updateDocs(docsId) {
	new Ajax.Updater("doc"+docsId, "/_inc/afjm/docs.php", {parameters:{docCatId:docsId},evalScripts:'true', method:'post'});
}
function updateAdminDocs(docsId) {
	new Ajax.Updater("adminDocs", "/_admin/afjm/adminDocs.php", {parameters:{docCatId:docsId},evalScripts:'true', method:'post'});
}
// Target links by Marc Francey
function targetLinks(domain) {
	var instr = new Number;
	var linkTarget = new String;
	var hrefValue = new String ;
	for (var i=0; i<=(document.links.length-1); i++) {			
			  hrefValue = (document.links[i].href);
			  if ((hrefValue.indexOf(domain)==-1) || (hrefValue.indexOf("_pdf")!=-1)   || (hrefValue.indexOf(".pdf")!=-1) || (hrefValue.indexOf("_blank")!=-1 || (hrefValue.indexOf("w3.org")!=-1))) { 
				  linkTarget = "_blank";
				  }
				  else {
				  linkTarget = "_self";
					  }
			 if (hrefValue.indexOf("javascript") > -1) {
				 linkTarget = "_self";
				 }
				document.links[i].target = linkTarget;
			}
	
	var formObject = document.getElementsByTagName('form');
	for (f=0; f<formObject.length; f++) {
		if ((formObject[f].action.indexOf('_pdf')!=-1) || (formObject[f].action.indexOf('_blank')!=-1)) {
			formObject[f].target = '_blank';
			}		
		}	
	}
// CKEDITOR Dynamic edition scripts

function createEditor(editorId,toolbarParams,lng) {
	var dynVar = "editor"+editorId;
	var reg = new RegExp("[\|]+", "g");
	var toolbarCode = "";
	var toolbarsArray = toolbarParams.split(reg);
	for (var i=0;i<toolbarsArray.length;i++) {
		toolbarCode += "["+toolbarsArray[i]+"]";
		if (i!=toolbarsArray.length-1) {toolbarCode += ",'/',";}
	}
	if (eval(dynVar)) {return;}
	var html = document.getElementById("editor"+editorId+'htmlcontent').innerHTML;
	document.getElementById("editor"+editorId+'content').style.display = 'none';
	// Create a new editor inside the div id="editor">
	var creator = dynVar+"= CKEDITOR.appendTo('editor"+editorId+"',{toolbar:["+toolbarCode+"],contentsCss:'/_css/afjm/ckeditor.css',doctype:'<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Strict\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-strict.dtd\">',language:'"+lng+"'});";
	eval (creator);
	eval(dynVar).setData( html );
	document.getElementById("edit_editor"+editorId).style.display = 'none'; // Hide the edit button
	document.getElementById("save_editor"+editorId).style.display = 'inline'; // Show the save button
	document.getElementById("cancel_editor"+editorId).style.display = 'inline'; // Show the cancel button
}
function saveEditor(editorId,ajaxCall,field) {
	var dynVar = "editor"+editorId;
	if (!eval(dynVar)) {return;}
	// Retrieve the editor "editorId" content. In an Ajax application, this data would be
	// sent to the server or used in any other way.
	var htmlCode = eval(dynVar).getData();
	// Destroy the editor.
	eval(dynVar).destroy();
	var desctructor = dynVar+"=null;";
	eval(desctructor);
	document.getElementById("save_editor"+editorId).style.display = 'none'; // Hide the save button
	document.getElementById("cancel_editor"+editorId).style.display = 'none'; // Hide the cancel button
	document.getElementById("edit_editor"+editorId).style.display = 'inline'; // Show the edit button
	new Ajax.Request(ajaxCall, {
		method: 'post',
		parameters: {'contentId':editorId,'htmlCode':htmlCode,'field':field}, 
		onSuccess: function (transport){responseTxt = transport.responseText;},
		onComplete: function (response) {
			document.getElementById("editor"+editorId+'htmlcontent').innerHTML = responseTxt;
			document.getElementById("editor"+editorId+'content').style.display = '';
		}
	});
}
function closeEditor(editorId) {
	var dynVar = "editor"+editorId;
	if (!eval(dynVar)) {return;}
	document.getElementById("editor"+editorId+'content').style.display = '';
	eval(dynVar).destroy();
	var desctructor = dynVar+"=null;";
	eval(desctructor);	
	document.getElementById("save_editor"+editorId).style.display = 'none'; // Hide the save button
	document.getElementById("cancel_editor"+editorId).style.display = 'none'; // Hide the cancel button
	document.getElementById("edit_editor"+editorId).style.display = 'inline'; // Show the edit button
}
function showHideEditable(editorId,showhide) {
	if (showhide=="show") {	
		document.getElementById("editor"+editorId+"content").className = 'editorHighlight'; // Highlight editable region	
	}
	if (showhide=="hide") {	
		document.getElementById("editor"+editorId+"content").className = 'editorEditable';  // Downlight editable region	
	}
}