var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4));

function getExchangeRate() {
	try {
        document.getElementById("cad").innerHTML = "<span style='text-decoration:blink;color:#ff0000;font-weight:bold;'>Updating</span>";
        document.getElementById("btncad").disabled = true;
        
        var path = new String(window.location);
        var path = path.substring(0, path.lastIndexOf("/"));
        var url = path + "/includes/ajaxsvr.php?cmd=getExchangeRate";
        
	    var loader = new net.ContentLoader(url, parseExchangeRate);
    } catch(e) {
        document.getElementById("cad").innerHTML = "Error!";
        document.getElementById("btncad").disabled = false;
    }        
}

function parseExchangeRate() {
	try {
        var result = this.req.responseText;
	    createCookie("ExchangeRate", result);
    } catch(e) {
        result = "???";
    }
    document.getElementById("cad").innerHTML = "(GBP) &pound;1.00 &raquo; (CAD) $" + result;
    document.getElementById("btncad").disabled = false;
}

function createCookie(name, value, days) {
    if(days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else { 
        var expires = ""; 
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while(c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function showImage(imName) {
    
    var winDlg = new Object();
    
    winDlg.width = 840;
    winDlg.height = 660;
    winDlg.name = (new Date()).getSeconds().toString();
    
    if (Nav4) {
        winDlg.left = window.screenX + ((window.outerWidth - winDlg.width) / 2);
        winDlg.top = window.screenY + ((window.outerHeight - winDlg.height) / 2);
        var attr = "screenX=" + winDlg.left + ",screenY=" + winDlg.top +
            ",resizable=no,width=" + winDlg.width + ",height=" + winDlg.height;
    } else {
        winDlg.left = (screen.width - winDlg.width) / 2;
        winDlg.top = (screen.height - winDlg.height) / 2;
        var attr = "left=" + winDlg.left + ",top=" + winDlg.top + ",resizable=no," +
                "width=" + winDlg.width + ",height=" + winDlg.height;
    }

    winDlg = window.open("", winDlg.name, attr)
    winDlg.document.write("<style type=text/css>");
    winDlg.document.write("a { text-decoration:underline; font-family: Arial,Helvetica,Verdana,Sans-Serif; font-size: 12px; color: #000000; }");
    winDlg.document.write("a:hover { color: #ff0000; }");
    winDlg.document.write("</style>");
    winDlg.document.write("<table width=100% cellpadding=2 cellspacing=2 border=0>");
    winDlg.document.write("<tr><td width=100% align=center>");
    winDlg.document.write("<img src=" + imName + " border=0 style=\"padding:4px; border:2px solid #808080;\">");
    winDlg.document.write("</td></tr>");
    winDlg.document.write("<tr><td align=center>");
    winDlg.document.write("<input type=button value=\"Close\" style=\"width:100px;height:24px;\" onclick=\"window.close();\">");
    winDlg.document.write("</td></tr></table>");
    winDlg.focus()

}

function createCurrencyHtml() {
    document.write("<tr><td valign=top style='padding:8px 0px 8px 20px;'>\n" +
        "<form id=cadform name=cadform method=post><div class=news><h3>Exchange Rate</h3>\n" +
        "<p>British Pound to Canadian Dollar<br><span id=cad name=cad></span><br><br>\n" +
        "<input type=button id=btncad name=btncad value='Refresh' style='width:100px;' " +
        "onclick='getExchangeRate();'></p></div></form></td></tr>\n");
}

function doGoogleCASearch() {

	try {
		var searchSpec = document.getElementById("gglcaSearch").value;
		var url = "http://www.google.ca/search?hl=en&q=" + escape(searchSpec) + 
									"&btnG=Google+Search&meta=cr%3DcountryCA";
		var hWnd = window.open(url);
		hWnd.focus;
	} catch(e) {
		alert(e.message);
	}
	
}