var agt=navigator.userAgent.toLowerCase(); 

/* ** BROWSER VERSION ** */
// Note: On IE5, these return 4, so use is_ie5up to detect IE5. 
var is_major = parseInt(navigator.appVersion); 
var is_minor = parseFloat(navigator.appVersion); 

var is_opera = (agt.indexOf("opera") != -1); 
var is_webtv = (agt.indexOf("webtv") != -1);
var is_safari = (agt.indexOf('safari')!=-1);
var is_gecko = (agt.indexOf('gecko') != -1);
var is_chrome = (agt.indexOf('chrome') != -1);

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)&&(agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)&&(agt.indexOf('webtv')==-1));
var is_nav2 = (is_nav && (is_major == 2)); 
var is_nav3 = (is_nav && (is_major == 3)); 
var is_nav4 = (is_nav && (is_major == 4)); 
var is_nav4up = (is_nav && (is_major >= 4)); 
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) ); 
var is_nav5 = (is_nav && (is_major == 5)); 
var is_nav5up = (is_nav && (is_major >= 5)); 

var is_ie   = (agt.indexOf("msie") != -1 && !is_opera);
var is_ie3  = (is_ie && (is_major < 4)); 
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) && (agt.indexOf("msie 5.5")==-1)&& (agt.indexOf("msie 6.0")==-1) && (agt.indexOf("msie 6.5")==-1)); 
var is_ie4up  = (is_ie  && (is_major >= 4)); 
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) ); 
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
var is_ie55 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5")!=-1) );
var is_ie55up  = (is_ie  && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6  = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0")!=-1) );
var is_ie7  = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.0")!=-1));
if(is_ie7){is_ie55up=true;}
// KNOWN BUG: The variables is_aol, is_aol3, and is_aol4 aren't 100% reliable. 
var is_aol   = (agt.indexOf("aol") != -1); 
var is_aol3  = (is_aol && is_ie3); 
var is_aol4  = (is_aol && is_ie4); 

var isNav, isIE;
var coll = "";
var styleObj = "";
if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape") {
		isNav = true;
	} else {
		isIE = true;
		coll = "all.";
		styleObj = ".style"; 
	}
}

function ChangeBottomFolder() {
	var F=document.forms[0];
	F.BottomFolder.selectedIndex=F.TopFolder.selectedIndex;
}

function ChangeFolder() {
	var F=document.forms[0];
	F.TopFolder.selectedIndex=F.BottomFolder.selectedIndex;
}

function openWin(url, winName, width, height, features) {
    var hWin;
	if(features == "compose"){
		var winnum = 1 + Math.floor(Math.random() * 10000);
		hWin = window.open(url, winName + winnum,'directories=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,titlebars=no,toolbar=no,width=' + width + ',height=' + height);
	}else if (features == "yes"){
		hWin = window.open(url, winName, 'directories=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,titlebars=no,toolbar=no,width=' + width + ',height=' + height);
		hWin.focus();
	}else if (features == "no"){
		hWin = window.open(url, winName, 'directories=no,location=no,menubar=no,status=no,scrollbars=no,resizable=no,titlebars=no,toolbar=no,width=' + width + ',height=' + height);
		hWin.focus();
	}else if(features == "modal"){
		hWin = window.showModalDialog(url, winName, 'location:no;menubar:no;status:no;scrollbars:yes;resizable:yes;titlebars:no;toolbar:no;dialogWidth:' + width + 'px;dialogHeight=' + height +'px;center:yes;');
		hWin.focus();
    }

    if (document.getElementById('popupBlocked')) {
        detectPopupBlocking(hWin, document.getElementById('popupBlocked'));
    }
}

function detectPopupBlocking(popup, divToShow) {
    this.blocked = true;
    var that = this;
    if (!popup || popup.closed || typeof popup == 'undefined' || typeof popup.closed == 'undefined') {
        divToShow.style.display = 'block';
    }
    if (is_chrome) {
        var timer = setTimeout(function() {
            if (popup && typeof (popup.Mesg) === 'undefined') {
                divToShow.style.display = 'block';
            }
        }, 250);
        return;
    }
};

function Get(field, value){
	var url = document.forms[0].action += '&' + field + '=' + (value != null ? value : 'Yes');
	document.location = url;
}

function Mesg(Msg){if (Msg.length > 0){alert(Msg);}}

function Post(field, value){
	document.forms[0].action += '&' + field + '=' + (value != null?value:'Yes');

	if (typeof(Validate) == 'undefined' || Validate())
		document.forms[0].submit();
}

function Print(url) {
	window.open(url,'Print','height=400,width=600,scrollbars=yes,status=yes,resizable=1,toolbar=yes,menubar=yes');
}

function SelectAll() {
	for (var i=0;i<document.forms[0].elements.length;i++){
		var e=document.forms[0].elements[i];
		e.checked=!e.checked;
	}
}

function setFocus(args){
	if(args!=null){
		eval('document.forms[0].'+args+'.focus()');
	}else{
		for(var i=0; i<document.forms[0].length; i++){
			if (document.forms[0].elements[i].type != 'hidden'){
				document.forms[0].elements[i].focus();
				return;
			}
		}
	}
}

function SetOption(name, value){
	var value = new String(value);
	var i = 0;
	var docForm = document.forms[0];
	var formLength = i = docForm.length;
	while(i--){if (docForm.elements[i].name == name){var element = docForm.elements[i];break;}}
	if (element == null){return;}
	switch(element.type){
	case 'checkbox': element.checked = (element.value == value);break;
	case 'radio': i = formLength;while(i--){if (docForm.elements[i].name == name && docForm.elements[i].value == value){	docForm.elements[i].checked = true;}}break;
	case 'select-one': i = element.length;while(i--){if(element.options[i].value.toLowerCase() == value.toLowerCase()){element.selectedIndex = i;}}break;
	case 'select-multiple':	i = element.length;while(i--){if(element.options[i].value.toLowerCase() == value.toLowerCase()){element.options[i].selected = true;}}break;
	case 'text': element.value = value;break;
	case 'hidden':element.value = value;break;
	}
}

function Sort(SortKey){
	var F=document.forms[0];
	if (F.Sort.value.indexOf(SortKey) == -1)
		F.Sort.value = SortKey;
	else if (F.Sort.value.indexOf('Rev') == -1)
		F.Sort.value = 'Rev' + SortKey;
	else
		F.Sort.value = SortKey;
	
	F.submit(); 
}

function Source(url) {
	window.open(url,'Source','height=400,width=600,scrollbars=yes,status=yes,resizable=1');
}

function check_escape(sFolderName)
{
	if(sFolderName.indexOf('%23')!=-1)
		return sFolderName;
	sFolderName = escape(sFolderName);
	return sFolderName;
}

function EnableFormFields( bEnabled, Array )
{
	var length = Array.length;

	while( length-- )
	{
		if (!Array[length]) break;
		
		var ff = Array[length];
		if ( ff.tagName == "FIELDSET" ) continue;
		ff.readOnly = ff.disabled = bEnabled ? false : true;
	}
} 

function SetCookie(cookieName, cookieValue) {
    document.cookie = cookieName + "=" + cookieValue + ";expires=" + new Date(2020, 12, 31);
}

function GetCookie(cookieName) {
    var aCookie = document.cookie.split("; ");
    var i = aCookie.length;
    while (i--) {
        var aFolderOpen = aCookie[i].split("=");
        if (cookieName == aFolderOpen[0]) {
            return (aFolderOpen[1]);
        }
    }
    return null;
}

function DeleteCookie(cookieName) {
    if (GetCookie(cookieName)) {
        document.cookie = cookieName + "=;expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}
