function errorHandler(message)
{
	$('disabledZone').style.visibility = 'hidden';
    if (typeof message == "object" && message.name == "Error" && message.description)
    {
        alert("Error: " + message.description);
    }
    else
    {
        alert(message);
    }
}

function pageHeight2 () {
	var winHeight = 480, myHeight;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	
	if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
		  winHeight = window.innerHeight;
		 }
	if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winHeight = document.body.offsetHeight;
	 }
	}
	
	if (test1 > test2) // all but Explorer Mac
	{
		myHeight = document.body.scrollHeight;
	}
	else // Explorer Mac;
	     //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		myHeight = document.body.offsetHeight;
	}

	alert(winHeight + '/' + myHeight);	
	if (winHeight > myHeight) myHeight = winHeight;

	return myHeight;
}

function pageHeight () {
	var myHeight = 500;

	if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myHeight = document.body.clientHeight;
	  }
	return myHeight;
}

function toggle(theID) {
foo = document.getElementById(theID);
if (foo.style.display == 'none') foo.style.display = 'inline';
else foo.style.display = 'none';
return;
}

// this function puts the dark screen over the entire page
function dark()
{
   var myHeight = pageHeight();	
   var page_screen = document.getElementById('page_screen');
   page_screen.style.height = myHeight + 'px';
   page_screen.style.display = 'block';
}

// this function removes the dark screen and the page is light again
function light()
{
   var page_screen = document.getElementById('page_screen');
   page_screen.style.display = 'none';
}

function stripNonAlphaNumeric(str) {
  var r = str.replace(/[^a-zA-Z0-9]+/g,'');
  return r;
}

function fixString(str) {
  var r = str.replace(/"/g,"'");
  r = r.replace(/#/g, "");
  r = r.replace(/''/g,"' '");
  return r;
}

function editContent(groupID,blockID,instanceID,wysiwyg) {
	//DWRUtil.useLoadingMessage();
	DWREngine._execute(_cfscriptLocation,null,'makeEditContent',groupID,blockID,instanceID,wysiwyg,showEdit);
	return false;
}

function editHeader(groupID,blockID,instanceID) {
	//DWRUtil.useLoadingMessage();
	DWREngine._execute(_cfscriptLocation,null,'makeEditHeader',groupID,blockID,instanceID,showEdit);
	return false;
}

function showEdit(editContent) {
	var foo = document.getElementById('editWindow');
	var bar = document.getElementById('editContent');
	var winW = 630, winH = 460; w=850; h=600;
	var xc,yc;
	
	if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    winW = window.innerWidth;
	    winH = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    winW = document.documentElement.clientWidth;
	    winH = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    winW = document.body.clientWidth;
	    winH = document.body.clientHeight;
	  }
		 
    xc = Math.round((winW/2)-(w/2))
    yc = Math.round((winH/2)-(h/2))
    
    foo.style.left = xc + "px";
    foo.style.top  = yc + "px";
    foo.style.display = 'block';
	bar.innerHTML = editContent;

	dark();
}

function hideEdit() {
	var foo = document.getElementById('editWindow');
	var bar = document.getElementById('editContent');
	bar.innerHTML = '';
	foo.style.display='none';
	light();
}

function updateContent (groupID,blockID,instanceID,new_Content,escapeFlag) {
	var sendContent = new_Content;
	if(escapeFlag) sendContent = escape(new_Content);
	DWREngine._execute(_cfscriptLocation,null,'update_Content',groupID,blockID,instanceID,sendContent,escapeFlag,doneEdit);
	return false;
}

function updateHeader (groupID,blockID,instanceID,new_Content) {
	//DWRUtil.useLoadingMessage();
	DWREngine._execute(_cfscriptLocation,null,'update_Header',groupID,blockID,instanceID,new_Content,doneEdit);
	return false;
}

function doneEdit(doneArray) {
	// array is [groupID,blockID,instanceID,newContent]
	var foo = document.getElementById('miniCMS_' + doneArray[0] + '_' + doneArray[1] + '_' + doneArray[2]);
	foo.innerHTML = doneArray[3];
	hideEdit();
}

function contactWindow() {
window.open('/contact.cfm','contactWindow','width=550,height=450,toolbar=no,scrollbars=no,resizable=yes');
}
