﻿// General JS functions

// Set the size of framecontainer width/height here
var fcW = 767;
var fcH = 550; /* 2009-11-25: AD: Adjusted height with 45px margin-top for #NavigationGlobal */

// Centre sites main frame
function centreframe(w) {
    var bWidth = document.body.offsetWidth;
    var bHeight = document.body.offsetHeight;
    var iHeight = document.documentElement.clientHeight;
    var aHeight = (iHeight) ? iHeight : bHeight;
    // Recentre main frame...
    var oFrame = document.getElementById("framecontainer");
    var xL = (bWidth/2)-(fcW/2);
    if (xL < 0) xL = 0;
    var xT = (aHeight/2)-(fcH/2);
    if (xT < 0) xT = 0;
    if (oFrame!=null) {
        oFrame.style.left = xL+"px";
        oFrame.style.top = xT+"px";
        if (w==1) oFrame.style.visibility = "visible";
    }
    // ... and main content overlay...
    var oFrame = document.getElementById("framecontainer2");
    if (oFrame!=null) {
        oFrame.style.left = xL+"px";
        oFrame.style.top = xT+"px";
        if (w==1) oFrame.style.visibility = "visible";
    }
}

// Ensure we post back to correct url and not underlying template...
function SubmitForm() {
    var form = document.forms[0];
    form.submitted.value = "1";
    form.action = document.location.href;
    form.submit();
}

// Launch bouncemeter
function OpenBounceometer() {
//    var bo = window.open("/bounceometer/shock.html", "bounceometer", "");
//    bo.focus();
      document.location.href="/bounceometer/shock.html";
}

// Open a new window
function OpenPopup(url, w, h) {
    var op = window.open(url, "popup", "menubar=0,resizable=0,width="+w+",height="+h+",scrollbars=1,location=0");
    op.focus();
}

// Select an item in <select>ion list or radio group by its value
function SelectByValue(src, val) {
    var type = (src.type) ? src.type : (src.length>0) ? src[0].type : "";
    if (type=="select-one") {
        for (var x=0;x<src.length;x++) {
            if (src[x].value == val) {
                src[x].selected = true;
                break;
            }
        }
    } else if (type=="radio") {
        for (var x=0;x<src.length;x++) {
            if (src[x].value == val) {
                src[x].checked = true;
                break;
            }
        }
    }
}

// Catch enter key for search submission
function CatchEnter(event) {
	if ((window.event && window.event.keyCode == 13) || 
		(event && event.which == 13)) {
		SubmitForm();
	} else {
		return true;
	}
	return false;
}

// Allow preview popup to link to admin console
function GoAdminURL(url) {
    // Allows preview window to update admin window
    if (window.opener && !window.opener.closed) {
        try {
            window.opener.document.location.href = url;
            window.opener.focus();
            window.close();
        }
        catch (e) {window.close();}
    } else {
        document.location.href = url;        
    }
}