
//---------------------------------------------------------------------
//	Enables all elements in the form so that their content can 
//  be posted back to the server (mainly for date fields)
//---------------------------------------------------------------------
function enableAllFieldsInForm(){
	var aElems = document.forms[0].elements;
	for(var i=0; i<aElems.length; i++){
		aElems[i].disabled = false;
	}
}

//---------------------------------------------------------------------
//	Using displayDatePicker, allows modification of a Form elements date
//	The date must be in the dd/MM/yyyy
//---------------------------------------------------------------------
function editDateFormElement(sElemId){
	var oElem = document.getElementById(sElemId);
	if(oElem){
		//make sure the date is in the yyyymmdd format
		var sDefaultDate = "";
		if(oElem.value.length==10){
			var a = oElem.value.split('/');
			if(a.length == 3){
				sDefaultDate = a[2] + a[1] + a[0];
			}
		}
		
		//passinto the datepicker
		var sDateYYYYMMDD = displayDatePicker(sDefaultDate);
		
		//reset to display in the form
		if(sDateYYYYMMDD) {
		
			if(sDateYYYYMMDD!='clear'){
				var yyyy = sDateYYYYMMDD.substring(0, 4);
				var MM = sDateYYYYMMDD.substring(4, 6);
				var dd = sDateYYYYMMDD.substring(6);
				oElem.value = dd + "/" + MM + "/" + yyyy;
			} else {
				oElem.value = '';
			}
			return(true);
		}
	}//fi elem
	return(false);
}//editDateFormElement()

//---------------------------------------------------------------------
//	Displays a Popup dialog with a date picker.  The default date and
//	the returned values are both in yyyyMMdd format!!!
//---------------------------------------------------------------------
function displayDatePicker(sCurrentDateYYYYMMDD){
	var sQS = "";
	if(sCurrentDateYYYYMMDD) {
		sQS = "?date=" + sCurrentDateYYYYMMDD;
	}
	var oOut = displayPopUp('/global/dialog/DatePickerDialog.aspx'+sQS, 193, 164);
	return((oOut && oOut.date) ? oOut.date : "");
}

//---------------------------------------------------------------------
//	Displays a Popup dialog confirming a Delete of an item
//---------------------------------------------------------------------
function confirmDelete(){
	return(displayYesNoPopup("Are you sure you want to delete this item?").answer=="yes");
}

//---------------------------------------------------------------------
//	Displays a Popup dialog with the provided question and Yes and No as answers
//---------------------------------------------------------------------
function displayYesNoPopup(sQuestion){
	return(displayQuestionPopup(sQuestion, new Array("Yes", "No")));
}
//---------------------------------------------------------------------
//	Displays a Popup dialog with the provided question and OK and Cancel as answers
//---------------------------------------------------------------------
function displayOKCancelPopup(sQuestion){
	return(displayQuestionPopup(sQuestion, new Array("OK", "Cancel")));
}

//---------------------------------------------------------------------
//	Displays a Popup dialog with the provided question and OK as an answer
//---------------------------------------------------------------------
function displayOKPopup(sQuestion){
	return(displayQuestionPopup(sQuestion, new Array("OK")));
}

//---------------------------------------------------------------------
//	Displays a Popup dialog with the provided question and possible answers
//	IMPORTANT!!!! The answer returned is all in lower case!!!!!!!!!!!!!!
//---------------------------------------------------------------------
function displayQuestionPopup(sQuestion, aAnswers){
	var args = new Object();
	args.question = sQuestion;
	args.answers = aAnswers;
	return(displayPopUpArgs("/global/dialog/QuestionDialog.htm", args, 500, 200));
}

//---------------------------------------------------------------------
//	Displays a Popup passing in the provided arguments.  
//---------------------------------------------------------------------
function displayPopUpArgs(sPageSource, args, iWidthPx, iHeightPx){
	var sPopupPage = "/global/dialog/popup.htm";
	
	args.src = sPageSource;
	args.width = parseInt(iWidthPx);
	if(isNaN(args.width) || args.width > (screen.availWidth-50)) args.width = screen.availWidth-50;
	args.height = parseInt(iHeightPx);
	if(isNaN(args.height) || args.height > (screen.availHeight-60)) args.height = screen.availHeight-60;

	return(window.showModalDialog(sPopupPage, args, "dialogHeight:" + (args.height+60) + "px;" +
				"dialogWidth:" + (args.width+50) + "px;center=yes;help=no;resizable=yes;scroll=no;status=no;unadorned=yes"));
}

//---------------------------------------------------------------------
//	Displays a Popup with the provided dimensions
//---------------------------------------------------------------------
function displayPopUp(sPageSource, iWidthPx, iHeightPx){
	var sPopupPage = "/global/dialog/popup.htm";
	
	var args = new Object();
	args.src = sPageSource;
	args.width = parseInt(iWidthPx);
	if(isNaN(args.width) || args.width > (screen.availWidth-50)) args.width = screen.availWidth-50;
	args.height = parseInt(iHeightPx);
	if(isNaN(args.height) || args.height > (screen.availHeight-60)) args.height = screen.availHeight-60;

	return(window.showModalDialog(sPopupPage, args, "dialogHeight:" + (args.height+60) + "px;" +
				"dialogWidth:" + (args.width+50) + "px;center=yes;help=no;resizable=yes;scroll=no;status=no;unadorned=yes"));
}

//---------------------------------------------------------------------
//	Displays a Popup and refreshes the current window
//---------------------------------------------------------------------
function displayPopUpRefresh(sPageSource, iWidthPx, iHeightPx){
	//var FROM_SERVER = true;
	displayPopUp(sPageSource, iWidthPx, iHeightPx);
	//this is a temporary fix... 
	window.location.replace(window.location);
	//window.location.reload(FROM_SERVER);
}
