function showModalWindow(url, name, height, width)
{
	var handle;
	if (window.showModalDialog1)
		handle = window.showModalDialog(url, name, "dialogHeight:" + height + "px;dialogWidth:" + width+ "px;resizable=yes");
	else
	{
		handle = window.open(url, name, "height=" + height + ",width=" + width+ ",toolbar=no,modal=yes,dependent=yes,directories=no,status=no,location=no,menubar=no,scrollbars=no,resizable=yes");
		handle.focus();
	}
}
function showPopupWindow(url, name, height, width)
{
	var handle;
	handle = window.open(url, name, "height=" + height + ",width=" + width+ ",toolbar=no,dependent=yes,directories=no,status=no,location=no,menubar=no,scrollbars=yes,resizable=yes");
	handle.focus();
}
function showLeaseTech(PurchasePrice)
{
	var url = "/acquire/leaseTech/payment_calculator.asp?PurchasePrice=" + PurchasePrice;
	 showModalWindow(url, "leasetech", 330, 560);
//	var LeaseTech = window.open(,'LeaseTech','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=560,height=330,resizable=no');
}

function showPartnerProfile(Profile) {
	window.open ('assets/partnerprofiles/partnerprofile.asp?Profile='+Profile, 'Profile','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=550,left = 100,top = 100');
}

function getElement(item)
{
    var el;
    if (document.getElementById) // Standards
        el = document.getElementById(item);
    else if (document.all) // IE
        el = document.all[item];
    else if (document.layers) // NN
        el = document.layers[item];
    return el;
}

// Show/hide an element
function showHide(id)
{
    var el = typeof(id)=='string' ? getElement(id) : id;
    var s = el.style;
    var show = false;
    if(s.display=='' && el.offsetWidth!=undefined && el.offsetHeight!=undefined)
        show = (el.offsetWidth!=0 && el.offsetHeight!=0) ? true : false;
    show = (s.display=='' || s.display=='block') ? false : true;
    
    s.display = show  ? 'block' : 'none';

    // todo: make it hide/show multiple times only revealing bit hidden
    if (show)
    {
        var height = el.scrollHeight>0 ? el.scrollHeight : el.offsetHeight;
        var top = el.scrollTop>0 ? el.scrollTop : el.offsetTop;
        if (top+height>document.documentElement.clientHeight)
            window.scrollBy(0, height);
    }

    return false;
}
function getScrollXY()
{
    var x = 0, y = 0;
    if (document.body && (document.body.scrollLeft || document.body.scrollTop)) // Standards
    {
        y = document.body.scrollTop;
        x = document.body.scrollLeft;
    }
    else if (document.documentElement &&
        (document.documentElement.scrollLeft || document.documentElement.scrollTop)) // IE6
    {
        y = document.documentElement.scrollTop;
        x = document.documentElement.scrollLeft;
    }
    else if (typeof(window.pageYOffset) == 'number' ) // NN
    {
        y = window.pageYOffset;
        x = window.pageXOffset;
    }
    return [x, y];
}

function closeBox(className, version) {
    var el = document.getElementById(className);
    if (el)
        document.getElementById(className).style.display = "none";
    setCookie(className, version, 365);
}
function setCookie(name, value, days) {
    var expiry = new Date();
    expiry.setDate(expiry.getDate() + days);
    document.cookie = name + "=" + escape(value) +
	";expires=" + expiry.toGMTString();
}
function getCookie(name, defaultValue) {
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length)))
        return defaultValue;
    if (start == -1)
        return defaultValue;
    var end = document.cookie.indexOf(";", len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}
function showBox(id, version) {
    el = document.getElementById(id);
    oldVersion = getCookie(id, 0);
    if (el && version > oldVersion)
        el.style.display = "block";
}
