/**
 * Javascript functions to add user interactivity with the web site
 * 
 * @Copyright 2008 - F-Secure Corporation, maintained by KL Web Development Team
 */

// START NEW BRAND HOMEPAGE
function initHomepage()
{
    equalize_subboxes_divider();
    eqPage();
}

function equalize_subboxes_divider()
{
    document.getElementById("subbox_divider1").style.height = get_highest_subbox() + "px";
    document.getElementById("subbox_divider2").style.height = get_highest_subbox() + "px";
}

function get_highest_subbox()
{
    //todo: change to a loop?
    var subbox1 = document.getElementById("subbox1").offsetHeight;
    var subbox2 = document.getElementById("subbox2").offsetHeight;
    var subbox3 = document.getElementById("subbox3").offsetHeight;
    var subboxesHeights = new Array();
    subboxesHeights[0] = subbox1;
    subboxesHeights[1] = subbox2;
    subboxesHeights[2] = subbox3;
    return getMaxValue(subboxesHeights)
}

function getMaxValue(heightArray)
{        
    var maxValue = heightArray[0];
    for (var i=0; i<heightArray.length; i++)
    {
        if (heightArray[i] > maxValue)
        {
            maxValue = heightArray[i];
        }         
    }
    return maxValue;
}

function getRowTwoRightColumnHeight()
{
    var rowTwoRightColumnHeight = document.getElementById("rowTwoRightColumn").offsetHeight;
    return rowTwoRightColumnHeight;
}

function getRowThreeRightColumnHeight()
{
    var rowThreeRightColumnHeight = document.getElementById("rowThreeRightColumn").offsetHeight;
    return rowThreeRightColumnHeight;  
}

function getTotalEqRightColumnHeight()
{
    //var standardPadding = 16; //16px
	var standardPadding = 32; //32px
    var total = getRowTwoRightColumnHeight() + standardPadding + getRowThreeRightColumnHeight();
    return total;
}

function getRowTwoLeftColumnHeight()
{
    var topLayerHeight = 10;
    var bottomLayerHeight = 6; //magic
    var rowTwoLeftColumnHeight = document.getElementById("rowTwoLeftColumn").offsetHeight - bottomLayerHeight;
    return rowTwoLeftColumnHeight;
}

function getRowThreeLeftColumnHeight()
{
    var topLayerHeight = 10;
    var bottomLayerHeight = 6; //magic
    var rowThreeLeftColumnHeight = document.getElementById("rowThreeLeftColumn").offsetHeight - bottomLayerHeight;
    return rowThreeLeftColumnHeight;  
}

function getTotalEqLeftColumnHeight()
{
    //var standardPadding = 16; //16px
	var standardPadding = 32; //32px    
    var total = + getRowTwoLeftColumnHeight()
            + standardPadding + + getRowThreeLeftColumnHeight();
    return total;
}

function eqPage()
{
    var left = getTotalEqLeftColumnHeight();
    var right = getTotalEqRightColumnHeight();
    var offset = 0;
    if (left > right)
    {
        offset = left - right;
        var magic = 3; //explicit magic
        document.getElementById("rowThreeRightColumn").style.height = (getRowThreeRightColumnHeight() + offset - magic) + "px";      
    }    
    else if (left < right)
    {
        var magic = 28; //magic
        offset = right - left;
		if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
			document.getElementById("rowThreeLeftInnerColumn").style.minHeight = (getRowThreeLeftColumnHeight() + offset - magic) + "px";
			document.getElementById("rowThreeLeftInnerColumn").style.height = (getRowThreeLeftColumnHeight() + offset - magic) + "px";
		}else{
			document.getElementById("rowThreeLeftInnerColumn").style.height = (getRowThreeLeftColumnHeight() + offset - magic) + "px";
		}
    }
    else if (left == right)
    {
        //do nothing
    }
    else
    {
        //this should not happen either
    }
}
// END NEW BRAND HOMEPAGE

// START NEW BRAND ESTORE MAINPAGE
function getMaximumEstoreSubboxHeight()
{
    var subbox1 = document.getElementById("subbox1").offsetHeight;
    var subbox2 = document.getElementById("subbox2").offsetHeight;
    var subbox3 = document.getElementById("subbox3").offsetHeight;
    var subbox4 = document.getElementById("subbox4").offsetHeight;
    var subboxesHeights = new Array();
    subboxesHeights[0] = subbox1;
    subboxesHeights[1] = subbox2;
    subboxesHeights[2] = subbox3;
    subboxesHeights[3] = subbox4;
    return getMaxValue(subboxesHeights)
}

function eqEstoreSubboxDividerHeight()
{
    document.getElementById("subbox_divider1").style.height = getMaximumEstoreSubboxHeight() + "px";
    document.getElementById("subbox_divider2").style.height = getMaximumEstoreSubboxHeight() + "px";
    document.getElementById("subbox_divider3").style.height = getMaximumEstoreSubboxHeight() + "px";
}
//END NEW BRAND ESTORE MAINPAGE

function popUp(URL,title,w,h) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1'
    window.open(URL, "", winprops)
}

function clearDefaultValue (searchField, searchButton) {
    if (searchField.defaultValue == searchField.value) 
    {
        searchField.value = '';
    }    
    else if (searchField.value == '') 
    {
        searchField.value = searchField.defaultValue;
    }
    else
    {    
        //do nothing
    }
}

function validateSearchField (searchForm, searchField) {
    if (searchField.value == "Search" || searchField.value == "")
    {
        return false; //do nothing
    }
    else
    {
        searchForm.submit();
    }
}

function printStateMenu(country) { 
    var stateSelect = '';
    if (country == 'United States') {
        stateSelect = '<select style="width:100px;" name="State" id="state">' +
        '<option value="AK">Alaska</option>' + 
        '<option value="AL">Alabama</option>' +
        '<option value="AR">Arkansas</option>'+
        '<option value="AZ">Arizona</option>'+
        '<option value="CA">California</option>'+
        '<option value="CO">Colorado</option>'+
        '<option value="CT">Connecticut</option>'+
        '<option value="DC">District of Columbia</option>'+
        '<option value="DE">Delaware</option>'+
        '<option value="FL">Florida</option>'+
        '<option value="GA">Georgia</option>'+
        '<option value="HI">Hawaii</option>'+
        '<option value="IA">Iowa</option>'+
        '<option value="ID">Idaho</option>'+
        '<option value="IL">Illinois</option>'+
        '<option value="IN">Indiana</option>'+
        '<option value="KS">Kansas</option>'+
        '<option value="KY">Kentucky</option>'+
        '<option value="LA">Louisiana</option>'+
        '<option value="MA">Massachusetts</option>'+
        '<option value="MD">Maryland</option>'+
        '<option value="ME">Maine</option>'+
        '<option value="MI">Michigan</option>'+
        '<option value="MN">Minnesota</option>'+
        '<option value="MO">Missouri</option>'+
        '<option value="MS">Mississippi</option>'+
        '<option value="MT">Montana</option>'+
        '<option value="NC">North Carolina</option>'+
        '<option value="ND">North Dakota</option>'+
        '<option value="NE">Nebraska</option>'+
        '<option value="NH">New Hampshire</option>'+
        '<option value="NJ">New Jersey</option>'+
        '<option value="NM">New Mexico</option>'+
        '<option value="NV">Nevada</option>'+
        '<option value="NY">New York</option>'+
        '<option value="OH">Ohio</option>'+
        '<option value="OK">Oklahoma</option>'+
        '<option value="OR">Oregon</option>'+
        '<option value="PA">Pennsylvania</option>'+
        '<option value="RI">Rhode Island</option>'+
        '<option value="SC">South Carolina</option>'+
        '<option value="SD">South Dakota</option>'+
        '<option value="TN">Tennessee</option>'+
        '<option value="TX">Texas</option>'+
        '<option value="UT">Utah</option>'+
        '<option value="VA">Virginia</option>'+
        '<option value="VT">Vermont</option>'+
        '<option value="WA">Washington</option>'+
        '<option value="WI">Wisconsin</option>'+
        '<option value="WV">West Virginia</option>'+
        '<option value="WY">Wyoming</option>'+
        '</select>';
    }
    else {
        stateSelect = '<select style="width:100px;" name="State" id="state" disabled>'+
        '<option value="">State</option>'+
        '</select>';
    }
    document.getElementById('stateSelect').innerHTML = stateSelect;
}
/* technical support form */
function PopulateList(source_name,dest_name,keys,values)
{
    var a_keys = new Array();
    a_keys=keys.split("#");
    a_values=values.split("#");
 
    var form_source=document.getElementById(source_name);
    user_key=form_source.options[form_source.selectedIndex].value;
    var form_dest=document.getElementById(dest_name);
 
    var value_index;
    for(i in a_keys)
    { 
        if (a_keys[i] == user_key)
        {
            value_index=i;
            break;
        }
        else
        {
            value_index=-1;
        }
    }
    // clear drop down
    //for(i = 0; i < form_dest.options; i++)
    //{ form_dest.options[i]=null;
    //} 
    form_dest.options.length = 0;
    // find value
    if (value_index >= 0)
    {
        var val = new Array();
        val = a_values[value_index].split(";");
        // populate drop down
        for(i in val)
        {
            form_dest.options[i]=new Option(val[i], val[i], false, false);
        }
    }
    else
    { 
        alert("Unknown value selected");
    }
}