// Flag for whether or not to automatically call the print function
var gAutoPrint = true;
function printSpecial() {
	if (document.getElementById != null) {
		var html = '<HTML>\n<HEAD>\n';
		if (document.getElementsByTagName != null) {
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}		
		html += '\n</HE' + 'AD>\n<BODY>\n';		
		var printElem = document.getElementById("print");		
		if (printElem != null) {
			html += printElem.innerHTML;
		}
		else {
			alert("Could not find the print section in the webpage");
			return;
		}			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else {
		alert("Sorry, this print feature is only available in current browsers.  Please click the print button on your browser interface or press Ctrl+ P on your keyboard to print");
	}
}

// Submit Form on document to next page
function SubmitForm() {
	document.forms[0].submit();
}

function KofC_ChooseCSS() {
    if (navigator.userAgent.toLowerCase().indexOf('mac_ppc') != -1) { // AOL 5, MAC OS 9
        document.write('<link rel="STYLESHEET" type="text/css" href="/common/knights-mac.css">');
    }
    else {
        document.write('<link rel="STYLESHEET" type="text/css" href="/common/knights.css">');
    }
}

function KofC_ChangeState(id,state) {
    if (document.getElementById) { // NETSCAPE 6, IE 5.X+
        document.getElementById(id).className = state;
    }
	else if (document.all) {
        document.all[id].className = state;
    }
}

function KofC_OpenNewWindow(url,type,name,w,h) {
    var type;
    var new_win;
    var features;
    var toolbar;
    var location;
    var statusbar;
    var menubar;
    var resizable;
    var scrollbars;
    type = type.toLowerCase();
    if (type == 'html') {
        h=h-50;
        toolbar = 1;
        location = 1;
        statusbar = 1;
        menubar = 1;
        resizable = 'yes';
        scrollbars = 1;
        features =
        'height=' + h + ',' +
        'width=' + w + ',' +
        'top=' + (screen.height - h)/6 + ',' +
        'left=' + (screen.width - w)/2 + ',' +
        'toolbar=' + toolbar + ',' +
        'location=' + location + ',' +
        'statusbar=' + statusbar + ',' +
        'menubar=' + menubar + ',' +
        'resizable=' + resizable + ',' +
        'scrollbars=' + scrollbars;
    }
    else if (type == 'media') {
        toolbar = 0;
        location = 0;
        statusbar = 1;
        menubar = 0;
        resizable = 'no';
        scrollbars = 1;
        features =
        'height=' + h + ',' +
        'width=' + w + ',' +
        'top=' + (screen.height - h)/2 + ',' +
        'left=' + (screen.width - w)/2 + ',' +
        'toolbar=' + toolbar + ',' +
        'location=' + location + ',' +
        'statusbar=' + statusbar + ',' +
        'menubar=' + menubar + ',' +
        'resizable=' + resizable + ',' +
        'scrollbars=' + scrollbars;
    }
    else if (type == 'warning') {
        toolbar = 0;
        location = 0;
        statusbar = 1;
        menubar = 0;
        resizable = 'no';
        scrollbars = 1;
        features =
        'height=400' + ',' +
        'width=600' + ',' +
        'top=' + (screen.height - h)/2 + ',' +
        'left=' + (screen.width - w)/2 + ',' +
        'toolbar=' + toolbar + ',' +
        'location=' + location + ',' +
        'statusbar=' + statusbar + ',' +
        'menubar=' + menubar + ',' +
        'resizable=' + resizable + ',' +
        'scrollbars=' + scrollbars;
    }
    else if (type == 'flash') {
        toolbar = 0;
        location = 0;
        statusbar = 1;
        menubar = 0;
        resizable = 'no';
        scrollbars = 0;
        features =
        'height=' + h + ',' +
        'width=' + w + ',' +
        'top=' + (screen.height - h)/2 + ',' +
        'left=' + (screen.width - w)/2 + ',' +
        'toolbar=' + toolbar + ',' +
        'location=' + location + ',' +
        'statusbar=' + statusbar + ',' +
        'menubar=' + menubar + ',' +
        'resizable=' + resizable + ',' +
        'scrollbars=' + scrollbars;
    }
    else {
        toolbar = 0;
        location = 1;
        statusbar = 0;
        menubar = 0;
        resizable = 'yes';
        scrollbars = 1;
        features =
        'height=' + h + ',' +
        'width=' + w + ',' +
        'top=' + (screen.height - h)/4 + ',' +
        'left=' + (screen.width - w)/2 + ',' +
        'toolbar=' + toolbar + ',' +
        'location=' + location + ',' +
        'statusbar=' + statusbar + ',' +
        'menubar=' + menubar + ',' +
        'resizable=' + resizable + ',' +
        'scrollbars=' + scrollbars;
    }
    new_win = window.open(url,name,features) ;
    new_win.focus();
}

function KofC_determineOS() {
    var isOSX;
    if (navigator.userAgent.toLowerCase().indexOf('os x') != -1) { // MAC OS X
        isOSX = true;
    }
    else {
        isOSX = false;
    }
}

function KofC_rotateHomePageImage() {
    var randomNumber = Math.floor(3*Math.random()+1);
    var randomImage = '/images/level0_photo'+randomNumber+'.jpg';
    document.writeln('<img src="'+randomImage+'" alt="Three men" title="Three men" width="353" height="130" vspace="4" border="0">');
}

function getQueryStringValue(paramName) {
    // GET THE &param=value pairs to the right of the ?
    var qString = window.location.href.split("?")[1];
    var paramArray = qString.split("&");
    for(var i=0;i<paramArray.length;i++) {
        var temp = paramArray[i].split("=")
        if(temp[0] == paramName) return (temp[1]);
    }

}
function KofC_limitTextarea(limitField, limitNum, limitDisclaimer) {
    var oDisclaimer;
    if (document.getElementById) {
        oDisclaimer = document.getElementById(limitDisclaimer);
    }
    else if (document.all) {
        oDisclaimer = document.all[limitDisclaimer];
    }
    if (limitField.value.length > limitNum) {
        //limitField.value = limitField.value.substring(0, limitNum);
        oDisclaimer.style.display = "block";
    }
    else {
        oDisclaimer.style.display = "none";
    }
}

/* function CalculateTotal(frm, elementStartNo, elementEndNo, sectionName) {
    var order_total = 0;
    for (var i=elementStartNo; i < elementEndNo; i++) {
        form_field = frm.elements[i];
        item_quantity = parseInt(form_field.value);
            if (item_quantity >= 0) {
                order_total += item_quantity;
            }
        }
    //  frm.sectionName.value = order_total;
	eval("frm."+sectionName+".value = order_total");
} */
KofC_ChooseCSS();
KofC_determineOS();