/* get the width of the window */
function getWidth(){
    var myWidth = 0, myHeight = 0;
    if (typeof(window.innerWidth) == 'number') {
        /* Not IE */
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }
    else 
        if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            /* IE 6+ in 'standards compliant mode' */
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        }
        else 
            if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                /* IE 4 compatible */
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight;
            }
    return myWidth;
}

/*
 * Rotating popup for the people page
 */
//var images = new Array("benning", "littlefield", "roose", "brochu", "cahill", "remington", "jessica", "brian");
var images = new Array("benning", "littlefield", "jessica", "brian", "cahill", "remington");
//var titles = new Array("<h3>Greg Benning</h3>Managing Director", "<h3>Miles Littlefield</h3>Associate", "<h3>Robert Roose</h3>Vice President", "<h3>Matthew Brochu</h3>Associate", "<h3>Peter Cahill</h3>Managing Director", "<h3>James Remington</h3>Managing Director", "<h3>Jessica</h3>Associate", "<h3>Brian</h3>Associate");
var titles = new Array("<h3>Greg Benning</h3>Managing Director", "<h3>Miles Littlefield</h3>Associate", "<h3>Jessica Dumphy</h3>Vice President", "<h3>Brian Stornelli</h3>Associate", "<h3>Peter Cahill</h3>Managing Director", "<h3>James Remington</h3>Managing Director");
var imgWidth = 115;
var lastPosition = "benning";
var freeze_id = -1;
var frozen = false;
function rotate(position){
    if (position == -1) {
        position = freeze_id;
    }
    if (lastPosition != null) 
        document.getElementById(lastPosition).style.display = "none";
    lastPosition = images[position];
    document.getElementById(images[position]).style.display = "block";
}

function showPopUp(position){
    if (!frozen) {
        document.getElementById("popup").style.left = ((getWidth() - 950) / 2 + 105 + position * 95) + "px";
        document.getElementById("popup").style.top = 370 + "px";
        document.getElementById("popup").style.display = "block";
        document.getElementById("popup").innerHTML = titles[position];
        freeze_id = position;
    }
}

function hidePopUp(){

}

function freeze(id){
    frozen = true;
    //id.onclick = "javascript:rotate("+freeze_id+")";
}

function unfreeze(id){
    frozen = false;
    //id.onclick = "";
}


var selected = "medical_technology";
function select(id){
    document.getElementById(selected).style.display = "none";
    document.getElementById(selected + "_link").className = "=";
    selected = id;
    document.getElementById(selected).style.display = "block";
    document.getElementById(selected + "_link").className = "selected";
}


/* Video popup */
function show(id){
    url = "http://www.benningllc.com/video.php?p=" + id;
    height = (id == 'todd' ? 365 : 350);
    window.open(url, '_blank', 'toolbar=no,menubar=no,locaton=no,directories=no,scrollbars=no,status=no,resizable=no,width=390,height=' + height);
    return true;
}

function checkform(){
    for (i = 0; i < fieldstocheck.length; i++) {
        if (eval("document.subscribeform.elements['" + fieldstocheck[i] + "'].type") == "checkbox") {
            if (document.subscribeform.elements[fieldstocheck[i]].checked) {
            }
            else {
                alert("Please enter your " + fieldnames[i]);
                eval("document.subscribeform.elements['" + fieldstocheck[i] + "'].focus()");
                return false;
            }
        }
        else {
            if (eval("document.subscribeform.elements['" + fieldstocheck[i] + "'].value") == "") {
                alert("Please enter your " + fieldnames[i]);
                eval("document.subscribeform.elements['" + fieldstocheck[i] + "'].focus()");
                return false;
            }
        }
    }
    for (i = 0; i < groupstocheck.length; i++) {
        if (!checkGroup(groupstocheck[i], groupnames[i])) {
            return false;
        }
    }
    
    return true;
}

var fieldstocheck = new Array();
var fieldnames = new Array();
function addFieldToCheck(value, name){
    fieldstocheck[fieldstocheck.length] = value;
    fieldnames[fieldnames.length] = name;
}

var groupstocheck = new Array();
var groupnames = new Array();
function addGroupToCheck(value, name){
    groupstocheck[groupstocheck.length] = value;
    groupnames[groupnames.length] = name;
}

function compareEmail(){
    return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}

function checkGroup(name, value){
    option = -1;
    for (i = 0; i < document.subscribeform.elements[name].length; i++) {
        if (document.subscribeform.elements[name][i].checked) {
            option = i;
        }
    }
    if (option == -1) {
        alert("Please enter your " + value);
        return false;
    }
    return true;
}

