function modifyClass(theClass,element,value) {
    var cssRules;
    for (var S = 0; S < document.styleSheets.length; S++){
        if (document.styleSheets[S]['rules']) {
            cssRules = 'rules';
        } else if (document.styleSheets[S]['cssRules']) {
            cssRules = 'cssRules';
        } else {
            return false;
        }
        for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
            if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
                if(document.styleSheets[S][cssRules][R].style[element]){
                    document.styleSheets[S][cssRules][R].style[element] = value;
                    return true;
                }
            }
        }
        if(document.styleSheets[S].insertRule){
            document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
            return true;
        } else if (document.styleSheets[S].addRule) {
            document.styleSheets[S].addRule(theClass,element+': '+value+';');
            return true;
        }
        return false;
    }
}

function is_function(o) {
    return typeof(o) == 'function' && (!Function.prototype.call || typeof(o.call) == 'function');
}

function getScreenHeight() {
    if (browserIs("MSIE 8.0")) {
        return document.documentElement.scrollHeight;
    } else if (browserIs("MSIE 7.0")) {
        return false;
    } else if (window.innerHeight && window.scrollMaxY) {
        return (window.innerHeight + window.scrollMaxY);
    } else {
        return (document.body.offsetHeight + document.body.offsetTop);
    }
}

function element_from_clone(id, cloneId) {
    clone = document.getElementById(cloneId);
    if (clone === null) {
        return false;
    }
    el = clone.cloneNode(true);
    el.id = id;
    setSuperId(el, id);
    return el;
}

/**
 * Appends the specified input in front of all the sub elements ids
 */
function setSuperId(element, id, counter) {
    counter = !counter ? 0 : counter;
    if (element.childNodes !== undefined) {
        for (child in element.childNodes) {
            if (element.childNodes[child].id !== undefined) {
                if (element.childNodes[child].id == "") {
                    cID = id + counter;
                    counter++;
                } else {
                    cID = id + element.childNodes[child].id;
                }
                element.childNodes[child].id = cID;
            }
            if (element.childNodes[child].childNodes !== undefined) {
                setSuperId(element.childNodes[child], id, counter);
            }
        }
    }
}

/**
* Same as PHP $_GET
* @param urlVar The name of the URL variable you would like to read
* @return value The value of the specified variable, null if not found
*/
function get_url_var(urlVar) {
    urlVars = (("" + document.location).split("?"));
    if (urlVars.length > 0) {
        urlVars = urlVars[urlVars.length - 1].split("&");
        for (i = 0; i < urlVars.length; i++) {
            varData = urlVars[i].split("=");
            if (varData[0] == urlVar) {
                return varData[1];
            }
        }
    }
    return null;
}

/**
* Returns true or false if the user's browser is the one specified
* @param bName The name of the browser to check for
* @return bool true / false if the browser match or not
*/
function browserIs (bName) {
    return navigator.userAgent.indexOf(bName) >= 0;
}

/**
* BROKEN IN INTERNET EXPLORER
* Includes specified javascript file(s)
* @param jsFileName Name of single JS file to include
* @param jsFileArray Array of JS files to include
*/
function includeJS (jsFileName, jsFileArray) {
    if (jsFileName != null) {
        newFile      = document.createElement('script');
        newFile.type = 'text/JavaScript';
        newFile.src  = 'includes/js/' + jsFileName + '.js';
        document.getElementsByTagName("head")[0].appendChild(newFile);
    }
    if (jsFileArray != null) {
        for (var i = 0; i < jsFileArray.length; i++) {
            newFile      = document.createElement('script');
            newFile.type = 'text/JavaScript';
            newFile.src  = 'includes/js/' + jsFileArray[i] + '.js';
            document.getElementsByTagName("head")[0].appendChild(newFile);
        }
    }
}

/**
* BROKEN IN INTERNET EXPLORER
* Includes specified CSS file
* @param cssFileName Name of single CSS file to include
* @param cssFileArray Array of CSS files to include
*/
function includeCSS (cssFileName, cssFileArray) {
    if (cssFileName != null) {
        newFile       = document.createElement('link');
        newFile.type  = 'text/css';
        newFile.rel   = 'stylesheet';
        newFile.href  = 'includes/css/' + cssFileName + '.css';
        newFile.media = 'screen';
        document.getElementsByTagName("head")[0].appendChild(newFile);
    }
    if (cssFileArray != null) {
        for (var i = 0; i < cssFileArray.length; i++) {
            newFile       = document.createElement('link');
            newFile.type  = 'text/css';
            newFile.rel   = 'stylesheet';
            newFile.href  = 'includes/css/' + cssFileArray[i] + '.css';
            newFile.media = 'screen';
            document.getElementsByTagName("head")[0].appendChild(newFile);
        }
    }
}

function urlencode(str) {
    string = escape(str).replace(/%20/g, '+').replace(/@/g, '%40');
    while (string.contains("*")) {
        string = string.replace("*", '%2A');
    }
    while (string.contains("/")) {
        string = string.replace("/", '%2F');
    }
    while (string.contains("+")) {
        string = string.replace("+", '%2B');
    }
    return string;
}

function urldecode(str) {
    string = unescape(str);
    while (string.contains("+")) {
        string = string.replace("+", " ");
    }
    return string;
}

function showScreen() {
    screenLayer.style.height = getScreenHeight() + 'px';
    screenLayer.style.display = 'block';
    topLayer.style.height = getScreenHeight() + 'px';
    topLayer.style.display = 'block';
}

function hideScreen() {
    screenLayer.style.display = 'none';
    topLayer.style.display = 'none';
}

function showMessage(message, className) {
    /**
    messageBox.className = className;
    messageBox.innerHTML = message;
    messageBox.show();
    showScreen();
    **/
   alert(message);
}

function hideMessage() {
    messageBoxe.className = 'default';
    messageBox.hide();
    hideScreen();
}

/**
* Marquees the document title
* @param start bool, start or stop scrolling
* @param scrollSpeed The timeout in milliseconds
*/
function marqueeTitle(start, scrollSpeed) {
    if (start) {
        titleCounter = 0;
        originalTitle = document.title + '    ';
    } else {
        document.title = originalTitle;
    }
    titleString = '';
    for (i = titleCounter; i < originalTitle.length; i++) {
        titleString = titleString + originalTitle[i];
    }
    for (i = 0; i < titleCounter; i++) {
        titleString = titleString + originalTitle[i];
    }
    document.title = titleString;
    titleCounter++;
    if (titleCounter >= originalTitle.length) {
        titleCounter = 0;
    }
    titleTimeout = setTimeout("marqueeTitle(false, " + scrollSpeed + ")", scrollSpeed);
}

/**
* Returns a randomly generated hex color
* @return String A randomly generated hexadecimal color value (including the #)
*/
function randomHexColor() {
    colorArray = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
    newColor = '#';
    for (var i = 0; i < 6; i++) {
        newColor += colorArray[Math.round(Math.random() * (colorArray.length - 1))];
    }
    return newColor;
}

function setDefaultTitle (title) {
    defaultTitle = title;
}

function appendTitle (appendage) {
    document.title = defaultTitle + ' | ' + appendage;
}

function toMillis (input) {
    alert('test');
    input = input.split(":");
    alert('test');
    hours = parseInt(input[0]) * 60 * 60 * 1000;
    alert(hours);
    minutes = parseInt(input[1]) * 60 * 1000;
    seconds = parseInt(input[2]) * 1000;
    millis = parseInt(input[3]);
    return hours + minutes + seconds + millis;
}

function getLocalMillis (timezoneOffset) {
    d = new Date();
    return toMillis((d.getUTCHours() + timezoneOffset) + ":" + d.getMinutes() + ":" + d.getSeconds() + ":" + d.getMilliseconds());
}

function fromMillis (input) {
    hours = Math.floor(input / (60 * 60 * 1000)) < 10 ? '0' + Math.floor(input / (60 * 60 * 1000)) : Math.floor(input / (60 * 60 * 1000));
    input -= hours * 60 * 60 * 1000;
    mins = Math.floor(input / (60 * 1000)) < 10 ? '0' + Math.floor(input / (60 * 1000)) : Math.floor(input / (60 * 1000));
    input -= mins * 60 * 1000;
    secs = Math.floor(input / 1000) < 10 ? '0' + Math.floor(input / 1000) : Math.floor(input / 1000);
    input -= secs * 1000;
    millis = input < 10 ? '0' + input : input;
    return hours + ':' + mins + ':' + secs + ':' + millis;
}

function drawImageFromString (imageString, id) {
    imageString = imageString.split(",");
    imageWidth = parseInt(imageString[0]);
    imageHeight = parseInt(imageString[1]);
    image = new Element('div', id);
    image.style.width = imageWidth + 'px';
    image.style.height = imageHeight + 'px';
    for (i = 0, counter = 2; i < imageHeight; i++) {
        for (var ii = 0; ii < imageWidth; ii++, counter++) {
            pixel = new Element('div', id + 'Pixel' + (counter - 2));
            pixel.style.width = '1px';
            pixel.style.height = '1px';
            pixel.style.left = ii + 'px';
            pixel.style.top = i + 'px';
            pixel.style.backgroundColor = imageString[counter];
            image.appendChild(pixel);
        }
    }
    return image;
}

/**
* Returns the specified cookie's value
* @param checkName The cookie name to retrieve the value of
* @return String The value of the specified cookie, null if cookie not found
*/
function getCookie (checkName) {
    allCookies = document.cookie.split(';');
    for (var i = 0; i < allCookies.length ; i++) {
        tempCookie = allCookies[i].split( '=' );
        if (tempCookie[0].replace(/^\s+|\s+$/g, '') == checkName) {
            return tempCookie.length > 1 ? unescape(tempCookie[1].replace(/^\s+|\s+$/g, '')) : '';
        }
    }
    return null;
}

/**
* Sets the specified cookie
* @param name The name of the cookie
* @param value The value of the cookie
* @param expires Time in minutes until the cookie expires
* @param path The path to store the cookies in (usually '/')
* @param domain The domain to store the cookies for (usually '')
* @param secure Not sure what this does (usually '')
*/
function setCookie(name, value, expires, path, domain, secure) {
    today = new Date();
    today.setTime(today.getTime());
    if (expires) {
        expires = (expires * 60) * 1000;
    }
    expires_date = new Date(today.getTime() + (expires));
    document.cookie = name + "=" + escape(value) +
    (expires ? ";expires=" + expires_date.toGMTString() : "") +
    (path ? ";path=" + path : "") +
    (domain ? ";domain=" + domain : "") +
    (secure ? ";secure" : "");
}

/**
* Deletes the specified cookie
* @param name The name of the cookie to delete
* @param path The path of the cookie to delete (usually '/')
* @param domain The domain of the cookie to delete (usually '')
*/
function deleteCookie(name, path, domain) {
    if (getCookie(name) != null) {
        document.cookie = name + "=" +
        (path ? ";path=" + path : "") +
        (domain ? ";domain=" + domain : "" ) +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}

function is_array (mixed_var) {
    var key = '';
    var getFuncName = function (fn) {
        var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
        if (!name) {
            return '(Anonymous)';
        }
        return name[1];
    };

    if (!mixed_var) {
        return false;
    }
    this.php_js = this.php_js || {};
    this.php_js.ini = this.php_js.ini || {};
    if (typeof mixed_var === 'object') {
        if (this.php_js.ini['phpjs.objectsAsArrays'] && ((this.php_js.ini['phpjs.objectsAsArrays'].local_value.toLowerCase && this.php_js.ini['phpjs.objectsAsArrays'].local_value.toLowerCase() === 'off') || parseInt(this.php_js.ini['phpjs.objectsAsArrays'].local_value, 10) === 0)) {
            return mixed_var.hasOwnProperty('length') && !mixed_var.propertyIsEnumerable('length') && getFuncName(mixed_var.constructor) !== 'String';
        }
        if (mixed_var.hasOwnProperty) {
            for (key in mixed_var) {
                if (false === mixed_var.hasOwnProperty(key)) {
                    return false;
                }
            }
        }
        return true;
    }
    return false;
}

function scaleAllElements(percent) {
    percent = percent / 100;
    for (child in document.body.childNodes) {
        curChild = document.body.childNodes[child];
        if (curChild.style) {
            alert(curChild);
        }
    }
}

function createElement(id, type) {
    atts = type.split(':');
    type = atts[0];
    if (atts.length > 1) {
        atts = atts[1].split(',');
        for (i = 0; i < atts.length; i++) {
            atts[i] = ('' + atts[i]).split('=');
        }
    } else {
        atts = null;
    }
    if (browserIs("MSIE 6.0")) {
        string = '';
        if (type == 'div') {
            string = '<div';
            endString = '></div>';
        } else if (type == 'img') {
            string = '<img';
            endString = '/>';
        }
        string += (id === null ? '' : " id='" + id + "'");
        if (atts !== null) {
            for (var i = 0; i < atts.length; i++) {
                string += ' ' + atts[i][0] + "='" + atts[i][1] + "'";
            }
        }
        string += endString;
        tempContainer.innerHTML += string;
        if (id === null) {
            el = null;
        } else {
            el = document.getElementById(id);
        }
    } else {
        el = document.createElement(type);
        if (id !== null) {
            el.id = id;
        }
        if (atts !== null) {
            for (i = 0; i < atts.length; i++) {
                el.setAttribute(atts[i][0], atts[i][1]);
            }
        }
    }
    return el;
}
