JUNO.util.Browser = new function() {
    this.occur = -1;
    this.found = "";
    this.agentString = navigator.userAgent.toLowerCase();
    this.getName = function() {
        return (this._check('chrome')!=-1)?'Chrome':
               (this._check('msie')!=-1)?'Internet Explorer':
               (this._check('omniweb')!=-1)?'OmniWeb':
               (this._check('opera')!=-1)?'Opera':
               (this._check('webtv')!=-1)?'WebTv':
               (this._check('icab')!=-1)?'iCab':
               (this._check('konqueror')!=-1)?'Konqueror':
               (this._check('firefox')!=-1)?'Firefox':
               (this._check('netscape')!=-1)?'Netscape Navigator': 
               (this._check('camino')!=-1)?'Camino':
               (this._check('safari')!=-1)?'Safari':
               (this._check('mozilla')!=-1)?'Mozilla':
               'Unknown';               
    };
    this.getVersion = function() {
        if(this.getOs()=="Mac") {
          if(this.getName()=="Safari") {
            this._check('applewebkit')
          }
        } else {
          this.getName();
        }
        //return this.agentString.charAt(this.occur + 1 + this.found.length) + (
        //(this.agentString.charAt(this.occur + 2 + this.found.length)==".")?"." + this.agentString.charAt(this.occur + 3 + this.found.length):"");
        var retVersion = "";
        var startNum  = 1;
        while(1) {
       	  if((this.agentString.charAt(this.occur + startNum + this.found.length)) && (isNaN(this.agentString.charAt(this.occur + startNum + this.found.length))==false || this.agentString.charAt(this.occur + startNum + this.found.length)==".")) {
            retVersion += this.agentString.charAt(this.occur + startNum + this.found.length);
       	  } else {
       	  	break;
       	  }
          startNum++;
        }
        return retVersion.split(".")[0]+(retVersion.split(".")[1]?"." + retVersion.split(".")[1]:"");
    };
    this.getOs = function() {
        return (this._check('linux')!=-1)?'Linux':
               (this._check('mac')!=-1)?'Mac':
			   (this._check('windows 98')!=-1)?'Win98':
               (this._check('win')!=-1)?'Windows':
               (this._check('x11')!=-1)?'Unix':
               'Unknown'
    };
    this.getJsVersion = function() {
        if(window.ScriptEngine) {
            return(ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion());
        }
        else {
            return('unknown');
        }
    };
    this.supportsAJAX = function() {
        var xmlhttpcheck=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		// JScript gives us Conditional compilation, we can cope with old IE versions.
		// and security blocked creation of the objects.
		 try {
		  xmlhttpcheck = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
		  try {
		   xmlhttpcheck = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
		   xmlhttpcheck = false;
		  }
		 }
		@end @*/
		if (window.XMLHttpRequest) {
	      xmlhttpcheck = new XMLHttpRequest();
	    }
        if (!xmlhttpcheck) {
            return false;
        }
        else {
            return true;
        }
    };
    this._check = function(checkStr) {
        this.found = checkStr;
        this.occur = this.agentString.indexOf(checkStr);
        return this.occur;
    };
    this.getUrlDomain = function(url_name) {
        var url   = url_name;
        var index = url.indexOf("://");
    
        if( index != -1 ) {
            url = url.substring( index + 3 );
        }
    
        var index = url.indexOf("?");
        if( index != -1 ) {
            url = url.substring( 0, index );
        }
    
        index = url.indexOf("/");
        if( index != -1 ) {
            url = url.substring( 0, index );
        }
    
        index = url.indexOf(":");
        if( index != -1 ) {    
            url = url.substring( 0, index );
        }
    
        index = url.lastIndexOf(".");
        index = url.lastIndexOf("." , index -1 );
        var domain = url.substring(index);
        return domain;        
    };
    this.detectAJAX = function() {
        n  = this.getName();
        v  = this.getVersion();
        Os = this.getOs();
        j  = this.getJsVersion();
        s  = this.supportsAJAX();
        
        if (Os == 'Win98') {
			if ( (n == 'Firefox') && (v >= 1.0) ) {
            	if(v >=2 ) {
	              	return 2;
	            } else {
	            	return 1;
	            }
            }
            else if ( ((n == 'Internet Explorer') && (v >= 6.0)) && (parseFloat(j)>=5.5) && (s==true)) {
                  return 1;
            }
			else if (n == 'Chrome') {
                return 1;
            }
            else {
                return 0;
            }
		}
		else if (Os == 'Windows') {
            if ( (n == 'Firefox') && (v >= 1.0) ) {
            	if(v >=2 ) {
	              	return 2;
	            } else {
	            	return 1;
	            }
            }
            else if ( ((n == 'Internet Explorer') && (v >= 6.0)) && (parseFloat(j)>=5.5) && (s==true)) {
              //if(v == 7)
                return 2;
              //else
                //return 1;
            }
            else if (n == 'Chrome') {
                return 1;
            }
            else {
                return 0;
            }
        }
        else if (Os == 'Mac') {
            if ((n == 'Safari') && (v >= 312.1)) {
                return 1;
            }
            else if( n == 'Camino'){
                return 1;
            }
            else
                return 0;
        }
        else {
            return 0;
        }
    };
};
JUNO.util.Cookie = new function() {
  this.getCookie = function(name){
    if(typeof (document.cookie) == 'string'){
      var start = document.cookie.indexOf(name+"=");
      var len = start+name.length+1;
      if ((!start) && (name != document.cookie.substring(0,name.length))){
        return null;
      }
      if (start == -1) return null;
      var end = document.cookie.indexOf(";",len);
      if (end == -1) end = document.cookie.length;
      return unescape(document.cookie.substring(len,end));
    } else {
      return "";
    }
  };
  this.setCookie = function(name, value, expires, path, domain, secure) {
    if(typeof (document.cookie) == 'string'){
      document.cookie = name + "=" + escape(value) +
            ( (expires) ? ";expires=" + expires.toGMTString() : "") +
            ( (path) ? ";path=" + path : "") +
            ( (domain) ? ";domain=" + domain : "") +
            ( (secure) ? ";secure" : "");
    }
  };
  this.deleteCookie = function(name, path, domain) {
    if (this.getCookie(name)) {
      document.cookie = name + "=" +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ";expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  };
};
function redirectToLogin() {
    ajaxSupported = JUNO.util.Cookie.getCookie('ajaxSupported');
      
      x = JUNO.util.Browser.detectAJAX();
      date = new Date();
      date.setYear(2038);
      date.setMonth(1);
      date.setDate(1);
      domain = JUNO.util.Browser.getUrlDomain(document.location.href);
      var cookieFormat;
      if (x == 1) {
          ajaxSupported = "1";
          cookieFormat = "1/" + _jsFileCrc;
          JUNO.util.Cookie.setCookie('ajaxSupported', cookieFormat , date, "/", domain );
      }
      else if (x == 2) {
        ajaxSupported = "2";
        cookieFormat = "2/" + _jsFileCrc;
        JUNO.util.Cookie.setCookie('ajaxSupported', cookieFormat , date, "/", domain );
      }  
      else {
          ajaxSupported = "0";
          cookieFormat = "0/" + _jsFileCrc;
          JUNO.util.Cookie.setCookie('ajaxSupported', cookieFormat , date, "/", domain );
      }
    return ajaxSupported;
}
