//*******************************************************************************
//AUTHOR:        JOHN CAZARES & Christian Longtin
//DATE:          JUNE 12, 200&
//FILE:          iPerceptionsGlobal.js
//DESCRIPTION:   This file is located on the iPerceptions Server and contains 
//               all common files for the invitation javascripts. This javascript
//               is included in the individual survey javascripts and can be used
//               to shut off all scripts.
//MODIFICATIONS:
//*******************************************************************************

var browser = new BrowserDetect(); 
var globalSwitch;

//If the Browser is Netscape then don't serve the invitation //|| browser.isSafari
if (( browser.isNS ) || (browser.isUnknownBrowser) || (browser.isUnknownPlatform))
{ 
    globalSwitch = false;  
}
else
{
    // To turn on all surveys change value to true
    globalSwitch = true;
    //globalSwitch = false;
}


// Call Hitit() to generate the popup invitation
if (globalSwitch && localSwitch) {
    Hitit();
}


//*******************************************************************************
//AUTHOR:        JOHN CAZARES
//DATE:          JUNE 12, 2007
//FIUNCTION:     createCookie(name,value,days)
//DESCRIPTION:   When calling createCookie() you have to give it three bits of 
//               information:
//               the name and value of the cookie and the number of days it is to 
//               remain active. In this case the name-value pair should become 
//               ppkcookie=testcookie and it should be active for 7 days.
//MODIFICATIONS: Christian Longtin - Changed expiry format from toGMTString to toUTCString
//*******************************************************************************
function createCookie(name,value,days) 
{
	if (days) 
	{ 
		var expDate = new Date();
		expDate.setTime(expDate.getTime()+(days*24*60*60*1000));
				
		var expires = "; expires="+expDate.toUTCString();		
	}
	else 
	    var expires = "";
	
	document.cookie = name+"="+value+expires+"; path=/";
}

//*******************************************************************************
//AUTHOR:        JOHN CAZARES
//DATE:          JUNE 12, 2007
//FIUNCTION:     readCookie(NameOfCookie)
//DESCRIPTION:   To read out a cookie, call this function and pass the name of the 
//               cookie. Put the name in a variable. First check if this variable 
//               has a value (if the cookie does not exist the variable becomes null,
//               which might upset the rest of your function), then do whatever is
//               necessary.
//MODIFICATIONS:
//*******************************************************************************
function readCookie(NameOfCookie) 
{
    //First check if there is a cookie by checking its length
    if (document.cookie.length > 0)
    {
        // Second we check to see if the cookie's name is stored in the
        // "document.cookie" object for the page.
        // If our cookie name is not present the value -1 is stored
        // in the variable called "begin".
        begin = document.cookie.indexOf(NameOfCookie+"=");
        if (begin != -1) 
        {
            begin += NameOfCookie.length+1;
            end = document.cookie.indexOf(";", begin);
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(begin, end)); 
        }
    }
    
    //else return null as the cookie was not set
    return null;
}

	
//*******************************************************************************
//AUTHOR:        JOHN CAZARES
//DATE:          JUNE 12, 2007
//FIUNCTION:     eraseCookie(name)
//DESCRIPTION:   Pass the name of the cookie to be erased and call createCookie()
//               to set the cookie with an expiry date of one day ago. The browser,
//               seeing that the expiry date has passed, immediately removes the 
//               cookie.
//MODIFICATIONS:
//*******************************************************************************
function eraseCookie(name) 
{
	createCookie(name,"",-1);
}



//*******************************************************************************
//AUTHOR:        Christian Longtin
//DATE:          JULY 20, 2007
//FIUNCTION:     setWindowedElements()
//DESCRIPTION:   Changes windowed elements so that they are transparent and are displayed under the invitation
//MODIFICATIONS: 
//*******************************************************************************
function setWindowedElements() {

    // Get the object tags
    var objects= document.getElementsByTagName('object');
 
    // Loop through objects
    for (var i = 0; i < objects.length; i++) {
        var oldObject = objects[i];     
        var innerH= oldObject.innerHTML;
        var embedIdx= innerH.search(/<embed\s/i);
        var modified= false;
        var embedContent= " "; 
        var objectContent= " ";
        var j;
        
        // Edit object and embed content depending on whether we found an embed tag
        if (embedIdx == -1)
            objectContent= innerH;
        else {
            objectContent= innerH.substring(0, embedIdx); 
            embedContent= innerH.substring(embedIdx);
        }
        
        // No need to edit object tag for firefox, netscape and opera
        if (!(browser.isFirefox || browser.isNS || browser.isOpera)) { 
            j= objectContent.search(/wmode/i);        
            
            // Object missing wmode
            if (j == -1) {
                modified= true;
                objectContent= "<param name='wmode' value='transparent'>" + objectContent;
            }
            else {      
                var isTransparent= objectContent.search(/<param(\s)+(name=(\")?wmode(\")?(\s)+value=(\")?transparent(\")?|value=(\")?transparent(\")?(\s)+name=(\")?wmode(\")?)(\s)*>/i);
                
                // If wmode not transparent then replace
                if (isTransparent == -1) {
                    modified= true;
                    var j= objectContent.search(/<param(\s)+(name=(\")?wmode(\")?(\s)+value=(\")?[a-zA-Z]+(\")?|value=(\")?[a-zA-Z]+(\")?(\s)+name=(\")?wmode(\")?)(\s)*>/i); 
                    var temp= objectContent.substring(0, j); 
                    var temp2= objectContent.substring(j); 
                    var k= temp2.search(/>/);
                    objectContent= temp + " <param name='wmode' value='transparent'> " + objectContent.substring(j + k + 1); 
                }
            }
        }
        
        // If there's an embed tag then edit 
        if (embedIdx != -1) {
            j= embedContent.search(/wmode/i);          
            
            // Embed missing wmode
            if (j == -1) {
                modified= true;
                embedContent= "<embed wmode='transparent' " + embedContent.substring(6);
            }
            else {
                var k= j + 7;   // Index of start of wmode value. Which is j + 7 characters -> wmode="
                var temp= embedContent.substring(k);
                var l= temp.indexOf(" ");
                var mode= temp.substring(0,l-1);    // Mode value
                
                // If not transparent we replace
                if (mode != "transparent") {
                    modified= true;
                    embedContent= embedContent.substring(0, j) + " wmode='transparent' " + embedContent.substring(k+l);
                }
            }
        }
        
        // If we have to replace the object
        if (modified) {
            var newObject = document.createElement('object');
            var parent = oldObject.parentNode;            
            newObject= oldObject;
            
            // Change innerHTML for Firefox and Netscape and others. Insert HTML and remove object in Explorer 
		if (browser.isIE) { 
                newObject.insertAdjacentHTML("beforeBegin", objectContent + embedContent);
                parent.removeChild(oldObject); 
                objects= document.getElementsByTagName('object')
                i= -1;
            }
            else {                
		        newObject.innerHTML= objectContent + embedContent;           
                parent.replaceChild(newObject, oldObject); 
            }
        }
    }    
}



//*******************************************************************************
//AUTHOR:        Christian Longtin
//DATE:          JULY 18, 2007
//FIUNCTION:     hideObjects()
//DESCRIPTION:   Hides windowed elements of page
//MODIFICATIONS: Returns whether at least one object needed to be hid
//*******************************************************************************
function hideObjects() {
    var hid= false;
    var objects;
    
    // If Firefox, Netscape or Opera look at embed tags
    if (browser.isFirefox || browser.isNS || browser.isOpera) {
	    objects = document.getElementsByTagName('embed');
   
        for (var i = 0; i < objects.length; i++) {
            var obj= objects[i];
            var mode= obj.getAttribute("wmode");        
              
            // If not transparent we hide
            if (mode != "transparent") {
                hid= true;
                obj.style.display= "none";
            } 
        }
    }
    else {  // For explorer and others look at object tags
        objects = document.getElementsByTagName('object');    
   
        for (i = 0; i < objects.length; i++) {
            var obj= objects[i];
            var objectContent= obj.innerHTML;
            var idxEmbed= objectContent.search(/<embed\s/i); 
            var objectContent= objectContent.substring(0, idxEmbed);
            var idx= objectContent.search(/wmode/i);
            
            // First check if embed is correctly set 
            if (idxEmbed == -1) {
                hid= true;
                obj.style.display= "none";
            }
            else {
                embedContent= obj.innerHTML.substring(idxEmbed);
                j= embedContent.search(/\swmode=(\")?transparent(\")?/i);

                // Embed missing wmode
                if (j == -1) {
                    hid= true;
                    obj.style.display= "none";
                }
            }
            
            // Object missing wmode then hide 
            if (idx == -1 && ! hid) {         
                hid= true;
                obj.style.display= "none";
            }
            else if (! hid) {
                var j= objectContent.search(/<param(\s)+(name=(\")?wmode(\")?(\s)+value=(\")?transparent(\")?|value=(\")?transparent(\")?(\s)+name=(\")?wmode(\")?)(\s)*>/i);
                
                // If no wmode param with a tranparent value was found then hide
                if (j == -1) {
                    hid= true;
                    obj.style.display= "none";
                }
            } 
        }
    }
	     
    return hid;
}


//*******************************************************************************
//AUTHOR:        Christian Longtin
//DATE:          AUG 03, 2007
//FIUNCTION:     DoHideObjects()
//DESCRIPTION:   Hides windowed elements of page no matter what are the object properties. (IE activeX issue)
//MODIFICATIONS: 
//*******************************************************************************
function doHideObjects() {  
    var objects = document.getElementsByTagName('object');

    // If no object tags then get the embeds
    if (objects.length == 0)
        objects = document.getElementsByTagName('embed');
 
    // Loop and hide all
    for (var i = 0; i < objects.length; i++) {
        objects[i].style.display= "none";
	    objects[i].style.visibility= "hidden";
    }
}


//*******************************************************************************
//AUTHOR:        Christian Longtin
//DATE:          SEP 25, 2007
//FIUNCTION:     frmHideObjects()
//DESCRIPTION:   Looks at windowed elements of iframes to see if object properties are properly set 
//MODIFICATIONS: 
//*******************************************************************************
function frmHideObjects() {  
    var objects = document.getElementsByTagName('iframe');
    var containsFrmToHide= false;     
    
    // Loop through iframes   
    for (var i = 1; i <= objects.length; i++) {
        var obj= objects[i]; 
        var hid= false;       
        var isReadable= true;
        
        // Check if we can actually read the iframe - issue with iframes containing external link to a different domain (access denied)
        try {
            var t= frames[i].document.documentElement.innerHTML;
        }
        catch (err) {
            isReadable= false;
        }                  
        
        // if we can't access iframe then hide
        if (frames[i] != null && isReadable) {
            var objectContent= frames[i].document.documentElement.innerHTML;             
            var startObj= objectContent.search(/<object\s/i);
            var endObj= objectContent.search(/<(\/)object>/i);           
           
            // Check transparency of object in iframe
            while (startObj != -1 && endObj != -1 && startObj < endObj) {
                var curObjectContent = objectContent.substring(startObj, endObj+9); 

                // Check if object is missing wmode param   
                var j= curObjectContent.search(/<param(\s)+(name=(\")?wmode(\")?(\s)+value=(\")?[(\s)(\')(\")(\+)a-zA-Z]+(\")?|value=(\")?[(\s)(\')(\")(\+)a-zA-Z]+(\")?(\s)+name=(\")?wmode(\")?)(\s)*>/i);
  
                // If no wmode param with a transparent value was found then hide
                if (!hid)
                    hid= (j == -1);
                
                objectContent= objectContent.substring(endObj+9);
                startObj= objectContent.search(/<object\s/i);
                endObj= objectContent.search(/<(\/)object>/i);
            } 
            
            if (startObj != -1 || endObj != -1 || startObj > endObj) hid= true;
        }
        
        // if there's an element to hide
        if (hid) {
            containsFrmToHide= true;
            
            if (browser.isSafari) {
                obj.style.width = "0px";
                obj.style.height = "0px";
                obj.style.border = "0px";
            }
            else {               
                obj.style.display= "none";
                obj.style.visibility= "hidden";
            }        
        }           
    }
    
    return containsFrmToHide;
}



//*******************************************************************************
//AUTHOR:        Christian Longtin
//DATE:          JULY 23, 2007
//FIUNCTION:     pageContainsWindowedElements()
//DESCRIPTION:   Detects if a page contains some windowed elements that have a higher z-index property
//MODIFICATIONS: 
//*******************************************************************************
function pageContainsWindowedElements() {
    var objects = document.getElementsByTagName('object'); if (objects.length > 0) return true;
    objects = document.getElementsByTagName('embed'); if (objects.length > 0) return true;
    objects = document.getElementsByTagName('iframe'); if (objects.length > 0) return true;
    
    return false;
}

 
//*******************************************************************************
//AUTHOR:        Christian Longtin
//DATE:          JUNE 12, 2007
//FIUNCTION:     showLayer()
//DESCRIPTION:   Shows the invitation layer via its css properties
//MODIFICATIONS: Added code for layer width, heigth and window bar with close button (Jun 18th, 2007)
//MODIFICATIONS: 
//*******************************************************************************
function showLayer(invitationPage, divWidth, divHeight, useShadow, shOpacity, hideMethod) {
    var useWindowed= pageContainsWindowedElements();
    var prmHideMethod= hideMethod;

    // How to adjust layer to client page
    if (!useWindowed) 
        hideMethod= "NoHide";
    else {
	    // If browser is safari then hide all objects no matter what
	    if (browser.isSafari) 
	        hideMethod= "DoHide"; 
	  
        // If we edit the objects
        if (hideMethod == "Replace") {
            setWindowedElements();            
        }
        else if (hideMethod == "DoHide") {
		    hideMethod= "Hide";
            doHideObjects();
        }       
        else if (hideMethod != "NoHide"){    // hideMethod is to default value (Hide elements)
            hideMethod= "Hide";
            var hidObjs= hideObjects(); 
         
            // If we don't have to hide objects - i.e. they are set with wmode to transparent - then we don't
            if (!hidObjs) 
                hideMethod= "NoHide";
        } 
    }    
    
    // Also look at iframes in addition to objects 
    if ( ! (browser.isFirefox || browser.isNS) && prmHideMethod == "frmHide") {
        if (frmHideObjects()) hideMethod= "Hide";
    } 

    // Create div to contain hidden layer with display info     
    var divInfo = document.createElement("div");
    divInfo.id= "divLayerInfo"; 
    divInfo.style.display= "none";
    divInfo.innerHTML= hideMethod;
    document.body.appendChild(divInfo);  
       
    // Create div to contain layer          
    var divLayer = document.createElement("div");
    divLayer.id= "inviteLayer"; 
    
    var shWidth= 0, shHeight= 0;                // Size of window vars
    var winWidth= 0, winHeight= 0;              // Size of window vars
    var divW= divWidth, divH= divHeight;        // Size of divLayer vars
    
    // Get window size - Non-IE
    if (typeof(window.innerWidth) == 'number') {
        winWidth= window.innerWidth;
        winHeight= window.innerHeight;
    }  // IE 6+ in 'standards compliant mode'
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        winWidth= document.documentElement.clientWidth;
        winHeight= document.documentElement.clientHeight;
    }  // IE 4 compatible
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        winWidth= document.body.clientWidth;
        winHeight= document.body.clientHeight;

    }

    // For shadow width
    var shWidth= winWidth;
    var shHeight= winHeight;
                
    // Set layer dimensions
    divLayer.style.width = divW + "px";
    divLayer.style.height = divH + "px";
    
    // Check that layer does not overflow
    if (divW > winWidth) divW= winWidth;
    if (divH > winHeight) divH= winHeight;
          
    // Set vars for postioning
    winWidth= parseInt((winWidth - divW)/2);
    winHeight= parseInt((winHeight - divH)/2);    
       
    // Position layer according to the left and the top  
    divLayer.style.position= "absolute"; 
    divLayer.style.left= winWidth + "px";
    divLayer.style.top= winHeight + "px";
    divLayer.style.display= "block";
    divLayer.style.zIndex= "100000";
    divLayer.style.overflow = "hidden";

    // Put transparent iframe in IE
    if (browser.isIE) 
        divLayer.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
   
    // iframe inside div layer that contains the html page   marginwidth='0' marginheight='0'
    var divData= "<iframe src='" + invitationPage  + "' frameborder='0' scrolling='no' style='margin:0; padding:0; border: 0px; width:100%; height: 100%' allowtransparency='true'></iframe>";
    divLayer.innerHTML= divData;

    // If we want to display the background shadow
    if (useShadow) {
        
        // If we need to block frame content in the shadow - no need for iframe blocker in Opera (opacity issues)
        if (useWindowed && ! browser.isOpera || (browser.isIE && browser.versionMajor < 7)) {
            
            // Create background cover
            var ifrmBlkObj = document.createElement("iframe");
            ifrmBlkObj.id = "ifmBlockObjs";
            ifrmBlkObj.frameborder = "0px";
            ifrmBlkObj.scrolling = "no";
            ifrmBlkObj.src= "about:blank"; 
            
            // For Firefox and Netscape remove the extra width given for toolbars
            if (! browser.isIE) {
                shWidth-= 22;
            }
            
            ifrmBlkObj.style.width = shWidth + "px";
            ifrmBlkObj.style.height = shHeight + "px";
            ifrmBlkObj.style.left= 0 + "px";
            ifrmBlkObj.style.top= 0 + "px";
            ifrmBlkObj.style.display= "none";
            ifrmBlkObj.style.opacity = parseInt(shOpacity*100);
            
            // Put different filter for explorer    
            if (browser.isIE)
                ifrmBlkObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
            else {
                ifrmBlkObj.style.filter = "alpha(opacity=" + parseInt(shOpacity*100) + ")";
                ifrmBlkObj.style.MozOpacity = shOpacity;
            }                
           
            ifrmBlkObj.style.zIndex= "80000";
            ifrmBlkObj.style.position= "absolute"; 
            document.body.appendChild(ifrmBlkObj);
	    document.getElementById("ifmBlockObjs").style.display= "block";
        }
        
        // Create div for background shadow
        var domWin = document.createElement("div");
        domWin.id= "bgCover";        

        domWin.style.position= "absolute"; 
        domWin.style.left= "0px";
        domWin.style.top=  "0px";
        domWin.style.display= "block";
        domWin.style.zIndex= "90000";
        domWin.style.backgroundColor= "black";       
        
        // Set opacity depending on browser
        if (browser.isOpera || browser.isSafari)
            domWin.style.opacity = shOpacity;
        else
            domWin.style.opacity = parseInt(shOpacity*100);
                
        // Condition for shadow per browser     
        if (browser.isIE) {
            domWin.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=" + parseInt(shOpacity*100) + ")";
            domWin.style.width = shWidth + "px";
            domWin.style.height = shHeight + "px";
        }
        else {
            domWin.style.width = "100%";
            domWin.style.height = "100%";
            domWin.style.MozOpacity = shOpacity;
            domWin.style.filter = "alpha(opacity=" + parseInt(shOpacity*100) + ")";
        }       
        
        document.body.appendChild(domWin);
    }
    
   document.body.appendChild(divLayer);  
} 



//*******************************************************************************
//AUTHOR:        JOHN CAZARES
//DATE:          JUNE 12, 200&
//FIUNCTION:     BrowserDetect()
//DESCRIPTION:   Detects the browser type.
//MODIFICATIONS:
//*******************************************************************************
function BrowserDetect() 
{
   ua = navigator.userAgent.toLowerCase();
   this._string = navigator.userAgent.toLowerCase();	 
   this.isUnknownBrowser = false;  
  
   this.isGecko= (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit= (ua.indexOf('applewebkit') != -1);
   this.isKonqueror= (ua.indexOf('konqueror') != -1); 
   this.isSafari= (ua.indexOf('safari') != - 1);
   this.isCamino= (ua.indexOf('camino') != -1);
   this.isOmniweb= (ua.indexOf('omniweb') != - 1);
   this.isOpera= (ua.indexOf('opera') != -1); 
   this.isIcab= (ua.indexOf('icab') != -1); 
   this.isAol= (ua.indexOf('aol') != -1); 
   this.isIE= (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1)); 
   this.isMozilla= (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirefox= (ua.indexOf('firefox') != -1);
   this.isNS= ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   this.isUnknownBrowser= (! this.isGecko && ! this.isAppleWebKit && ! this.isKonqueror && ! this.isSafari && ! this.isCamino && ! this.isOmniweb && ! this.isOpera && ! this.isIcab && ! this.isAol && ! this.isIE && ! this.isMozilla && ! this.isFirefox && ! this.isNS);

  
   var OSName="Unknown";
   this.isUnknownPlatform = true;
    if (navigator.appVersion.indexOf("Win")!=-1) {OSName="Windows"; this.isUnknownPlatform = false;}
    if (navigator.appVersion.indexOf("Mac")!=-1) {OSName="MacOS";this.isUnknownPlatform = false;}
    //if (navigator.appVersion.indexOf("X11")!=-1) {OSName="UNIX";this.isUnknownPlatform = false;}
    if (navigator.appVersion.indexOf("Linux")!=-1) {OSName="Linux";this.isUnknownPlatform = false;}
  
  /* browser name - changed by Larissa April 1, 2008
  this.isUnknownBrowser = false;  
  if (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1)){ this.isIE = true;}   
  else if((ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1)){ this.isGecko = true;}
   else if((ua.indexOf('applewebkit') != -1)){ this.isAppleWebKit = true;}
   else if((ua.indexOf('konqueror') != -1)){this.isKonqueror = true;}
   else if ((ua.indexOf('safari') != - 1)) {this.isSafari = true;}
   else if((ua.indexOf('camino') != -1) )  {this.isCamino = true; }
   else if ((ua.indexOf('omniweb') != - 1)) {this.isOmniweb = true;}
   else if ((ua.indexOf('opera') != -1))  {this.isOpera = true; }
   else if ((ua.indexOf('icab') != -1) ) {this.isIcab = true;}
   else if ((ua.indexOf('aol') != -1)) {this.isAol =  true;}
   else if ((this.isGecko && ua.indexOf('gecko/') + 14 == ua.length) ) {this.isMozilla = true ;}
   else if ((ua.indexOf('firefox') != -1) ) { alert(ua.indexOf('firefox'));this.isFirefox = true; }
   else if (( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1)))) {this.isNS = true;}
   else this.isUnknownBrowser = true;   */
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
 
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor =  ua.substring( ua.indexOf('rv:') + 3, ua.indexOf('rv:') + 8  );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = ua.substring( ua.indexOf('msie ') + 5, ua.indexOf('msie ') + 8 );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   if (this.isFirefox) {
      this.versionMinor =  ua.substring( ua.indexOf('firefox') + 8, ua.indexOf('firefox') + 13 );
   }
   if (this.isNS) {
	        var ua_arr = ua.split( " " );
	        for( a in ua_arr ) {
			        if( ua_arr[ a ].indexOf( "net" ) == 0) {
				        versionMinor = ua_arr[ a ].split("/")[1];
			        }
	        }
   }
   
   this.versionMajor = parseInt( this.versionMinor ); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isWinXP = ( ua.indexOf('windows nt 5.1') != -1);
   this.isWin2k = ( ua.indexOf('windows nt 5.0') != -1);
   this.isWin2k3 = ( ua.indexOf('windows nt 5.2') != -1);
   this.isWin98 =  ( ua.indexOf('98') != -1);
   this.isMac = ( ua.indexOf('mac') != -1);
   this.isOSX = (ua.indexOf('os x') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
	   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}








