/**
 * @fileoverview
 * API functions
 * @version $Revision: 84713 $ 
 * Copyright (C) 2004-2008 United Planet GmbH, Freiburg
*/

/**
* Creates an JavaScript date object from a html control.
* <p>
* Example usage:
* <p>
* <code>getDateObject(getElement("A84E5E7F9EA9ED1A829DB98DBF5459F59961FA3B"));</code>
* @param {object} oHtml Reference to a html input control of types "date", "time" or "date & time".
* @return JavaScript date object.
*/  
function getDateObject(oHtml){ return Helper.getDateObject(oHtml); }

/**
* Creates an JavaScript number object from a html control.
* <p>
* Example usage:
* <p>
* <code>getNumberObject(getElement("5F7S5E7F9EA9ED1A829DB98DBF5459F59961FA3B"));</code>
* @param {object} oHtml Reference to a html input control of types "integer", "double" or "currency".
* @return {object} JavaScript number object.
*/  
function getNumberObject(oHtml){ return Helper.getNumberObject(oHtml);}

/**
* Parses a local formatted string representing an integer value.
* (for example 1.234 -> 1234)
* <p>
* Example usage:
* <p>
* <code>getIntegerStringByLocal("1.234");</code>
* @param {string} strValue Local formatted integer string.
* @return {string} Integer formatted string.
*/    
function getIntegerStringByLocal(strValue){ return Helper.getIntegerStringByLocal(strValue); }
/**
* Parses a local formatted string representing a double value.
* (for example 3.215,20 -> 3215.20)
* <p>
* Example usage:
* <p>
* <code>getDoubleStringByLocal("1.234");</code>
* @param {string} strValue Local formatted double string.
* @return {string} double as formatted string.
*/    
function getDoubleStringByLocal(strValue){ return Helper.getFloatStringByLocal(strValue); }
/**
* @deprecated
* @private
*/    
function getFloatStringByLocal(strValue){ return Helper.getFloatStringByLocal(strValue); }
/**
* Parses a local formatted string representing a currency value.
* (for example 3.215,20 -> 3215.20)
* <p>
* Example usage:
* <p>
* <code>getCurrencyStringByLocal("1.234");</code>
* @param {string} strValue Local formatted currency string.
* @return {string} double as formatted string.
*/    
function getCurrencyStringByLocal(strValue){ return Helper.getCurrencyStringByLocal(strValue); }
/**
 * Parses a local formatted string representing an integer value and returns a JavaScript number object.
 * <p>
* Example usage:
* <p>
* <code>getIntegerByLocalString("1.234");</code>
* @param {string} strValue Local formatted integer string.
* @return JavaScript number object. 
*/    
function getIntegerByLocalString(strValue){ return Helper.getIntegerByLocalString(strValue); }
/**
 * Parses a local formatted string representing a double value and returns a JavaScript number object.
 * <p>
* Example usage:
* <p>
* <code>getDoubleByLocalString("1.234");</code>
* @param {string} strValue Local formatted string.
* @return JavaScript number object. 
*/    
function getDoubleByLocalString(strValue){ return Helper.getFloatByLocalString(strValue); }
/**
* @deprecated
* @private
*/    
function getFloatByLocalString(strValue){ return Helper.getFloatByLocalString(strValue); }
/**
 * Parses a local formatted string representing a currency value and returns a JavaScript number object.
 * <p>
* Example usage:
* <p>
* <code>getCurrencyByLocalString("1.234");</code>
* @param {string} strValue Local formatted currency string.
* @return JavaScript number object. 
*/    
function getCurrencyByLocalString(strValue){ return Helper.getCurrencyByLocalString(strValue); }

/**
 * Creates a local formatted string from an number string or a datetime string.
 * <p>
 * Example usage:
 * <p>
 * <code>toLocalString(getElement("DDB279D4974A17DB27A89F58DB36F7BF4E10DA13"),"123.45");</code>
 * @param oHtml Reference to a html input control of types "integer", "double", "currency" (format settings can be appended here, too).
 * @param strValue Number string or date string.
 * @return {String} Local formatted number as string or local formatted datetime as string
 */    
function toLocalString(oHtml, strValue){ return Helper.toLocalString(oHtml, strValue); }

/**
 * Creates a local formatted string from an number string or a datetime string
 * and writes it as value into a html control.
 * <p>
 * Example usage:
 * <p>
 * <code>writeLocalString(getElement("DDB279D4974A17DB27A89F58DB36F7BF4E10DA13"),"123.45");</code>
 * @param oHtml Reference to a html input control of types "date", "time", "date & time",
 * 				"integer", "double", "currency" (format settings can be appended here, too).
 * @param strValue Value to localize.
 * @return <code>True</code> or <code>false</code>.  
 */    
function writeLocalString(oHtml, strValue){ return Helper.writeLocalString(oHtml, strValue); }

/**
 * Checks a html control, as if "entry required" has been set OR checks all controls of a form, where "entry required" was set.
 * <p>
 * Example usage:
 * <p>
 * <code>checkRequired(getElement("E94A9FBDADD46039BB62F76870E1EC57C226C6DC"), "An alternative text!");</code>
 * @param oHtml Reference to a html input control or to a form control ("FormGroup")
 * @param strMessage (OPTIONAL) Text to show, if checkRequired returns <code>false</code>. If not set, value of FORM_CONSTR_REQUIRED
 * 					 from "preset texts" will be displayed.  
 * @return <code>True</code> or <code>false</code>.
 */
function checkRequired(oHtml, strMessage){ return Helper.checkRequired(oHtml, strMessage); }

/**
 * Calculates the difference of values from two html controls of type "date & time" and returns it as string
 * formatted as "2 days 3 minutes"
 * <p>
 * Example usage:
 * <p>
 * <code>getLocalDurationString(getElement("4E48F310711C446B4B04752A6B3239900D49F3A0"),getElement("E13A41C114E8754574DEA9767F505DDE3491C89A"));</code>
 * @param oHtmlDateFrom Reference to a html control of type "date & time"
 * @param oHtmlDateTo Reference to a html control of type "date & time"
 * @return {string} string formatted as "2 days 3 minutes".
 */   
function getLocalDurationString(oHtmlDateFrom, oHtmlDateTo){ return Helper.getLocalDurationString(oHtmlDateFrom, oHtmlDateTo); }

/**
 * Calculates a result of values from two html controls with an operator and writes it into a html control.
 * <p>
 * Example usage:
 * <p>
 * <code>calculate(getElement("F28BA7351E3C8F5123880548CFA72B64566A1421"), getElement("80467069EA61BD786CFFEB508786723D6451F2F5"), "+", getElement("B52A9E9FC555A820984E63DECF13BCAA33E308CD"));</code>
 * @param oHtml1 Reference to a html control of type "integer", "double", "currency"
 * @param oHtml2 Reference to a html control of type "integer", "double", "currency"
 * @param strOp Operator
 * @param oHtmlResult Result; Reference to a html control of type "integer", "double", "currency"
 * @return <code>True</code> or <code>false</code>.
 */
function calculate(oHtml1, oHtml2, strOp, oHtmlResult){ return Helper.calculate(oHtml1, oHtml2, strOp, oHtmlResult); }

/**
 * Writes a value in a viewcontrol or static textcontrol.
 * <p>
 * Example usage:
 * <p>
 * <code>setTextValueById("ID_labelcontrol900CB1AB", "Some text");</code>
 * @param id DOM id of the element; equivalent to the id-attribute value of the html element.
 * @param strValue Value to write.
 * @return <code>True</code> or <code>false</code>.
 */    
function setTextValueById(id, strValue){ return Browser.setValueByElementId(id, strValue); }

/**
 * Writes a value in a viewcontrol or static textcontrol.
 * <p>
 * Example usage:
 * <p>
 * <code>setTextValue(getElement("F28BA7351E3C8F5123880548CFA72B64566A1433"), "Some text");</code>
 * @param oHtml Reference to a html input control. 
 * @param strValue Value to write.
 * @return <code>True</code> or <code>false</code>.
 */
function setTextValue(oHtml, strValue){ return Browser.setValue(oHtml, strValue); }

/**
 * Reads a value from a viewcontrol or static textcontrol.
 * <p>
 * Example usage:
 * <p>
 * <code>getTextValueById("ID_labelcontrol900CB1AB");</code>
 * @param id DOM id of the element; equivalent to the id-attribute value of the html element.
 * @return Value from viewcontrol or static textcontrol.
 */    
function getTextValueById(id){ return Browser.getValueByElementId(id); }

/**
 * Reads a value from a viewcontrol or static textcontrol.
 * <p>
 * Example usage:
 * <p>
 * <code>getTextValue(getElement("F28BA7351E3C8F5123880548CFA72B64566A1433"));</code>
 * @param oHtml Reference to a html input control.
 * @return Value from viewcontrol or static textcontrol.
 */
function getTextValue(oHtml){ return Browser.getValue(oHtml); }

/**
 * Sets two datafields on a duration of a whole day: dateFrom 00:00 a.m., dateTo 00:00 a.m. next day.
 * <p>
 * Example usage (executable on an checkbox onclick() event):
 * <p>
 * <code>setFullDays(getElement("123401F1E55C9A193BE6EC4091B45C6A5A6C8154"), getElement("DD2E01F1E55C9A193BE6EC4091B45C6A5A6C8154"), getElement("4D0708BDECC7D088613F818CE1B09B8D812F5750") );</code>
 * @param oHtmlCheck Checkbox
 * @param oHtmlFrom dateFrom
 * @param oHtmlTo dateTo
 */
function setFullDays(oHtmlCheck, oHtmlFrom, oHtmlTo){ return Helper.setFullDays(oHtmlCheck, oHtmlFrom, oHtmlTo); }
/**
 * Inks rows and cells in a viewtablecontrol depending on a number value.
 * <p>
 * Example usage:
 * <p>
 * <code>inking("viewcontrolD54BA2DD", ">", 10, "#008000", "row");</code>
 * @param control Name of control, whose value should be checked (name from expert page of the column).
 * @param op Operator
 * @param comp Value to compare with.
 * @param color Value of color (hexadecimal or name)
 * @param colored Possible values: "row" = whole row (tr), "cell" = whole cell (td), "span" = text of cell (span).
 */    
function inking(control, op, comp, color, colored){ return Helper.inking(control, op, comp, color, colored); }

/**
 * Inks date or datetime values in a viewtablecontrol depending on a number value.
 * @see #inking
 * @param type Possible values: "date" = date, "datetime" = date & time.
 */
function inkingDate(control, op, type, color, colored){ return Helper.inkingDate(control, op, type, color, colored); }
/**
 * Inks strings in a viewtablecontrol depending on a number value.
 * @see #inking
 */
function inkingString(control, op, comp, color, colored){ return Helper.inkingString(control, op, comp, color, colored); }
/**
 * Returns the parent node, which is the row.
 * @param no Reference to a node.
 */
function getRow(no){ return Helper.getRow(no); }
/**
 * Returns the parent node, which is the col.
 * @param no Reference to a node.
 */
function getCol(no){ return Helper.getCol(no); }
/**
 * Compares a value of a date control with the current date.
 * <br>
 * Imperative for input and view controls (for view controls the expert attribute <code>jsobject = true (Boolean)</code> has to be set.)
 * <p>
 * Example usage:
 * <p>
 * <code>dateComparedToNow(getElement("5F7S5E7F9EA9ED1A829DB98DBF5459F59961FA3B"));</code>
 * @param p_oDate Reference to an html input control of type "date", "time" or "datetime"
 * @return a JavaScript number object. <br>
 * 			<UL>
 *				<LI>-1 if an error occurred or input field is empty. 
 *				<LI>0 if value is less than current date.
 *				<LI>1 if value equals current date.
 *				<LI>2 if value is greater than current date.
 *		   	</UL>
 * 
 */
function dateComparedToNow(p_oDate){ return Helper.dateComparedToNow(p_oDate); }

/**
 * Adds or subtracts a interval to/from a given JavaScript date object.
 * <p>
 * Example usage:
 * <p>
 * <code>
 * var dtNow = new Date();
 * <br>
 * var dtAdd1 = dateAdd("d", 1,  dtNow); // adds 1 day to current date.
 * <br>
 * var dtAdd2 = dateAdd("h", -2, dtNow); // subtracts 2 hours from current date.
 * </code>
 * @param {String} p_strInterval Possible values: "ms" - for milliseconds; "s" - for seconds; "mi" - for minutes; "h" - for hours; "d" - for days; "mo" - for months; "y" - for years;
 * @param {Integer} Number value for given interval, that should be added to date. Negative values are also possible.
 * @param {Date} JavaScript date object.
 * @return {object} JavaScript date object.
 */
function dateAdd(p_strInterval, p_iNum, p_oDate){return Helper.dateAdd(p_strInterval, p_iNum, p_oDate); }

/**
 * Executes an application-request.
 * <p>
 * Example usage:
 * <p>
 * <code>makeAppRequest("77C4E95D8F1EEC234D308C2C8C15CB63A97F7ABA", "3B8501CD6DFE930F85CC6305C4BDA16D95BC9F59", false, false, true); // opens page 3B8501CD6DFE930F85CC6305C4BDA16D95BC9F59 of application 77C4E95D8F1EEC234D308C2C8C15CB63A97F7ABA in an new window</code>
 * @param {string}  p_strApp Application GUID
 * @param {string}  p_strTarget Page GUID
 * @param {boolean} p_bClosePopup Close popup (if current page in popup).
 * @param {boolean} p_bChangeParent Set request into main window (if current page in popup). 
 * @param {boolean} p_bNewWindow Set request into a new popup window.
 */ 
function makeAppRequest(p_strApp, p_strTarget, p_bClosePopup, p_bChangeParent, p_bNewWindow){ return Helper.makeAppRequest(p_strApp, p_strTarget, null, p_bNewWindow, p_bClosePopup, p_bChangeParent); }
 
 /**
  * Triggers an User Workflow Event.
  * <p>
  * Example usage:
  * <p>
  * <code>triggerUserWorkflowEvent("<GUID>", {"param1":"value1","param2":"value2"}); // Trigger event with guid <GUID>. Define a generic event handler with the class "de.uplanet.lucy.server.workflow.eventhandler.UserWorkflowEventHandler" before.</code>
  * @param {string}  p_strEventGuid The paramter "eventGuid" of the generic event handler.
  * @param   oJsonParams json map containing name value pairs, which will be part of the querystring.  
  */ 
function triggerUserWorkflowEvent(p_strEventGuid, oJsonParams)
{
    if(p_strEventGuid)
    {
        var l_strUrl = Helper.getBaseUrl();
        l_strUrl = Helper.setUrlValueByParam("qs_wfEventGuid", p_strEventGuid,  l_strUrl);
        l_strUrl = Helper.setUrlValueByParam("rq_command", "workflow", l_strUrl);
        if(arguments.length > 1)
        {
            for(var param in oJsonParams)
                l_strUrl = Helper.setUrlValueByParam(param, oJsonParams[param], l_strUrl);
        }
        var oXmlHttp = new upXmlHttp();
        oXmlHttp.bResetTimeOut = false;
        oXmlHttp.bProcessResponse = true;
        oXmlHttp.processResponse = function()
        {
		    if(oRequest.readyState==State.done)
		    {
			    
			    if(oRequest.status == Status.ok)
			    {
				    // error response
				    if(ErrorHandler.Ajax.checkXMLResponse("triggerUserWorkflowEvent", oRequest))
				    {
					    return;
				    }
				    else
				    {
				        //success
				        return;
				    }
                }
			    else
			    {
				    ErrorHandler.Http.handleStatus("triggerUserWorkflowEvent", oRequest);
                    return;
			    }
            } 
        };
        oXmlHttp.bAsync = true;
        oXmlHttp.strUrl = l_strUrl;
        oXmlHttp.send();
    }
    else
    {
        alert("No process event GUID given.");
    }
    return true;
} 

