
//---------------------------------------------------------------------
//	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;
	}
}

//---------------------------------------------------------------------
//	Displays the Form for editing items - if no arguments are 
//	passed in, a new one is assumed
//---------------------------------------------------------------------
function editItem(){
	
	var sQS = arguments.length ? ('?iid=' + arguments[0] + '&icid=' + arguments[1]) : '';	
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/Item.aspx'+sQS, 700, 680);
	return(true);	
	
	
}//editItem()

//---------------------------------------------------------------------
//	Displays the Form for editing identifiers - if no arguments are 
//	passed in, a new one is assumed
//---------------------------------------------------------------------
function editIdentifier(){
	
	var sQS = arguments.length ? ('?identid=' + arguments[0]) : '';	
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/Identifiers.aspx'+sQS, 700, 680);
	return(true);	
	
	
}//editIdentifier()



//---------------------------------------------------------------------
//	Shows the data dots page 
//---------------------------------------------------------------------
function showDataDots(url){
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/DataDots.aspx?url='+url, 700, 680);
	return(true);	
	
	
}//showDataDots()



//---------------------------------------------------------------------
//	Displays the Form for replacing identifiers
//---------------------------------------------------------------------
function replaceIdentifier(){
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/IdentifierReplace.aspx', 700, 680);
	return(true);	
	
	
}//replaceIdentifier()

//---------------------------------------------------------------------
//	Displays the Form for editing items - if no arguments are 
//	passed in, a new one is assumed
//---------------------------------------------------------------------
function editPerson(){
	
	var sQS = arguments.length ? ('?iid=' + arguments[0]) : '';	
	
	var oOut = displayModalPopUpCrossBrowser('https://third-drawer.com//en-AU/Popups/Person.aspx'+sQS, 700, 680, true);
	return(true);	
	
	
}//editPerson()

//---------------------------------------------------------------------
//	Displays the Form for editing items - if no arguments are 
//	passed in, a new one is assumed
//---------------------------------------------------------------------
function editTravel(){
	
	var sQS = arguments.length ? ('?iid=' + arguments[0]) : '';	
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/Travel.aspx'+sQS, 700, 680);
	return(true);	
	
	
}//editTravel()

//---------------------------------------------------------------------
//	Displays the Form for editing items - if no arguments are 
//	passed in, a new one is assumed
//---------------------------------------------------------------------
function editInsurancePolicy(){

	var sQS = arguments.length ? ('?ipid=' + arguments[0]) : '';	
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/InsurancePolicies.aspx'+sQS, 700, 680);	
	
	return(true);	//we return true so the server event to redisplay the datagrid can happen
	
	
}//editItem()


//---------------------------------------------------------------------
//	Displays the Form for editing items - if no arguments are 
//	passed in, a new one is assumed
//---------------------------------------------------------------------
function editLocation(){
	
	var sQS = arguments.length ? ('?lid=' + arguments[0]) : '';	
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/Locations.aspx'+sQS, 700, 680);
	return(true);	
	
	
}//editItem()

//---------------------------------------------------------------------
//	Displays the Form for editing items - if no arguments are 
//	passed in, a new one is assumed
//---------------------------------------------------------------------
function editChangeAddress(){
	
	var sQS = arguments.length ? ('?cid=' + arguments[0]) : '';	
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/ChangeAddress.aspx'+sQS, 700, 680);
	return(true);	
	
	
}//editItem()

//---------------------------------------------------------------------
//	Displays the popup for messages and tasks
//---------------------------------------------------------------------
function editTasksMessages(){
	
	var sQS = arguments.length ? ('?tid=' + arguments[0]) : '';	
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/Task.aspx'+sQS, 700, 680);
	return(true);	
	
	
}//editItem()


//---------------------------------------------------------------------
//	Displays announcements
//---------------------------------------------------------------------
function editAnnouncements(){
	
	var sQS = arguments.length ? ('?aid=' + arguments[0]) : '';	
	
	var oOut = displayModalPopUpCrossBrowser('/en-AU/Popups/Announcement.aspx'+sQS, 700, 680);
	return(true);	
	
	
}//editAnnouncement()


//---------------------------------------------------------------------
//	Displays the popup for help
//---------------------------------------------------------------------
function displayHelp(){
	
	displayStandardPopUpCrossBrowser('Help/index.htm', 800, 680);
	//displayStandardPopUpCrossBrowser('/en-AU/Help/index.htm', 700, 680);
	return(false);
	
}//help()

//---------------------------------------------------------------------
//	Displays Export As page: this will not display as a page, but as a download dialogue box instead.
//---------------------------------------------------------------------
function displayExportAs(sType){
	
	
	var sPopupPage = '/en-AU/exportas.aspx?et=' + sType;
	top.location = sPopupPage;
	
	
}//displayExportAs()

//---------------------------------------------------------------------
//	Displays Export As page: this will not display as a page, but as a download dialogue box instead.
//---------------------------------------------------------------------
function displayExportAs(sType, sItemID){
	
	
	var sPopupPage = '/en-AU/exportas.aspx?et=' + sType + '&iid=' + sItemID;
	top.location = sPopupPage;
	
	
}//displayExportAs()

function notImplemented(){

	alert('Sorry, this functionality is still to be implemented.');
	return 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){
		var sDefaultDate = "";
		if(oElem.value.length==10){
			var a = oElem.value.split('/');
			if(a.length == 3){
				sDefaultDate = a[2] + a[1] + a[0];
			}
		}
		var sDateYYYYMMDD = displayDatePicker(sDefaultDate);
		
		if(sDateYYYYMMDD) {
			var yyyy = sDateYYYYMMDD.substring(0, 4);
			var MM = sDateYYYYMMDD.substring(4, 6);
			var dd = sDateYYYYMMDD.substring(6);
			oElem.value = dd + "/" + MM + "/" + yyyy;
			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('/Common/DatePickerDialog.aspx'+sQS, 187, 141);
	return((oOut && oOut.date) ? oOut.date : "");
}

//---------------------------------------------------------------------
//	Displays a Popup dialog confirming a Delete of an item
//---------------------------------------------------------------------
function confirmDelete(sMessage){
	if (sMessage)
	{
		return(confirmMessageDelete(sMessage,300,150));
	}
	else
	{	
		return(confirmMessageDelete("Are you sure you want to delete this item?",300,150));
	}
}

//---------------------------------------------------------------------
//	Displays a Popup dialog confirming a Delete of an item
//---------------------------------------------------------------------
function confirmMessageDelete(confirmMessage,winx,winy){	
	if (window.showModalDialog)
	{		
		return(displayYesNoPopup(confirmMessage,winx,winy).answer=="yes");
	}
	else
	{
		return(displayYesNoPopup(confirmMessage,winx,winy));
	}
}

//---------------------------------------------------------------------
//	Displays a Popup dialog with the provided question and Yes and No as answers
//---------------------------------------------------------------------
function displayYesNoPopup(sQuestion,winx,winy){
	if (window.showModalDialog)
	{			
		return(displayQuestionPopup(sQuestion, new Array("Yes", "No"),winx,winy));
	}
	else
	{
		return(confirm(sQuestion));
	}
	
}
//---------------------------------------------------------------------
//	Displays a Popup dialog with the provided question and OK and Cancel as answers
//---------------------------------------------------------------------
function displayOKCancelPopup(sQuestion){
	
	if (window.showModalDialog)
	{
		return(displayQuestionPopup(sQuestion, new Array("OK", "Cancel"),300,150));
	}
	else
	{
		return(confirm(sQuestion));
	}
}

//---------------------------------------------------------------------
//	Displays a Popup dialog with the provided question and OK as an answer
//---------------------------------------------------------------------
function displayOKPopup(sQuestion)
{
	if (window.showModalDialog)
	{
		return(displayQuestionPopup(sQuestion, new Array("OK"),300,150));
	}
	else
	{
		return(confirm(sQuestion));
	}
}

//---------------------------------------------------------------------
//	Displays a Popup dialog with the provided question and possible answers
//	IMPORTANT!!!! The answer returned is all in lower case!!!!!!!!!!!!!!
//---------------------------------------------------------------------
function displayQuestionPopup(sQuestion, aAnswers, winx, winy){
	var args = new Object();
	args.question = sQuestion;
	args.answers = aAnswers;
	return(displayPopUpArgs("/Common/QuestionDialog.htm", args, winx, winy));
}

//---------------------------------------------------------------------
//	Displays a Popup with the provided dimensions
//---------------------------------------------------------------------
function displayPopUp(sPageSource, iWidthPx, iHeightPx){
	var sPopupPage = "/Common/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=yes;unadorned=yes"));
	
		
	
}

//---------------------------------------------------------------------
//	Displays a Popup passing in the provided arguments.  
//---------------------------------------------------------------------
function displayPopUpArgs(sPageSource, args, iWidthPx, iHeightPx){
	var sPopupPage = "/Common/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 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);
}

function displayModalPopUpCrossBrowser(sPageSource, iWidthPx, iHeightPx){
	return displayModalPopUpCrossBrowser(sPageSource, iWidthPx, iHeightPx, true);
}

//---------------------------------------------------------------------
//	Displays a Modal Popup with the provided dimensions - works in cross browsers IE5+ on both Mac and Win, Firefox on Win, Safari on Mac
//---------------------------------------------------------------------
function displayModalPopUpCrossBrowser(sPageSource, iWidthPx, iHeightPx, isSsl){
	var sPopupPage = "";
	
	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;
	
	//if (window.showModalDialog)
	//{
	//	if (isSsl)
	//	{
	//		sPopupPage = "https://third-drawer.com/Common/popup.aspx?h="+(args.height+60);
	//	}
	//	else
	//	{
	//		sPopupPage = "/Common/popup.aspx?h="+(args.height+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=yes;unadorned=yes"));
	//}
	//else
	//{		
	// FireFox 3 implements showModalDialog, but is missing some paramaters which breaks it
	// So we just going to use the window.open instead for everyone. Let's keep it consistent
		if (isSsl)
		{
			sPopupPage = "https://third-drawer.com/Common/popupCrossBrowser.aspx?psrc=" + escape(sPageSource);
		}
		else
		{
			sPopupPage = "/Common/popupCrossBrowser.aspx?psrc=" + escape(sPageSource);
		}
		return(window.open(sPopupPage,"newWindow","height=" + (args.height+60) + "px," + "width=" + (args.width+50) + "px,alwaysRaised=yes,dependent=yes,resizable=yes,scrollbars=no,status=yes,location=no,menubar=no,modal=yes"));
	//}
		
	
}

function displayStandardPopUpCrossBrowser(sPageSource, iWidthPx, iHeightPx){
	return displayStandardPopUpCrossBrowser(sPageSource, iWidthPx, iHeightPx, false);
	
}
//---------------------------------------------------------------------
//	Displays a Standard Popup with the provided dimensions - works in cross browsers IE5+ on both Mac and Win, Firefox on Win, Safari on Mac
//---------------------------------------------------------------------
function displayStandardPopUpCrossBrowser(sPageSource, iWidthPx, iHeightPx, isSsl){
	var sPopupPage = "";
	
	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;	
	
	if (isSsl)
	{
		sPopupPage = "https://third-drawer.com/" + sPageSource;
	}
	else
	{
		sPopupPage = "/" + sPageSource;
	}
	return(window.open(sPopupPage,"newWindow","height=" + (args.height+60) + "px," + "width=" + (args.width+50) + "px,alwaysRaised=yes,center=yes,dependent=yes,resizable=yes,scrollbars=no,status=yes,location=no,menubar=no,modal=yes"));

		
	
}




