function activateEmail(field) {
    field.className='active';

    if(field.value=='Email')
        field.value='';
}

function deactivateEmail(field) {
    if(field.value=='')
        field.value='Email';
    field.className='passive';
}

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);

    var vars = query.split("&");
    for (var i=0; i < vars.length; ++i) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }

    return "";
}

function getOSVersion() {
    return navigator.userAgent;
}

function getVSvnVersion(verStr) {
    return unescape(getQueryVariable(verStr));
}

function setupFeedbackInfo(fieldId) {
    verOS = getOSVersion();
    verVSvn = getVSvnVersion("vsvn");
    verVSvnServ = getVSvnVersion("vsvn-server");

    info = "";
    if ( verVSvn != "" )
        info = info + "VSVN (" + verVSvn + "); ";

    if ( verVSvnServ != "" )
        info = info + "VSVNServer (" + verVSvnServ + "); ";

    info = info + "System (" + verOS + ")";

    elem = document.getElementById(fieldId);
    elem.value = info;
}

function setFocus(fieldId) {
    elem = document.getElementById(fieldId);
    elem.focus();
}

function get_testimonial() {
    items = new Array(2);
    items[0] = new Array(2);
    items[0][0] = "&laquo;It&#146;s not that VisualSVN has a lot of bells and whistles, it just works well.&raquo;";
    items[0][1] = "Scott Bellware [MVP]";
    items[1] = new Array(2);
    items[1][0] = "&laquo;I love that I can just move and rename and VisualSVN just &laquo;does the right thing&raquo;";
    items[1][1] = "Michael C. Neel";

    today = new Date();
    item = today.getDate() % items.length;

    text = items[item][0];
    auth = items[item][1];

    document.write('<p class="first">' + text + '<br/><strong>' + auth + '</strong></p>');
}

function leftTrim(sString)
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    return sString;
}

function rightTrim(sString)
{
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

function trimAll(sString)
{
    return rightTrim(leftTrim(sString));
}

function validate_required_field(field, ftitle)
{
    with (field)
    {
        var str = '';
        if (value != null)
            str = trimAll(value);

        if (str != '')
            return true;

        focus();
        alert('Field "' + ftitle +  '" must be filled out.');
        return false;
    }
}

function ExpandFaqEntry(elemid, expand) {
    var element = document.getElementById(elemid + "_answer");
    var zimg = document.getElementById(elemid + "_img");

    if (element == null || zimg == null) {
        return;
    }

    if (expand) {
        element.style.display = '';
        zimg.src = '/images/faq_minus.gif';
    }
    else {
        element.style.display = 'none';
        zimg.src = '/images/faq_plus.gif';    
    }
}

function ToggleFaqEntry(elemid) {
    var element = document.getElementById(elemid + "_answer");

    if (element.style.display == 'none') {
        ExpandFaqEntry(elemid, true);
        document.location.hash = '#' + elemid;
    }
    else {
        ExpandFaqEntry(elemid, false);
    }
}
