
//#######################################################
//#######################################################
//####
//#### Generic system routines
//####
//#######################################################
//#######################################################

//*******************************************************
//DROP A COOKIE
//
//Enter:
//PARAM 1: Cookie Name
//PARAM 2: Cookie Value
//PARAM 3: Cookie Expiry (in days)
//*******************************************************

function setCookie(c_name,value,exdays)
	{
	var exdate=new Date();		
	exdate.setDate(exdate.getDate() + exdays);

	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()+"; path=/");
	document.cookie=c_name + "=" + c_value;
	}

//*******************************************************
//RETRIEVE A COOKIE
//
//Enter:
//PARAM 1: Cookie Name
//*******************************************************

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
	{
  	x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  	y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  	x=x.replace(/^\s+|\s+$/g,"");
  	if (x==c_name)
    	{
    	return unescape(y);
    	}
  	}
return('');
}	
	
//*******************************************************
//GENERIC AJAX INVOKING ROUTINE
//
//Enter:
//PARAM 1: Routine to Run
//PARAM 2: String to Pass in
//PARAM 3: Routine to Execute on Return
//*******************************************************

function primeAjax(PARAM1,PARAM2,PARAM3)
	{
	if (window.XMLHttpRequest)
		{
		// code for IE7+, Firefix, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
	else if (window.ActiveXObject)
		{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	else
		{
		}
		
	xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4)
			{
			PARAM3(xmlhttp.responseText);
			}
		}	
		
//Start AJAX transaction
	
	xmlhttp.open("post",PARAM1,true);
	xmlhttp.send(PARAM2);				
	}

//#######################################################
//#######################################################
//####
//#### Individual Page Routines
//####
//#######################################################
//#######################################################

function nicEdit()
	{
    bkLib.onDomLoaded(function() {
			var myEditor=new nicEditor(
			{onSave : function(content, id, instance) {saveDoc(content);}},
			{fullPanel : true},
			{maxHeight : 100}).panelInstance('area1');

			myEditor.addEvent('key', function() {
				alert('plop');
				
			myEditor.addInstance('nicPara');
			});
		});
	}

function saveDoc(str)
	{

//SEND HTML FILE OVER AS ESCAPED HMTL WITH FILENAME OF CURRENT PAGE (PADDED OUT TO 48 BYTES)
//APPENDED TO BEGINNING 

	var html=escape(str).replace(/%/gi,'^');
	var pagename=document.location.href.split('=').pop()+"###################################################################################################";
	pagename=pagename.substr(0,64);
	primeAjax("http://www.coteghyll.com/cgi-bin/savedoc.cgi",pagename+html,docRes);		
	}
	
function docRes(str)
	{
	alert(str);
	}

