
// EDITOR
_editor_url = "/htmlarea/";
_editor_lang = "en";


// PAGE TIMEOUT
if (document.layers) {
  window.captureEvents(Event.MOUSEMOVE);
}

var tID = '';

//==============================================
// Dashboard Tabs
//==============================================
function dashDiv(selectedItem, containerName) {
    var container = document.getElementById(containerName);
	 
	    var sections = container.childNodes;
	 
	    if (sections.length > 0) {
	        for (i = 0; i < sections.length; i++) {
	            var selectNode = sections[i];
				
				var sItem = 'div' + selectedItem;
	 
	            if (selectNode.tagName == "DIV") {
	                if (selectNode.id == sItem) {
	                    selectNode.style.display = "";
	                } else {
	                    selectNode.style.display = "none";
	                }
	            }
	        }
	    }
		
		document.getElementById("link1").className= "dashTab";
		document.getElementById("link2").className= "dashTab";
		document.getElementById("link3").className= "dashTab";
		
		var sLink = 'link' + selectedItem;
		
		//alert(sLink);
		
		if (selectedItem != 0) {
			document.getElementById(sLink).className= "dashTabS";
		}
		
	}

//==============================================


//==============================================
// Clear Box
//==============================================
function clearBox(inputbutton, fillValue){
	if (inputbutton.value==fillValue) {
		inputbutton.value=''
	}
}
function fillBox(inputbutton, fillValue){
	if (inputbutton.value=="") {
		inputbutton.value=fillValue
	}
}
//==============================================


//==============================================
//Error Handler
//==============================================
function errorhandler() { 
	return true; 
}
//window.onerror=errorhandler;
//==============================================

//==============================================
//Add Category Check
//==============================================
function AddCategoryCheck(sCategoryButton, sText, sURL) {

	var sCategory = document.forms.CategoryForm.Category.value
	if (sCategory  != '') {
		document.forms.CategoryForm.action = sURL + '?PM=' + sCategoryButton
		document.forms.CategoryForm.submit();
	} 
	else {
		alert('You Must Enter an ' + sText);	
	}
	return false;
}
//==============================================

//==============================================
// Delete Check
//==============================================
function deleteCheck(sURL) {
	var confirmDelete = confirm("Are you sure you want to delete this item? \n ")
	if (confirmDelete == true) {
		document.forms[0].action = sURL + '?SubmitButton=Delete'
		document.forms[0].submit();
	} 
	return false;
}
//==============================================

//==============================================
//Link Delete
//==============================================
function linkdeleteCheck(sType, sItem, sURL) {
	
	var sType
	var sItem
	var confirmDelete = confirm("Delete This Item?")
	if (confirmDelete == true) {
		document.location = sURL + '?PM=delete' + sType + '&' + sType + '=' + sItem
	}
	else {
		
	}
}

//==============================================
//select delete checkboxes
//==============================================
function checkAll(theForm) {
    for (i=0,n=theForm.elements.length;i<n;i++)
        if (theForm.elements[i].name.indexOf('DeleteItems') !=-1)
            theForm.elements[i].checked = true;
}

function uncheckAll(theForm) {
    for (i=0,n=theForm.elements.length;i<n;i++)
        if (theForm.elements[i].name.indexOf('DeleteItems') !=-1)
            theForm.elements[i].checked = false;
}


//==============================================
// Popup function
//==============================================
function newPopupWindow(iId, sUrl)
{
	var popupWin
	popupWin = window.open (sUrl + iId, '100x400', 'toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width=520,height=300');
	popupWin.opener.top.name="windowOpener";
	popupWin.focus();
}
//==============================================

//==============================================
// Popup function
//==============================================
function newFileWindow(sType, iId)
{
	var popupWin
	popupWin = window.open ('/admin/files_fileassociation.asp?type=' + sType + '&Type_Id='+ iId, '100x400', 'toolbar=yes,location=yes,status=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=600');
	popupWin.opener.top.name="windowOpener";
	popupWin.focus();
}
//==============================================

function closePopup(sUrl) {
	opener.document.forms.details.submit();
	opener.focus();
	window.close();
	//popupWin.close();
}


//==============================================
// Open Help
//==============================================
function newHelp()
{
	var popupWin
	popupWin = window.open ('/admin/help_Popup.asp', '100x400', 'toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width=520,height=400');
	popupWin.opener.top.name="windowOpener";
	popupWin.focus();
}

//==============================================
//Category delete check for news
//==============================================

function NewsCategorydeleteCheck(sType, sItem, sItem2) {
	
		var sType
		var sItem
		var confirmDelete = confirm("Delete This Item?")
		if (confirmDelete == true) {
			document.location = '/admin/news_category.asp?PM=delete' + sType + '&' + sType + '=' + sItem + '&Category_Id=' + sItem2
		}
		else {
			//document.location = '/admin/membership.asp'
		}
}

	
//==============================================
//Category delete check for evets
//==============================================

function CategorydeleteCheck(sType, sItem, sItem2) {
	
		var sType
		var sItem
		var confirmDelete = confirm("Delete This Item?")
		if (confirmDelete == true) {
			document.location = '/admin/events_category.asp?PM=delete' + sType + '&' + sType + '=' + sItem + '&Category_Id=' + sItem2
		}
		else {
			//document.location = '/admin/membership.asp'
		}
	}
	
	//			document.location = '/admin/admin_events_category.asp?PM=delete' + sType + '&' + sType + '=' + sItem + '&Category_Id=' + sItem2
	
		

	
//==============================================
// Open printer window for events
//==============================================

function printpopupEvents(iIdEvents) {
		var popupWin
		popupWin = window.open ('events_printerfriendly.asp?Events_Id=' + iIdEvents, '400x400', 'toolbar=no,location=no,status=no,directories=no,menubar=yes,scrollbars=yes,resizable=no,width=520,height=300');
		popupWin.opener.top.name ="windowOpener";
		popupWin.focus();
	}
	


//==============================================
// Text Scrubber
//==============================================
function scrubText(sFieldToScrub) {

		var sTextToScrub = document.details.ContentLong.value;
		alert(sTextToScrub);
		sTextToScrub = RemoveHTML(sTextToScrub);

		alert(sTextToScrub);
	
		document.details.ContentLong.value = ""; //sTextToScrub;
}	
	
function convert(sTextToScrub){
	//this line replaces all double line breaks with a "<p></p>"
	//it also adds a <p> to the beginning and the </p> to the end
	//   \r\n stands for a line break, and \s stands for any empty space
	var txt = sTextToScrub
	
	txt="<p>"+txt.split(/\r\n(\s+)?\r\n/).join("</p><p>")+"</p>";
	
	//this line replaces all line breaks with a <br>
	txt=txt.split("\n").join("<br>");
	
	//this line replaces the links   target=""_blank""
	txt=txt.replace(/((http:\/\/)|(www))\.[^\s]+/gi,function(p1){return "<a href=http://"+p1+" target=\"_blank\">"+p1+"</a>";});
	
	//this line replaces all remaining line breaks with an empty space
	txt=txt.replace(/(\r|\n|\r\n)/gi,"");
	
	//this line adds a line breaks between each paragraph
	txt=txt.split("</p><p>").join("</p>\r\n<p>");
	
	//txt = clean(txt)
	//    opener.document.details.ContentLong.value = document.Scrub.NewContent.value;
	
	return txt //opener.document.richedit.idEditbox.document.body.innerHTML = txt;
	
}

function clean(sText) {

	sText = replace(sText,'–',unescape('dash'));
	sText = replace(sText,'“',unescape('"'));
	sText = replace(sText,'”',unescape('"'));
	sText = replace(sText,'•',unescape('<li>'));
	sText = replace(sText,'"',unescape('%22'));
	sText = replace(sText,'&',unescape('%26'));
	sText = replace(sText,'<',unescape('%3C'));
	sText = replace(sText,'>',unescape('%3E'));
	sText = replace(sText,' ',unescape('%A0'));
	sText = replace(sText,'¡',unescape('%A1'));
	sText = replace(sText,'¢',unescape('%A2'));
	sText = replace(sText,'£',unescape('%A3'));
	sText = replace(sText,'¥',unescape('%A5'));
	sText = replace(sText,'¦',unescape('%A6'));
	sText = replace(sText,'§',unescape('%A7'));
	sText = replace(sText,'¨',unescape('%A8'));
	sText = replace(sText,'©',unescape('%A9'));
	sText = replace(sText,'ª',unescape('%AA'));
	sText = replace(sText,'«',unescape('%AB'));
	sText = replace(sText,'¬',unescape('%AC'));
	sText = replace(sText,'­',unescape('%AD'));
	sText = replace(sText,'®',unescape('%AE'));
	sText = replace(sText,'¯',unescape('%AF'));
	sText = replace(sText,'°',unescape('%B0'));
	sText = replace(sText,'±',unescape('%B1'));
	sText = replace(sText,'²',unescape('%B2'));
	sText = replace(sText,'³',unescape('%B3'));
	sText = replace(sText,'´',unescape('%B4'));
	sText = replace(sText,'µ',unescape('%B5'));
	sText = replace(sText,'¶',unescape('%B6'));
	sText = replace(sText,'·',unescape('%B7'));
	sText = replace(sText,'¸',unescape('%B8'));
	sText = replace(sText,'¹',unescape('%B9'));
	sText = replace(sText,'º',unescape('%BA'));
	sText = replace(sText,'»',unescape('%BB'));
	sText = replace(sText,'¼',unescape('%BC'));
	sText = replace(sText,'½',unescape('%BD'));
	sText = replace(sText,'¾',unescape('%BE'));
	sText = replace(sText,'¿',unescape('%BF'));
	sText = replace(sText,'À',unescape('%C0'));
	sText = replace(sText,'Á',unescape('%C1'));
	sText = replace(sText,'Â',unescape('%C2'));
	sText = replace(sText,'Ã',unescape('%C3'));
	sText = replace(sText,'Ä',unescape('%C4'));
	sText = replace(sText,'Å',unescape('%C5'));
	sText = replace(sText,'Æ',unescape('%C6'));
	sText = replace(sText,'Ç',unescape('%C7'));
	sText = replace(sText,'È',unescape('%C8'));
	sText = replace(sText,'É',unescape('%C9'));
	sText = replace(sText,'Ê',unescape('%CA'));
	sText = replace(sText,'Ë',unescape('%CB'));
	sText = replace(sText,'Ì',unescape('%CC'));
	sText = replace(sText,'Í',unescape('%CD'));
	sText = replace(sText,'Î',unescape('%CE'));
	sText = replace(sText,'Ï',unescape('%CF'));
	sText = replace(sText,'Ð',unescape('%D0'));
	sText = replace(sText,'Ñ',unescape('%D1'));
	sText = replace(sText,'Ò',unescape('%D2'));
	sText = replace(sText,'Ó',unescape('%D3'));
	sText = replace(sText,'Ô',unescape('%D4'));
	sText = replace(sText,'Õ',unescape('%D5'));
	sText = replace(sText,'Ö',unescape('%D6'));
	sText = replace(sText,'×',unescape('%D7'));
	sText = replace(sText,'Ø',unescape('%D8'));
	sText = replace(sText,'Ù',unescape('%D9'));
	sText = replace(sText,'Ú',unescape('%DA'));
	sText = replace(sText,'Û',unescape('%DB'));
	sText = replace(sText,'Ü',unescape('%DC'));
	sText = replace(sText,'Ý',unescape('%DD'));
	sText = replace(sText,'Þ',unescape('%DE'));
	sText = replace(sText,'ß',unescape('%DF'));
	sText = replace(sText,'à',unescape('%E0'));
	sText = replace(sText,'á',unescape('%E1'));
	sText = replace(sText,'â',unescape('%E2'));
	sText = replace(sText,'ã',unescape('%E3'));
	sText = replace(sText,'ä',unescape('%E4'));
	sText = replace(sText,'å',unescape('%E5'));
	sText = replace(sText,'æ',unescape('%E6'));
	sText = replace(sText,'ç',unescape('%E7'));
	sText = replace(sText,'è',unescape('%E8'));
	sText = replace(sText,'é',unescape('%E9'));
	sText = replace(sText,'ê',unescape('%EA'));
	sText = replace(sText,'ë',unescape('%EB'));
	sText = replace(sText,'ì',unescape('%EC'));
	sText = replace(sText,'í',unescape('%ED'));
	sText = replace(sText,'î',unescape('%EE'));
	sText = replace(sText,'ï',unescape('%EF'));
	sText = replace(sText,'ð',unescape('%F0'));
	sText = replace(sText,'ñ',unescape('%F1'));
	sText = replace(sText,'ò',unescape('%F2'));
	sText = replace(sText,'ó',unescape('%F3'));
	sText = replace(sText,'ô',unescape('%F4'));
	sText = replace(sText,'õ',unescape('%F5'));
	sText = replace(sText,'ö',unescape('%F6'));
	sText = replace(sText,'÷',unescape('%F7'));
	sText = replace(sText,'ø',unescape('%F8'));
	sText = replace(sText,'ù',unescape('%F9'));
	sText = replace(sText,'ú',unescape('%FA'));
	sText = replace(sText,'û',unescape('%FB'));
	sText = replace(sText,'ü',unescape('%FC'));
	sText = replace(sText,'ý',unescape('%FD'));
	sText = replace(sText,'þ',unescape('%FE'));
	sText = replace(sText,'ÿ',unescape('%FF'));

	return sText;
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}	

function RemoveHTML(sText) {
	var regEx = /<[^>]*>/g;
	return sText.replace(regEx, "");
}
