
// global js object
var selectBox = {
	
	theBody : null, // object for page body
	submitBtn : null, // object for the submit button
	iFrame : null, // object for the iFrame
	
	// onload function
	init: function(){
		if (!document.getElementById || !document.getElementsByTagName) { return; }
		
		this.browser = this.searchString(this.dataBrowser)
		this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
		
		if((this.browser == "Explorer") && (this.version < 7)) {
			
			selectBox.submitBtn = document.getElementById("submitter");
			selectBox.addEvent(selectBox.submitBtn, 'click', selectBox.createIframe);
		}

	},
	
	createIframe : function() {
		
		// get the body tag of the document
		selectBox.theBody = document.getElementsByTagName("body")[0];
		selectBox.theBody.style.height = "100%";
		
		// create the iFrame and its properties 
		selectBox.iFrame = document.createElement("iframe");
		selectBox.iFrame.src = "javascript:false;";
		selectBox.iFrame.id = "ie-iframe";
		selectBox.iFrame.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		
		// append the iFrame to the body (See the screen.css file for more styling of the iFrame based on the id, ie-iframe
		selectBox.theBody.appendChild(selectBox.iFrame);
		
	},
	
	addEvent : function(obj, type, func) {
    	if (obj.addEventListener) {obj.addEventListener(type, func, false);}

    	else if (obj.attachEvent) {
      		obj["e" + type + func] = func;
      		obj[type + func] = function() {obj["e" + type + func] (window.event);}
      		obj.attachEvent("on" + type, obj[type + func]);

    	}

    	else {obj["on" + type] = func;}
  	},
	
	// used to parse the strings for browser and operating system
    searchString : function(data) {

        // loop through all the items in the array passed
        for (var i=0, allData=data.length; i<allData; i++) {

            // assign the 'string' property's value to dataString, if it exists
            var dataString = data[i].string;

            // assign the 'prop' property's value to dataProp, if it exists
            var dataProp = data[i].prop;

            // assign either the 'versionSearch' or the 'identity' property's value to browserDetect.versionSearchString
            // 'versionSearch' is given preference by listing it before 'identity'
            this.versionSearchString = data[i].versionSearch || data[i].identity;

            // execute this block of code if there is a 'string' property
            if (dataString) {

               // search the indicated string (the indicated navigator property) for the associated 'subString' property
               if (dataString.indexOf(data[i].subString) != -1) {

	              // if there is a match, return the value of the 'identity' property,
	              // which gets assigned to browserDetect.browser
	              return data[i].identity;

	           }
            }

            // execute this block of code if there was a 'prop' property
            else if (dataProp) {

               // return the value of the 'identity' property if the 'prop' value exists,
               // which gets assigned to browserDetect.browser
               return data[i].identity;

            }
       }

       return "An unknown browser";
    },

    // used to determine the version number of the browser
    searchVersion : function(dataString) {

        var index = dataString.indexOf(this.versionSearchString);

        if (index == -1) {return;}

        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },

    dataBrowser : [

    { string: navigator.userAgent,  
      subString: "OmniWeb",         
      versionSearch: "OmniWeb",   
      identity: "OmniWeb" },        

    { string: navigator.vendor,
      subString: "Apple",
      versionSearch: "Version",
      identity: "Safari" },

    { prop: window.opera,           
      identity: "Opera" },

    { string: navigator.vendor,
      subString: "iCab",
      identity: "iCab" },

    { string: navigator.vendor,
      subString: "KDE",
      identity: "Konqueror" },

    { string: navigator.userAgent,
      subString: "Firefox",
      identity: "Firefox" },

    { string: navigator.vendor,
      subString: "Camino",
      identity: "Camino" },

    { // for newer Netscapes (6+)
      string: navigator.userAgent,
      subString: "Netscape",
      identity: "Netscape" },

   { string: navigator.userAgent,
     subString: "MSIE",
     identity: "Explorer",
     versionSearch: "MSIE" },

   { string: navigator.userAgent,
     subString: "Gecko",
     identity: "Mozilla",
     versionSearch: "rv" },

   { // for older Netscapes (4-)
     string: navigator.userAgent,
     subString: "Mozilla",
     identity: "Netscape",
     versionSearch: "Mozilla" }

   ],

   dataOS : [

   { string: navigator.platform,
     subString: "Win",
     identity: "Windows" },

   { string: navigator.platform,
     subString: "Mac",
     identity: "Mac" },

   { string: navigator.platform,
     subString: "Linux",
     identity: "Linux" }

   ]

}

selectBox.init();