function passThroughTo (e) {

    var target = (window.event) ? window.event.srcElement : e.target;

    var form = document.getElementById('submit_form');

    switch ( target.id ) {

        case 'california_streaming' :

            form.action = 'http://www.californiastreaming.org/digitalHome.asp';

            var username  = document.getElementById('ca_stream_username');
            var password  = document.getElementById('ca_stream_password');

            password.value = '';

            username.name = 'username';

            form.method = 'get';
            form.target = 'castream';

            break;

        case 'check_out_media' :

            form.action = '/cgi-bin/webmax/login.pl';

            var username  = document.getElementById('media_username');
            var password  = document.getElementById('media_password');

            username.name = 'uid';
            password.name = 'pass';

            form.method = 'post';
            form.target = 'webmax';

            break;

    }

    form.submit();

    return false;

}

function popUpWindow(e) {

    var target = (window.event) ? window.event.srcElement : e.target;

    var parent = target.parentNode;

    //prevent default behavior

    if (window.event) {

      window.event.cancelBubble = true;
      window.event.returnValue  = false;

    } else if (e && e.preventDefault) {

      e.preventDefault();

    } else {

     element.action = 'javascript:void(0);';

    }

    var url = parent.id + '.html';

    var width  = 350;
    var height = 400;

    document.open(url,'Information','width=' + width + ',height=' + height + ',toolbar=no,menu=no,location=no'); 
 
    return false;

}

function forgotPassword(e) {

    var target = (window.event) ? window.event.srcElement : e.target;

    //prevent default behavior

    if (window.event) {

      window.event.cancelBubble = true;
      window.event.returnValue  = false;

    } else if (e && e.preventDefault) {

      e.preventDefault();

    } else {

     element.action = 'javascript:void(0);';

    }

    var url = 'http://www.californiastreaming.org/forgotpassword.asp?fromDigital=1';
 
    window.open(url,'Forgot_Password'); 

    return false;

}

function guestLogin(e) {

    var form      = document.getElementById('checkout_guest');
    var lastname  = document.getElementById('lastname');
    var firstname = document.getElementById('firstname');

    var name = prompt('Please enter your first and last name (e.g. Bill Clinton):');

    var names = name.split(" ");

    firstname.value = names.shift();
    lastname.value  = names.join(" ");

    form.target = "_blank";

    form.submit();
  
    return true;

}

function addListeners(e) {

    listen = document.getElementById('california_streaming');
    addEvent(listen, 'click', passThroughTo, false);

    listen = document.getElementById('check_out_media');
    addEvent(listen, 'click', passThroughTo, false);

    listen = document.getElementById('forgot_castream');
    addEvent(listen, 'click', forgotPassword, false);

    listen = document.getElementById('forgot_checkout');
    addEvent(listen, 'click', popUpWindow, false);

    listen = document.getElementById('guest_login');
    addEvent(listen, 'click', guestLogin, false);

}

addEvent(window, 'load', addListeners, false);
