/****************************************

	scripts.js

	Set of generic functions designed to work
	with web sites

*****************************************/
var SiteExt = "php";

/***********************************************
*
*		Function: strReplace
*		Description: Simple search and replace function
*
***********************************************/
function strReplace(s, r, w){
     return s.split(r).join(w);
}

/***********************************************
*
*		Function: ReplaceHTMLEntities
*		Description: Restores pesky html items in forms
*
***********************************************/
function ReplaceHTMLEntities(template)
{
template = strReplace(template,"<!textarea","</textarea");
template = strReplace(template,"%form","<form");
template = strReplace(template,"<!form","</form");
template = strReplace(template,"%nbsp%","&nbsp;");
template = strReplace(template,"%amp%","&amp;");
template = strReplace(template,"%quot%","&quot;");
template = strReplace(template,"%lt%","&lt;");
template = strReplace(template,"%gt%","&gt;");
template = strReplace(template,"%copy;%"	,"&copy;"	);
template = strReplace(template,"%reg;%"		,"&reg;"	);
template = strReplace(template,"%cent;%"	,"&cent;"	);
template = strReplace(template,"%pound;%"	,"&pound;");
template = strReplace(template,"%yen;%"		,"&yen;"	);
template = strReplace(template,"%euro;%"	,"&euro;"	);
template = strReplace(template,"%sect;%"	,"&sect;"	);

return template;
}

/***********************************************
*
*		Function: ImagePicker
*		Description: Open the image picker window for
*			selected image type.  Checks if the FCK is
*			availible, or defaults to the old system
*
***********************************************/
var PickerType = false;
var Picker_Type;
function ImagePicker(type)
{
	if(PickerType == false)
	{
		Picker_Type = type
	    var myAjax = new Ajax.Request(
        "../fckeditor/editor/filemanager/browser/default/browser.html",
        {method: 'head', onSuccess: runPicker_fck, on405: runPicker_fck, on404: runPicker_old });
  }
  else if(PickerType == "fck")
  {
  	ImagePicker_fck(type);
  }
  else if(PickerType == "old")
  {
  	ImagePicker_old(type);
  }

}
function runPicker_fck(httpdata)
{
	ImagePicker_fck(Picker_Type);
	Picker_Type = false;
}

function runPicker_old(httpdata)
{
	ImagePicker_old(Picker_Type);
	Picker_Type = false;
}

/***********************************************
*
*		Function: ImagePicker_fck
*		Description: Open the FCK image picker window for
*			selected image type.
*
***********************************************/
function ImagePicker_fck(type)
{
	PickerType = "fck";
  var width=850, height=600;
  var left = 10;
  var top = 10;
//	OpenFileBrowser('../fckeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/'+SiteExt+'/connector.'+SiteExt+'&Type='+type,width,height);
	OpenFileBrowser('../fckeditor/editor/filemanager/browser/default/browser.html?Connector=..%2F..%2Fconnectors%2F'+SiteExt+'%2Fconnector.'+SiteExt+'&Type='+type,width,height);

}

/***********************************************
*
*		Function: ImagePicker_old
*		Description: Open the old image picker window for
*			selected image type.
*
***********************************************/
function ImagePicker_old(type)
{
	PickerType = "old";
  var width=850, height=600;
  var left = 10;
  var top = 10;
  var styleStr = 'toolbar=no,location=no,dependent=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("ImagePicker." + SiteExt + "?ImageType="+type,"msgWindow", styleStr);
  if (msgWindow.opener == null) msgWindow.opener = self;

}

/***********************************************
*
*		Function: ImagePicker
*		Description: Open the image picker window for
*			selected image type.
*
***********************************************/
function GalleryPicker(field, form) {
	if(form == '') form = "form1";
	var url = '../fckeditor/editor/plugins/g2image/g2image.php?g2ic_form='+form+'&g2ic_field='+field+'&g2ic_tinymce=0';
	var name = 'g2image';
	var w = 800;
	var h = 600;
	var valLeft = (screen.width) ? (screen.width-w)/2 : 0;
	var valTop = (screen.height) ? (screen.height-h)/2 : 0;
	var features = 'width='+w+',height='+h+',left='+valLeft+',top='+valTop+',resizable=1,scrollbars=1';
	window.open(url, name, features);
}

/***********************************************
*
*		Function: OpenFileBrowser
*		Description: Open the image picker window for
*			selected image type.
*
***********************************************/
function OpenFileBrowser( url, width, height )
{
	// oEditor must be defined.
	
	var iLeft = (screen.width   - width ) / 2 ;
	var iTop  = ( screen.height - height ) / 2 ;

	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;

	// The "PreserveSessionOnFileBrowser" because the above code could be 
	// blocked by popup blockers.
/*	if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
	{
		// The following change has been made otherwise IE will open the file 
		// browser on a different server session (on some cases):
		// http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
		// by Simone Chiaretta.
		var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
		if ( oWindow )
			oWindow.opener = window ;
		else
			alert( oEditor.FCKLang.BrowseServerBlocked ) ;
    }
    else
*/		window.open( url, 'FCKBrowseWindow', sOptions ) ;
}


/***********************************************
*
*		Function: SetUrl
*		Description: 
*
***********************************************/
function SetUrl(imagefile)
{
	var file = new File.Basename(imagefile,File.Basename.UNIX);
	var dir = strReplace(imagefile, file.basename(), '');
	dir = dir.substring(dir.indexOf('/images/') + 8);
	ImageReturn(file.basename(), dir);
}


/***********************************************
*
*		Function: OpenWindow
*		Description: Standard Window opening function
*
***********************************************/
function OpenWindow( url, winname, width, height )
{
	// oEditor must be defined.

	var iLeft = (screen.width   - width ) / 2 ;
	var iTop  = ( screen.height - height ) / 2 ;
	winname = strReplace(winname, " ","_");

	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes" ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;

	// The "PreserveSessionOnFileBrowser" because the above code could be
	// blocked by popup blockers.
	var msgWindow = window.open( url, winname, sOptions ) ;
	if (msgWindow.opener == null) msgWindow.opener = self;
}


/***********************************************
*
*		Function: fixhtml
*		Description: Restores troublsome html to normal for editing
*
***********************************************/
var htmlfixed = 0;
function fixhtml(textfield)
{
	if( htmlfixed == 0 && !isNull(document.getElementById(textfield)) )
	{
		var cbody = document.getElementById(textfield);
		cbody.value = ReplaceHTMLEntities(cbody.value);
	}
}

/***********************************************
*
*		Function: starteditor
*		Description: Starts the FCKeditor in the
*			textfield.  Checks to make sure it isn't
*			started more than once.
*
***********************************************/
var EditorStarted = Array();
function starteditor(textfield)
{
// Automatically calculates the editor base path based on the _samples directory.
// This is usefull only for these samples. A real application should use something like this:
// oFCKeditor.BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
	if(EditorStarted[textfield] != 1)
	{
		fixhtml(textfield);

		var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('admin/'))+'fckeditor/' ;

		var oFCKeditor = new FCKeditor( textfield ) ;
		oFCKeditor.BasePath	= sBasePath ;
		oFCKeditor.Height = 400;
		oFCKeditor.ReplaceTextarea();

		EditorStarted[textfield] = 1;
	}
}

/***********************************************
*
*		Function: moveOptions
*		Description: Moves items from one select box to another
*			selFromName	= Starting select
*			selToName		= Ending Select
*			bMoveAll		= 1 to move all or 0 only move selected
*			moveAction	= 0 Update Both Lists, 1 Update only Start list, 2 Update only End List
*
*			Required select box to be in div tag with same name and "_div" suffix.
*
*		Add <a href="javascript:moveOptions('Select1','Select2', false, 0)">
*		Remove <a href="javascript:moveOptions('Select2','Select1', false, 0)">
*
***********************************************/
function moveOptions(selFromName, selToName, bMoveAll, moveAction)
{
	var selFrom = document.getElementById(selFromName);
	var selTo = document.getElementById(selToName);

	if (selFrom.selectedIndex >= 0 || bMoveAll || moveAction == 3)
	{
		var divFrom = document.getElementById(selFromName + "_div");
		var divTo = document.getElementById(selToName + "_div");

		var scrollFrom = 0;
		var saNewFrom = new Array(selFrom.options.length + selTo.options.length);
		var saNewTo = new Array(selFrom.options.length + selTo.options.length);
		var j=0;
		var k=0;
		for (var i=0; i < selTo.options.length; i++)
		{
			saNewTo[j] = "<option " + (selTo.options[i].selected ? "selected " : "") + "value=\"" + selTo.options[i].value + "\">" + selTo.options[i].text;
			if (j == 0)
				{
					var s = "";
					while ((selTo.options[i].text.length + s.length) < 40)
						s += "\xA0";
					saNewTo[j] += s;
				}
			j++;
		}
		for (var i=0; i < selFrom.options.length; i++)
		{
			if ((selFrom.options[i].selected || bMoveAll) && moveAction != 3)
			{
				saNewTo[j] = "<option " + (selFrom.options[i].selected ? "selected " : "") + "value=\"" + selFrom.options[i].value + "\">" + selFrom.options[i].text;
				if (j == 0)
				{
					var s = "";
					while ((selFrom.options[i].text.length + s.length) < 40)
						s += "\xA0";
					saNewTo[j] += s;
				}
				j++;
				scrollFrom = i-1;
			}
			else
			{
				saNewFrom[k] = "<option " + (selFrom.options[i].selected ? "selected " : "") + "value=\"" + selFrom.options[i].value + "\">" + selFrom.options[i].text;
				if (k == 0)
				{
					var s = "";
					while ((selFrom.options[i].text.length + s.length) < 40)
						s += "\xA0";
					saNewFrom[k] += s;
				}
				k++;
			}
		}


		//Update the lists
		if(moveAction == 1 || moveAction == 0 || moveAction == 3)
		{
		var sFrom;
		if (document.all)
		{
			sFrom = "<select name=\"" + selFrom.name + "\" id=\"" + selFrom.id + "\" size=\"" + k + "\" multiple=\"multiple\"";
			if (k>30)
				sFrom += " style=\"margin-top:-3px; margin-left:-3px; font-size:12px\">";
			else if (k>0)
				sFrom += " style=\"height:100px; margin-top:-3px; margin-left:-3px; font-size:12px\">";
			else
				sFrom += " style=\"visibility:hidden;\">";
		}
		else
		{
			sFrom = "<select name=\"" + selFrom.name + "\" id=\"" + selFrom.id + "\" multiple=\"multiple\" style=\"overflow:auto;width:210px;height:100px;font-size:12px\">";
		}
		sFrom += saNewFrom.join('');
		sFrom += "</select>";
		divFrom.innerHTML = sFrom;
		selFrom = document.getElementById(divFrom.id.substr(0,divFrom.id.length-4));
		}

		if(moveAction == 2 || moveAction == 0 || moveAction == 3)
		{
		var sTo;
		if (document.all)
		{
			sTo = "<select name=\"" + selTo.name + "\" id=\"" + selTo.id + "\" size=\"" + j + "\" multiple=\"multiple\"";
			if (j>30)
				sTo += " style=\"margin-top:-3px; margin-left:-3px; font-size:12px\">";
			else if (j>0)
				sTo += " style=\"height:100px; margin-top:-3px; margin-left:-3px; font-size:12px\">";
			else
				sTo += " style=\"visibility:hidden;\">";
		}
		else
		{
			sTo = "<select name=\"" + selTo.name + "\" id=\"" + selTo.id + "\" multiple=\"multiple\" style=\"overflow:auto;width:210px;height:100px;font-size:12px\">";
		}
		sTo += saNewTo.join('');
		sTo += "</select>";
		divTo.innerHTML = sTo;
		selTo = document.getElementById(divTo.id.substr(0,divTo.id.length-4));
		}
		//wait a msec, and then scroll the lists
		if (scrollFrom < selFrom.options.length && scrollFrom >=0)
			window.setTimeout("var selFrom = document.getElementById('" + selFrom.id + "'); selFrom.selectedIndex=" + scrollFrom + "; selFrom.options[" + scrollFrom + "].selected=false;",1);
		if (selTo.options.length > 0)
			window.setTimeout("var selTo = document.getElementById('" + selTo.id + "'); selTo.options[selTo.options.length-1].selected=selTo.options[selTo.options.length-1].selected;",1);

	}
}

/***********************************************
*
*		Function: allSelect
*		Description: Selects all items in a select field
*
***********************************************/
function allSelect(selectname)
{
  List = document.getElementById(selectname);
  for (i=0;i<List.length;i++)
  {
     List.options[i].selected = true;
  }
}


/***********************************************
*
*		Function: menuswitch
*		Description: Switches classes to hide items.
*
***********************************************/
function menuswitch(menutag)
{
	var MenuTags = Cookie.get("MenuTag");
	if(!isNull(MenuTags))
	{
		var MenuArray = MenuTags.split(";");
		var item = -1;
		for(var i=0; i < MenuArray.length; i++)
		{
			var MenuItem = MenuArray[i].split(",");
			if(MenuItem[0] == menutag.id)
			{
				item = i;
				break;
			}
		}
	}
	else
	{
		var MenuArray = Array();
		var item = 0;
	}
	if(item == -1)
		item = MenuArray.length;

	if( menutag.className == "MenuOpen" )
	{
		MenuArray[item] = menutag.id+",MenuClosed";
		menutag.className = "MenuClosed";
	}
	else
	{
		MenuArray[item] = menutag.id+",MenuOpen";
		menutag.className = "MenuOpen";
	}
	Cookie.set("MenuTag",MenuArray.join(";"));

}

/***********************************************
*
*		Function: RecallMenus
*		Description: 
*
***********************************************/
function RecallMenus()
{
	var MenuTags = Cookie.get("MenuTag");
	if(!isNull(MenuTags))
	{
		var MenuArray = MenuTags.split(";");
		var item = 0;
		for(var i=0; i < MenuArray.length; i++)
		{
			var MenuItem = MenuArray[i].split(",");
			if($(MenuItem[0]))
			{
				$(MenuItem[0]).className = MenuItem[1];
			}
		}		
	}

	MenuTags = Cookie.get("ToggleTag");
	if(!isNull(MenuTags))
	{
		var MenuArray = MenuTags.split(";");
		var item = 0;
		for(var i=0; i < MenuArray.length; i++)
		{
			var MenuItem = MenuArray[i].split(",");
			if($(MenuItem[0]))
			{
				$(MenuItem[0]).style.display = MenuItem[1];
			}
		}		
	}
}

/***********************************************
*
*		Function: MemoryToggle
*		Description: 
*
***********************************************/
function MemoryToggle(field, toggletype)
{
	var MenuTags = Cookie.get("ToggleTag");
	var menutag = $(field);
	if(!isNull(MenuTags))
	{
		var MenuArray = MenuTags.split(";");
		var item = -1;
		for(var i=0; i < MenuArray.length; i++)
		{
			var MenuItem = MenuArray[i].split(",");
			if(MenuItem[0] == menutag.id)
			{
				item = i;
				break;
			}
		}
	}
	else
	{
		var MenuArray = Array();
		var item = 0;
	}
	if(item == -1)
		item = MenuArray.length;

	if( menutag.style.display == "none" )
	{
		MenuArray[item] = menutag.id+",";
	}
	else
	{
		MenuArray[item] = menutag.id+",none";
	}
	Effect.toggle(field, toggletype);
	Cookie.set("ToggleTag",MenuArray.join(";"));
}

/***********************************************
*
*		Function: tabswitch
*		Description: Switches classes to hide and
*			unhide tabs.
*
***********************************************/
function tabswitch(currenttag, list)
{
	if(list.indexOf(",") != -1)
	{
		tablist = list.split(",");
		for(i=0; i < tablist.length; i++)
		{
			if(!isNull(document.getElementById(tablist[i])))
				document.getElementById(tablist[i]).className="MenuClosed";
			if(!isNull(document.getElementById(tablist[i] + "_button")))
				document.getElementById(tablist[i] + "_button").className="MenuTabs";
		}
	}
	else
		document.getElementById(list).className="MenuClosed";

	TagOpen = document.getElementById(currenttag);
	if(!isNull(TagOpen))
		TagOpen.className = "MenuOpen";

	TagOpenButton = document.getElementById(currenttag + "_button");
	if(!isNull(TagOpenButton))
		TagOpenButton.className = "MenuTabs_Active";
}

/***********************************************
*
*		Function: SwitchSort
*		Description: 
*
***********************************************/
function SwitchSort(sortable,currsort)
{
	if(currsort == sortable.form.Sort.value)
	{
		if(sortable.value == "") {
			sortable.value = "DESC"
		}
		else {
			sortable.value = ""
		}
	}
	else
	{
		sortable.value = ""
	}
}

/***********************************************
*
*		Function: showBrowserSize
*		Description: Information function used for debugging
*
***********************************************/
function showBrowserSize()
{
	var winW = 630, winH = 460;

	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth;
	  winH = document.body.offsetHeight;
	 }
	}

	alert(
	 "Window width = "+winW+"\n"
	+"Window height = "+winH
	)
}
/***********************************************
*
*		Function: getQueryVariable
*		Description: 
*
***********************************************/
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return false;
}

/***********************************************
*
*		Function: ajax_request
*		Description: Requires the prototype library
*
***********************************************/
function ajax_request(url, data, returnfunc) {
    var myAjax = new Ajax.Request(
        url +  "." + SiteExt,
        {method: 'post', parameters: data, onComplete: returnfunc}
    );
}

/***********************************************
*
*		Function: ajax_request
*		Description: Requires the prototype library
*
***********************************************/
function ajax_response(originalRequest) {
    if(!bHasRedirect) {
        //process originalRequest.responseText;
    }
    else {
        bHasRedirect = false;
        ajax_request(originalRequest.responseText, "");
    }
}

/***********************************************
*
*		Function: isObject
*		Description:
*
***********************************************/
function isObject(a)
{
     return (typeof a == 'object' && !!a) || isFunction(a);
}

/***********************************************
*
*		Function: isUndefined
*		Description:
*
***********************************************/
function isUndefined(a)
{
     return typeof a == 'undefined';
}

/***********************************************
*
*		Function: isNull
*		Description:
*
***********************************************/
function isNull(a)
{
      return typeof a == 'object' && !a;
}

/***********************************************
*
*		Function: isFunction
*		Description:
*
***********************************************/
function isFunction(a)
{
      return typeof a == 'function';
}

/***********************************************
*
*		Function: isEmpty
*		Description:
*
***********************************************/
function isEmpty(o)
{
      if (isObject(o))
  {
           for (var i in o)
   {
                return false;
           }
      }
      return true;
}

/***********************************************
*
*		Function: isBoolean
*		Description:
*
***********************************************/
function isBoolean(a)
{
      return typeof a == 'boolean';
}

/***********************************************
*
*		Function: isArray
*		Description:
*
***********************************************/
function isArray(a)
{
  return isObject(a) && a.constructor == Array;
}

/***********************************************
*
*		Function: isNumeric
*		Description:
*
***********************************************/
function isNumeric(a)
{
	NumRegExp = /^-{0,1}\d*\.{0,1}\d+$/g
	
	if(NumRegExp.test(a))
	{
		return true;
	}
	else
	{
		return false;
	}
}

/***********************************************
*
*		Function: in_array
*		Description:
*
***********************************************/
function in_array(needle, haystack){
	return ('_|_'+ haystack.join('_|_') +'_|_').indexOf('_|_' + needle + '_|_') > -1;
}

/***********************************************
*
*		Function: trim
*		Description:
*
***********************************************/
function trim(str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}
/***********************************************
*
*		Function: setActiveStyleSheet
*		Description:
*
***********************************************/
var oldLink = null;
// code to change the active stylesheet
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
		  if(isFunction(Cookie.set))
			  Cookie.set("LoadedStyle",title);
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}
/***********************************************
*
*		Function: StyleSheetList
*		Description:
*
***********************************************/
function StyleSheetList(idName) {
  var i, a, main, nodes, StyleLink;
  var nodes =	Builder.node('div',{
				id: 'Stylesheets',
				className: "Stylesheets",
				style: "display:none;"
				});
	var nodeContainer = Builder.node('div');
	nodes.appendChild(nodeContainer);
	var Loaded = Cookie.get("LoadedStyle");
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			StyleLink = Builder.node('span',{
			onclick: "setActiveStyleSheet(this,'" + a.getAttribute("title") + "');",
			style: "",
			className: "Clickable"
			},a.getAttribute("title") + ' ');
			if(isNull(Loaded) && a.getAttribute("rel").indexOf("alternate") == -1)
			{
				StyleLink.style.fontWeight = 'bold';	
				oldLink = StyleLink;
			}
			else if(!isNull(Loaded) && Loaded == a.getAttribute("title"))
			{
				setActiveStyleSheet(StyleLink,a.getAttribute("title"))
			}
			nodeContainer.appendChild(StyleLink);
    }
  }
  idName.appendChild(nodes);
}

/***********************************************
*
*		Function: checkAll
*		Description: Takes a form field and checks all the boxes
*			ie. checkAll(document.form1.fields)
*
***********************************************/
function checkAll(field)
{
	var i;
	if(isUndefined(field.length))
	{
		field.checked = true;
		if(isFunction(field.onclick))
			field.onclick();
		if(isFunction(field.onchange))
			field.onchange();
	}
	else
	{
		for (i = 0; i < field.length; i++)
		{
			field[i].checked = true ;
			if(isFunction(field[i].onclick))
				field[i].onclick();
			if(isFunction(field[i].onchange))
				field[i].onchange();
		}
	}
}
/***********************************************
*
*		Function: checkAll_form
*		Description: Takes a form field and checks all the boxes
*			ie. checkAll_form($('fields').form, 'fields')
*
***********************************************/
function checkAll_form(formfield,fieldname)
{
	var i;
	for (i = 0; i < formfield.length; i++)
	{
		if(formfield[i].name == fieldname)
		{
			formfield[i].checked = true ;
			if(isFunction(formfield[i].onclick))
				formfield[i].onclick();
			if(isFunction(formfield[i].onchange))
				formfield[i].onchange();
		}
	}
}

/***********************************************
*
*		Function: uncheckAll
*		Description: Takes a form field and unchecks all the boxes
*			ie. uncheckAll(document.form1.fields)
*
***********************************************/
function uncheckAll(field)
{
	var i;
	if(isUndefined(field.length))
	{
		field.checked = false;
		if(isFunction(field.onclick))
			field.onclick();
		if(isFunction(field.onchange))
			field.onchange();
	}
	else
	{
		for (i = 0; i < field.length; i++)
		{
			field[i].checked = false ;
			if(isFunction(field[i].onclick))
				field[i].onclick();
			if(isFunction(field[i].onchange))
				field[i].onchange();
		}
	}
}
/***********************************************
*
*		Function: uncheckAll_form
*		Description: Takes a form field and unchecks all the boxes
*			ie. uncheckAll_form($('fields').form, 'fields')
*
***********************************************/
function uncheckAll_form(formfield,fieldname)
{
	var i;
	for (i = 0; i < formfield.length; i++)
	{
		if(formfield[i].name == fieldname)
		{
			formfield[i].checked = false ;
			if(isFunction(formfield[i].onclick))
				formfield[i].onclick();
			if(isFunction(formfield[i].onchange))
				formfield[i].onchange();
		}
	}
}

/***********************************************
*
*		Function: uncheckAll_form2
*		Description: Takes a form field and unchecks all the boxes
*			ie. uncheckAll_form($('fields').form, 'fields')
*
***********************************************/
function uncheckAll_form2(field, formfield,fieldname)
{
	var i;
	for (i = 0; i < formfield.length; i++)
	{
		if(formfield[i].name == fieldname && formfield[i].id != field.id)
		{
			formfield[i].checked = false ;
			if(isFunction(formfield[i].onclick))
				formfield[i].onclick();
			if(isFunction(formfield[i].onchange))
				formfield[i].onchange();
		}
	}
}

/***********************************************
*
*		Function: uncheckAll_form2
*		Description: Takes a form field and unchecks all the boxes
*			ie. uncheckAll_form($('fields').form, 'fields')
*
***********************************************/
function uncheckHeaders_form(formfield,fieldname)
{
	var i;
	for (i = 0; i < formfield.length; i++)
	{
		if(formfield[i].name == fieldname && formfield[i].id.substring(0,2) == "H_")
		{
			formfield[i].checked = false ;
			Chkbox2List(strReplace(fieldname,'[]','') + '_text',formfield[i]);
//			if(isFunction(formfield[i].onclick))
//				formfield[i].onclick();
			if(isFunction(formfield[i].onchange))
				formfield[i].onchange();
		}
	}
}


/***********************************************
*
*		Function: Chkbox2List
*		Description: 
*
***********************************************/
function Chkbox2List(list, field)
{
	list = $(list);
	var listarray = list.innerHTML.split(";");
	
	if(field.checked && !in_array(field.title, listarray))
	{
		list.innerHTML = list.innerHTML + (list.innerHTML == "" ? "": ";") + field.title;
	}
	else if(!field.checked && in_array(field.title, listarray))
	{
		list.innerHTML = strReplace(list.innerHTML, field.title, "");
		list.innerHTML = strReplace(list.innerHTML, ";;", ";");
		if(list.innerHTML.substring(list.innerHTML.length -1) == ";")
			list.innerHTML = list.innerHTML.substring(0,list.innerHTML.length -1);
	}
}

/***********************************************
*
*		Function: MultipleDelete
*		Description: 
*
***********************************************/
function MultipleDelete(formElement, confirmMessage, EditScript)
{
	if(confirm(confirmMessage))
	{
//		formElement.action=EditScript;
		$('Command').value='DeleteMultiple';
		var PostData = Form.serialize(formElement) + "&Ajax=1";
		ajax_request(strReplace(EditScript,"." + SiteExt,""), PostData, MultipleDeleteReturn);
	}
}

/***********************************************
*
*		Function: MultipleDeleteReturn
*		Description: 
*
***********************************************/
function MultipleDeleteReturn(httpdata, oJSN)
{
	var ReturnData = httpdata.responseText;

	if(oJSN == "DeleteMultiple")
	{
		var DataArray = json_parse(ReturnData, null);
		for (idField in DataArray)
		{
			if(!isNumeric( idField))
			{
				var idArray = DataArray[idField].split(',');
				for(var i=0; i < idArray.length; i++)
				{
					var RowElement = $("Data-" + idField + "-" + idArray[i]);
					if(RowElement)
						RowElement.parentNode.removeChild(RowElement);
				}
			}
		}

	}
	else
	{
		alert("An Error Occurred durring Delete. " + ReturnData);
	}
}


/***********************************************
*
*		Function: include_dom
*		Description: Includes Javascript files.
*
***********************************************/
function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

/***********************************************
*
*		Function: include_once
*		Description: Includes Javascript files.
*
***********************************************/
var included_files = new Array();
function include_once(script_filename) {
    if (!in_array(script_filename, included_files)) {
        included_files[included_files.length] = script_filename;
        include_dom(script_filename);
    }
}


if(isUndefined(ScriptDirHeader))
{
	var ScriptDirHeader = "../";
}

include_dom(ScriptDirHeader + "includes/titles/addEvent.js");
include_dom(ScriptDirHeader + "includes/titles/sweetTitles.js");
//include_dom(ScriptDirHeader + "includes/ajax/prototype.js");
//include_dom(ScriptDirHeader + "includes/ajax/scriptaculous.js");  // Causes a crash in IE
include_dom(ScriptDirHeader + "includes/ajax/unittest.js");
include_dom(ScriptDirHeader + "includes/ajax/custom.js");
include_dom(ScriptDirHeader + "fckeditor/fckeditor.js");
include_dom(ScriptDirHeader + "includes/json_parse.js");



