function Softsmart_Page_IsInternetExplorer(){
	var browser = navigator.userAgent;
	if (browser.indexOf('MSIE') >= 0){return true;} else {return false;}
}

function Softsmart_Page_IsSafari(){
	var browser = navigator.userAgent;
	if (browser.indexOf('Safari') >= 0 && browser.indexOf('Chrome') < 0){return true;} else {return false;}
}

function Softsmart_Page_IsGoogleCrome(){
	var browser = navigator.userAgent;
	if (browser.indexOf('Chrome') >= 0){return true;} else {return false;}
}

function Softsmart_Page_IsFirefox(){
	var browser = navigator.userAgent;
	if (browser.indexOf('Firefox') >= 0){return true;} else {return false;}
}

function Softsmart_Page_LogOff(coreLevels){
	document.form.action = coreLevels + 'Core/Login.aspx?UserCode=Logoff';
	document.form.target = '_self';
	document.form.submit();
}

var ValidChars = '1234567890', GroupSeperator = '', DecimalChar = '.', ForbiddenKeys = 'cxv', DecimalPlaces = 2;
var DefaultValue = '0';
function Softsmart_Numeric_GetKeyCode(e){
    if (window.event){return window.event.keyCode;} else if (e){return e.which;} else {return null;}
}

function Softsmart_Numeric_GetKeyChar(key){return String.fromCharCode(key).toLowerCase();}

function Softsmart_Numeric_KeyRestrict(txtSource, e, allowDecimal){
    var key = Softsmart_Numeric_GetKeyCode(e);
    if (key == null){return true;}
    var keyChar = Softsmart_Numeric_GetKeyChar(key);
    if (keyChar == '.' && txtSource.value.indexOf(DecimalChar) != -1){return false;}
    if (allowDecimal){ValidChars = ValidChars + DecimalChar;}
    ValidChars = ValidChars.toLowerCase();
    if (ValidChars.indexOf(keyChar) != -1){return true;}
    if (key == null || key == 0 || key == 8 || key == 9 || key == 13 || key == 27){return true;}
    
    return false;
}

function Softsmart_Numeric_NoCopyMouse(e){
    var isRight = (e.button) ? (e.button == 2) : (e.which == 3);
    if(isRight){return false;}
    return true;
}

function Softsmart_Numeric_NoCopyKey(e){
    var isCtrl;

    if (window.event){isCtrl = e.ctrlKey} else {isCtrl = (window.Event) ? ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;}
    if (isCtrl){if (ForbiddenKeys.indexOf(Softsmart_Numeric_NoCopyKey(Softsmart_Numeric_NoCopyKey(e))) != -1){return false;}}

    return true;
}

function Softsmart_Numeric_FormatNumber(txtSource, allowDecimal){
    var num = txtSource.value;        
    if (num == '' || isNaN(num)){txtSource.value = DefaultValue; return;}
    txtSource.value = Softsmart_Numeric_FormatCurrency(num, allowDecimal)
}

function Softsmart_Numeric_ClearDefaultText(txtSource){if (txtSource.value == DefaultValue){txtSource.value = "";}}

function Softsmart_Numeric_FormatCurrency(num, allowDecimal){
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if(cents < 10){cents = "0" + cents;}
    
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++){
        num = num.substring(0,num.length - (4 * i + 3)) + GroupSeperator + num.substring(num.length - (4 * i + 3));
	}
    
    if (allowDecimal){return (num + DecimalChar + cents);}
    return num;
}
