


/* (c) 2006-7 Ghost(TM) Inc. (http://G.ho.st/home) . All rights reserved.
G.ho.st licenses this software to you under the terms of the 
Common Public License Version 1.0 http://www.opensource.org/licenses/cpl.php 
*/

/**====================================================================================== **
/*  File: common.js    				    		                                          **
/*  Creator: Rami khalyleh                                                                **
/*  Create date: 2007-06-11                                                               **
/*  Authors: Rami khalyleh,...                                                            **
/*                                                                                        **
/**====================================================================================== */
// Global variables
var browserName = getBrowserName();
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var isChrome = navigator.userAgent.indexOf('Chrome') != -1;
var isSafari = !isChrome && (navigator.appVersion.indexOf('Safari') != -1);
var isAOL = navigator.appVersion.indexOf("AOL") != -1;
var version = getBrowserVersion();
var isFirefox =  navigator.userAgent.indexOf("Firefox") !=-1 ? true : false ;

//set cookie domain to parent domain
var cookieDomain;


// Write vbscript detection on ie win. IE on Windows doesn't support regular
// JavaScript plugins array detection.
if(isIE && isWin && !isAOL){
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('On Error Resume Next \n');
  document.write('x = null \n');
  document.write('MM_FlashControlVersion = 0 \n');
  document.write('var VBFlashVer \n');
  document.write('For i = 9 To 1 Step -1 \n');
  document.write('	Set x = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n');
  document.write('	MM_FlashControlInstalled = IsObject(x) \n');
  document.write('	If MM_FlashControlInstalled Then \n');
  document.write('		MM_FlashControlVersion = CStr(i) \n');
  document.write('		Exit For \n');
  document.write('	End If \n');
  document.write('Next \n');
  document.write('VBFlashVer = x.GetVariable("$version")\n');
  document.write('Sub app_FSCommand(ByVal command, ByVal args)\n');
  document.write('    call app_DoFSCommand(command, args)\n');
  document.write('end sub\n');
  document.write('<\/SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}

/* This method responsible to get the browser name and flash version and then pass them to canvas*/
function getBrowserAndFlashVerion(){
	var browser = getBrowserName();
	var flashVersion = detectFlash();
	var browserVersion = getBrowserVersion();
	callLaszloMethod("setBrowserAndFlashVerion", new Array(browser, flashVersion, browserVersion), true);
}

/* Browser name method */
function getBrowserName(){
	var nVer = navigator.appVersion;
	var nAgt = navigator.userAgent;
	var browserName  = '';
	var fullVersion  = 0; 
	var majorVersion = 0;
		
	// In Internet Explorer, the true version is after "MSIE" in userAgent
	if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
		browserName  = "IE";
		fullVersion  = parseFloat(nAgt.substring(verOffset+5));
		majorVersion = parseInt(''+fullVersion);
	}
		
	// In Opera, the true version is after "Opera" 
	else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
		browserName  = "Chrome";
		fullVersion  = parseFloat(nAgt.substring(verOffset+6)); // Have not tested this for Chrome
		majorVersion = parseInt(''+fullVersion);
	}
		
	// In Opera, the true version is after "Opera" 
	else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
		browserName  = "Opera";
		fullVersion  = parseFloat(nAgt.substring(verOffset+6));
		majorVersion = parseInt(''+fullVersion);
	}
		
	// In most other browsers, "name/version" is at the end of userAgent 
	else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
	{
		browserName  = nAgt.substring(nameOffset,verOffset);
		fullVersion  = parseFloat(nAgt.substring(verOffset+1));
		if (!isNaN(fullVersion)) majorVersion = parseInt(''+fullVersion);
		else {fullVersion  = 0; majorVersion = 0;}
	}
		
	// Finally, if no name and/or no version detected from userAgent...
	if ( browserName.toLowerCase() == browserName.toUpperCase()
		 || fullVersion==0 || majorVersion == 0 ){
		 browserName  = navigator.appName;
		 fullVersion  = parseFloat(nVer);
		 majorVersion = parseInt(nVer);
	}
	
	if(navigator.userAgent.toLowerCase().indexOf("firefox") >= 0){
		browserName = "Firefox";
		var splitArray = navigator.userAgent.toLowerCase().split("firefox");
		fullVersion = splitArray[1].split("/")[1].split(" ")[0];
		majorVersion = parseInt(''+fullVersion);
	}

	return browserName;
}
/* Browser version method */
function getBrowserVersion(){
	var nVer = navigator.appVersion;
	var nAgt = navigator.userAgent;
	var browserName  = '';
	var fullVersion  = 0; 
	var majorVersion = 0;
		
	// In Internet Explorer, the true version is after "MSIE" in userAgent
	if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
		browserName  = "IE";
		//fullVersion  = parseFloat(nAgt.substring(verOffset+5)); // this will not return the value after the ". " if that value was 0
		fullVersion  = nAgt.substring(verOffset+5).split(";")[0];
		majorVersion = parseInt(''+fullVersion);
		
	}
	// In Chrome
	else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
		browserName  = "Chrome";
		fullVersion  = nAgt.substring(verOffset).split("/")[1].split(" ")[0]; // Tested for chrome
		majorVersion = parseInt(''+fullVersion);
	}
	
	// In Opera, the true version is after "Opera" 
	else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
		browserName  = "Opera";
		fullVersion  = parseFloat(nAgt.substring(verOffset+6));
		majorVersion = parseInt(''+fullVersion);
	}
		
	// In most other browsers, "name/version" is at the end of userAgent 
	else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
	{
		browserName  = nAgt.substring(nameOffset,verOffset);
		fullVersion  = parseFloat(nAgt.substring(verOffset+1));
		if (!isNaN(fullVersion)) majorVersion = parseInt(''+fullVersion);
		else {fullVersion  = 0; majorVersion = 0;}
	}
		
	// Finally, if no name and/or no version detected from userAgent...
	if ( browserName.toLowerCase() == browserName.toUpperCase()
		 || fullVersion==0 || majorVersion == 0 ){
		 browserName  = navigator.appName;
		 fullVersion  = parseFloat(nVer);
		 majorVersion = parseInt(nVer);
	}
	
	if(navigator.userAgent.toLowerCase().indexOf("firefox") >= 0){
		browserName = "Firefox";
		var splitArray = navigator.userAgent.toLowerCase().split("firefox");
		fullVersion = splitArray[1].split("/")[1].split(" ")[0];
		majorVersion = parseInt(''+fullVersion);
	}

	return fullVersion;
}

function detectFlash() {  
    var actualVersion = 0;
    if (navigator.plugins && 
        (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) ) {

        // Some version of Flash was found. Time to figure out which.
        // Set convenient references to flash 2 and the plugin description.
        var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
        var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

        var flashVersion = parseInt(flashDescription.substring(16));
        var minorVersion = flashDescription.substring(flashDescription.indexOf('r') + 1);
    } else if (! isIE) {
        var flashVersion = 0;
        var minorVersion = 0;
    } else {
        var vbver =  eval('VBFlashVer');
        if (vbver) {
            vbver = vbver.substring(vbver.indexOf(' ') + 1).split(',');
            var flashVersion = vbver[0];
            var minorVersion = vbver[2];
        } 
    }
  
    actualVersion = parseFloat(flashVersion + '.' + minorVersion)

    // If we're on msntv (formerly webtv), the version supported is 4 (as of
    // January 1, 2004). Note that we don't bother sniffing varieties
    // of msntv. You could if you were sadistic...
    if (navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 4;  

    return actualVersion;
}

function doLaunchApp(AppName, arg1, arg2){
	callLaszloMethod("doLaunchAppFromWizard", new Array(AppName, arg1, arg2), true);
}

function getOSName() {
	var usrAgnet = navigator.userAgent.toLowerCase();
	if (usrAgnet.indexOf("windows") >= 0) {
		return "windows"
	} else if (usrAgnet.indexOf("linux") >= 0) {
		return "linux";
	} else if (usrAgnet.indexOf("mac") >= 0) {
		return "mac";
	}
}

/**
 * 
 * @return {}
 */
function getDomainName(){
	if(!cookieDomain){
		var host = window.location.host+"";
		var serverNameDotArray = host.split(":")[0].split(".");
		if (serverNameDotArray.length > 2) {
		   if ((serverNameDotArray[serverNameDotArray.length - 2].length > 2) && (serverNameDotArray[serverNameDotArray.length - 1].length > 2)) {
		    cookieDomain = "." + serverNameDotArray[serverNameDotArray.length - 2] + "." + serverNameDotArray[serverNameDotArray.length - 1];
		   }
	   else {
	    		cookieDomain = "." + serverNameDotArray[serverNameDotArray.length - 3] + "." + serverNameDotArray[serverNameDotArray.length - 2] + "."
	      			+ serverNameDotArray[serverNameDotArray.length - 1];
	   		}
		}
	}
	return cookieDomain;
}

function doOpenNewWindow(url){
	openNewWindow(url);
}

/* opens a focused popup window */
function openNewWindow(src, attrs) {
	if (attrs) {
		attrs = 'top=0,left=0,scrollbars=yes,resizable=yes,'+attrs;
	} else {
		var attrs = 'top=0,left=0,scrollbars=yes,resizable=yes';
	}
	var newWindow = window.open(src,'_blank',attrs);
	if (window.focus){
		newWindow.focus();
	} 
	
}

function addCookie(cookieName, cookieValue, expInMills , cookiePath, cookieDomain) {
  var cookie = cookieName + "=" + cookieValue;
  if (expInMills) {
    var expireDate = new Date();
    expireDate.setTime(expireDate.getTime() + expInMills);
    cookie += "; expires=" + expireDate.toGMTString();
  }
  if (cookiePath){
        cookie += "; path=" + cookiePath;
  }
  if (cookieDomain) {
        cookie += "; domain=" + cookieDomain;
  }
  else{
  	
  	var domainName = getDomainName();
  	if(domainName != "null" && domainName != null){
  	cookie += "; domain=" + domainName;
  	}
  }
  document.cookie = cookie;
}

function addNewLanguageCookie(lang){
	var currentDate=new Date();
	var cookieName="ghostcookieWSLanguage";
	var str='<ghostCookie><type>ghostcookieWSLanguage</type><language>'+lang+'</language><time>'+currentDate+'</time></ghostCookie>';
	addCookie(cookieName,str,1000000000000, "/");
}

/**
 * delete the cookie with the passed name from the cookies
 */
function deleteCookie (cookieName) {
  var expireDate = new Date();
  expireDate.setTime (expireDate.getTime()-1);
  document.cookie = cookieName += "=; expires=" + expireDate.toGMTString();
}


/**
 * return the cookie value as a string if the cookie name was found
 */
function getCookie (cookieName) {
  var cookie = document.cookie.match ('(^|;) ?' + cookieName + '=([^;]*)(;|$)');
  if (cookie){
    return ( unescape ( cookie[2] ) );
  } else {
    return null;
  }
}

function getAllCookies(){
	var cookies = document.cookie;
		return( cookies);
}

function getRememberCookies(){
	var cookiesArrays= document.cookie.split(';')
	var allCookies ="null";
	for(var i=0;i<cookiesArrays.length;i++){
		if(cookiesArrays[i].indexOf("ghostcookieRemember") != -1){
			if(allCookies == "null"){
				allCookies = cookiesArrays[i]+";";
			}
			else{
				allCookies = allCookies +cookiesArrays[i]+";";
			}
			
  
		}
		else if(cookiesArrays[i].indexOf("ghostcookieWSLanguage") != -1){
			if(allCookies == "null"){
				allCookies = cookiesArrays[i]+";";
			}
			else{
				allCookies = allCookies +cookiesArrays[i]+";";
			}
		
		}
	}
	if(allCookies  != "null"){
		var result=escape(allCookies);
		if (isSafari) {
			setTimeout('lz.embed.callMethod(\'getUsersCookies(\''+result+'\')\')', 2000);
		} else {
			lz.embed.callMethod('getUsersCookies(\''+result+'\')')
		}
	}
	
}

/**
 *return the language from the cookie
 */
function getLangCookie(){
	var lang = getCookie("ghostcookieWSLanguage");
	if(lang != null && lang != "null"){
		lang = lang.split("<language>")[1];
		lang = lang.split("</language>")[0];
		return lang.toLowerCase();
	}
	return null;
}

/**
 * the lower code is the modification to detectFlash() method
 */
var FlashDetect = new function(){
    var self = this;
    self.installed = false;
    self.raw = "";
    self.major = -1;
    self.minor = -1;
    self.revision = -1;
    self.revisionStr = "";
    var activeXDetectRules = [
        {
            "name":"ShockwaveFlash.ShockwaveFlash.7",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash.6",
            "version":function(obj){
                var version = "6,0,21";
                try{
                    obj.AllowScriptAccess = "always";
                    version = getActiveXVersion(obj);
                }catch(err){}
                return version;
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        }
    ];
    /**
     * Extract the ActiveX version of the plugin.
     * 
     * @param {Object} The flash ActiveX object.
     * @type String
     */
    var getActiveXVersion = function(activeXObj){
        var version = -1;
        try{
            version = activeXObj.GetVariable("$version");
        }catch(err){}
        return version;
    };
    /**
     * Try and retrieve an ActiveX object having a specified name.
     * 
     * @param {String} name The ActiveX object name lookup.
     * @return One of ActiveX object or a simple object having an attribute of activeXError with a value of true.
     * @type Object
     */
    var getActiveXObject = function(name){
        var obj = -1;
        try{
            obj = new ActiveXObject(name);
        }catch(err){
            obj = {activeXError:true};
        }
        return obj;
    };
    /**
     * Parse an ActiveX $version string into an object.
     * 
     * @param {String} str The ActiveX Object GetVariable($version) return value. 
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseActiveXVersion = function(str){
        var versionArray = str.split(",");//replace with regex
        return {
            "raw":str,
            "major":parseInt(versionArray[0].split(" ")[1], 10),
            "minor":parseInt(versionArray[1], 10),
            "revision":parseInt(versionArray[2], 10),
            "revisionStr":versionArray[2]
        };
    };
    /**
     * Parse a standard enabledPlugin.description into an object.
     * 
     * @param {String} str The enabledPlugin.description value.
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseStandardVersion = function(str){
        var descParts = str.split(/ +/);
        var majorMinor = descParts[2].split(/\./);
        var revisionStr = descParts[3];
        return {
            "raw":str,
            "major":parseInt(majorMinor[0], 10),
            "minor":parseInt(majorMinor[1], 10), 
            "revisionStr":revisionStr,
            "revision":parseRevisionStrToInt(revisionStr)
        };
    };
    /**
     * Parse the plugin revision string into an integer.
     * 
     * @param {String} The revision in string format.
     * @type Number
     */
    var parseRevisionStrToInt = function(str){
        return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
    };
    /**
     * Is the major version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required major version.
     * @type Boolean
     */
    self.majorAtLeast = function(version){
        return self.major >= version;
    };
    /**
     * Is the minor version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required minor version.
     * @type Boolean
     */
    self.minorAtLeast = function(version){
        return self.minor >= version;
    };
    /**
     * Is the revision version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required revision version.
     * @type Boolean
     */
    self.revisionAtLeast = function(version){
        return self.revision >= version;
    };
    /**
     * Is the version greater than or equal to a specified major, minor and revision.
     * 
     * @param {Number} major The minimum required major version.
     * @param {Number} (Optional) minor The minimum required minor version.
     * @param {Number} (Optional) revision The minimum required revision version.
     * @type Boolean
     */
    self.versionAtLeast = function(major){
        var properties = [self.major, self.minor, self.revision];
        var len = Math.min(properties.length, arguments.length);
        for(i=0; i<len; i++){
            if(properties[i]>=arguments[i]){
                if(i+1<len && properties[i]==arguments[i]){
                    continue;
                }else{
                    return true;
                }
            }else{
                return false;
            }
        }
    };
    /**
     * Constructor, sets raw, major, minor, revisionStr, revision and installed public properties.
     */
    self.FlashDetect = function(){
        if(navigator.plugins && navigator.plugins.length>0){
            var type = 'application/x-shockwave-flash';
            var mimeTypes = navigator.mimeTypes;
            if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
                var version = mimeTypes[type].enabledPlugin.description;
                var versionObj = parseStandardVersion(version);
                self.raw = versionObj.raw;
                self.major = versionObj.major;
                self.minor = versionObj.minor; 
                self.revisionStr = versionObj.revisionStr;
                self.revision = versionObj.revision;
                self.installed = true;
            }
        }else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
            var version = -1;
            for(var i=0; i<activeXDetectRules.length && version==-1; i++){
                var obj = getActiveXObject(activeXDetectRules[i].name);
                if(!obj.activeXError){
                    self.installed = true;
                    version = activeXDetectRules[i].version(obj);
                    if(version!=-1){
                        var versionObj = parseActiveXVersion(version);
                        self.raw = versionObj.raw;
                        self.major = versionObj.major;
                        self.minor = versionObj.minor; 
                        self.revision = versionObj.revision;
                        self.revisionStr = versionObj.revisionStr;
                    }
                }
            }
        }
    }();
};
FlashDetect.JS_RELEASE = "1.0.4";


// xml document
var browserConfigDoc;

//browser name 
var browserName = '';

//browser version
var fullVersion;

//browser flash version
var flashVersion = 0.0;

//operating system name
var osName = null;

//object holds how ghost is dealing with this browser
var myBrowserTag = null;

//type:boolean. if the browser enabling popup or not
var popupBlocked = null;

//boolean, check if cookies are enabled or not
var cookieEnabled = null;

//boolean, check if the browser is supported or not
var browserSupported = null;

//boolean, if ghost supports current version
var flashSupported = null;

//boolean, check if flash is installed
var flashInstalled = null;

//latest supported flash
var latestSupportedFlash = null;

//min flash version that is supported by Ghost
var minSupportedFlash = null;

//is Ghost supporting this browser on the current operating system
var osSupported = null;

//language.xml document that's retrieved to be filled in the language combobox
var langDoc;

//ghost user name that's set from the URL
var ghost_userName = null;

//where the current browser recommeded to use or not
var recommendedBrowser = null;

//URL parameter's values
var pValues = new Array();

//URL parameter's names
var pNames = new Array();


// This snippit of code needs common.js
//if the language is specified in the url we should not do a redirect
if(window.location.search.indexOf("language") < 0){
	// if the language is not specified in the url we try to get the language cookie
	var langCookie = getLangCookie();
	// if the language cookie is null then the default language is English
	if(langCookie == null){
		try{
			langCookie = defaultLanguage;
		}catch(e){
			langCookie = "en";
		}
	}
	// if the language cookie is English which is the default we should not do a redirect
	if (langCookie != "en") {
		// if the language cookie is not English, we should do a redirect by appending "language=LANG" to the query parameters and be careful not to loose any previous query params
		if (window.location.search != "") {
			window.location.search += ("&language="+langCookie);
		} else {
			window.location.search += ("?language="+langCookie);
		}
	}
}

function setComboboxLanguage(){
	var lng = getParamValue("language");
	lng = decodeURIComponent(lng);
	if(!lng)return;
	var cmbo = document.getElementById("lanuagesCombobox");
	for(var i=0; i<cmbo.options.length; i++){
		if(lng.toLowerCase().indexOf(cmbo.options[i].value.toLowerCase()) >= 0){
			cmbo.options[i].selected = true;
		}
	}
}

function initBrowserInfo(){
	browserName = getBrowserName().toLowerCase();
	fullVersion = parseInt(getBrowserVersion());
	flashVersion = FlashDetect.major;
	getBrowserConfigDoc();
}
/**
 * to load xml doc
 * @param {} docURL
 * @return {}
 */
function loadHomePageXmlDoc(xmlString) {
	var xmlDoc;
	if (window.ActiveXObject) {
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML(xmlString);
			return xmlDoc;
		} else if (document.implementation && document.implementation.createDocument) {
			//for Mozila
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(xmlString,"text/xml");
			return xmlDoc;
		}
	return xmlDoc;
}

/**
 * load homePageConfig.xml document
 * @return {}
 */
function getBrowserConfigDoc(){
	//VCURL must be used to avoid cross-domin error
	if(!browserConfigDoc){
		browserConfigDoc = loadHomePageXmlDoc(browserConfig);	
	}
	return browserConfigDoc;
}

/**
 * load my brwoser info tag from the homePageConfig.xml document
 */
function getMyBrowserTag(){
	if(!myBrowserTag){
		var browsersArray = getBrowserConfigDoc().getElementsByTagName("browser");
		for (var i = 0; i < browsersArray.length; i++) {
			if (browsersArray[i].getAttribute("name").toLowerCase() == browserName) {
				if (browsersArray[i].getAttribute("version") == fullVersion) {
					myBrowserTag = browsersArray[i];
				}
			}
		}
		
	}
	return myBrowserTag;
}

/**
 * set if the browser supported or not
 * @return {}
 */
function isSupportedBrowser() {
	if(!browserSupported){
		if(!getMyBrowserTag()){
			browserSupported = false;
		}else{
			browserSupported = getMyBrowserTag().getAttribute("isSupported");
		}
	}
	return browserSupported;
}

/**
 * if the brwoser supports current flash version number
 */
function isSupportedFlash(){
	if(!flashSupported){
		var flashVersionNumber = new Number(flashVersion);
		var minSupprtedVersion = new Number(getMinSupportedFlash());
		flashSupported = (flashVersionNumber >= minSupprtedVersion);
	}
	return flashSupported;
}

/**
 * @return the latest flash version that supported by the browser
 */
function getLatestSupportedFlash() {
	if(!latestSupportedFlash){
		var supportedFalshes = getMyBrowserTag().getElementsByTagName("supportedFlashes")[0];
		var numberOfSupportedFlashes = supportedFalshes.getElementsByTagName("flashVersion");
		var textObject = numberOfSupportedFlashes[numberOfSupportedFlashes.length- 1];
		var textNumber = getTextTagContent(textObject);
		latestSupportedFlash = new Number(textNumber);
	}
	return latestSupportedFlash;
}

/**
 * return the min suppported flash
 */
function getMinSupportedFlash(){
	if(!minSupportedFlash){
		var supportedFalshes = getMyBrowserTag().getElementsByTagName("supportedFlashes")[0];
		var numberOfSupportedFlashes = supportedFalshes.getElementsByTagName("flashVersion");
		var textObject = numberOfSupportedFlashes[0];
		var textNumber = getTextTagContent(textObject);
		minSupportedFlash = new Number(textNumber);
	}
	return minSupportedFlash;
}

/**
 * 
 */
function isFlashInstalled(){
	return FlashDetect.installed;
}

/**
 * 
 */
function isSupportedOS(){
	if(!osSupported){
		var supportedOsBrowser = getMyBrowserTag().getAttribute("isSupported");
		if(supportedOsBrowser == "true"){
			var osTag = getOSChildTag(getMyBrowserTag().getElementsByTagName("OS")[0]);
			osSupported = osTag ? osTag.getAttribute("isBlocked"): false;
		}else{
			osSupported = false;
		}
	}
	return osSupported;
}

/**
 * do for public using
 * get the child tag of OS tag
 * @param {} osTag
 */
function getOSChildTag(osTag){
	var osTagChildren = osTag.getElementsByTagName("os");
	for(var j=0; j<osTagChildren.length; j++){
		if(osTagChildren[j].getAttribute("name").toLowerCase() == getOSName().toLocaleString().toLowerCase()){
			return osTagChildren[j];
		}
	}
	return null;
}

/**
 * set os name
 */
function getOSName() {
	if(!osName){
		var usrAgnet = navigator.userAgent.toLowerCase();
		if (usrAgnet.indexOf("windows") >= 0) {
			osName = "windows";
		} else if (usrAgnet.indexOf("linux") >= 0) {
			osName = "linux";
		} else if (usrAgnet.indexOf("mac") >= 0) {
			osName = "mac";
		}
		return osName
	}
	return osName
}

/**
 * @param instName: the tag name of the instruction in the homePageConfig.xml
 * @return the instruction based on instName
 */

function getInstruction(instName) {
	var instObj = getMyBrowserTag().getElementsByTagName("instructions")[0].getElementsByTagName(instName)[0];
	return getTextTagContent(instObj);
}

/**
 * check if recommended brwoser
 */
function isRecommededBrowser(){
	if(!recommendedBrowser){
		var recommdedTags = getBrowserConfigDoc().getElementsByTagName("recommendedBrwosers")[0].getElementsByTagName("recommdedBrowser");
		for(var i=0; i<recommdedTags.length; i++){
			if(recommdedTags[i].getAttribute("version") == fullVersion){
				recommendedBrowser = true;
				break;
			}
		}
	}
	return recommendedBrowser;
}

/**
 * 
 * @return {}
 */
function isCookieEnabled(){
	if(!cookieEnabled){
		cookieEnabled = (navigator.cookieEnabled) ? true : false;
		try{
			if(browserName.toLowerCase().indexOf("safari") >=0){
				cookieEnabled = navigator.cookieEnabled;
			}else{
				document.cookie = "testcookie@ghost";
				cookieEnabled = (document.cookie.indexOf("testcookie@ghost") != -1 ? true : false);
				
			}
		}catch(e){
			if (typeof navigator.cookieEnabled == "undefined") {
					document.cookie = "testcookie@ghost"
					cookieEnabled = (document.cookie.indexOf("testcookie@ghost") == -1 ? true : false);
			}else{
				cookieEnabled = false;
			}
		}
	}
	return cookieEnabled;
}

/**
 * to check if the browser is blocked popup
 * 
 * @return
 */
function isBlockedPopUp() {
	if (!popupBlocked ) {
		try {
			var mine = window.open('', '',
					'width=0,height=0,left=0,top=0,scrollbars=no');
			mine.close()
			popupBlocked = false;// convert netstate value from null to true
		} catch (err) {
			popupBlocked = true;// convert netstate value from null to false
		}
	}  
	return popupBlocked;
}

/**
 * returns scressn size
 */
function getScreenMaxSize() {
	var xMax;
	var yMax;

	if (typeof(screen.availWidth) == 'number') {
		xMax = screen.availWidth;
		yMax = screen.availHeight;
	} else if (typeof(screen.width) == 'number') {
		xMax = screen.width;
		yMax = screen.height;
	} else if (typeof(window.outerWidth) == 'number') {
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	} else if (document.documentElement
			&& (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		xMax = document.documentElement.clientWidth;
		yMax = document.documentElement.clientHeight;
	} else if (document.body
			&& (document.body.clientWidth || document.body.clientHeight)) {
		xMax = document.body.clientWidth;
		yMax = document.body.clientHeight;
	} else {
		xMax = 640;
		yMax = 480;
	}
	var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
	if (isMac)
		yMax = yMax - 20;

	return "minimizable=no, width="
			+ xMax
			+ ", height="
			+ yMax
			+ ", resizable=no,"
			+ " fullscreen=yes, titlebar=no, directories=no, channelmode=no, scrollbars=no,"
			+ " status=no, toolbar=no, menubar=no, location=no";

}

/**
 * load the language document from language.xml
 */
function getLangDoc(){
	if (!langDoc) {
		langDoc = loadHomePageXmlDoc(languageConfig);
	}
	return langDoc;
}

/**
 * redirect home page with the selected language
 * @param {} combobox
 */
function onChangeLanguage(combobox) {
	addNewLanguageCookie(combobox.value);
	var query = "";
	for (var i = 0; i < pValues.length; i++) {
		if (pNames[i].indexOf("language") >=0) {
			query += (pNames[i] + "=" + combobox.value.toLowerCase());
		} else {
			query += (pNames[i] + "=" + pValues[i]);
		}
		query += "&";
	}
	query = query.substring(0, query.length - 1);
	var docLoc = document.location+"";
	var _baseURL="";
	if(docLoc.indexOf("?")>=0){
		_baseURL = docLoc.split("?")[0];
	}else{
		_baseURL = docLoc;
	}
	window.location = _baseURL + "?" + query;
}

/**
 * extract url params and fill them in pNames and pValues arrays
 */
function extractURLQueries(){
	var loc = document.location + "";
	var attrs = loc.split("?")[1];
	if (attrs && pNames.length == 0 && pValues.length == 0) {
		var nms = attrs.split("&");
		for (var i = 0; i < nms.length; i++) {
			if(nms[i].indexOf("=") <0){
				ghost_userName = nms[i];
				continue;
			}
			pNames.push(nms[i].split("=")[0]);
			pValues.push(nms[i].split("=")[1]);
		}
	}
}

/**
 * return the value of a url parameter based on parameter name
 * @param {} paramName
 */
function getParamValue(paramName){
	extractURLQueries();
	for (var i = 0; i < pNames.length; i++) {
		if (pNames[i] == paramName) {
			return pValues[i];
		}
	}
	return null;
}


//*** open any URL from this function ****************
function  goToUrl(url){	
	var queruStr = document.location.search.substring(1);	
	//open the url's in addtion to the language value if it exist
	if(queruStr.search(/language=/i) != -1)
	{
	//open method with the language value
	window.open (url + "?" + queruStr,"_self");
	return true;
	}else
	{
	//open method without the language value because its not exist
	window.open (url ,"_self");	
	return false;
	}
}

/**
 * dummy function to test if there is blocked plugin
 */
function testBlockedPlugins(){
	
}

function doDirectLogin(){
	extractURLQueries();
	if(ghost_userName){
		
	}
}


/**
 * @return the text text of the passed tag
 */
function getTextTagContent(htmlTag) {
	return (htmlTag.textContent || htmlTag.innerText || htmlTag.text);
}


/* (c) 2006-7 Ghost(TM) Inc. (http://G.ho.st/home) . All rights reserved.
G.ho.st licenses this software to you under the terms of the 
Common Public License Version 1.0 http://www.opensource.org/licenses/cpl.php 
*/

/**====================================================================================== **
/*  File: general.js     				                                              **
/*  Creator: Mohammad Taweel...                                                             **
/*  Create date: 2009-01-28                                                               **
/*  Authors: Mohammad Taweel...					                                          **
/*                                                                                        **
/**====================================================================================== */
/* 
 * This javascript library should be included the first thing in vc.html & main.jsp, where it is responsible for
 * limiting the domains from where those pages are accessed.
*/


// VCURL defines the URL that the vc.html should be loaded from (or is loaded from) which is the main domain URL
// that is visible to the user or could be used directly in the browser to load the vc.html
var VCURL = window.location.protocol + "//" + window.location.host;


if ( (location.pathname == "/") || (location.pathname == "/home/") || ((location.pathname == "/main.jsp") || (location.pathname == "/home/main.jsp")) || (location.pathname == "/vc.html") ) {
	if ( (location.hostname.indexOf("cdn.") >=0 ) || (location.hostname.indexOf("www.")>=0 ) || (location.hostname.indexOf("server.")>=0) || (location.hostname.indexOf("upload.")>=0) || (location.hostname.indexOf("secureapi.")>=0) ) {
	// if the user is calling the main.jsp or vc.html we need to make sure that he is doing so directly without adding any subdomain prefix's (e.g cdn, www ...)
	// The cases for this is that:
	// 1- if the user is calling the "server only" in the url (e.g. http://www.g.ho.st/)
	// 2- if the user is calling the server's home page only in the url (e.g. http://cdn.g.ho.st/home/)
	// 3- if the user is calling main.jsp directly (e.g. http://www.g.ho.st/main.jsp) or (http://www.g.ho.st/home/main.jsp)
	// 4- if the user is calling vc.html directly (e.g. http://cdn.g.ho.st/vc.html)
 	 	var cleanHost = location.host.substring(location.host.indexOf(".")+1);
 	 	var cleanLocation =  location.protocol + '//' + cleanHost + location.pathname+window.location.search;
 		window.location = cleanLocation;
	}
} 
/**
 * The main pages (homepage "main.jsp" & "vc.html" ) should not be accessed from the sharing domain.
 * As a security measure, this should prevent calling the sing-in API using the share domain which is used for G.ho.st
 * file system, where one can open a certain html file that contains a script that reads the cookies from the sharing
 * domain. 
 */
if (location.hostname.toLowerCase().match("sharing")) { // if name contains sharing
	
	var hName = location.hostname.toLowerCase();
	
	// files.ghostsharing.com
	// files.test.ghostsharing.com
	// ghostsharing.com
	// test.ghostsharing.com
	// files.dev.testghostsharing.com
	//dev.testghostsharing.com
	
	
	if(hName.match("testghostsharing")){ // coming from dev domains
		
		// files.qa.testghostsharing.com
		//qa.testghostsharing.com 
		
		var pref = "";
		
		if(hName.match("files")){ // with files prefix 
			pref = hName.split(".")[1];	
		}else{ // without files prefix 
			pref = hName.split(".")[0];
		}
		
		window.location.hostname=pref+".testghost.com";
		
	}else{ // coming from production domains
		// ghostsharing 
		
	
	// files.ghostsharing.com 
	//ghostsharing.com
	
	// files.test.ghostsharing.com 
	// test.ghostsharing.com
	
		if(hName.match("files")){
		
			var tokens = hName.split(".");
			if(tokens.length==3){
				
				window.location.hostname="g.ho.st";
				
			}else{
				
				window.location.hostname=tokens[1]+".g.ho.st";
				
			}
			
			
			
		}else{
			
			// no files 
			
			var tokens = hName.split(".");
			// ghostsharing.com 
			if(tokens.length==2){
				window.location.hostname="g.ho.st";
			}else{
				
				// sub.g.ho.st
				window.location.hostname=tokens[0]+".g.ho.st";
				
			}
			
		}
		
		
		var tokens = hName.split(".");
		
		
		if(hName.match("test")){ // files.test.ghostsharing.com or test.ghostsharing.com
				window.location.hostname="test.g.ho.st";
		}else{ // files.ghostsharing.com
			window.location.hostname="g.ho.st";
		}
		
	}
	
}

function getXMLHttpRequest() {
	var request = false;
	if (window.ActiveXObject) {
		var versions = ["Microsoft.XmlHttp","MSXML2.XmlHttp","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.5.0"];
		for (var i = 0; i<versions.length; i++) {
			try {
				request  = new ActiveXObject(versions[i]);
				break;
			} catch(e) {}
		}
	} else if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	}
	return request;
}

/*
 * (c) 2006-7 Ghost(TM) Inc. (http://G.ho.st/home) . All rights reserved.
 * G.ho.st licenses this software to you under the terms of the Common Public
 * License Version 1.0 http://www.opensource.org/licenses/cpl.php
 */

/*******************************************************************************
 * ====================================================================================== /*
 * Creator: Ragheb Khaseeb
 * date: 2009-03-01 
 * Authors: Ragheb Khaseeb... ** /* **
 * /**======================================================================================
 */
 
 
 /***************************************************************************************
  * notifications area messages
  * 1)view use recommeded browser
  * 2)view update flash version 
  ***************************************************************************************/
  
 /**
  * view the notification if there is needing to be viewed
  */
 function viewNotifications(){
	try{
		var isSup = isSupportedBrowser();
	}catch(e){}
 	if(isSup && isSup == "true"){	
 		getRecommededBrowserNote();
 	}else{
 		if(!isRecommededBrowser()){
 	 		document.getElementById("changeBrowser").style.display = "";
 	 	}
 	}
 	try{
 		getUpdateFlashNote();
 	}catch(e){}
 	viewNotSupportedBrowserNot();
 }

 /**
  * view the notification message if the user uses not recommeded browser
  */
 function getRecommededBrowserNote(){
 	if(!isRecommededBrowser()){
 		document.getElementById("changeBrowser").style.display = "";
 	}
 }
 
 function viewNotSupportedBrowserNot(){
 	if(!isSupportedBrowser() || isSupportedBrowser() == "false"){
 		document.getElementById("notSupportedBrowser").style.display = "";
 	}
 }
 
 /**
  * if the user uses supported flash but not the latest version
  */
 function getUpdateFlashNote(){
	 var latestVersionInt = parseInt(getLatestSupportedFlash());
 	if(isSupportedFlash() && (flashVersion < latestVersionInt)){
 		var txtCntnt = document.createTextNode(flashVersion+"");
 		document.getElementById("currentFlashVersion").appendChild(txtCntnt);
 		document.getElementById("upgradeFlashNotification").style.display = "";
 	}
 }
 
 /**********************************************
  * warning messages area
  * 1)install flash or update the flash version in case of the flash is not supported
  * 2)enable cookie
  * 3)enable popup
  *********************************************/
 
 /**
  * the table that contains all the warning messages
  */
 function viewWarningTable(){
 	var viewWarning = false;
 	if(getEnableCookieWarn()){
 		viewWarning = true;
 	}
 	if(getInstallFlashWarn()){
 		viewWarning = true;
 	}
 	try{
	 	if(getUpgradeFlashWarn()){
	 		viewWarning = true;
	 	}
 	}catch(e){}
 	if(viewWarning){
 		document.getElementById("LoginRegBackgroundArea").style.display = "";
		document.getElementById("loginBtns").style.display = "none";
 		document.getElementById("WarningMessageTable").style.display = "";
 	}
 }
 
 /**
  * view enable cookie warning message
  * @return true if the message will appear
  */
 function getEnableCookieWarn(){
 	if(!isCookieEnabled()){
 		document.getElementById("EnableCookies").style.display = "";
 		return true;	
 	}
 	return false;
 }
 
 /**
  * if the browser does not contains flash
  * @return true if the message will appear
  */
 function getInstallFlashWarn(){
 	if(!isFlashInstalled()){
	 	document.getElementById("InstallFlash").style.display = "";
		return true;
 	}
 	return false;
 	
 }
 
 /**
  * this message will appear the user uses old flash version
  * @return {Boolean}
  */
 function getUpgradeFlashWarn(){
 	if(isFlashInstalled() && !isSupportedFlash()){
 		document.getElementById("UpgradeFlash").style.display = "";
 		return true;
 	}
 	return false;
 }
 
 /*************************************************
 * parse home page url and view the co-branding logo
 **************************************************/
function getCoBrandingLogo() {
	var loc = document.location + "";
	try {
		var imgSrc = getParamValue("promotionURL");
		if(imgSrc){
			var _table = document.getElementById("CoBrandingLogoTable");
			_table.style.display = "";
			var logo = document.getElementById("CoBrandingLogo");
			logo.src = imgSrc;
		}
	} catch (e) {
	}
}

/*****************************************
 * hide the top internal green button 
 ****************************************/
function viewHideInternalBtn() {
	var doc = document.location + "";
	if(doc == VCURL || doc.indexOf(VCURL+"/main.jsp") >=0 || doc.indexOf(VCURL+"/?")>=0  || doc == VCURL+"/" || doc.indexOf(VCURL+"/icafe.jsp") >=0 || doc.indexOf(VCURL+"/icafe_tl.jsp") >=0){
		document.getElementById("InternalGreenButton").style.display = "none";
	}
}
 
 /**********************comboBox languages************************************
  * 
  * fill the languages in the combobox of id lanuagesCombobox
  ****************************************************************************/
 function viewLanguages(){
	var langArray = getLangDoc().getElementsByTagName("language");
	var langCombo = document.getElementById("lanuagesCombobox");
	var option;
	var optionLabel;
	var textNodeContent;
	var textChild;
	var lang = getParamValue("language");
	if (lang == null || lang == "null") {
		lang = "en";
	}
	for (var i = 0; i < langArray.length; i++) {
		option = document.createElement("option");
		textNodeContent = getTextTagContent(langArray[i]
				.getElementsByTagName("value")[0]);
		option.setAttribute("value", textNodeContent);
		optionLabel = getTextTagContent(langArray[i]
				.getElementsByTagName("label")[0]);
		textChild = document.createTextNode(optionLabel);
		if (lang) {
			if (lang.toLowerCase() == textNodeContent.toLowerCase()) {
				option.setAttribute("selected", "selected")
			}
		}
		option.appendChild(textChild);
		langCombo.appendChild(option)
	}
 }
 
 
 /*********************
  *Embed widget function
  ***********************************/
function box (boxname,menustate){
	if (document.getElementById){
		document.getElementById(boxname).style.visibility = menustate;
	}else {
	document[boxname].visibility = menustate;
	} 
}

/****************************************
 * view referral message
 */
function viewReferralMessage(){
	if(!oralInfo || oralInfo == null || oralInfo == "null"){
		document.getElementById("ScreenShotsArea").style.display = "";
		return ;
	}
	if(getParamValue("referral")){
		document.getElementById("ScreenShotsArea").style.display = "none";
		document.getElementById("Referral").style.display = "";
		var tempOral = oralInfo.split("<--->");
		var message1 = document.createTextNode(tempOral[0]+"  "+tempOral[1]);
		var message2 = document.createTextNode(getParamValue("referral")+"@g.ho.st");
		document.getElementById("referral_id").appendChild(message2);
		document.getElementById("referral_email").appendChild(message1);
		return true;
	}else{
		document.getElementById("ScreenShotsArea").style.display = "";
	}
	return false;
}

/****************************************
 * view promotionCode message 
 */
function viewpromotionCode(){
	if(getParamValue("promotionCode") && getParamValue("promotionCode").toLowerCase() == "survey"){
		document.getElementById("promotionCodeTable").style.display = "";
		ghaction="registration";
	}
}

/*********************
  *Swap Images Functions, running on mouse over
  ***********************************/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++){
  	x.src=x.oSrc;
  }
}

function MM_preloadImages() { 
  	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  
  if(!d)d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/**
 * top menu functions
 */

/////////////////////////////////////////////////////////////////////////////////////
/////// Header tool bar (show and hide menus)
function onFunction(bg2){
obj=document.getElementById(bg2);
obj.style.backgroundImage ='url(/images/menubar_slice_on.gif)';}
function showSubMenu(id4){
hideAll()
if(id4 == "vc"){
document.getElementById("vc").style.backgroundImage ='url(/images/menubar_slice_on.gif)';
document.getElementById("virtualcomputer").style.display = "";}
else
if(id4 == "mainLink"){
document.getElementById("mainLink").style.backgroundImage ='url(/images/menubar_slice_on.gif)';
document.getElementById("mainLink").style.display = "";}
else
if(id4 == "part"){
document.getElementById("part").style.backgroundImage ='url(/images/menubar_slice_on.gif)';
document.getElementById("Partners").style.display = "";}
else
if(id4 == "comm"){
document.getElementById("comm").style.backgroundImage ='url(/images/menubar_slice_on.gif)';
document.getElementById("community").style.display = "";}
else
if(id4 == "buzz"){
document.getElementById("buzz").style.backgroundImage ='url(/images/menubar_slice_on.gif)';
document.getElementById("Buzz_").style.display = "";}
else
if(id4 == "about"){
document.getElementById("about").style.backgroundImage ='url(/images/menubar_slice_on.gif)';
document.getElementById("AboutUs").style.display = "";}
}
function hideAll(){
document.getElementById("mainLink").style.backgroundImage ='none';
document.getElementById("vc").style.backgroundImage ='none';
document.getElementById("virtualcomputer").style.display = "none";
document.getElementById("comm").style.backgroundImage ='none';
document.getElementById("community").style.display = "none";
document.getElementById("part").style.backgroundImage ='none';
document.getElementById("Partners").style.display = "none";
document.getElementById("buzz").style.backgroundImage ='none';
document.getElementById("Buzz_").style.display = "none";
document.getElementById("about").style.backgroundImage ='none';
document.getElementById("AboutUs").style.display = "none";}

/**
 * ToolTip functions
 * 
 */

var disappeardelay=100  
var verticaloffset=-3 
var enablearrowhead=1 
var arrowheadimg=["/images/arrowdown.gif", "/images/arrowup.gif"] 
var arrowheadheight=11 //height of arrow image (amount to reveal)

var ie=document.all 
var ns6=document.getElementById&&!document.all
verticaloffset=(enablearrowhead)? verticaloffset+arrowheadheight : verticaloffset

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e){
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (e.type=="mouseover")
obj.visibility="visible"
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
if (whichedge=="rightedge"){
edgeoffsetx=0
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-30
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffsetx=dropmenuobj.contentmeasure-obj.offsetWidth
return edgeoffsetx
}
else{
edgeoffsety=0
var topedge=ie && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-3000 : window.pageYOffset+window.innerHeight-3000
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) //move up?
edgeoffsety=dropmenuobj.contentmeasure+obj.offsetHeight+(verticaloffset*2)
return edgeoffsety
}
}

function displayballoontip(obj, e){ //main ballooon tooltip function
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous tooltip?
dropmenuobj.style.visibility="hidden"
clearhidemenu()
//obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(obj.getAttribute("rel"))
showhide(dropmenuobj.style, e)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")+verticaloffset
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
if (enablearrowhead)
displaytiparrow()
}

function displaytiparrow(){ //function to display optional arrow image associated with tooltip
tiparrow=document.getElementById("arrowhead")
tiparrow.src=(edgeoffsety!=0)? arrowheadimg[0] : arrowheadimg[1]
var ieshadowwidth=(dropmenuobj.filters && dropmenuobj.filters[0])? dropmenuobj.filters[0].Strength-1 : 0
//modify "left" value depending on whether there's no room on right edge of browser to display it, respectively
tiparrow.style.left=(edgeoffsetx!=0)? parseInt(dropmenuobj.style.left)+dropmenuobj.offsetWidth-tiparrow.offsetWidth-13+"px" : parseInt(dropmenuobj.style.left)+13+"px"
//modify "top" value depending on whether there's no room on right edge of browser to display it, respectively
tiparrow.style.top=(edgeoffsety!=0)? parseInt(dropmenuobj.style.top)+dropmenuobj.offsetHeight-tiparrow.offsetHeight-ieshadowwidth+arrowheadheight+"px" : parseInt(dropmenuobj.style.top)-arrowheadheight+"px"
tiparrow.style.visibility="visible"
}
function delayhidemenu(){
delayhide=setTimeout("dropmenuobj.style.visibility='hidden'; dropmenuobj.style.left=0; if (enablearrowhead) tiparrow.style.visibility='hidden'",disappeardelay)
}
function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}
function reltoelement(linkobj){ //tests if a link has "rel" defined and it's the ID of an element on page
var relvalue=linkobj.getAttribute("rel")
return (relvalue!=null && relvalue!="" && document.getElementById(relvalue)!=null && document.getElementById(relvalue).className=="balloonstyle")? true : false
}
function initalizetooltip(){
var all_links=document.getElementsByTagName("a")
if (enablearrowhead){
tiparrow=document.createElement("img")
tiparrow.setAttribute("src", arrowheadimg[0])
tiparrow.setAttribute("id", "arrowhead")
document.body.appendChild(tiparrow)
}
for (var i=0; i<all_links.length; i++){
if (reltoelement(all_links[i])){ //if link has "rel" defined and it's the ID of an element on page
all_links[i].onmouseover=function(e){
var evtobj=window.event? window.event : e
displayballoontip(this, evtobj)
}
all_links[i].onmouseout=delayhidemenu
} } }
if (window.addEventListener)
window.addEventListener("load", initalizetooltip, false)
else if (window.attachEvent)
window.attachEvent("onload", initalizetooltip)
else if (document.getElementById)
window.onload=initalizetooltip
/////////////////////

