// caMessages.js - messages for STAR Web
// Copyright © Cuadra Associates, Inc. 2005-2008. All rights reserved.
// Version 4.1.13

var caDefaultInvalidMessage = 
	"Value entered is invalid for this field";

var caWaitForFormToLoad = 
	"Please wait for page to finish loading before clicking anything.";

var caDependencyInvalid = 
	"has a dependency which has not been validated.";

// Text for alert generated when the pre-update validation encounters an occurrence of a field longer
// than the max.  [The cursor will be positioned in the offending field.]
var caOccurrenceTooLong = "Cannot update. A field occurrence is longer than 1014 characters." ;

// Text for alert generated when the user clicks on a browser navigation button (e.g., X, Next, Previous...)
var caDataEntryUnauthorizedNavigation = 
	"To ensure the integrity of the update to this record, first click Done and \n" +
	"then Close the window, or Cancel any changes and then Close the window. \n" +
	" \n" +
	"Click Cancel below to stay in the current input form to take the appropriate \n" +
	"Done or Cancel action, or OK to have the input form window closed without \n" +
	"explicit instructions to STAR Web on the update operation to be performed." ;
										  
// Text for alert generated when the user attempts to navigate to a DE window that contains an active
// document.  [The command will be ignored, and the DE window will receive the focus.]
var caDataEntryWindowInUse = "You are already editing a record in this window." ;
	
var caDataEntryUnrecognizedActionType =  // type is concatenated
	"Unrecognized action type: ";
	
// This should not happen (system error), but means that no element could be found in 
// a newly created row. Element would be used to set the current source element.	
var caDataEntryUnabletoLocateSubField =
	"Unable to locate subfield.";
	
var caDataEntryUnabletoLocateField =
	"Unable to locate field name: ";

var caSubmitIndirectFails =
	"Submit Indirect not in SELECT element!" ;

var caCannotFindTarget =
	"Can't find target.";

var caDataEntryCopyTo_mainFrameNameNotFound =
	"No matching name for @1 in @2.";

var caDataEntryCancelDirty =
	"A record that has been edited is open in a data entry window. Click Cancel to keep the record open and the session active.  Click OK to close the record, ignoring the changes, and Exit the session.  If you click OK, all changes made to the open record will be lost.";
	
var caDataEntryContinueClean =
	"An unedited record is open in a data entry window. Click Cancel to keep the record open and the session active. Click OK to close the record and Exit the session. The open record will not be saved.";
	
var caDataEntryPriceNonNumeric =
	'The price value entered is not valid.'
	
var caDataEntryPrice3Decimals =
	'The price value entered has more than two decimal places.'
	
var caDataEntryPercentNonNumeric =
	'The percent value entered is not valid.'
	
var caDataEntryPercentExceeds100Percent =
	'The percentage entered exceeds 100.'

var caDataEntryPercent3Decimals =
	'The percentage value entered has more than two decimal places.'

var caDataEntryNumericFieldContainsNonNumeric =
    "Field contains data not in the numeric format."

var caDataEntryNumericFieldContainsDecimal =
    "Numeric format does not allow decimals."
	
var caDataEntryCodedHasInvalidData =
    "Coded data format has invalid character(s): @1"

var caDataEntryButtonForSelectListNotFound =
	"Button for @1 not found!"
	
var caDataEntryButtonForTargetNotFound =
  "Button for @1 not found!" 

var caDateInvalidDate =
  "Invalid date."
  
var caDateInvalidSerialDate =
  "Invalid serial date."
  
var caDateInvalidDateComponents =
  "Invalid date component(s)."
  
var caDateInvalidDayValue =
   "Invalid 'day' value."
   
var caDateInvalidMonthValue =
   "Invalid 'month' value."   
   
var caDateInvalidYearValue =
   "Invalid 'year' value."

// Get a message with the name MessageVariableName (a string)
// Returns the associated string, or the name if the string is not defined.
function caGetMessage(alertorconfirm, messageVariableName, target) {
	// args= type, messageid, substitution args

	var LENX = caGetMessage.arguments.length;

    try {
    var mainString = eval(messageVariableName) ;
    }
   catch (e) 
   {
    	var mainString = messageVariableName ;
   } 
	for (var ix = 4; ix <= LENX; ix++)
	{
		// Insert into @x where x=1,2,3...
		var searchStr = "@" + (ix-3).toString();  // @1 @2...
		var replaceStr = caGetMessage.arguments[ix-1];  // arg0 ,arg1, arg2, arg3 (start with arg3
		var re = new RegExp(searchStr);
		var result = mainString.replace(re, replaceStr);
		mainString = result;
	}
    var msg = mainString;
	
	if (alertorconfirm == "alert")
	{
		var messageContainer=target.starwebObject.messageContainer;
		if(messageContainer){
			eqAttachEvent(messageContainer.HTMLelement,'mouseup',displayMessage);
			messageContainer.setError(msg);				
		}
			//var flag;
			//if(flag=document.getElementById(getAssocImage(target.name)) ){
			//	flag.src=__ConfigVars.errorImage;
			//};
			if ("caOccurrenceTooLong"==messageVariableName)
			{
				target.starwebObject.validity = "LOCAL-MAXLENGTH"; 
			}
			else
			{
			   target.starwebObject.validity = "LOCAL-ERROR"; 
			}
	  	return;
	}
	else if (alertorconfirm == "confirm")
	{
   	  	ret = confirm(msg);
	  	return ret;
	}
	else
	{
		return msg;	
		
	}

}
