
/**
 *  Insert any css extra files here.
 * 
 * @Author: Michael Mifsud
 */
 /* Tooltip Bug Fix. */
function stm() {}
function htm() {}


/** 
 *  Some global constants. 
 */
var dynCal_CSS           = '/calendar.css';
var isIres               = true;    
var ires_imageDir        = '/libimages';
var ires_cssDir          = '/libcss';
var ires_jsDir           = '/libjs';

var _LOAD_END_           = false;


/**
 * A call to get an element by its id.
 * All javascript should use this to ensure browser compatability.
 * 
 * @param string id The id of the element.
 */
function AOT_getElementById(id) {
    //alert(id);
    if (document.getElementById(id)) {
        return document.getElementById(id);
    } else if (document.all(id)) {
        return document.all(id);
    }
}

/**
 * Submit a form by javascript.
 * 
 * @param form The form object to submit
 */
function AOT_submitForm(form) {
    form.submit();
}

/**
 *  Popup window by stew@aot.com.au 2004-02-03
 * 
 * @param string theURL The url to show in the popup window
 */
function AOT_popUp(theURL) { 
  var width = arguments[1] ? arguments[1] : 455;
  var height = arguments[2] ? arguments[2] : 500;
  var popupWin = window.open(theURL,'info','top=20,left=20,scrollbars=yes,width='+width+',height='+height+',resizable=yes');
  popupWin.focus();
  return false;
}

/**
 * Change the classname of an element in the HTML page.
 * 
 * @param id string 
 * @param newClass string 
 */
function AOT_changeClass(id, newClass) {
  var identity = AOT_getElementById(id);
  identity.className = newClass;
}

/**
 * Truncate a given string to the specified length
 * 
 * @param string The string to truncate
 * @param int The length to truncate to
 * @return The truncated string or entire string if len is > str.length
 */
function AOT_elementTrucate(element, len) {
    var str = element.value;
    
    if (str.length >= len) {
      conf = window.confirm('Would you like to truncate the remarks text to 255 characters.');
      if (conf) {
        nl = str.substr(0, len-nl).search('\n');  // Count the newline chars
        element.value = str.substr(0, len-nl);
      }
    }
}

/**
 * Submit a form once only, used for submitting payment form.
 * 
 * @Author: Michael Mifsud
 */
var wasSubmitted = false;
function submitOnce(btn)
{
    if (wasSubmitted == true) {
        alert("Request already submitted, please wait....");
        //return false;
     } else {
        btn.className = 'btn_disable';
        btn.blur();
        wasSubmitted = true;
     }
}

/**
 *  example call 
 *    insertOptionAt (document.formName.selectName, 
 *                  new Option('text', 'value'), 3);
 * @Author: Michael Mifsud
 */
function insertOptionAt(select, option, index) {
    for (i = select.options.length; i > index; i--)
        select.options[i] = select.options[i - 1];
    
    select.options[index] = option;
}

/**
 * Clear a select element.
 * 
 * @return The selected element
 */
function AOT_clearOptions(select) {
    for (i = select.options.length-1; i >= 0; i--) {
        select.options[i] = null;
    }
}

/**
 * Fill a select element with an array of supplied option objects.
 * 
 * @param select The select form element
 * @param optArray The array of new options
 * @param selected (optional) The selected element
 */
function AOT_setOptions(select, optArray) {
    // The optional argument selected?
    var selected = arguments[2] ? arguments[2] : optArray.length-1;
    
    AOT_clearOptions(select);
    
    // Insert new options.
    for (i = 0; i < optArray.length; i++) {
        select.options[i] = optArray[i];
    }
    // Set selected element
    select.options[selected].selected = true;
    
    // return the select element
    return select;
}

/**
 * A vd (var_dump) type wrapper for javascript
 * @param mixed object
 */
function vd(object) {
    alert(object);
}


/**
 * Remove White Space from start and/or end of given string
 * White Space is defined as:
 *   Space, Carriage Return, newline, form feed, TABs, Vertical TABs
 * 
 * NOTE: This function is attachect to the string object:
 * <code>
 *   var str = "Hello  ";
 *   str.trim();
 *   alert(str);
 * </code>
 */
function AOT_trim ( )
{
   return this.replace(/^\s+|\s+$/g, "");
}
/** Add the method to the String object to trim whitespace characters. */
String.prototype.trim  = AOT_trim;



///////////////// Event Handelers //////////////////
// TODO: Replace with the methods in the event.js file...

/**
 * onMouseMove event handler
 */
//document.onmousemove = function () {
//    if (_LOAD_END_) {
//        if (is_ie5up || is_nav6up || is_gecko) {
//            if (arguments[0]) {
//                ires_mouseX = arguments[0].pageX;
//                ires_mouseY = arguments[0].pageY;
//                //alert("mouseX = "+ ires_mouseX + ", mouseY = " + ires_mouseY);
//            } else {
//                if (is_ie6||is_ie6up){
//                    if(document.body) {
//                        ires_mouseX=event.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
//                        ires_mouseY=event.clientY+document.body.scrollTop+document.documentElement.scrollTop;
//                    }
//                } else {
//                    ires_mouseX = event.clientX + document.body.scrollLeft;
//                    ires_mouseY = event.clientY + document.body.scrollTop;
//                }
//                arguments[0] = null;
//            }
//            // Put callback handlers here
//            if (isTooltip) {
//                MoveTipEvent();
//            }
//            if (isCalendar) {
//                dynCalendar_oldOnmousemove();
//            }
//        }
//    }
//}  

/**
* Callbacks for document.onclick
*/
//document.onclick = function () {
//    if (_LOAD_END_) {
//        if (is_ie5up || is_nav6up || is_gecko) {
//            if(!dynCalendar_mouseoverStatus){
//                for(i=0; i<dynCalendar_layers.length; ++i){
//                    
//                    dynCalendar_layers[i]._hideLayer();
//                }
//            }
//            // Put callback handlers here
//            if (isCalendar) {
//                // Onclick show/hide the calendar
//                dynCalendar_oldOnclick(arguments[0] ? arguments[0] : null);
//            }
//        }
//    }
//}    



/**
* javascript:turnOnHourglass() a simple function for ie5.5+ to have an hourglass cursor 
* whilst waiting for the background page to begin loading
**/

function turnOnHourglass()
{
    document.body.style.cursor = "wait";
}



    
_LOAD_END_ = true;

