﻿/**********************************************************************************
Description:
  This script contains base functions that can be used by all other pages that
  require java script
**********************************************************************************/

var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

function getRef(id) {
    if (isDOM) return document.getElementById(id);
    if (isIE4) return document.all[id];
    if (isNS4) return document.layers[id];
}

// replaces all occurencies of a value in a string
function MultiReplace(str, regExpValue, valToReplace)
{
    while (str.indexOf(regExpValue) > -1)
    {
        str = str.replace(regExpValue, valToReplace);
    }
            
    return str;
}

// return the value of the selected option in a select list
function getSelectedValue(control) {
    if (control != null) {
        return control.options[control.selectedIndex].value;
    } else {
        return null;
    }
}

// return the text of the selected option in a select list
function getSelectedText(control) {
    if (control != null) {
        return control.options[control.selectedIndex].text;
    } else {
        return null;
    }
}

// gain access to the text property
function getObjInnerText (obj) {
    return (obj.innerText) ? obj.innerText: (obj.textContent) ? obj.textContent: "";
} 

function setObjInnerText (obj, text) {
    if (obj.innerText) {
        alert('innerText');
        obj.innerText = text;
    } else if (obj.textContent) {
        alert('textContext');
        obj.textContext = "123";
    }
} 

function formatCurrency(amount, symbol)
{
	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('.') > -1) s = s.substring(0, s.indexOf('.'));
	//if(s.indexOf('.') < 0) { s += '.00'; }
	//if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return symbol + s;
}


Number.prototype.formatMoney = function(c, d, t){
    var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t)
    + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};


