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 editorFormContent;
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:"800", width:"760"};
	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();
	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 editBannerContent()
{
	if ( editorBannerContent )
		return;

	var html = document.getElementById( 'bannerContent' ).innerHTML;
	document.getElementById( 'bannerContent' ).style.display = 'none';
	
	document.getElementById( 'editBannerContentButton' ).style.display = 'none';
	document.getElementById( 'saveBannerContentButton' ).style.display = '';
	document.getElementById( 'previewBannerContentButton' ).style.display = '';
	

	// Create a new editor inside the <div id="bannerContent">, setting its value to html
	var config = {height:"460", width:"760"};
	editorBannerContent = CKEDITOR.appendTo( 'bannerContentEditor', config, html );
	CKFinder.SetupCKEditor( editorBannerContent, '/3rdparty/ckfinder/' );
}

function previewBannerContent()
{
	if ( !editorBannerContent )
		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( 'bannerContent' ).innerHTML = editorBannerContent.getData();
	document.getElementById( 'bannerContent' ).style.display = '';
	
	document.getElementById( 'editBannerContentButton' ).style.display = '';
	document.getElementById( 'saveBannerContentButton' ).style.display = 'none';
	document.getElementById( 'previewBannerContentButton' ).style.display = 'none';
	
	// Destroy the editor.
	editorBannerContent.destroy();
	editorBannerContent = null;
}
function saveBannerContent()
{
	if ( !editorBannerContent )
		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( 'bannerContent' ).innerHTML = editorBannerContent.getData();
	document.getElementById( 'bannerContent' ).style.display = '';
	
	document.getElementById( 'editBannerContentButton' ).style.display = '';
	document.getElementById( 'saveBannerContentButton' ).style.display = 'none';
	document.getElementById( 'previewBannerContentButton' ).style.display = 'none';
	
    system_post("page_id="+page_id+"&saveBannerContent="+escape(document.getElementById( 'bannerContent' ).innerHTML));
	
	// Destroy the editor.
	editorBannerContent.destroy();
	editorBannerContent = null;
}


function editformFreeText($formitem_id)
{
	if ( editorFormContent )
		return;

	var html = document.getElementById( 'formContent'+$formitem_id ).innerHTML;
	
	document.getElementById( 'formContent'+$formitem_id ).style.display = 'none';
	document.getElementById( 'editFormContentButton'+$formitem_id ).style.display = 'none';
	document.getElementById( 'previewFormContentButton'+$formitem_id ).style.display = '';
	

	// Create a new editor inside the <div id="formContent">, setting its value to html
	var config = {height:"300", width:"760"};
	editorFormContent = CKEDITOR.appendTo( 'formContentEditor'+$formitem_id, config, html );
	CKFinder.SetupCKEditor( editorFormContent, '/3rdparty/ckfinder/' );
}

function previewformFreeText($formitem_id)
{
	if ( !editorFormContent )
		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( 'formContent'+$formitem_id ).innerHTML = editorFormContent.getData();
	document.getElementById( 'formContent'+$formitem_id ).style.display = '';
	
	document.getElementById( 'editFormContentButton'+$formitem_id ).style.display = '';
	document.getElementById( 'previewFormContentButton'+$formitem_id ).style.display = 'none';
	
	//Copy editor contents to a hidden field to POST
	document.getElementById( 'txtext'+$formitem_id ).value = escape(document.getElementById( 'formContent'+$formitem_id ).innerHTML);
	
	// Destroy the editor.
	editorFormContent.destroy();
	editorFormContent = 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 ){
		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){
			notifyTimeout=5000;
		}else{
			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);
	}else{

		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(editorNotifyContent.getData());
		var notify='';
		if (document.getElementById('notifyDelay').checked==true){
			notifyTimeout=5000;
		}else{
			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+"\" })";
		
		document.getElementById( 'notifyContent' ).innerHTML = editorNotifyContent.getData();
		document.getElementById('notifyContent').style.display='';
		
		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 ;
}
	//]]>
