// CHECK CLIENT BROWSER & PLATFORM
// original code from http://developer.apple.com/internet/_javascript/
//
// USAGE:    browserNaming();
// NOTES:    call it from within an external JS document
// RESULT:    browserNew = true/false
//            browserName = IE/NS/Opera
//            browserNameLong = IE5/etc
//            Macintosh = true/false
// WORKS:    everything

    var its;
    var browserName;
    var browserNameLong;
    var browserNew;
    var preloadFlag = false;
    var Macintosh = navigator.userAgent.indexOf('Mac')>0;

    function its() {
        var n = navigator;
        var ua = ' ' + n.userAgent.toLowerCase();
        var pl = n.platform.toLowerCase();
        var an = n.appName.toLowerCase();

        // browser version
        this.version = n.appVersion;
        this.nn = ua.indexOf('mozilla') > 0;

        // 'compatible' versions of mozilla aren't navigator
        if(ua.indexOf('compatible') > 0) {
            this.nn = false;
        }
        
        this.opera = ua.indexOf('opera') > 0;
        this.ie = ua.indexOf('msie') > 0;
        this.major = parseInt( this.version );
        this.minor = parseFloat( this.version );

        // platform
        this.mac = ua.indexOf('mac') > 0;
        this.win = ua.indexOf('win') > 0;

        // workaround for IE5 which reports itself as version 4.0
        if(this.ie) {
            if(ua.indexOf("msie 5") > 1) {
            var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
            this.major = parseFloat(navigator.appVersion.substr(msieIndex,3));
            }
        }

        return this;
    }

    function browserNaming() {
        its = new its();
        
        // is it a DOM-enabled browser?
        if (!document.getElementById) {
            browserNew = false;
        }
        else {
            browserNew = true;
        }

        // need the name, too
        if (its.opera) {
            browserName = "Opera";
        }
        else if (its.ie) {
            browserName = "IE";
        }
        else {
            browserName = "NS";
        }

        // and the number
        browserNameLong = browserName + its.major;
    
    }
    //initialise browser checking
    browserNaming();

// REMOVES THE LINK BORDER IN IE5/NS6
// original code by evil@chelu.ro
//
// USAGE:    getLinksToBlur();
// NOTES:    call it from within the preload function
// WORKS:    ie4+, ns6+

	

	function unblur() {
		this.blur();
	}

	function getLinksToBlur() {
		if ((browserNew) || (browserName == "IE")) {
			if (browserNew) {
				links = document.getElementsByTagName("a");
			}
			else {
				links = document.all.tags("a");
			}
			for(i=0; i<links.length; i++) {
				links[i].onfocus = unblur
			}
		}
		if (browserName == "IE") {
			if (browserNew) {
				drops = document.getElementsByTagName("select");
			}
			else {
				drops = document.all.tags("select");
			}
			for(i=0; i<drops.length; i++) {
				drops[i].onfocus = unblur
			}
		}
	}
	

//WINDOW MOVE TO SCREEN TOP LEFT AND RESIZE TO FULL AVAILABLE SCREEN AREA
//
// USAGE:    winMoveResize();
// NOTES:    call it from within the preload function
// WORKS:    ie4+, ns4+, opera5+

	function winMoveResize() {
		//check for netscape, IE. Netscape does not properly support resizing.

		window.moveTo(0,0);
		width = screen.availWidth;
		height = screen.availHeight;
		if (browserName == "IE") {
			window.resizeTo(width, height);
			//do Netscape size correction
		}else if (browserName == "NS" && browserNew == true) {
			window.resizeTo(width- 5, height - 20);
		}else if (browserNameLong == "NS4") {
			window.resizeTo(width- 5, height - 5);
		}
	}

//OPEN NEW WINDOW
//
// USAGE:   newWin(theurl,winName,windowWidth,windowHeight,center,status,menubar,toolbar,resizable,scroll,offset,xPos,yPos)
//			
//			Function Arguments
//
//			theurl = string to file to be opened (eg 'flash.html')
//			winName = string name of new window (eg 'myFlashWin')
//			windowWidth = width of new window in pixels (eg 200)
//			windowHeight = height of new window in pixels (eg 100)
//			center = boolean value to center new window on screen (eg true)
//			status = visibility of status bar must be string of yes or no (eg 'no')
//			menubar = visibility of menu bar must be string of yes or no (eg 'no')
//			toolbar = visibility of tool bar must be string of yes or no (eg 'no')
//			resizable = set if window can be manually resized must be string of yes or no (eg 'yes')
//			scroll = enable/disable scroll bars string of yes or no (eg 'no')
//			offset = boolean value to offset new window on screen (eg true)
//			xPos = amount of offset from left of screen in pixels (eg 20)
//			yPos = amount of offset from top of screen in pixels (eg 20)
// NOTES:   Suports all window chrome and reszing options
//			Enables centering on screen
// WORKS:   ie4+, ns4+, opera5+


	function newWin(theurl,winName,windowWidth,windowHeight,center,status,menubar,toolbar,resizable,scroll,offset,xPos,yPos) {
		//check if browser is version 4 or above, and if centering is desired
		if (its.major >= 4 && center == true) {
			wX = (screen.width/2)-(windowWidth/2+10);
			wY = (screen.height/2)-(windowHeight/2+20);
		}else if (offset == true) {
			wX = xPos;
			wY = yPos; // offset window
		}else {
			wX = 0;
			wY = 0; // set window pos to 0,0 if browser is not ver 4 or center == false && offset == false
		}
		theurl = theurl;
	    var popped = window.open(theurl,winName,'width='+windowWidth+',height='+windowHeight+',status='+status+',menubar='+menubar+',toolbar='+toolbar+',scrollbars='+scroll+',resizable='+resizable+',screenX='+wX+',screenY='+wY+',left='+wX+',top='+wY);
		if (browserName == "NS" || document.all) {
		popped.focus();
		}
	}
