function system_replaceall(text, strA, strB)
{
    while ( text.indexOf(strA) != -1)
    {
        text = text.replace(strA,strB);
    }
    return text;
}
function system_post(params)
{
  var xmlhttp=false;
  try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
   }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  xmlhttp.open("POST","/ajax.php",false);
  //Send the proper header information along with the request
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-length", params.length);
  xmlhttp.setRequestHeader("Connection", "close");
  xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		//alert(xmlhttp.responseText);
	}
  }
  xmlhttp.send(params);
}
var globalurl='';
function linkclick(url,name)
{
  ajax_url='ajax.php?ajax_link_hit=1&url='+url+'&name='+name;
  globalurl=url;
  var xmlhttp=false;
  try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
   }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  xmlhttp.open("GET",ajax_url,true);
  xmlhttp.onreadystatechange = function() {
	if(xmlhttp.readyState == 4){
         window.open("http://"+globalurl);
       }
 }
  xmlhttp.send(null);
}
function showhide(object)
{
  if(document.getElementById(object).style.display=='none')
  {
    document.getElementById(object).style.display='';
  }
  else
  {
    document.getElementById(object).style.display='none';
  }
}

	//<![CDATA[

var editorPageContent;
var editorBannerContent;
var editorNotifyContent;

function editPageContent()
{
	if ( editorPageContent )
		return;

	var html = document.getElementById( 'pageContent' ).innerHTML;
	document.getElementById( 'pageContent' ).style.display = 'none';
	
	document.getElementById( 'editPageContentButton' ).style.display = 'none';
	document.getElementById( 'savePageContentButton' ).style.display = '';
	document.getElementById( 'previewPageContentButton' ).style.display = '';
	

	// Create a new editor inside the <div id="pageContent">, setting its value to html
	var config = {height:"300", width:"560", resize_minHeight:"400", resize_minWidth:"500"};
	editorPageContent = CKEDITOR.appendTo( 'pageContentEditor', config, html );
	CKFinder.SetupCKEditor( editorPageContent, '/3rdparty/ckfinder/' );
}
function previewPageContent()
{
	if ( !editorPageContent )
		return;

	// Retrieve the editor contents. In an Ajax application, this data would be
	// sent to the server or used in any other way.
	document.getElementById( 'pageContent' ).innerHTML = editorPageContent.getData();
	document.getElementById( 'pageContent' ).style.display = '';
	
	document.getElementById( 'editPageContentButton' ).style.display = '';
	document.getElementById( 'savePageContentButton' ).style.display = 'none';
	document.getElementById( 'previewPageContentButton' ).style.display = 'none';
	

	// Destroy the editor.
	editorPageContent.destroy();
	editorPageContent = null;
}
function savePageContent()
{
	if ( !editorPageContent )
		return;
	// Retrieve the editor contents. In an Ajax application, this data would be
	// sent to the server or used in any other way.
	document.getElementById( 'pageContent' ).innerHTML = editorPageContent.getData();
	if(escape(document.getElementById( 'pageContent' ).innerHTML)=='')
	{
		document.getElementById( 'pageContent' ).innerHTML='&nbsp;';
	}
	document.getElementById( 'pageContent' ).style.display = '';
    system_post("page_id="+page_id+"&savePageContent="+escape(document.getElementById( 'pageContent' ).innerHTML));
	
	document.getElementById( 'editPageContentButton' ).style.display = '';
	document.getElementById( 'savePageContentButton' ).style.display = 'none';
	document.getElementById( 'previewPageContentButton' ).style.display = 'none';
	
	
	// Destroy the editor.
	editorPageContent.destroy();
	editorPageContent = null;
}

function editNotification($notify_id){
	if ( editorNotifyContent ){
		document.getElementById('notifyContent').innerHTML=editorNotifyContent.getData();
		document.getElementById('notifyContentEditor').style.display='none';
		document.getElementById('notifyContent').style.display='';
		document.getElementById('editNotifyButton').value='Edit';
		document.getElementById('previewNotifyButton').style.display='';
		document.getElementById('saveNotifyButton').style.display='';
		// Destroy the editor.
		editorNotifyContent.destroy();
		editorNotifyContent = null;
	}else{
		var html = document.getElementById( 'notifyContent' ).innerHTML;
		document.getElementById( 'notifyContent' ).style.display = 'none';
		document.getElementById('notifyContentEditor').style.display='';
		document.getElementById('previewNotifyButton').style.display='none';
		document.getElementById('saveNotifyButton').style.display='none';
		document.getElementById('editNotifyButton').value='Close Editor';

		// Create a new editor inside the <div id="formContent">, setting its value to html
		var config = {height:"300", width:"760"};
		editorNotifyContent = CKEDITOR.appendTo( 'notifyContentEditor', config, html );
		CKFinder.SetupCKEditor( editorNotifyContent, '/3rdparty/ckfinder/' );
	}
}

function previewNotification(){
	//Execute notify with the selected parameters and content string.
	
	if ( editorNotifyContent ){
		document.getElementById( 'notifyContent' ).innerHTML = editorNotifyContent.getData();
		document.getElementById('notifyContent').style.display='';
	}

	var notifyTitle = document.getElementById('notifyTitle').value;
	var notifyIcon = document.getElementById('xFilePath').value;
	var notifyLink = document.getElementById('notifyLink').value;
	var notifyPosition = document.getElementById('notifyPosition').value;
	var notifyContent = escape(document.getElementById( 'notifyContent' ).innerHTML);
	var notify='';
	if (document.getElementById('notifyDelay').checked==true){
		var notifyTimeout=document.getElementById('notifyTimeout').value;
	}else{
		var notifyTimeout=false;
	}
	
	notify="$(\"#container-"+notifyPosition+"\").notify(\"create\", {title:\""+notifyTitle+"\", text:unescape(\""+notifyContent+"\")";
	if (notifyIcon.length > 0){
		notify=notify+", icon:\""+notifyIcon+"\"";
	}
	if (notifyLink.length > 0){
		notify=notify+"},{click:function(e,instance){window.open(\""+notifyLink+"\",\"_blank\");}";
	}
	notify=notify+"}, { expires:\""+notifyTimeout+"\" })";
	
	eval(notify);
	
}

function saveNotification(page_id){
	//Save the notification event
	if ( editorNotifyContent ){
		document.getElementById( 'notifyContent' ).innerHTML = editorNotifyContent.getData();
		document.getElementById('notifyContentEditor').style.display='none';
		document.getElementById('notifyContent').style.display='';
		// Destroy the editor.
		editorNotifyContent.destroy();
		editorNotifyContent = null;
	}
		
	ajax_notify_save(page_id);
}

function BrowseServer()
{
	// You can use the CKFinder class to render CKFinder in a page:
	var finder = new CKFinder() ;
	finder.BasePath = '/3rdparty/ckfinder/' ;	// The path for the installation of CKFinder (default = '/ckfinder/').
	finder.SelectFunction = SetFileField ;
	finder.Popup() ;

	// It can also be done in a single line, calling the 'static'
	// Popup( basePath, width, height, selectFunction ) function:
	// CKFinder.Popup( '../../', null, null, SetFileField ) ;
	//
	// The 'Popup' function can also accept an object as the only argument.
	// CKFinder.Popup( { BasePath : '../../', SelectFunction : SetFileField } ) ;
}

// This is a sample function which is called when a file is selected in CKFinder.
function SetFileField( fileUrl )
{
	document.getElementById( 'xFilePath' ).value = fileUrl ;
}
	//]]>
