﻿//The code below enables multiple css files to be called up for browser hacks and a print.css file 

// BEGIN: styleSheetPicker object definition
// <![CDATA[


function styleSheetPicker() {

    this.ieScreen = this.iePrint = this.otherScreen = this.otherPrint = "";
    this.isOpera = navigator.userAgent.indexOf('Opera') > -1;
    this.isSafari = navigator.userAgent.indexOf('AppleWebKit') > -1;

    //Gavin Bruce 01/02/08 : This will target just the Mozilla browser.
    this.isMozilla = navigator.userAgent.indexOf('Mozilla') > -1 && navigator.userAgent.indexOf('SeaMonkey') == -1 && navigator.userAgent.indexOf('K-Meleon') == -1 && navigator.userAgent.indexOf('Firefox') == -1 && navigator.userAgent.indexOf('MSIE') == -1 && navigator.userAgent.indexOf('AppleWebKit') == -1;

    this.isEditMode = false; var theDnnForm = document.forms['Form'];
    this.isIE6 = navigator.userAgent.indexOf('MSIE 6') > -1;
    this.isIE8 = navigator.userAgent.indexOf('MSIE 8') > -1;
	this.isIE9 = navigator.userAgent.indexOf('MSIE 9') > -1;
    if (!theDnnForm) {
        theDnnForm = document.Form;
    }
    //iterate thru form.
    var elems = theDnnForm.elements;

    //Gavin Bruce 12/12/07 : Determine if user is in edit mode by finding a radio button with the value of EDIT and seeing if it is checked.
    for (var ix = 0; ix < elems.length; ix++) {
        var elem = elems[ix];
        if (elem.type == 'radio') {
            if (elem.value == 'EDIT') {
                if (elem.checked) {
                    this.isEditMode = true;
                }
            }
        }
    }
}






styleSheetPicker.prototype.render = function() {
    if (document.createStyleSheet) {
        // IE
        if (this.ieScreen && !this.isIE8 && !this.isIE9) {
			//add ieScreen which represents a path to 'iehacks.css'
            document.createStyleSheet(this.ieScreen);
            if (this.isEditMode) {
                document.createStyleSheet('/Portals/_default/Skins/SkinResources/CSS/admin.css');
            }
        }

        if (this.iePrint) {
            var ieP = document.createStyleSheet(this.iePrint);
            ieP.media = "print";
        }
        if (this.isIE6) {
            document.createStyleSheet('/Portals/_default/Skins/SkinResources/CSS/ie6.css');
        }
    }
    else {
        var head = document.getElementsByTagName("head")[0];

        //Gavin Bruce 12/12/07 : If safari, include the safari style sheet.
        if (this.isSafari) {
            head.innerHTML += "<link rel=\"stylesheet\" href=\"/Portals/_default/Skins/SkinResources/CSS/safari.css\"/>";
        }

        //Gavin Bruce 12/12/07 : If opera, include the opera style sheet.
        if (this.isOpera) {
            head.innerHTML += "<link rel=\"stylesheet\" href=\"/Portals/_default/Skins/SkinResources/CSS/opera.css\"/>";
        }

        //Gavin Bruce 12/12/07 : If in dnn edit mode, include the admin style sheet.
        if (this.isEditMode) {
            head.innerHTML += "<link rel=\"stylesheet\" href=\"/Portals/_default/Skins/SkinResources/CSS/admin.css\"/>";
        }

        if (this.otherScreen != "") {
            head.innerHTML += "<link rel=\"stylesheet\" href=\"" + this.otherScreen + "\"/>";
        }

        if (this.otherPrint != "") {
            head.innerHTML += "<link rel=\"stylesheet\" media=\"print\" href=\"" + this.otherPrint + "\"/>";
        }

        //Gavin Bruce 12/12/07 : If mozilla, include the mozilla style sheet.
        if (this.isMozilla) {
            head.innerHTML += "<link rel=\"stylesheet\" href=\"/Portals/_default/Skins/SkinResources/CSS/mozilla.css\"/>";
        }

    }
}
// END: styleSheetPicker object definition

var picker = new styleSheetPicker();

// IE stylesheets
picker.ieScreen = "/Portals/_default/Skins/SkinResources/CSS/iehacks.css";
picker.iePrint = "/Portals/_default/Skins/SkinResources/CSS/print.css";

// Other browser stylesheets
// Don't need this: picker.otherScreen = "default.css";
picker.otherPrint = "/Portals/_default/Skins/SkinResources/CSS/print.css";
picker.render();
// ]]>

