﻿/*
*** mod date:		09/07/08
--- description:	removes the dashed line round links
                    
--- usage:			uses a mootools 'domready' function to apply to all links on the page
*/
function unblur() {
	this.blur();
} 
function blurLinks() {
	if (!document.getElementById) return;
	theLinks = document.getElementsByTagName("A");
	theAreas = document.getElementsByTagName("AREA");
	for(i=0; i<theLinks.length; i++) {theLinks[i].onfocus = unblur;}
	for(i=0; i<theAreas.length; i++) {theAreas[i].onfocus = unblur;}
}
window.addEvent('domready', function(){blurLinks();});

//forces a user to confirm prior to posting the page
function confirmDelete(){
    return confirm("This option will:\n\n    - Delete the selected item\n\nAre you sure you want to do this?");
}

//forces a user to confirm prior to posting the page
function confirmNewsSubjectDelete(){
    return confirm("This option will:\n\n    - Delete the selected News Subject\n    - Delete all News Articles associated with this Subject\n\nAre you sure you want to do this?");
}

//forces a user to confirm prior to posting the page
function confirmFaqSectionDelete(){
    return confirm("This option will:\n\n    - Delete the selected FAQ Subject\n    - Delete all FAQ's associated with this Subject\n\nAre you sure you want to do this?");
}

//forces a user to confirm prior to posting the page
function confirmParentPageDelete(){
    return confirm("This option will:\n\n    - Delete the selected Page\n    - Delete all child pages under this page\n\nAre you sure you want to do this?");
}

//forces a user to confirm prior to posting the page
function confirmModuleUnlock(){
    return confirm("While a module is Checked Out other users will not be able to:\n\n    - Add, amend, order or delete rows.\n\nAre you sure you want to do this?");
}
function confirmModuleLock(){
    return confirm("Checking this module back in when another\nuser has it checked out can potentially:\n\n    - Destroy or alter data unexpectedly\n    - Cause sort ordering to go out of sync\n    - Annoy the other user if they were working...\n\nAre you sure you want to do this?");
}

/*
*** mod date:		17/apr/07
--- description:	toggles a page element.
                    
--- usage:			pass the id of the elelment - the function evaluates it's
                    current visiblity and toggles it.
*/
function showHideElement(id) {
	var obj = $(id);
	if (obj.style.display == "inline") {
		obj.style.display = "none";
	} else {
		obj.style.display = "inline";
	}
}

/*
flags as panel and hidden field as deleted
*/
function setPicAsDeleted(pnlID, hfID){
	$(pnlID).setStyle('display','none');
	$(hfID).setProperties({value: 'True'});
}

//checks the file extension of the passed frm field
function checkFileExt(id,arrExt) {
	var valid_bln = false;
	var valid_arr = arrExt;
	var valid_files_arr = valid_arr.split(",")
	for (var i=0; i<valid_files_arr.length; i++) {
		if ($(id).value.toLowerCase().match(valid_files_arr[i])) {
			valid_bln = true;
		}
	}
	if (valid_bln == false) {
		return(false);
	} else {
		return(true);
	}
}


//checks the length of the passed field
function checkFieldLength(fieldID,maxLength) {
	var fieldID = $(fieldID);
	var fieldIDLength = fieldID.value.length;
	if(fieldIDLength > maxLength) {
		return false;
	} else {
		return true;
	}   
}

function getDateObject(date_txt) {
    return new Date(parseFloat(date_txt.split("/")[2]), parseFloat(date_txt.split("/")[1])-1, parseFloat(date_txt.split("/")[0]));
}

function compareStartEndDates(StartDate, EndDate){
    var dteStartDate = getDateObject($(StartDate).value);
    var dteEndDate = getDateObject($(EndDate).value);
    
    if (dteStartDate.getTime() >= dteEndDate.getTime()) {
		return(false);
	} else {
		return(true);
	}    
}



/*
	only allow numeric chars
*/
function DecimalNumbersOnly(e) {
	var key;
	var keychar;

	if (window.event) {
	   key = window.event.keyCode;
	} else if (e) {
	   key = e.which;
	} else {
	   return true;
	}
	keychar = String.fromCharCode(key);

	// control keys and numbers
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) {
	   return true;
	} else if ((("0123456789.").indexOf(keychar) > -1)) {
	   return true;
	} else {
	   return false;
	}
}

