document.getElementsByClass=function(tag, classname){
	var tagcollect=document.all? document.all.tags(tag): document.getElementsByTagName(tag); //IE5 workaround
	var filteredcollect=new Array();
	var inc=0;
	for (i=0;i<tagcollect.length;i++){
		if (tagcollect[i].className==classname)
		filteredcollect[inc++]=tagcollect[i];
	}
	return filteredcollect;
}

function toggledivbyclass(name)
{
	classitems=document.getElementsByClass('div',name);
	for(i=0;i<classitems.length;i++)
	{
		if(classitems[i].style.display!='none')
		{
			classitems[i].style.display='none';
		}
		else
		{
			classitems[i].style.display='block';
		}
	}
}

function togglediv(name)
{
	if(document.getElementById(name).style.display!='none')
	{
		document.getElementById(name).style.display='none';
	}
	else
	{
		document.getElementById(name).style.display='block';
	}
}
function nse(to,domain)
{
	document.location='mailto:'+to+'@'+domain;
}

function highlight(n) {
        var div = document.getElementById(n);
        if(!div)
                return;
		div.style.background="rgb(230,240,255)";               
}
function nohighlight(n) {
        var div = document.getElementById(n);
        if(!div)
                return;
		div.style.background="transparent";               
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function ConfirmBlockDelete()
{
return confirm("This will delete the block AND ALL CHILD BLOCKS it may contain.");
}
function ConfirmFolderDelete()
{
return confirm("=== CAUTION ===\n\nThis will delete the folder and ALL PAGES AND SUBFOLDERS\nit may contain.");
}
function ConfirmPageDelete()
{
return confirm("This will delete the page and any contents.");
}
function ConfirmDelete()
{
return confirm("Are you sure you want to delete?");
}
function NotNull(name)
{
	if(document.getElementById(name).value=='')
		alert('You must put a reason for deleting the items.');
	return document.getElementById(name).value!='';
}

/*does all processing on genenric amounts of linked selects!!!
<script type="text/javascript">
<!--
selects=new Array();
selects[0]=document.forms['FrmAdminControl'].elements['test.0'];
selects[1]=document.forms['FrmAdminControl'].elements['test.1'];
selects[2]=document.forms['FrmAdminControl'].elements['test.2'];

initLinkedSelect(selects);
-->

requires following names on options so we know what goes where

<select name"=test.0">
<option value="dog">Dog</option>
<option value="cat">Cat</option>
</select>
<select name="test.1">
<option value="dog-fido">Fido</option>
<option value="dog-rover">Rover</option>
<option value="cat-boots">Boots</option>
<option value="cat-pussy">Pussy</option>
</select>
<select> name="test.2">
<option value="dog-fido-dead">Dead</options>
...
...
</select>
*/

function initLinkedSelect(selects) {
	var options = new Array();
	var nextselect = new Array();
	for (k = selects.length-2 ; k >= 0 ; k-- ){
		from=selects[k];
		to=selects[k+1];
		options[from.name]=new Array();
		(from.style || from).visibility = "visible";
		for (var i=0; i < to.options.length; i++) {
			options[from.name][i] = new Array(to.options[i].text,to.options[i].value);
		}

		nextselect[from.name]=k;
		from.onchange = function() {
			to=selects[nextselect[this.name]+1];
			var fromCode = this.options[this.selectedIndex].value+'-';
			var selectedoption=0;
			selectedoption=to.options[to.selectedIndex].text;
			to.options.length = 0;
			for (i = 0; i < options[this.name].length; i++) {
				if (options[this.name][i][1].indexOf(fromCode) == 0) {
					to.options[to.options.length] = new Option(options[this.name][i][0],options[this.name][i][1]);
					if(options[this.name][i][0]==selectedoption)
						to.options[to.options.length-1].selected=true;
				}
			}
			if(selects[nextselect[to.name]] && selects[nextselect[to.name]].onchange){
				selects[nextselect[to.name]].onchange();
			} else {
				
			}
		}
		from.onchange();
	}
}

// using a Select create divs with id equal to a options value and watch the div appear! 
//set onchange="SelectDivFromDropDown(this)
function SelectDivFromDropDown(select)
{
	for(i=0;i<select.options.length;i++)
	{
		if(select.options[i].value && document.getElementById(select.options[i].value))
			document.getElementById(select.options[i].value).style.display='none';
	}
	if(document.getElementById(select.value))
		document.getElementById(select.value).style.display='block';
}

function LoadIframeFromForm(sURL,sFormName,sDivName,sExtraGetVars)
{
	//Get the URL
	var sURL='';
	sURL=SendAsGetToURL(sURL,sFormName)+sExtraGetVars;
	var ifrmdoc = getIframeDocument('frame.'+sFormName);

	if(document.getElementById(sDivName).style.display!='none')
	{
		document.getElementById(sDivName).style.display='none';
	}
	else
	{
		document.getElementById(sDivName).style.display='block';
		//Redirect the iframe.
		ifrmdoc.body.innerHTML='<p>Loading</p>';
		ifrmdoc.location.replace(sURL);
	}
}

function OpenWindowFromForm(sURL,sFormName,sExtraGetOptions)
{
	sURL=SendAsGetToURL(sURL,sFormName)+sExtraGetOptions;
	window.open(sURL,"","width=200,height=200,location=yes,scrollbars");
}

function SendAsGetToURL(sURL,sFormName)
{	
	var sGetString='';
	if(FormCollection[sFormName])
	{
		for (sFieldName	in FormCollection[sFormName])
		{
			if(eval('document.'+sFormName+'.'+sFieldName+'.type')=='checkbox')
			{
				if (eval('document.'+sFormName+'.'+sFieldName+'.checked'))
					sGetString+=sFieldName+'='+eval('document.'+sFormName+'.'+sFieldName+'.checked')+'&';
			} 
			else 
			{
				sGetString+=sFieldName+'='+eval('document.'+sFormName+'.'+sFieldName+'.value')+'&';
			}
			
		}
	}
	return sURL+'?'+sGetString;
	
}
function getIframeDocument(id) {
	if(document.frames)
		return document.frames[id].document;
	var ifrm = getid(id);
	if(ifrm.contentDocument)
		return ifrm.contentDocument;
	else if(ifrm.contentWindow)
		return ifrm.contentWindow.document;
	else if(ifrm.document)
		return ifrm.document;
}
function getid(id) {
	if(document.all)
		return document.all(id);
	else if(document.getElementById)
		return document.getElementById(id);
	return false;
}
function PleaseWait(button)
{
	button.disabled=true;
	button.value='PLEASE WAIT';
	button.style.color='red';
	button.form.submit();
	return false;
}

function SendFormValue(ToURL,FormElement,GetVarName)
{
	document.location.replace(ToURL+'?'+GetVarName+'='+FormElement.value);
}
function setIDHTMLToVal(fieldElement,someID)
{
	span=getElementById(someID);
	if(span)
	{
		span.innerHTML=this.value;
	}
}
