//http://tech.irt.org/articles/js064/index.htm
function getCookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

var ie       = (navigator.appVersion.indexOf('MSIE')    != -1)                    ? true : false;
var ns       = ((typeof(document.all) == 'undefined') && document.getElementById) ? true : false;

function setCookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (true) ? ";expires=Sun 01-Jan-2070 00:00:00 UTC" : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function login(form) {
    if(!form.username.value.length) {
        alert('Please enter your Username');
        form.username.focus();
        return false;
    } else {
        if(!form.password.value.length) {
            alert('Please enter your Password');
            form.password.focus();
            return false;
        } else {
            return true;
        }
    }
}

function cC(bg,o,p) {
    val = Math.round(parseInt(bg.substring(o,p), 16) * 0.7);
    if(val > 255) {
        val = 255;
    } else if(val < 0) {
        val = 0;
    }

    val = val.toString(16);
    if(val.length == 1) {
        val = '0'+val;
    }
    return val;
}

function sB(bg) {
    d = document;
    setCookie('bgcolor',bg);
    d.body.style.backgroundColor = bg;
    color = '#' + cC(bg,1,3) + cC(bg,3,5) + cC(bg,5,7);
    if(d.getElementById('pageTitle') != null) {
        d.getElementById('pageTitle').style.color = color;
    }

    if(d.getElementById('selMenu') != null) {
        d.getElementById('selMenu').style.color   = color
    }

    if(d.getElementById('loginButton') != null) {
        d.getElementById('loginButton').style.backgroundColor = color;
    }



    //Attempt to change the color of the links!!!
    doc_style=document.styleSheets[0];
    rules = doc_style.rules;

    if(ie) {
        for(i=0; i< rules.length; i++) {
            if(rules.item(i).selectorText == 'A') {
                doc_style.addRule('A', 'color: ' + color);
                //rules.item(i).style.color=color;
                break;
            }
        }
    }






}

function rB() {
    if(val = getCookie('bgcolor')) {
        sB(val);
    } else {
        sB('#3399CC');
    }
}

function dGl() {
    if(ie) {
        document.write('<img src="/images/dot.png" width="30" height="100%" border="0" alt="" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/grad_left.png\', sizingMethod=scale);">');
    } else {
        document.write('<img src="/images/grad_left.png" width="30" height="100%" border="0" alt="">');
    }
}
function dGr() {
    if(ie) {
        document.write('<img src="/images/dot.png" width="30" height="100%" border="0" alt="" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/grad_right.png\', sizingMethod=scale);">');
    } else {
        document.write('<img src="/images/grad_right.png" width="30" height="100%" border="0" alt="">');
    }
}

function oW(e, url, width, height, attrs, optional_name) {

    ah = screen.availHeight - 30;
    aw = screen.availWidth - 10;

    xc = (aw - width) / 2;
    yc = (ah - height) / 2;

    //Make up a window name based on the URL.
    window_name = optional_name ? optional_name : url.replace(/[^a-z]*/gi,'');

    if (ie) {
        //Status=yes is forced for SP2 compatibility.
	    attrs += ',status=yes,location=no';
	}

    //Status=yes is forced for SP2 compatibility.
	w = window.open(url, window_name, 'width='+width+',height='+height+',left='+xc+',top='+yc+','+attrs);

    //Test that it worked!
    if(!w) {
        alert('Please disable your popup blocker!');
    } else {
        w.focus();
    }
}

function search(dd) {
    location.href = dd.options[dd.selectedIndex].value;
}

function sS(e,idx) {
    oW(e, '/email_marketing_screenshot.html?' + idx, 700,600);
}

function fSs(e,idx) {
    oW(e, '/email_marketing_feature_screenshot.html?' + idx, 700,600);
}

function cSs(e,idx) {
    oW(e, '/Hilltop_Mail_screenshots.html?' + idx, 700,600);
}

function gSs(t, e,idx) {
    switch (t){
        case 9:
            url = '/ppc_screenshot.html';
            break;

        case 10:
            url = '/viral_screenshot.html';
            break;

    
    }
    
    oW(e, url+'?' + idx, 700,600);
}



function sI(idx) {
    var img = document.getElementById('img');
    var tit = document.getElementById('tit');
    var pl  = document.getElementsByName('prev_link')
    var nl  = document.getElementsByName('next_link')

    pl[0].disabled = (idx == 0) ? true : false;
    pl[1].disabled = (idx == 0) ? true : false;
    nl[0].disabled = (idx == (images.length-1)) ? true : false;
    nl[1].disabled = (idx == (images.length-1)) ? true : false;

    pl[0].style.color = (idx == 0) ? 'gray' : '';
    pl[1].style.color = (idx == 0) ? 'gray' : '';
    nl[0].style.color = (idx == (images.length-1)) ? 'gray' : '';
    nl[1].style.color = (idx == (images.length-1)) ? 'gray' : '';

    if (idx >= 0 && idx < images.length) {

        if (img.filters) {
            img.filters[0].Apply();
        }

        img.src = images[idx].src;
        img.style.display = '';
        tit.innerHTML = screens[idx][0];

        if (img.filters) {
            img.filters[0].Play();
        }
    }
}

function sIa(p) {
    idx = ((idx+p) >= 0 && (idx+p) < images.length) ? idx+p : idx;
    sI(idx);
}



function updateCheckboxes(oChkBox){
    if (oChkBox) {
        checked_items = new Array();
        var hidden_fld  = eval('oChkBox.form.' + oChkBox.name.substr(3,oChkBox.name.length));
       var items   = eval("oChkBox.form." + oChkBox.name);
        if(items.length) {
            for( i=0; i<items.length; i++ ){
                if( items[i].checked ){
                    checked_items[checked_items.length] = items[i].value;
                }
            }
            hidden_fld.value = checked_items.join(',');
        } else {
            if (items.checked) {
                hidden_fld.value = items.value;
            } else {
                hidden_fld.value = '';
            }
        }
    }
}

function overButton() {}

function pT() {
    oW('onclick', '/product_tour/page01.htm',620,580);
}




