<!--
//=====================================================================================================
//17/06/2011===========================================================================================
//=====================================================================================================
//=====================================================================================================
function addLoadEvent(func) {
	var oldonload=window.onload;
	if (typeof window.onload!="function") {
		window.onload=func;
	} else {
		window.onload=function() {
			oldonload();
			func();
		}//end function
	}//end if (typeof window.onload!="function")
}//end function
//=====================================================================================================
function SizeMenus() {
	xmc=document.getElementById("mc");
	if (xmc) {
		xmcULs=xmc.getElementsByTagName("ul");
		xh=0;
		for (u=0;u<xmcULs.length;u++) {
			if (xmcULs[u].className=="hpsc") {
				txh=xmcULs[u].offsetHeight;
				if (txh<125) {xmcULs[u].style.minHeight="125px"};
				if (txh>125) {xmcULs[u].style.minHeight="311px"};
				if (txh>311) {xmcULs[u].style.minHeight="497px"};
			}//end if (xmcULs[u].className=="hptc")
		}//next u<=xmcULs.length

//
//		var xLEFTs=new Array(xmcULs.length);
//
//		for (u=0;u<xmcULs.length;u++) {
//			if (xmcULs[u].className=="hpsc") {
//				txl=xmcULs[u].offsetLeft;
//				xLEFTs[u]=txl;
//			}//end if (xmcULs[u].className=="hptc")
//		}//next u<=xmcULs.length
//		xLEFTs.sort();
//		
//		for (l=0;l<=xLEFTs.length;l++) {
//			for (u=0;u<xmcULs.length;u++) {
//				if (xmcULs[u].offsetLeft==xLEFTs[u]) {
//					xmcULs[u].style.marginTop=-xmcULs[u].offsetTop-1+"px";
//				}//end if (xmcULs[u].className=="hptc")
//			}//next u<=xmcULs.length
//		}//next l<=xLEFTS.length
//		
		
		
	}//end if (xmc)
}//end function
//=====================================================================================================
function SetInputHighlights() {
	pxInputs=document.getElementsByTagName("input");
	for (pi=0;pi<pxInputs.length;pi++) {
		if (pxInputs[pi].type=="text") {
			pxInputs[pi].onfocus=function() {
					if (this.defaultValue==this.value) {
						this.select();
					}//end if ()
					ShowEpiLabel(this);
				}//end function
			pxInputs[pi].onkeyup=function() {
					ShowEpiLabel(this);
				}//end function
			pxInputs[pi].onblur=function() {
					HideEpiLabel(this);
				}//end function
			pxInputs[pi].onmouseup=function(){return false};//because safari is special
		}//end if (pxInputs[pi].type=="text")
	}//next pi<pxInputs.length
	pxTextAreas=document.getElementsByTagName("textarea");
	for (pi=0;pi<pxTextAreas.length;pi++) {
		pxTextAreas[pi].onfocus=function() {
				if (this.defaultValue==this.value) {
					this.select();
				}//end if ()
				ShowEpiLabel(this);
			}//end function
		pxTextAreas[pi].onkeyup=function() {
				ShowEpiLabel(this);
			}//end function
		pxTextAreas[pi].onblur=function() {
				HideEpiLabel(this);
			}//end function
		pxTextAreas[pi].onmouseup=function(){return false};//because safari is special
	}//next pi<pxTextAreas.length
}//end function
//=====================================================================================================
function ShowEpiLabel(theInput) {
	theMaxLength=theInput.getAttribute("maxlength");
	if (theMaxLength) {
		theSpan=theInput.parentNode.getElementsByTagName("span")[0];
		if (!theSpan) {
			theSpan=document.createElement("span");
			theInput.parentNode.appendChild(theSpan);
		}//end if (theSpan)
		if (theInput.value.length>theMaxLength) {theInput.value=theInput.value.substr(0, theMaxLength)};
		theSpan.innerHTML="&nbsp;"+theInput.value.length+"/"+theMaxLength+" Characters";
	}//end if (theMaxLength)
}//end function
//=====================================================================================================
function HideEpiLabel(theInput) {
	theMaxLength=theInput.getAttribute("maxlength");
	if (theMaxLength) {
		theSpan=theInput.parentNode.getElementsByTagName("span")[0];
		if (theSpan) {
			theInput.parentNode.removeChild(theSpan);
		}//end if (theSpan)
	}//end if (theMaxLength)
}//end function
//=====================================================================================================
function HideOtherSubMenus(TheDiv) {
	xULs=TheDiv.parentNode.parentNode.parentNode.getElementsByTagName("ul");
	for (u=0;u<xULs.length;u++) {
		xULs[u].style.display="none";
	}//next u<xULs.length
}//end function
//=====================================================================================================
function ToggleVis(TheDiv) {
	Subject=document.getElementById(TheDiv);
	Attribute=Subject.style.display;
	if (Attribute=="block") {
		Subject.style.display="none"
	} else {
		HideOtherSubMenus(Subject);
		Subject.style.display="block";
		Subject.onclick=function(){ToggleVis(TheDiv)};
	}//end if (Attribute=="block")
}//end function
//=====================================================================================================
function BrowserIs(xCheck) {
	xBrowser=navigator.appVersion;
	if (xBrowser.indexOf(xCheck)>0) {
		return "yes";
	} else {
		return "no";
	}//end if (xBrowser.indexOf(xCheck)>0)
}//end function
//=====================================================================================================
function FixTextForXHTML(theHTML) {
	theXHTML="";
	xStringLength=theHTML.length;
	for (char=0;char<xStringLength;char++) {
		MyChar=theHTML.substring(char, char+1);
		if (MyChar=="<") {
			var xSwitch="lowercase";
		}//end if (MyChar=="<")
		if (MyChar==">") {
			var xSwitch="normalcase";
		}//end if (MyChar==">")
		if (xSwitch=="lowercase") {
//			theXHTML+=MyChar.toLowerCase();
			theXHTML+=MyChar;
		} else {
			theXHTML+=MyChar;
		}//end if (xSwitch="lowercase")
	}//next char
	theXHTML=theXHTML.replace(/<area([^>]*)\s*>/gi,'<area$1 />');
	theXHTML=theXHTML.replace(/<base([^>]*)\s*>/gi,'<base$1 />');
	theXHTML=theXHTML.replace(/<basefont([^>]*)\s*>/gi,'<basefont$1 />');
	theXHTML=theXHTML.replace(/<bgsound([^>]*)\s*>/gi,'<bgsound$1 />');
	theXHTML=theXHTML.replace(/<br([^>]*)\s*>/gi,'<br$1 />');
	theXHTML=theXHTML.replace(/<col([^>]*)\s*>/gi,'<col$1 />');
	theXHTML=theXHTML.replace(/<frame([^>]*)\s*>/gi,'<frame$1 />');
	theXHTML=theXHTML.replace(/<hr([^>]*)\s*>/gi,'<hr$1 />');
	theXHTML=theXHTML.replace(/<img([^>]*)\s*>/gi,'<img$1 />');
	theXHTML=theXHTML.replace(/<input([^>]*)\s*>/gi,'<input$1 />');
	theXHTML=theXHTML.replace(/<link([^>]*)\s*>/gi,'<link$1 />');
	theXHTML=theXHTML.replace(/<meta([^>]*)\s*>/gi,'<meta$1 />');
	theXHTML=theXHTML.replace(/<param([^>]*)\s*>/gi,'<param$1 />');
	theXHTML=theXHTML.replace(/ name=([^>]*)\s*>/gi, ">");
	theXHTML=theXHTML.replace(/ id=([^>]*)\s*>/gi, ">");
	//fiddles for firefox
	theXHTML=theXHTML.replace(/<b>([^*]*)\s*<\/b>/gi,'<strong>$1</strong>');
	theXHTML=theXHTML.replace(/<i>([^*]*)\s*<\/i>/gi,'<em>$1</em>');
	//fiddles for safari
	theXHTML=theXHTML.replace(/ class="apple-style-span"/gi, "");
	theXHTML=theXHTML.replace(/<br \/><\/blockquote>/gi,"</blockquote>");
	theXHTML=theXHTML.replace(/<br \/><\/li>/gi,"</li>");
	theXHTML=theXHTML.replace(/ class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"/gi, "");
	theXHTML=theXHTML.replace(/<span style="font-weight: bold;">([^*]*)\s*<\/span>/gi, "<strong>$1</strong>");
	theXHTML=theXHTML.replace(/<span style="font-style: italic;">([^*]*)\s*<\/span>/gi, "<em>$1</em>");
	theXHTML=theXHTML.replace(/<span style="text-decoration: underline;">([^*]*)\s*<\/span>/gi, "<u>$1</u>");
	theXHTML=theXHTML.replace(/<span style="vertical-align: sub;">([^*]*)\s*<\/span>/gi, "<sub>$1</sub>");
	theXHTML=theXHTML.replace(/<span style="vertical-align: super;">([^*]*)\s*<\/span>/gi, "<super>$1</super>");
	//fiddles for IE
	theXHTML=theXHTML.replace(/align=justify/gi, "align=\"justify\"");
	theXHTML=theXHTML.replace(/align=left/gi, "align=\"left\"");
	theXHTML=theXHTML.replace(/align=right/gi, "align=\"right\"");
	theXHTML=theXHTML.replace(/align=center/gi, "align=\"center\"");
	theXHTML=theXHTML.replace(/target=_blank/gi, "target=\"_blank\"");
	theXHTML=theXHTML.replace(/target=_self/gi, "target=\"_self\"");
	theXHTML=theXHTML.replace(/<strike>([^*]*)\s*<\/strike>/gi, "<span style=\"text-decoration: line-through;\">$1</span>");
	theXHTML=theXHTML.replace(/<sup><sub>([^*]*)\s*<\/sub><\/sup>/gi, "<sub>$1</sub>");
	theXHTML=theXHTML.replace(/<sub><sup>([^*]*)\s*<\/sup><\/sub>/gi, "<sup>$1</sup>");
	return theXHTML;
}//end function
//=====================================================================================================
function DrawSpacer() {
	strSpacer="";
	strSpacer+="<img";
	strSpacer+=" src=\"/images/admin/spacer.png\"";
	strSpacer+=" width=\"1\"";
	strSpacer+=" height=\"20\"";
	strSpacer+=" hspace=\"2\"";
	strSpacer+=" alt=\" \"";
	strSpacer+=" />";
	return strSpacer;
}//end function
//=====================================================================================================
function ButtonExecute(xBUTTONaction, xGWYSareaId) {
	document.getElementById(xGWYSareaId).contentWindow.document.execCommand(xBUTTONaction, '', xGWYSareaId);
	UpdateHTML();
}//end function
//=====================================================================================================
function DrawButton(xGWYSareaId, xBUTTONaction) {
	strButton="";
	strButton+="<button";
	strButton+=" onclick=\"ButtonExecute('"+xBUTTONaction+"','"+xGWYSareaId+"');return false;\"";
	strButton+=" title=\""+xBUTTONaction+"\"";
	strButton+=" id=\""+xGWYSareaId+xBUTTONaction+"\"";
	strButton+=" >";
	strButton+="<img";
	strButton+=" src=\"/images/admin/"+xBUTTONaction+".png\"";
	strButton+=" width=\"20\"";
	strButton+=" height=\"20\"";
	strButton+=" alt=\""+xBUTTONaction+"\"";
	strButton+=" />";
	strButton+="</button>";
	return strButton;
}//end function
//=====================================================================================================
function SetFontName(xGWYSareaId) {
	xDropDownID="fontnamedrop"+xGWYSareaId;
	xDropDownElem=document.getElementById(xDropDownID);
	xDropDownIndex=xDropDownElem.selectedIndex;
	xDropDownValue=xDropDownElem.options[xDropDownIndex].value;
	document.getElementById(xGWYSareaId).contentWindow.document.execCommand("FontName",0,xDropDownValue);
	UpdateHTML();
}//end function
//=====================================================================================================
function DrawFontName(xGWYSareaId) {
	xDropDownID="fontnamedrop"+xGWYSareaId;
	strDropdown="";
	strDropdown+="<select";
	strDropdown+=" name=\""+xDropDownID+"\"";
	strDropdown+=" id=\""+xDropDownID+"\"";
	strDropdown+=" onchange=\"SetFontName('"+xGWYSareaId+"');return false;\"";
	strDropdown+=">";
	strDropdown+="<option value=\"\">Font</option>";
	strDropdown+="<option value=\"arial\">Arial</option>";
	strDropdown+="<option value=\"tahoma\">Tahoma</option>";
	strDropdown+="<option value=\"verdana\">Verdana</option>";
	strDropdown+="<option value=\"times new roman\">Times</option>";
	strDropdown+="</select>";
	return strDropdown;
}//end function
//=====================================================================================================
function SetFontSize(xGWYSareaId) {
	xDropDownID="fontsizedrop"+xGWYSareaId;
	xDropDownElem=document.getElementById(xDropDownID);
	xDropDownIndex=xDropDownElem.selectedIndex;
	xDropDownValue=xDropDownElem.options[xDropDownIndex].value;
	document.getElementById(xGWYSareaId).contentWindow.document.execCommand("FontSize",0,xDropDownValue);
	UpdateHTML();
}//end function
//=====================================================================================================
function DrawFontSize(xGWYSareaId) {
	xDropDownID="fontsizedrop"+xGWYSareaId;
	strDropdown="";
	strDropdown+="<select";
	strDropdown+=" name=\""+xDropDownID+"\"";
	strDropdown+=" id=\""+xDropDownID+"\"";
	strDropdown+=" onchange=\"SetFontSize('"+xGWYSareaId+"');return false;\"";
	strDropdown+=">";
	strDropdown+="<option value=\"\">Size</option>";
	for (s=1;s<8;s++) {
		strDropdown+="<option value=\""+s+"\">"+s+"</option>";
	}//next s<8
	strDropdown+="</select>";
	return strDropdown;
}//end function
//=====================================================================================================
function ToggleView(xTEXTareaId, xGWYSareaId) {
	xGWYStextarea=document.getElementById(xTEXTareaId);
	xGWYSarea=document.getElementById(xGWYSareaId);
	xGWYSstatus=document.getElementById("status"+xTEXTareaId);
//	if (xGWYStextarea.style.display!="none") {
//		xGWYStextarea.style.display="none";
//		xGWYSarea.style.display="";
//		xGWYSstatus.innerHTML="WYSIWYG mode";
//		UpdateGWYS(xTEXTareaId, xGWYSareaId);
//		xGWYSarea.focus();
//		EnableButtons(xTEXTareaId);
//	} else {
//		UpdateHTML();
//		xGWYStextarea.style.display="";
//		xGWYSarea.style.display="none";
//		xGWYSstatus.innerHTML="HTML mode";
//		xGWYStextarea.focus();
//		DisableButtons(xTEXTareaId);
//	}//end if (xGWYStextarea.style.display!="none")
	if (xGWYStextarea.style.display=="none") {
		UpdateHTML();
		xGWYStextarea.style.display="";
		xGWYSarea.style.display="none";
		xGWYSstatus.innerHTML="HTML mode";
//		xGWYStextarea.focus();
		DisableButtons(xTEXTareaId);
	} else {
		xGWYStextarea.style.display="none";
		xGWYSarea.style.display="";
		xGWYSstatus.innerHTML="WYSIWYG mode";
		UpdateGWYS(xTEXTareaId, xGWYSareaId);
//		xGWYSarea.focus();
		EnableButtons(xTEXTareaId);
	}//end if (xGWYStextarea.style.display=="none")
	return false;
}//end function
//=====================================================================================================
function EnableButtons(xTEXTareaId) {
	ARRxTOOLbar=new Array(2);
	ARRxELEMtype=new Array(2);
	ARRxTOOLbar[0]="standard"+xTEXTareaId;
	ARRxTOOLbar[1]="advanced"+xTEXTareaId;
	ARRxELEMtype[0]="button";
	ARRxELEMtype[1]="select";
	for (t=0;t<ARRxTOOLbar.length;t++) {
		xTOOLbarId=ARRxTOOLbar[t];
		for (e=0;e<ARRxELEMtype.length;e++) {
			xTOOLbar=document.getElementById(xTOOLbarId);
			if (xTOOLbar) {
				xElements=xTOOLbar.getElementsByTagName(ARRxELEMtype[e]);
				for (i=0;i<xElements.length;i++) {
					xElementId=xElements[i].id;
					if (xElementId&&xElementId!="toggleview") {
						xElementObject=document.getElementById(xElementId);
						xElementObject.setAttribute("disabled", "");
						xElementObject.setAttribute("class", "");
						xElementObject.removeAttribute("disabled");
						xElementObject.removeAttribute("class");
					}//end if (xElementId&&xElementId!="toggleview")
				}//next i<xElements.length
			}//end if (xTOOLbar)
		}//next	e<ARRxELEMtype.length
	}//next	t<ARRxTOOLbar.length
	return false;
}//end function
//=====================================================================================================
function DisableButtons(xTEXTareaId) {
	ARRxTOOLbar=new Array(2);
	ARRxELEMtype=new Array(2);
	ARRxTOOLbar[0]="standard"+xTEXTareaId;
	ARRxTOOLbar[1]="advanced"+xTEXTareaId;
	ARRxELEMtype[0]="button";
	ARRxELEMtype[1]="select";
	for (t=0;t<ARRxTOOLbar.length;t++) {
		xTOOLbarId=ARRxTOOLbar[t];
		for (e=0;e<ARRxELEMtype.length;e++) {
			xTOOLbar=document.getElementById(xTOOLbarId);
			if (xTOOLbar) {
				xElements=xTOOLbar.getElementsByTagName(ARRxELEMtype[e]);
				for (i=0;i<xElements.length;i++) {
					xElementId=xElements[i].id;
					if (xElementId&&xElementId!="toggleview") {
						xElementObject=document.getElementById(xElementId);
						xElementObject.setAttribute("disabled", "disabled");
						xElementObject.setAttribute("class", "disabled");
					}//end if (xElementId&&xElementId!="toggleview")
				}//next i<xElements.length
			}//end if (xTOOLbar)
		}//next	e<ARRxELEMtype.length
	}//next	t<ARRxTOOLbar.length
	return false;
}//end function
//=====================================================================================================
function ModalPopUp(ModalURL,ModalID,ModalWIDTH,ModalHEIGHT) {
	if (window.showModalDialog) {
		ModalARGS='dialogWidth:'+ModalWIDTH+'px;dialogHeight:'+ModalHEIGHT+'px;resizable:no;scroll:no;status:no;unadorned:yes;';
		ModalReturn=window.showModalDialog(ModalURL,ModalID,ModalARGS);
	} else {
		ModalARGS='modal=yes,status=no,scrollbars=no,location=no,menubar=no,toolbar=no,resizable=no,width='+ModalWIDTH+',height='+ModalHEIGHT+',top=10,left=100';
		window.open(ModalURL,ModalID,ModalARGS);
		alert("Click OK to apply changes");
	}//end if (window.showModalDialog)
	return ModalReturn;
}//end function
//=====================================================================================================
function DrawToggle(xTEXTareaId, xGWYSareaId) {
	strButton="";
	strButton+="<button";
	strButton+=" onclick=\"ToggleView('"+xTEXTareaId+"','"+xGWYSareaId+"');return false;\"";
	strButton+=" title=\"code view\"";
	strButton+=" >";
	strButton+="<img";
	strButton+=" src=\"/images/admin/toggle.png\"";
	strButton+=" width=\"20\"";
	strButton+=" height=\"20\"";
	strButton+=" alt=\"code view\"";
	strButton+=" />";
	strButton+="</button>";
	return strButton;
}//end function
//=====================================================================================================
function ShowFileUpload(i1, i2, i3) {
//	xUPLOADvars=showModalDialog("/components/gwys/gwys_file_upload.aspx",null,"dialogHeight:100px;dialogWidth:300px;resizable:no;scroll:no;status:no;unadorned:yes;");
	xUPLOADvars=ModalPopUp("/components/gwys/gwys_file_upload.aspx","gwys_file_upload",300,100);
	if (xUPLOADvars!=null) {
		xUPLOADvars=xUPLOADvars.split("|");
		if (xUPLOADvars.length>-1) {xUPLOADsrc=xUPLOADvars[0]};
		if (xUPLOADvars.length>0) {xUPLOADwidth=xUPLOADvars[1]};
		if (xUPLOADvars.length>1) {xUPLOADheight=xUPLOADvars[2]};
		oi1=document.getElementById(i1);
		oi2=document.getElementById(i2);
		oi3=document.getElementById(i3);
		if (oi1&&xUPLOADsrc) {oi1.value=xUPLOADsrc};
		if (oi2&&xUPLOADwidth) {oi2.value=xUPLOADwidth};
		if (oi2&&xUPLOADheight) {oi3.value=xUPLOADheight};
	}//end if (xUPLOADvars!=null)
}//end function
//=====================================================================================================
function DrawColourButton(xGWYSareaId, xCOLOURarea) {
	strButton="";
	strButton+="<button";
	strButton+=" onclick=\"ShowColourDialog('"+xGWYSareaId+"','"+xCOLOURarea+"');return false;\"";
	strButton+=" title=\""+xCOLOURarea+"\"";
	strButton+=" id=\""+xGWYSareaId+xCOLOURarea+"\"";
	strButton+=" >";
	strButton+="<img";
	strButton+=" src=\"/images/admin/"+xCOLOURarea+".png\"";
	strButton+=" width=\"20\"";
	strButton+=" height=\"20\"";
	strButton+=" alt=\""+xCOLOURarea+"\"";
	strButton+=" />";
	strButton+="</button>";
	return strButton;
}//end function
//=====================================================================================================
function ShowColourDialog(xGWYSareaId, xCOLOURarea) {
//	xCOLOURcode=showModalDialog("/components/gwys/gwys_colour_picker.htm",null,"dialogHeight:205px;dialogWidth:179px;resizable:no;scroll:no;status:no;unadorned:yes;");
	xCOLOURcode=ModalPopUp("/components/gwys/gwys_colour_picker.htm","gwys_colour_picker",179,205);
	if (xCOLOURarea=="ForeColor") {
		document.getElementById(xGWYSareaId).contentWindow.document.execCommand("ForeColor",false,xCOLOURcode);
	} else {
		document.getElementById(xGWYSareaId).contentWindow.document.execCommand("BackColor",false,xCOLOURcode);
	}//end if (xCOLOURarea=="BackColor")
}//end function
//=====================================================================================================
function DrawLinkButton(xGWYSareaId) {
	strButton="";
	strButton+="<button";
	strButton+=" onclick=\"ShowLinkDialog('"+xGWYSareaId+"');return false;\"";
	strButton+=" id=\""+xGWYSareaId+"link\"";
	strButton+=" title=\"Insert Link\"";
	strButton+=" >";
	strButton+="<img";
	strButton+=" src=\"/images/admin/CreateLink.png\"";
	strButton+=" width=\"20\"";
	strButton+=" height=\"20\"";
	strButton+=" alt=\"Insert Link\"";
	strButton+=" />";
	strButton+="</button>";
	return strButton;
}//end function
//=====================================================================================================
function ShowLinkDialog(xGWYSareaId) {
//	xLINKvars=showModalDialog("/components/gwys/gwys_link.htm",null,"dialogHeight:170px;dialogWidth:400px;resizable:no;scroll:no;status:no;unadorned:yes;");
	xLINKvars=ModalPopUp("/components/gwys/gwys_link.htm","gwys_link",400,170);
	if (xLINKvars!=null) {
		xLINKvars=xLINKvars.split("||");
		xLINKhref=xLINKvars[0];
		xLINKtarget=xLINKvars[1];
		xGWYSframe=document.getElementById(xGWYSareaId).contentWindow;
		if (xGWYSframe.document.getSelection) {//firefox
			xGWYSselection=xGWYSframe.getSelection().getRangeAt(0);
			xGWYScontent=xGWYSselection.toString();
			xLINKhtml="<a";
			xLINKhtml+=" href=\""+xLINKhref+"\"";
			xLINKhtml+=" target=\""+xLINKtarget+"\"";
			xLINKhtml+=">";
			xLINKhtml+=xGWYScontent;
			xLINKhtml+="</a>";
			xGWYSframe.document.execCommand("insertHTML",false,xLINKhtml);
		} else if (xGWYSframe.getSelection) {//safari
			xGWYSselection=xGWYSframe.getSelection().getRangeAt(0);
			xGWYScontent=xGWYSselection.toString();
			xLINKhtml="<a";
			xLINKhtml+=" href=\""+xLINKhref+"\"";
			xLINKhtml+=" target=\""+xLINKtarget+"\"";
			xLINKhtml+=">";
			xLINKhtml+=xGWYScontent;
			xLINKhtml+="</a>";
			xGWYSframe.document.execCommand("insertHTML",false,xLINKhtml);
		} else if (xGWYSframe.document.selection) {//ie
			xGWYSframe.focus();
			xGWYSselection=xGWYSframe.document.selection.createRange();
			xGWYScontent=xGWYSselection.htmlText;
			xLINKhtml="<a";
			xLINKhtml+=" href=\""+xLINKhref+"\"";
			xLINKhtml+=" target=\""+xLINKtarget+"\"";
			xLINKhtml+=">";
			xLINKhtml+=xGWYScontent;
			xLINKhtml+="</a>";
			xGWYSselection.pasteHTML(xLINKhtml);
		}//end if (xGWYSframe.getSelection)
	}//end if (xLINKvars!=null)
}//end function
//=====================================================================================================
function DrawDownloadButton(xGWYSareaId) {
	strButton="";
	strButton+="<button";


	strButton+=" onclick=\"ShowDownloadDialog('"+xGWYSareaId+"');return false;\"";
	strButton+=" id=\""+xGWYSareaId+"download\"";
	strButton+=" title=\"Insert Download\"";
	strButton+=" >";
	strButton+="<img";
	strButton+=" src=\"/images/admin/CreateDownload.png\"";
	strButton+=" width=\"20\"";
	strButton+=" height=\"20\"";
	strButton+=" alt=\"Insert Download\"";
	strButton+=" />";
	strButton+="</button>";
	return strButton;
}//end function
//=====================================================================================================
function ShowDownloadDialog(xGWYSareaId) {
//	xDOWNLOADvars=showModalDialog("/components/gwys/gwys_download.aspx",null,"dialogHeight:110px;dialogWidth:400px;resizable:no;scroll:no;status:no;unadorned:yes;");
	xDOWNLOADvars=ModalPopUp("/components/gwys/gwys_download.aspx","gwys_download",400,110);
	if (xDOWNLOADvars!=null) {
		xDOWNLOADvars=xDOWNLOADvars.split("||");
		xDOWNLOADname=xDOWNLOADvars[0];
		xDOWNLOADdesc=xDOWNLOADvars[1];
		xDOWNLOADfile=xDOWNLOADvars[2];
		xDOWNLOADtype=xDOWNLOADvars[3];
		xDOWNLOADsize=xDOWNLOADvars[4];
		xDOWNLOADicon="/images/fileicons/"+xDOWNLOADtype+".gif\"";
		xDOWNLOADhtml="<table summary=\"download "+xDOWNLOADname+"\">"
		xDOWNLOADhtml+="<tr valign=\"top\">";
		if (ImageExists(xDOWNLOADicon)=="yes") {
			xDOWNLOADhtml+="<td rowspan=\"2\">";
			xDOWNLOADhtml+="<img src=\""+xDOWNLOADicon+"\" width=\"70\" height=\"70\" alt=\""+xDOWNLOADtype+" file\" />";
			xDOWNLOADhtml+="</td>";
		}//end if (ImageExists(xDOWNLOADicon)=="yes")
		xDOWNLOADhtml+="<td>";
		xDOWNLOADhtml+="<a href=\"/downloads/"+xDOWNLOADfile+"\" target=\"_blank\">"+xDOWNLOADname+"</a>";
		xDOWNLOADhtml+="</td>";
		xDOWNLOADhtml+="</tr>";
		xDOWNLOADhtml+="<tr>";
		xDOWNLOADhtml+="<td>"+xDOWNLOADdesc+"<br />"+xDOWNLOADsize+" "+xDOWNLOADtype+"</td>";
		xDOWNLOADhtml+="</tr>";
		xDOWNLOADhtml+="</table>";
		xGWYSframe=document.getElementById(xGWYSareaId).contentWindow;
		if (xGWYSframe.document.getSelection) {//firefox
			xGWYSselection=xGWYSframe.getSelection().getRangeAt(0);
			xGWYScontent=xGWYSselection.toString();
			xGWYSframe.document.execCommand("insertHTML",false,xDOWNLOADhtml);
		} else if (xGWYSframe.getSelection) {//safari
			xGWYSselection=xGWYSframe.getSelection().getRangeAt(0);
			xGWYScontent=xGWYSselection.toString();
			xGWYSframe.document.execCommand("insertHTML",false,xDOWNLOADhtml);
		} else if (xGWYSframe.document.selection) {//ie
			xGWYSframe.focus();
			xGWYSselection=xGWYSframe.document.selection.createRange();
			xGWYScontent=xGWYSselection.htmlText;
			xGWYSselection.pasteHTML(xDOWNLOADhtml);
		}//end if (xGWYSframe.getSelection)
	}//end if (xDOWNLOADvars!=null)
}//end function
//=====================================================================================================
function DrawCleanWord(xTEXTareaId, xGWYSareaId) {
	strButton="";
	strButton+="<button";
	strButton+=" onclick=\"CleanWord('"+xTEXTareaId+"','"+xGWYSareaId+"');return false;\"";
	strButton+=" id=\""+xGWYSareaId+"cleanword\"";
	strButton+=" title=\"Clean Word HTML\"";
	strButton+=" >";
	strButton+="<img";
	strButton+=" src=\"/images/admin/CleanWord.png\"";
	strButton+=" width=\"20\"";
	strButton+=" height=\"20\"";
	strButton+=" alt=\"Clean Word HTML\"";
	strButton+=" />";
	strButton+="</button>";
	return strButton;
}//end function
//=====================================================================================================
function CleanWord(xTEXTareaId, xGWYSareaId) {
	if (confirm("This will clean up MS Word HTML to produce better code for use in web browsers.\n\nIf the Word code is really bad to start with, the result may be unpredictable.")) {
		xHTMLtoStartWith=document.getElementById(xGWYSareaId).contentWindow.document.body.innerHTML;
		xHTMLtoEndWith=xHTMLtoStartWith;
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<?xml[^>]*>/gi, "");
		xHTMLtoEndWith=xHTMLtoEndWith.replace("<?", "");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<p[^>]*>/gi, "<p>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<div[^>]*>/gi, "<div>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<span[^>]*>/gi, "<span>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<strong[^>]*>/gi, "<strong>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<em[^>]*>/gi, "<em>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<b[^>]*>/gi, "<strong>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<i[^>]*>/gi, "<em>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<\/b[^>]*>/gi, "</strong>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<\/i[^>]*>/gi, "</em>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<u[^>]*>/gi, "<u>");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<o:p[^>]*>/gi, "");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<\/o:p[^>]*>/gi, "");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/&nbsp;/gi, "");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<span>/gi, "");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<\/span>/gi, "");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<[^>]*><\/[^>]*>/gi, "");
		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<[^>]*><\/[^>]*>/gi, "");
//		xHTMLtoEndWith=xHTMLtoEndWith.replace(/<p>([^*]*)\s*<\/p>/gi,'[p]$1[/p]');	//replace all complete tags with placeholder
		xHTMLtoEndWith=FixTextForXHTML(xHTMLtoEndWith);
		document.getElementById(xTEXTareaId).value=xHTMLtoEndWith;
		UpdateGWYS(xTEXTareaId, xGWYSareaId);
	}//end if (confirm("This will clean up MS Word HTML to produce better code for use in web browsers.\n\nIf the Word code is really bad to start with, the result may be unpredictable."))
}//end function
//=====================================================================================================
function DrawImageButton(xGWYSareaId) {
	strButton="";
	strButton+="<button";
	strButton+=" onclick=\"ShowImageDialog('"+xGWYSareaId+"');return false;\"";
	strButton+=" id=\""+xGWYSareaId+"Image\"";
	strButton+=" title=\"Insert Image\"";
	strButton+=" >";
	strButton+="<img";
	strButton+=" src=\"/images/admin/InsertImage.png\"";
	strButton+=" width=\"20\"";
	strButton+=" height=\"20\"";
	strButton+=" alt=\"Insert Image\"";
	strButton+=" />";
	strButton+="</button>";
	return strButton;
}//end function
//=====================================================================================================
function ShowImageDialog(xGWYSareaId) {
//	xIMGvars=showModalDialog("/components/gwys/gwys_image.aspx",null,"dialogHeight:545px;dialogWidth:600px;resizable:no;scroll:no;status:no;unadorned:yes;");
	xIMGvars=ModalPopUp("/components/gwys/gwys_image.aspx","gwys_image",600,545);
	if (xIMGvars!=null) {
		xIMGvars=xIMGvars.split("||");
		xIMGsrc=xIMGvars[0];
		xIMGwidth=xIMGvars[1];
		xIMGheight=xIMGvars[2];
		xIMGalt=xIMGvars[3];
		xIMGalign=xIMGvars[4];
		xIMGmargin=xIMGvars[5];
		xIMGframe=xIMGvars[6];
		xIMGborder="0";
		xIMGhtml="<img";
		xIMGhtml+=" src=\""+xIMGsrc+"\"";
		xIMGhtml+=" width=\""+xIMGwidth+"\"";
		xIMGhtml+=" height=\""+xIMGheight+"\"";
		xIMGhtml+=" alt=\""+xIMGalt+"\"";
		if (xIMGframe=="no") {
			xIMGhtml+=" align=\""+xIMGalign+"\"";
		}//end if (xIMGframe=="no")
		xIMGhtml+=" hspace=\""+xIMGmargin+"\"";
		xIMGhtml+=" vspace=\""+xIMGmargin+"\"";
		xIMGhtml+=" border=\""+xIMGborder+"\"";
		xIMGhtml+=" />";
		if (xIMGframe=="yes") {
			if (xIMGalign=="left") {
				xIMGhtml="<div style=\"padding: 5px; border: 5px solid #f6f6f6; text-align: center; float: left; margin-right: 5px;\">"+xIMGhtml+"<br />"+xIMGalt+"</div>"
			}//end if (xIMGalign=="left")
			if (xIMGalign=="right") {
				xIMGhtml="<div style=\"padding: 5px; border: 5px solid #f6f6f6; text-align: center; float: right; margin-left: 5px;\">"+xIMGhtml+"<br />"+xIMGalt+"</div>"
			}//end if (xIMGalign=="right")
			if (xIMGalign=="") {
				xDIVwidth=(xIMGwidth*1)+20;
				xIMGhtml="<div style=\"padding: 5px; border: 5px solid #f6f6f6; text-align: center; width: "+xDIVwidth+"px; \">"+xIMGhtml+"<br />"+xIMGalt+"</div>"
			}//end if (xIMGalign=="")
		}//end if (xIMGframe=="yes")
		xGWYSframe=document.getElementById(xGWYSareaId).contentWindow;
		if (xGWYSframe.document.getSelection) {//firefox
			xGWYSselection=xGWYSframe.getSelection().getRangeAt(0);
			xGWYScontent=xGWYSselection.toString();
			xGWYSframe.document.execCommand("insertHTML",false,xIMGhtml);
		} else if (xGWYSframe.getSelection) {//safari
			xGWYSselection=xGWYSframe.getSelection().getRangeAt(0);
			xGWYScontent=xGWYSselection.toString();
			xGWYSframe.document.execCommand("insertHTML",false,xIMGhtml);
		} else if (xGWYSframe.document.selection) {//ie
			xGWYSframe.focus();
			xGWYSselection=xGWYSframe.document.selection.createRange();
			xGWYScontent=xGWYSselection.htmlText;
			xGWYSselection.pasteHTML(xIMGhtml);
		}//end if (xGWYSframe.getSelection)
	}//end if (xIMGvars!=null)
}//end function
//=====================================================================================================
function DrawToolBarButtons(xTEXTareaId, xGWYSareaId, xTOOLbarType) {
	strOutput="";
	xTOOLbarId=xTOOLbarType+xTEXTareaId;
	xTOOLbar=document.getElementById(xTOOLbarId);
	if (xTOOLbarType=="advanced") {
		strOutput+=DrawButton(xGWYSareaId, "Copy");
		strOutput+=DrawButton(xGWYSareaId, "Cut");
		strOutput+=DrawButton(xGWYSareaId, "Paste");
		strOutput+=DrawButton(xGWYSareaId, "Delete");
		strOutput+=DrawButton(xGWYSareaId, "Print");
		strOutput+=DrawSpacer();
		strOutput+=DrawButton(xGWYSareaId, "SelectAll"); //weird - selects everything in the page, not the editor
		strOutput+=DrawButton(xGWYSareaId, "Unselect");
		strOutput+=DrawButton(xGWYSareaId, "InsertMarquee");
		strOutput+=DrawButton(xGWYSareaId, "CreateBookmark");
		strOutput+=DrawButton(xGWYSareaId, "UnBookmark");
		strOutput+=DrawButton(xGWYSareaId, "InsertHorizontalRule");
		strOutput+=DrawButton(xGWYSareaId, "InsertIFrame");
		strOutput+=DrawButton(xGWYSareaId, "InsertParagraph");
		strOutput+=DrawSpacer();
		strOutput+=DrawButton(xGWYSareaId, "CreateLink");
		strOutput+=DrawButton(xGWYSareaId, "Unlink");
		strOutput+=DrawButton(xGWYSareaId, "InsertImage");
	}//end if (xTOOLbarType=="advanced")
	if (xTOOLbarType=="standard") {
//		strOutput+=DrawFontName(xGWYSareaId);
		strOutput+=DrawFontSize(xGWYSareaId);
		strOutput+=DrawSpacer();
		strOutput+=DrawButton(xGWYSareaId, "bold");
		strOutput+=DrawButton(xGWYSareaId, "Italic");
		strOutput+=DrawButton(xGWYSareaId, "Underline");
		strOutput+=DrawSpacer();
		strOutput+=DrawButton(xGWYSareaId, "JustifyLeft");
		strOutput+=DrawButton(xGWYSareaId, "JustifyFull");
		strOutput+=DrawButton(xGWYSareaId, "JustifyCenter");
		strOutput+=DrawButton(xGWYSareaId, "JustifyRight");
		strOutput+=DrawSpacer();
		strOutput+=DrawButton(xGWYSareaId, "Indent");
		strOutput+=DrawButton(xGWYSareaId, "Outdent");
		strOutput+=DrawButton(xGWYSareaId, "InsertOrderedList");
		strOutput+=DrawButton(xGWYSareaId, "InsertUnorderedList");
		strOutput+=DrawSpacer();
		strOutput+=DrawButton(xGWYSareaId, "StrikeThrough");
		strOutput+=DrawButton(xGWYSareaId, "Subscript");
		strOutput+=DrawButton(xGWYSareaId, "Superscript");
		strOutput+=DrawSpacer();
		strOutput+=DrawColourButton(xGWYSareaId, "BackColor");
		strOutput+=DrawColourButton(xGWYSareaId, "ForeColor");
		strOutput+=DrawSpacer();
		strOutput+=DrawLinkButton(xGWYSareaId);
		strOutput+=DrawButton(xGWYSareaId, "Unlink");
//		strOutput+=DrawSpacer();
//		strOutput+=DrawImageButton(xGWYSareaId);
//		strOutput+=DrawSpacer();
//		strOutput+=DrawButton(xGWYSareaId, "RemoveFormat");
//		strOutput+=DrawToggle(xTEXTareaId, xGWYSareaId);
	}//end if (xTOOLbarType=="standard")
	xTOOLbar.innerHTML=strOutput;
}//end function
//=====================================================================================================
function DrawToolBar(xTEXTareaId, xGWYSareaId, xTOOLbarType) {
	xTOOLbar=document.createElement("div");
	xTOOLbar.setAttribute("id", xTOOLbarType+xTEXTareaId);
	xTOOLbar.className="gwysToolBar";
	xTEXTarea=document.getElementById(xTEXTareaId);
	xPARENTnode=xTEXTarea.parentNode;
	xPARENTnode.insertBefore(xTOOLbar, xTEXTarea);
	DrawToolBarButtons(xTEXTareaId, xGWYSareaId, xTOOLbarType);
}//end function
//=====================================================================================================
function UpdateHTML() {
	arrTextAreas=document.getElementsByTagName("textarea");
	for(var i=0;i<arrTextAreas.length;i++) {
		xTEXTareaId=arrTextAreas[i].id;
		xGWYSareaId="gwys"+xTEXTareaId;
		if (arrTextAreas[i].className=="gwysTextArea") {
			xXHTML=document.getElementById(xGWYSareaId).contentWindow.document.body.innerHTML;
			xXHTML=FixTextForXHTML(xXHTML);
			document.getElementById(xTEXTareaId).value=xXHTML;
		}//end if (arrTextAreas[i].className=="gwys")
	}//next i<=arrTextAreas.length
}//end function
//=====================================================================================================
function UpdateGWYS(xTEXTareaId, xGWYSareaId) {
	xGWYScontent=document.getElementById(xGWYSareaId).contentWindow.document;
	xGWYScontent.open();
	xGWYScontent.write("<head></head>"+document.getElementById(xTEXTareaId).value);
	xGWYScontent.close();
	SetStyleSheet(xGWYSareaId);
}//end function
//=====================================================================================================
function SetStyleSheet(xGWYSareaId) {
	xGWYScss=document.createElement("link");
	xGWYScss.setAttribute("href","/components/gwys/gwys_styles.css");
	xGWYScss.setAttribute("rel","stylesheet");
	xGWYScss.setAttribute("type","text/css");
	xGWYSarea=document.getElementById(xGWYSareaId).contentWindow.document;
	if (BrowserIs("MSIE")=="yes") {
		document.getElementById(xGWYSareaId).contentWindow.document.createStyleSheet(xGWYScss.href);
	} else {
		if (xGWYSarea.getElementsByTagName("head")[0]) {
			xGWYSarea.getElementsByTagName("head")[0].appendChild(xGWYScss);
		} else {
			document.getElementById(xGWYSareaId).contentWindow.document.createStyleSheet(xGWYScss.href);
		}//end if (xGWYSarea.getElementsByTagName("head")[0])
	}//end if (BrowserIs("MSIE")=="yes")
}//end function
//=====================================================================================================
function ConvertToWYSIWYG(xTEXTareaId, xGWYSareaId, xSTATUSbarId) {
	xGWYSarea=document.createElement("iframe");
	xGWYSarea.setAttribute("id", xGWYSareaId);
	xGWYSarea.frameBorder="0";
	xGWYSarea.className="gwysEditArea";
	xTEXTarea=document.getElementById(xTEXTareaId);
	xTEXTarea.setAttribute("onkeyup", "UpdateGWYS(\""+xTEXTareaId+"\", \""+xGWYSareaId+"\");");
	xTEXTarea.setAttribute("onblur", "UpdateGWYS(\""+xTEXTareaId+"\", \""+xGWYSareaId+"\");");
	xTEXTarea.style.display="none";
	xPARENTnode=xTEXTarea.parentNode;
	xPARENTnode.insertBefore(xGWYSarea, xTEXTarea);
	xSTATUSbar=document.createElement("div");
	xSTATUSbar.setAttribute("id", xSTATUSbarId);
	xSTATUSbar.className="gwysStatusBar";
	xPARENTnode.insertBefore(xSTATUSbar, xTEXTarea.nextSibling);
	xSTATUSbar.innerHTML="WYSIWYG mode";
	xGWYScontent=xGWYSarea.contentWindow.document;
	xGWYScontent.designMode="on";
	if (BrowserIs("MSIE")=="no") {
		xGWYScontent.execCommand("styleWithCSS", false, false);
	}//end if (BrowserIs("MSIE")=="no")
	UpdateGWYS(xTEXTareaId, xGWYSareaId);
}//end function
//=====================================================================================================
function ShowProgress() {
	//this function does not do anything
	//it is just here to avoid an error
	//if the progress bar script is not included later in the page
	return true;
}//end function
//=====================================================================================================
function GenGWYSelements() {
	arrTextAreas=document.getElementsByTagName("textarea");
	for(var i=0;i<arrTextAreas.length;i++) {
		xTEXTareaId=arrTextAreas[i].id;
		xFORMid=document.getElementById(xTEXTareaId).form.id;
		xGWYSareaId="gwys"+xTEXTareaId;
		xSTATUSbarId="status"+xTEXTareaId;
		if (arrTextAreas[i].className=="gwysTextArea") {
//			DrawToolBar(xTEXTareaId, xGWYSareaId, "advanced"); //pointless
			DrawToolBar(xTEXTareaId, xGWYSareaId, "standard");
			ConvertToWYSIWYG(xTEXTareaId, xGWYSareaId, xSTATUSbarId);
			SetStyleSheet(xGWYSareaId);
		}//end if (arrTextAreas[i].className=="gwys")
	}//next i<=arrTextAreas.length
}//end function
//=====================================================================================================
function AskForConfirmation(xMessage) {
	xResponse=confirm(xMessage);
	if (xResponse) {
		event.returnValue=true;
	} else {
		event.returnValue=false;
	}//end if (xResponse)
}//end function
//=====================================================================================================
function ApplyFormFunctions() {
	sxPAGEforms=document.getElementsByTagName("form");
	for (sf=0;sf<sxPAGEforms.length;sf++) {
		sxInputs=sxPAGEforms[sf].getElementsByTagName("input");
		xTextAreas=sxPAGEforms[sf].getElementsByTagName("textarea");
		xNUMfiles=0;
		xNUMtexts=0;
		for (si=0;si<sxInputs.length;si++) {
			xInputType=sxInputs[si].type;
			xInputID=sxInputs[si].id;
			if (xInputType=="file"||xInputID=="xIMAGEalt") {
				xNUMfiles++;
			}//end if (xInputType=="file"&&xInputValue!="")
		}//next si<sxInputs.length
		for (t=0;t<xTextAreas.length;t++) {
			xTextAreaClass=xTextAreas[t].className;
			if (xTextAreaClass=="gwysTextArea") {
				xNUMtexts++;
			}//end if (xTextAreaClass=="gwysTextArea")
		}//next t<xTextAreas.length
//		if (sxPAGEforms[sf].enctype!="multipart/form-data") {
			if (xNUMfiles>0&&xNUMtexts>0) {
//				sxPAGEforms[sf].enctype="multipart/form-data";
//				sxPAGEforms[sf].encoding="multipart/form-data";
				sxPAGEforms[sf].onsubmit=function() {
					UpdateHTML();
//					return ShowProgress();
				}//end function
			}//end if (xNUMfiles>0&&xNUMtexts>0)
			if (xNUMfiles==0&&xNUMtexts>0) {
//				sxPAGEforms[sf].enctype="application/x-www-form-urlencoded";
//				sxPAGEforms[sf].encoding="application/x-www-form-urlencoded";
				sxPAGEforms[sf].onsubmit=function() {
					UpdateHTML();
				}//end function
			}//end if (xNUMfiles==0&&xNUMtexts>0)
//			if (xNUMfiles>0&&xNUMtexts==0) {
//				sxPAGEforms[sf].enctype="multipart/form-data";
//				sxPAGEforms[sf].encoding="multipart/form-data";
//				sxPAGEforms[sf].onsubmit=function() {
//					return ShowProgress();
//				}//end function
//			}//(xNUMfiles>0&&xNUMtexts==0)
//		}//end if (sxPAGEforms[sf].enctype!="multipart/form-data")
	}//next sf<sxPAGEforms.length
}//end function
//=====================================================================================================















//=====================================================================================================
addLoadEvent(SetInputHighlights);
addLoadEvent(SizeMenus);
addLoadEvent(ApplyFormFunctions);
addLoadEvent(GenGWYSelements);
//=====================================================================================================
-->
