// FIREWORKS IMAGE ROLLOVER
function MM_findObj(n, d) { //v4.01
	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 && d.getElementById) x=d.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 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];}}
}


// FORM : PAGE NAVIGATION
function pageNavigation(form) {window.location.href = form.Mode.options[form.Mode.selectedIndex].value;}


// FORM : CHECK/UNCHECK ALL
function invertCheck(toggle, checkList, buttonIDs){
	if (checkList.length == null) {
		if ( toggle.checked ) { checkList.checked = true; }
		else { checkList.checked = false; }
	} else {
		for(i=0; i<checkList.length; i++){
			if ( toggle.checked ) { checkList[i].checked = true; }
			else { checkList[i].checked = false; }
		}
	}
	if (buttonIDs != null) {enableSubmit(checkList, buttonIDs);}
}


// FORM : ENABLE/DISABLE SUBMIT BUTTON(S)
function enableSubmit(checkList, buttonIDs) {
	var checkListValid = false;
	if (checkList.length == null) {
		if (checkList.checked == true) {checkListValid = true;} else {checkListValid = false;}
	} else {
		for (i=0; i<checkList.length; i++) {
			if (checkList[i].checked == true) {checkListValid = true;}
		}
	}
	if (buttonIDs.length == null) {
		if (checkListValid) {buttonIDs.disabled = false;} else {buttonIDs.disabled = true;}
	} else {
		for (i=0; i<buttonIDs.length; i++) {
			if (checkListValid) {buttonIDs[i].disabled = false;} else {buttonIDs[i].disabled = true;}
		}
	}
}
							
							

// FORM : MOVE CHECKED MESSAGES TO FOLDER
function moveToFolder(formID){
	var TempString = "";
	var max = formID.tid.length;
	for (var idx = 0; idx < max; idx++) {
		if (eval("formID.tid[" + idx + "].checked")==true && (TempString=="" || TempString==null)) {
			TempString = eval("formID.tid[" + idx + "].value");
		}
		else if (eval("formID.tid[" + idx + "].checked")==true) {
			TempString = TempString + "," + eval("formID.tid[" + idx + "].value");
		}
	}
	if (TempString == "" || TempString == null) {
		alert("You must select at least one message to move.");
		formID.NewFolder.selectedIndex = 0;
		return false;
	}
	var URL = formID.NewFolder.options[formID.NewFolder.selectedIndex].value;
	window.location.href = URL + "&MessageIds=" + TempString;
}


// 	FORM : OPEN ERROR DIALOG
function openErrorDialog(baseURL, errorCodes) {
	var browser_ver = "";
	var browser = "";
	var mouseoversupport = "";
	var browsername = navigator.appName;
	var browserversion = parseInt(navigator.appVersion);
	var newWindow;
	var width = 280;
	var height = 250;
	
	// determine browser type
	if (browsername == "Netscape") { browser = "ns"; browser_ver = "ns" + browserversion; }
	else if (browsername == "Microsoft Internet Explorer") { browser = "ie"; if (browserversion >= 4) { browser_ver = "ie" + browserversion; } else { browser_ver = "ie3"; }; }
	else if (browsername == "Opera") { browser = "op"; browser_ver = "op" + browserversion; }
	else { browser_ver = "ie5"; }
	
	// determine screen dimensions
	var screenwidth = (screen.width - width) / 2;
	var screenheight = (screen.height - height) / 2;
	
	if (browser_ver=="ns3" || browser_ver=="ns4") { popupwidth = width; popupheight = height; }
	else if (browser_ver=="ns5") { popupwidth = width; popupheight = height; }
	else if (browser_ver=="ie3" || browser_ver=="ie4" || browser_ver=="ie5") { popupwidth = width + 5; popupheight = height + 10; }
	else if (browser_ver=="op5") { popupwidth = width - 5; popupheight = height + 20; }
	else { popupwidth = width - 5; popupheight = height + 50; }
	
	newWindow = window.open(baseURL + '/Includes/ErrorWindow.cfm?ErrorCodes=' + errorCodes,'ErrorWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + popupwidth + ',height=' + popupheight + ',top=' + screenheight + ',left=' + screenwidth);
	newWindow.focus();
}


// 	FORM : ADD/REMOVE LIST ITEMS
function addSrcToDestList(formID) {
	destList = formID.destList;
	srcList = formID.srcList; 
	var len = destList.length;
	for(var i = 0; i < srcList.length; i++) {
		if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
		//Check if this value already exist in the destList or not
		//if not then add it otherwise do not add it.
		var found = false;
			for(var count = 0; count < len; count++) {
				if (destList.options[count] != null) {
					if (srcList.options[i].text == destList.options[count].text) {
						found = true;
						break;
					}
				}
			}
			if (found != true) {
				destList.options[len] = new Option(srcList.options[i].text, srcList.options[i].value); 
				len++;
			}
		}
	}
	clearSelection (srcList, destList);
}
function deleteFromDestList(formID) {
	var destList  = formID.destList;
	var len = destList.options.length;
	for(var i = (len-1); i >= 0; i--) {
		if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
			destList.options[i] = null;
		}
	}
	clearSelection (srcList, destList);
}
function buildUserList() {
	var TempList = "";
	var destListBox = window.document.forms[0].destList; 
	for (i=0; i<destListBox.options.length; i++) {
		if (i == 0) {TempList = destListBox.options[i].value;}
		else {TempList = TempList + ", " + destListBox.options[i].value;}
	}
	window.document.forms[0].UserList.value = TempList;
}

function buildUserList2() {
	var TempList = "";
	var destListBox = window.document.forms[0].destList; 
	for (i=0; i<destListBox.options.length; i++) {
		if (i == 0) {TempList = destListBox.options[i].value;}
		else {TempList = TempList + "," + destListBox.options[i].value;}
	}
	window.document.forms[0].UserList.value = TempList;
}
function clearSelection (srcList, destList) {
	//alert('Hi.');
	for (var i = 0; i < destList.options.length; i++) {
		destList.options[i].selected = false;
	}
	for (var i = 0; i < srcList.options.length; i++) {
		srcList.options[i].selected = false;
	}
}


// 	FORM : UPLOAD FILES
function addFiles(formID) {
	var formValid = true;
	for (i=1; i<=formID.NumFiles.value; i++) {
		value = eval("formID.Location" + i + ".value");
		extension = value.substring(value.lastIndexOf('.') + 1,value.length);
		if (extension.length != 2 && extension.length != 3 && extension.length != 4) {formValid = false;}
		if (eval("formID.Location" + i + ".value.length") == 0) {formValid = false;}
		if (eval("formID.FileName" + i + ".value.length") == 0) {formValid = false;}
	}
	if (formValid) {
		formID.Submit.disabled = false;
	} else {
		formID.Submit.disabled = true;
	}
}
function addFilesSubmit(formID) {
	formID.Submit.value = "Uploading In Progress";
	formID.Submit.disabled = true;
	formID.submit();
}


// 	FORM : ADD/EDIT APPOINTMENT
function showHideElement(formElement) {
	if (formElement.checked == true) {
		StartTime.style.display = "none";
		StopTime.style.display = "none";
	} else {
		StartTime.style.display = "";
		StopTime.style.display = "";
	}
}
function validateForm(form) {
	if ( form.Name.value.length != 0 ) {
		form.Submit[0].disabled = false;
		form.Submit[1].disabled = false;
	} else {
		form.Submit[0].disabled = true;
		form.Submit[1].disabled = true;
	}
}


// FORM : DATE CALCULATIONS
function updateDisplay(formID) {
	changeDropDown(formID.StartMonth, formID.StopMonth);
	changeDropDown(formID.StartDay, formID.StopDay);
	changeDropDown(formID.StartYear, formID.StopYear);
	ChangeOptionDays("Start");
	ChangeOptionDays("Stop");
}
function swapDate(formElement, monthValue, dayValue, yearValue) {
	eval("window.document." + formElement + "Month.value = monthValue");
	eval("window.document." + formElement + "Year.value = yearValue");
	ChangeOptionDays("Start");
	ChangeOptionDays("Stop");
	eval("window.document." + formElement + "Day[dayValue-1].selected = true");
}
function changeDropDown(setItem, changeItem) {
	if (changeItem.value < setItem.value) {changeItem.value = setItem.value;}
}
function DaysInMonth(WhichMonth, WhichYear)
{
	var DaysInMonth = 31;
	if (WhichMonth == 4 || WhichMonth == 6 || WhichMonth == 9 || WhichMonth == 11) DaysInMonth = 30;
	if (WhichMonth == 2 && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
	if (WhichMonth == 2 && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
	return DaysInMonth;
}
function ChangeOptionDays(Which) {
	DaysObject = eval("window.document.forms[0]." + Which + "Day");
	MonthObject = eval("window.document.forms[0]." + Which + "Month");
	YearObject = eval("window.document.forms[0]." + Which + "Year");
	
	Month = MonthObject[MonthObject.selectedIndex].value;
	Year = YearObject[YearObject.selectedIndex].value;
	
	DaysForThisSelection = DaysInMonth(Month, Year);
	CurrentDaysInSelection = DaysObject.length;
	
	if (CurrentDaysInSelection > DaysForThisSelection) {
		for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++) {
			DaysObject.options[DaysObject.options.length - 1] = null
		}
	}
	if (DaysForThisSelection > CurrentDaysInSelection) {
		for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++) {
			NewOption = new Option(DaysObject.options.length + 1, DaysObject.options.length + 1);
			DaysObject.add(NewOption);
		}
	}
	if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
	//changeDropDown(window.document.forms[0].StartMonth, window.document.forms[0].StopMonth);
}


// FORM : BLOCK SPECIAL CHARACTERS
function blockCharacters() {
	var isNS4 = (navigator.appName=="Netscape")?1:0;
	if (!isNS4) {
		if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) {
			event.returnValue = false;
		} else {
			if ((event.which > 32 && event.which < 48) || (event.which > 57 && event.which < 65) || (event.which > 90 && event.which < 97)){
				return false;
			}
		}
	}
}


// POPUP WINDOW
function DatePicker(url, date, width, height) {
	// define variables
	var browser_ver = "";
	var browser = "";
	var mouseoversupport = "";
	var browsername = navigator.appName;
	var browserversion = parseInt(navigator.appVersion);
	
	// determine browser type
	if (browsername == "Netscape") { browser = "ns"; browser_ver = "ns" + browserversion; }
	else if (browsername == "Microsoft Internet Explorer") { browser = "ie"; if (browserversion >= 4) { browser_ver = "ie" + browserversion; } else { browser_ver = "ie3"; }; }
	else if (browsername == "Opera") { browser = "op"; browser_ver = "op" + browserversion; }
	else { browser_ver = "ie5"; }
	
	var newWindow;
	
	// determine screen dimensions
	var screenwidth = (screen.width - width) / 2;
	var screenheight = (screen.height - height) / 2;
	
	if (browser_ver=="ns3" || browser_ver=="ns4") { popupwidth = screenwidth; popupheight = screenheight; }
	else if (browser_ver=="ns5") { popupwidth = screenwidth; popupheight = screenheight; }
	else if (browser_ver=="ie3" || browser_ver=="ie4" || browser_ver=="ie5") { popupwidth = screenwidth + 5; popupheight = screenheight + 10; }
	else if (browser_ver=="op5") { popupwidth = screenwidth - 5; popupheight = screenheight + 20; }
	else { popupwidth = screenwidth - 5; popupheight = screenheight + 50; }
	
	newWindow = window.open(url + '&Date=' + date,'Ad','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + width + ',height=' + height + ',top=' + popupheight + ',left=' + popupwidth);
	mouseoversupport = "yes";
	newWindow.focus();
}
