var hide = function(ele) {
    if(typeof ele === 'string') {
        ele = YAHOO.util.Dom.get(ele);
    }
    YAHOO.util.Dom.setStyle(ele, 'display', 'none');
};

var show = function(ele) {
    if(typeof ele === 'string') {
        ele = YAHOO.util.Dom.get(ele);
    }
    YAHOO.util.Dom.setStyle(ele, 'display', '');
};

function formatCurrency(amount) {
    var i = parseFloat(amount);
    if(isNaN(i)) {
        i = 0.00;
    }
    var minus = '';
    if(i < 0) {
        minus = '-';
    }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if(s.indexOf('.') < 0) {
        s += '.00';
    }
    if(s.indexOf('.') == (s.length - 2)) {
        s += '0';
    }
    s = minus + s;

    return formatThousandsCommas(s);
};

function formatThousandsCommas(amount) {
    var delimiter = ","; // replace comma if desired
    var a = amount.split('.', 2);
    var d = a[1];
    var i = parseInt(a[0]);
    if (isNaN(i)) {
        return '';
    }
    var minus = '';
    if (i < 0) {
        minus = '-';
    }
    i = Math.abs(i);
    var n = new String(i);
    a = [];
    while (n.length > 3) {
        var nn = n.substr(n.length - 3);
        a.unshift(nn);
        n = n.substr(0, n.length - 3);
    }
    if (n.length > 0) {
        a.unshift(n);
    }
    n = a.join(delimiter);
    if (d.length < 1) {
        amount = n;
    }
    else {
        amount = n + '.' + d;
    }
    amount = minus + amount;
    return amount;
}

function selectOptionByValue(selectElement, optionValue) {
    for (var i = 0; i < selectElement.options.length; i++) {
        selectElement.options[i].selected = selectElement.options[i].value == optionValue;
    }
};

function insertToken(tokenName) {
    var textarea = YAHOO.util.Dom.get('messageBox');
    textarea.focus();
    
    if (document.selection) {
        //IE
        document.selection.createRange().text= '[' + tokenName + ']';
    
    }
    else if (textarea.selectionStart) {
        //probably FF
        var start = textarea.selectionStart; 
        var end = textarea.selectionEnd; 

        textarea.value = textarea.value.substr(0, start) + '[' + tokenName + ']' + textarea.value.substr(end, textarea.value.length); 
    }
    else if (textarea.value == '') {
        //probably FF with an empty textarea
        textarea.value = '[' + tokenName + ']';
    }
    
};

function cursor_wait() {
  document.body.style.cursor = 'wait';
};

function cursor_clear()  {
  document.body.style.cursor = 'default';
};

function winPopup(link){
    window.open(link,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=1024, height=600")
};

