﻿var current_opacity = 0;

function initPage() {
    //read user name from cookie if needed
    var user_name = readCookie('user');
    var current_name = document.getElementById('txtUserName').value;
    if ((current_name.length == 0) && (user_name != null)) {
        //put stored user name in 
        document.getElementById('txtUserName').value = user_name;
    } 
    
    //show messages 
    showMessage();
}

function storeUser() {
    //save user name to cookie
    var user_name = document.getElementById('txtUserName').value;
    if (user_name.length > 0) {
        createCookie('user',user_name,30);
    }
}

function showMessage() {
    if (current_opacity < 100) {
        current_opacity += 5;
        var Message = document.getElementById("divMessage");
        if (Message) {
            Message.style.filter = "alpha(opacity='" + current_opacity + "')"; 
            Message.style.opacity = current_opacity * .01; 
            setTimeout("showMessage()", 50);
        }
    }
}

// called when orientation changes
function onOrientationChange() {
    // update the styles
    document.body.className = window.orientation == 0 ? '' : 'landscape';
    hideAddressBar();
}

function hideAddressBar() {
    window.scrollTo(0, 1);
    setTimeout(function() {
        window.scrollTo(0, 0);
    }, 0);
}

function $_event(o, e, f, cap) {
    o.addEventListener(e, f, cap);
}

//handle orientation events

if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
    $_event(window, 'orientationchange', onOrientationChange, false);
    if (window.addEventListener) window.addEventListener('orientationchange', onOrientationChange, false);
    if (window.addEventListener) window.addEventListener('load', onOrientationChange, false);
}  