﻿function checkScreenSize(lastScreenSize) {
    var curentScreenSize = screen.width + ',' + screen.height;
    if (lastScreenSize != curentScreenSize) {
        if (document.location.href.lastIndexOf('?') != -1) {
            document.location.href += '&screenSize=' + curentScreenSize;
        }
        else {
            document.location.href += '?screenSize=' + curentScreenSize;
        }
    }
}

if (navigator.userAgent.match(/iPhone/i)) {
    var currentWidth = 0;
    window.onorientationchange = function () {
        var orientation = window.orientation;
        var root = document.getElementsByTagName('body')[0];

        if (window.innerWidth != currentWidth) {
            currentWidth = window.innerWidth;
            var orient = currentWidth == 320 ? "profile" : "landscape";
            root.setAttribute("orient", orient);
            window.scrollTo(0, 1);
        }
    }
}

function setFontSize(fontSize) {
    currentFontSize = fontSize;
    document.body.style.fontSize = fontSize + "em";
    document.cookie = "fontSize=" + fontSize + ";"
}

function changeFontSize() {
    if (typeof currentFontSize == "undefined") { currentFontSize = "0.85"; }
    switch (currentFontSize) {
        case "0.85": setFontSize("1"); break;
        case "1": setFontSize("0.75"); break;
        default: setFontSize("0.85")
    }
}

//Get cookie routine by Shelley Powers
function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        // if cookie exists
        if (offset != -1) {
            offset += search.length
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset);
            // set index of end of cookie value
            if (end == -1) end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}

function bottomFunction() {
    if (get_cookie("fontSize") != "") {
        setFontSize(get_cookie("fontSize"));
    }
}

function clickRealtimeButton(rtValue) {
    if (typeof rtValue == 'undefined' || (rtValue != 'true' && rtValue != 'false')) {
        var rtbutton = document.getElementById('rtbutton');
        var arr = rtbutton.src.split('/');
        switch (arr[arr.length - 1]) {
            case 'real_time_off.gif':
                document.getElementById('isRealTimeEnabled').value = 'true';
                break;
            case 'real_time_ico.gif':
                document.getElementById('isRealTimeEnabled').value = 'false';
                break;
            default: break;
        }
    } else {
        document.getElementById('isRealTimeEnabled').value = rtValue;
    }
    document.pushrealtime.submit();
}

function setActionType(frmElement, actionType) {
    frmElement.actionType.value = actionType;
    frmElement.submit();
}
