var agt 		= navigator.userAgent.toLowerCase();
var is_major 	= parseInt(navigator.appVersion);
var is_minor 	= parseFloat(navigator.appVersion);

// Opera and WebTV spoof Navigator.
var isNav  	= ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var isNav2 		= (isNav && (is_major == 2));
var isNav3 		= (isNav && (is_major == 3));
var isNav4 		= (isNav && (is_major == 4));
var isNav4up 	= (isNav && (is_major >= 4));
var isNavonly 	= (isNav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
var isNav6 		= (isNav && (is_major == 5));
var isNav6up 	= (isNav && (is_major >= 5));
var isGecko 	= (agt.indexOf('gecko') != -1);

var isIE		= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var isIE3		= (isIE && (is_major < 4));
var isIE4		= (isIE && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var isIE4up		= (isIE && (is_major >= 4));
var isIE5		= (isIE && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var isIE55		= (isIE && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var isIE5up		= (isIE && !isIE3 && !isIE4);
var isIE55up	= (isIE && !isIE3 && !isIE4 && !isIE5);
var isIE6		= (isIE && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var isIE6up		= (isIE && !isIE3 && !isIE4 && !isIE5 && !isIE55);


//drop down select navigation script
function doNav(control){
	if (control.options[control.selectedIndex].value != "none") {
		location = control.options[control.selectedIndex].value
	}
}

//open Super Ezy Window
var superEzyWindowObject;
function openSuperEzy() {
	var se_detect = 'https://www.mlcsuperezy.com/mercury/error/detect.html';
	var resizeParm = "resizable=yes"
	if (isNav) { resizeParm = "resizable=no" }
	superEzyWindowObject = window.open(se_detect,"remotewin", "width=800,height=600,toolbar=no,scrolling=auto,directories=no,status=no,scrollbars=yes,menubar=no," + resizeParm);
	if (superEzyWindowObject.opener == null) superEzyWindowObject.opener = window;
	superEzyWindowObject.opener.name = "opener";
}

/*
General function for opening a window.
windowName - the variable and the the link target name for the window
location - the location to load into the window
height - window height
width - window width
otherAttributes - 
positionRelativeTo - object that the new window should be positioned relative to, either a window or screen object, default is screen.
align - horizontal alignment, values same as td alignment 'center', 'right' & 'left', left is default
vAlign - vertical alignment, values same as td alignment 'middle', 'bottom' & 'top', top is default
leftOffset - horizontal pixel offset to aligned positioned
topOffset - vertical pixel offset to aligned positioned

htmlContent - content to write directly to window
*/

function openWindow( windowName, location, height, width, otherAttributes, positionRelativeTo, align, vAlign, leftOffset, topOffset, htmlContent ){

	topOffset=(topOffset)?topOffset:0;
	leftOffset=(leftOffset)?leftOffset:0;
	var moveToFlag=true;
	align=(align=="center")?(2):( (align=="right")?(1):(0) );
	vAlign=(vAlign=="middle")?(2):( (vAlign=="bottom")?(1):(0) );
	
	if( positionRelativeTo ){
		if( positionRelativeTo.screenX ){
			topOffset+=positionRelativeTo.screenY;
			leftOffset+=positionRelativeTo.screenX;
			topOffset+=(vAlign)?(( positionRelativeTo.outerHeight - height )/vAlign):0;
			leftOffset+=(align)?(( positionRelativeTo.outerWidth - width )/align):0;
		} else if( positionRelativeTo.screenLeft ){
			topOffset+=positionRelativeTo.screenTop;
			leftOffset+=positionRelativeTo.screenLeft;
			topOffset+=(vAlign)?(( positionRelativeTo.document.body.offsetHeight - height )/vAlign ):0;
			leftOffset+=(align)?(( positionRelativeTo.document.body.offsetWidth - width )/align ):0;
			var moveToFlag=false;
		} else if( positionRelativeTo.colorDepth){
			if( center=="center" ){
				if( positionRelativeTo.availHeight ){
					topOffset+(vAlign)?(( positionRelativeTo.availHeight - height )/vAlign ):0;
					leftOffset+=(align)?(( positionRelativeTo.availWidth - width )/align ):0;
				} else if( positionRelativeTo.height ){
					topOffset+=(vAlign)?(( positionRelativeTo.height - height )/vAlign ):0;
					leftOffset+=(align)?(( positionRelativeTo.width - width )/align ):0;
				}
			}
		}
	}
	
	location=(htmlContent)?"":location;
	var windowObj = window.open( location, windowName, "width=" + height + ",height=" + width + ",top=" + topOffset + ",left=" + leftOffset + "," + otherAttributes);
	if( windowObj.moveTo && moveToFlag ){
		windowObj.moveTo( leftOffset, topOffset )
	}
	if(htmlContent){
		windowObj.document.open();
		windowObj.document.write(htmlContent);
		windowObj.document.close();
	}
	windowObj.focus()
	
	eval( windowName + " = windowObj;" )
	return windowObj
}

function openNewWindow( windowName, location, height, width, otherAttributes, positionRelativeTo, align, vAlign, leftOffset, topOffset, htmlContent ){
    openWindow( windowName, location, height, width, otherAttributes, positionRelativeTo, align, vAlign, leftOffset, topOffset, htmlContent );
}

// -------------- functions for Bookmark a page --------------

function getCookieVal(offset) {  
    var endstr = document.cookie.indexOf (";", offset);  
    if (endstr == -1)    
    endstr = document.cookie.length;  
    return unescape(document.cookie.substring(offset, endstr));
}
    
function GetCookie(name) {  
    var arg = name + "=";  
    var alen = arg.length;  
    var clen = document.cookie.length;  
    var i = 0;  
    while (i < clen) {    
        var j = i + alen;    
        if (document.cookie.substring(i, j) == arg)      
            return getCookieVal(j);    
        i = document.cookie.indexOf(" ", i) + 1;    
        if (i == 0) break;   
    }  
    return null;
}

function SetCookie(name, value) {  
    var argv = SetCookie.arguments;  
    var argc = SetCookie.arguments.length;  
    var expires = (argc > 2) ? argv[2] : null;  
    var path = (argc > 3) ? argv[3] : null;  
    var domain = (argc > 4) ? argv[4] : null;  
    var secure = (argc > 5) ? argv[5] : false;  
    document.cookie = name + "=" + escape(value) + 
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
        ((path == null) ? "" : ("; path=" + path)) +  
        ((domain == null) ? "" : ("; domain=" + domain)) +    
        ((secure == true) ? "; secure" : "");
}

// Set as MLC start page
function setStartPage(linkURL) {
    // default to expire in 3 years time
    var expDays = 1095;
    var exp = new Date(); 
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

    // alert('call setCookie name[MLC_bookmarked_URL], value[' + linkURL + ']');
    SetCookie('MLC_Bookmarked_Start_Page', linkURL, exp, '/');   //sabela make sure path set to /
}

// add page to bookmark (ie only)
function addbookmark(linkURL,linkTitle){
	window.external.AddFavorite(linkURL,linkTitle);
}


/*
The following code puts the installed version of flash into a variable - PluginVersion,
if flash is not installed PluginVersion = -1
*/
var PluginVersion = -1; 
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
		for (var i = 0; i < words.length; ++i)
		{
		if (isNaN(parseInt(words[i])))
		continue;
		PluginVersion = words[i]; 
		}
} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0  && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next\n');
		document.write('If IsObject( CreateObject("ShockwaveFlash.ShockwaveFlash.3") ) Then \n');
			document.write('PluginVersion = 2 \n');
			document.write('Do While not Err.Number = 429 \n');
				document.write('PluginVersion = PluginVersion + 1 \n');
				document.write('IsObject( CreateObject("ShockwaveFlash.ShockwaveFlash." & PluginVersion+1 ) ) \n');
			document.write('Loop  \n');
		document.write('End If  \n');
	document.write('</scr' + 'ipt\> \n');
}

/*
The following is a simple function that will write HTML to the document if a minimum version of flash is present
htmlFlash - the HTML to be written if the browser has the minimum flash version
htmlNoFlash - the HTML to be written if the browser does not have the minimum flash version
flashMinimum - the minimu flash version to be tested for

eg:
inlineFlashContent( "<Flash object HTML/>",  "Sorry go get flash", 5)

if you have flash player 4 (or lower) you will see:
Sorry go get flash

if you have flash player 5 (or higher) you will see:
<Flash object HTML/>
*/
function inlineFlashContent( htmlFlash,  htmlNoFlash, flashMinimum){
	document.open()
	if( PluginVersion >= flashMinimum ){
		document.write(htmlFlash)
	} else {
		document.write(htmlNoFlash)
	}
	document.close()
}
