﻿// JavaScript Document


function $dom(type, name) {
    var element = null;
    // Try the IE way; this fails on standards-compliant browsers
    try {
        element = document.createElement('<' + type + ' name="' + name + '">');
    } catch (e) {
    }
    if (!element || element.nodeName != type.toUpperCase()) {
        // Non-IE browser; use canonical method to create named element
        element = document.createElement(type);
        element.name = name;
    }
    return element;
}


// class  helper 

function $ac(obj, className) {

    if (obj != null) {
        obj.setAttribute("class", className);
        obj.setAttribute("className", className);
    }
}



function roundNumber(rnum) {

    var rlength = 4; // The number of decimal places to round to
    var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10, rlength);

    return newnumber;
}


function roundForInterface(rnum, length) {

    var newnumber = Math.round(rnum * Math.pow(10, length)) / Math.pow(10, length);
    return newnumber;
}

function roundMin(rnum) {

    var roundedNumber = (Math.floor(rnum * 100) + 1) / 100;

    return roundedNumber;

}


function roundMax(rnum) {

    var roundedNumber = Math.floor(rnum * 100) / 100;

    return roundedNumber;

}



function toggle(obj) {
    var el = document.getElementById(obj);

    if (el.style.display != 'none') {

        el.style.display = 'none';
    }
    else {
        el.style.display = 'Block';
    }
}


// -- Fuck Toggle !


//  ---  date Time  Formating  

function DetectBrowser() {
    var temp = navigator.appName;
    temp = temp.toLowerCase();

    if (temp == 'microsoft internet explorer')
        return 'IE';
    else
        return 'NS';
}


//-- Combo Functions 

function ComboAdd(Object, Value, String) {
    Value = Value
    String = String

    if (Value.length < 1 || String.length < 1)
        return false
    Object[Object.length] = new Option(String, Value);
    //Object.selectedIndex = Object.length-1;
}


function ComboDel(Object) {
    var selected_index = Object.selectedIndex
    if (selected_index >= 0) {
        Object.options[Object.selectedIndex] = null;
        if (selected_index > 0)
            Object.selectedIndex = selected_index - 1
        else
            Object.selectedIndex = 0;
    }
}

//-- End Aditional Functions 

