// from: http://msdn.microsoft.com/en-us/library/ms537509%28VS.85%29.aspx
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
function checkVersion() {
    var msg = "You're not using Internet Explorer.";
    var ver = getInternetExplorerVersion();

    if (ver > -1) {
        if (ver >= 8.0)
            msg = "You're using a recent copy of Internet Explorer."
        else
            msg = "You should upgrade your copy of Internet Explorer.";
    }
    alert(msg);
}

//
// Insert email but make it hard for robots to gather
//<!-- Original:  CDR Software -->
//<!-- Web Site:  http://www.cdrsoft.com  -->
//
//<!-- This script and many more are available free online at -->
//<!-- The JavaScript Source!! http://javascript.internet.com -->
//
//<!-- Begin
function mailTo(user, domain) {
    document.write('<a href=\"mailto:' + user + '@' + domain + '\">');
    document.write(user + '@' + domain + '</a>');
}
function mailToWithText(user, domain, text) {
    document.write('<a href=\"mailto:' + user + '@' + domain + '\">');
    document.write(text + '</a>');
}

//
// Get the height of the client window
function getClientHeight() {
    if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    return window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    return document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    return document.body.clientHeight;
    }
}
//
// Get the height of the client window
function getClientWidth() {
//    return 800;
    if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    return window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    return document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    return document.body.clientWidth;
    }
}

//
// get the position of the object with "id"
function getPos(id)
{
	var obj = document.getElementById(id);
	var curleft = curtop = 0;
	if(obj.offsetParent)
	{
	    while(1)
	    {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
			    break;
			obj = obj.offsetParent;
	    }
	}
	return [curleft, curtop];
}

//
// resize the object given by "what" so that it is tall enough to fill the screen assuming it
// is placed where the object "where" is placed.
function fillRestOfScreen(what, where) {
   
//    alert(navigator.userAgent);
//    alert("fillRestOfScreen was called:" + what + " " + where);

    var h1 = getClientHeight();
    var w1 = getClientWidth();

//    alert("clientH= " + h1.toString() + " clientW= " + w1.toString());
    document.getElementById(what).style.height = (h1-8) + "px";
    document.getElementById(what).style.width = (w1-18) + "px";
}


function sizeDeepZoom() {
//    alert("sizeDeepZoom called:" + navigator.userAgent);

    // IE7 and before re-size without extra help, so look for those and leave them alone
    var ver = getInternetExplorerVersion();
    //alert("sizeDeepZoom called: browser version  = " + ver);
    if ((ver == -1) || (ver >= 8))
    {
        fillRestOfScreen("zoom", "zoom");
    }
}

function sizePageTurn(pageRatio) {
    //    alert("sizePageTurn: " + pageRatio);
    //    var pageRatio = 9.0 / 11.0; // height / width

    var clientHeight = getClientHeight();
    var clientWidth = getClientWidth();
    if (navigator.userAgent.indexOf("MSIE") == -1) {
        clientWidth -= 39;
    }
    else {
        clientWidth -= 22;
        clientHeight -= 4;
    }

    var newWidth = clientWidth;
    var newHeight = newWidth * pageRatio;

    // this code will limit the height of the page to the client window hieght
    // this also linmits how wide the image acan be.
//    if (newHeight > clientHeight) {
//        newHeight = clientHeight;
//        newWidth = newHeight / pageRatio;
//    }
    document.getElementById("zipzap").style.width = newWidth + "px";
    document.getElementById("zipzap").style.height = newHeight + "px";
}

