﻿//<!--
// ISAU.DE Library 1.4
// General utility functions
// Partially based on "Browser Detect Lite  v2.1"
//
// Last revised: 24.06.2011

// GetObjectByIdOrName: Get object either bei it's id or name attribute.
// arg1: id or name of the object or the object itself
function  GetObjectByIdOrName(currentObject)
{
	var obj;
	if (typeof currentObject == "string") {
		obj = document.getElementById(currentObject);
		if (! obj) {
			obj = document.getElementsByName(currentObject);
			obj = (obj.length) ? obj[0] : null;
		}
	}
	else obj = currentObject; //currentObject already is the object
	return obj;
}

// "Browser Detect Lite  v2.1" has been modified by Ralf Isau (ri)
//		to  adapt to his website and to include  
//		Apple Safari (isSafari), isIE4upMac, isIE5upMac, isIE7x, isIE7up, versionMajor
//		Last revised: 05.06.2008
//
// With acknoledgement to ...
// http://www.dithered.com/javascript/browser_detect/index.html
// Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
// Michael Lovitt to include OmniWeb and Dreamcast

function BrowserCheck() {
	var ua = navigator.userAgent.toLowerCase(); 
	this.ua = ua;
	//!! EXAMPLES:
	//!! MS IE 8		"mozilla/4.0 (compatible; msie 8.0; windows nt 5.1; trident/4.0)"
	//!! FIREFOX 5.0	"mozilla/5.0 (macintosh; intel mac os x 10.6; rv:5.0) gecko/20100101 firefox/5.0"

	// browser name
	this.isGecko     = (ua.indexOf('gecko') != -1);
	this.isMozilla   = (this.isGecko && (ua.indexOf("gecko/") + 14 == ua.length));
	this.isFirefox   = (ua.indexOf("firefox") != -1); 
	this.isSafari    = (ua.indexOf("safari") != -1);
	this.isOpera     = (ua.indexOf("opera") != -1); 
	this.isKonqueror = (ua.indexOf("konqueror") != -1); 
	this.isIcab      = (ua.indexOf("icab") != -1); 
	this.isAol       = (ua.indexOf("aol") != -1); 
	this.isWebtv     = (ua.indexOf("webtv") != -1); 
	this.isOmniweb   = (ua.indexOf("omniweb") != -1);
	this.isDreamcast = (ua.indexOf("dreamcast") != -1);
	this.isIE        = ( (ua.indexOf("msie") != -1) && (!this.isOpera) && (!this.isSafari) && (!this.isWebtv) ); 
	this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (!this.isOpera) && (!this.isSafari) && (!this.isWebtv) && (ua.indexOf('hotjava') == -1) ) );
	// mimicry and compatible browsers
	this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);
	
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion); // complete version number (e.g. 5.5 for IE5.5 or 8 for IE8)
	this.versionGeneration = parseInt(this.versionMinor);
	
	// correct version number for NS6+ 
	if (this.isNS && this.isGecko) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	
	// correct version number for IE4+ 
	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	
	// correct version number for Opera 
	else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}
	
	// correct version number for Firefox (Macintosh)
	else if (this.isFirefox) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('firefox/') + 8 ) );
	}
	
	// correct version number for Safari 
	else if (this.isSafari) {
		if (ua.indexOf('safari/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('safari/') + 7 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('safari ') + 7 ) );
		}
	}
	
	// correct version number for Konqueror
	else if (this.isKonqueror) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
	}
	
	// correct version number for iCab 
	else if (this.isIcab) {
		if (ua.indexOf('icab/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
		}
	}
	
	// correct version number for WebTV
	else if (this.isWebtv) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('webtv/') + 6 ) );
	}

	this.versionMajor = parseInt(this.versionMinor); // Main version number (e.g. 5 for IE5.5)
	
	if (this.isGecko) {
		if (!this.isSafari) {
			this.geckoVersion = ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) );
		}
		else {
			this.geckoVersion = ua.substring( (ua.lastIndexOf('safari/') + 7), (ua.lastIndexOf('safari/') + 10) );
		}
	}

	// 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) );
	this.isMac   = (ua.indexOf('mac') != -1);
	this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('linux') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
	
	// specific browser shortcuts
	this.isNS3up = (this.isNS && this.versionMinor >= 3);
	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.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.isIE7x = (this.isIE && this.versionMajor == 7);
	this.isIE7up = (this.isIE && this.versionMajor >= 7);
	this.isIE8x = (this.isIE && this.versionMajor == 8);
	this.isIE8up = (this.isIE && this.versionMajor >= 8);
	this.isIE9x = (this.isIE && this.versionMajor == 9);
	this.isIE9up = (this.isIE && this.versionMajor >= 9);
	
	this.isIE4xMac = (this.isIE4x && this.isMac);
	this.isIE4upMac = (this.isIE4up && this.isMac);
	this.isIE5upMac = (this.isIE5up && this.isMac);
}

//???
//
// Get date form: d.m.yyyy
// Example: 1.2.2008 (for Februrary 1st, 2008)
//
function Date_dmyyyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();

  // Normalize differend year values returned by different browsers (IE and NS) in the year 2000.
  if(y < 2000)
  	{ if(y >= 100)
	  {
		y = y - 100 + 2000;
	  }
	  else
	  {
	  	y += 1900;
	  }
  }

  return "" + d + "." + m + "." + y;
}


//
// get last modified date of the current document.
// Variables:
//		deflt = Default value if server/browser returns an invalid value
//
function Date_LastModified(deflt)
{
  var lmd = window.document.lastModified;
  var s   = "";
  var d1;

  // check if we have a valid date before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + Date_dmyyyy(new Date(d1));
  }
  else
  {
	s = "" + deflt;
  }

  return s;
}

//
// Get the full path name of the basis URI of active document's file.
// Arguments:
//		CSSRelativeURI (String)	Relative URI of the first CSS file loaded
//								on the actual web site (optional).
//		Default:	"css/" is style sheet exists, otherwise "/"
//		Example:	Base URI	http://www.isau.de/
//					CSS path	http://www.isau.de/css/
//					CSSRelativeURI "css/"
// Side effects:
//		The function needs at least one CSS file loaded into the (X)HTML document.
//		Otherwise it cuts the document's path at the substring specified by CSSRelativeURI.
//
function GetBasisURI(CSSRelativeURI)
{
	var strPath = "";
	var p;

	if (document.styleSheets.length) {
		if (! CSSRelativeURI) {
			CSSRelativeURI = "css/";
		} 
		p = document.styleSheets.item(0);
		strPath = p.href;
	}
	else {
		if (! CSSRelativeURI) {
			CSSRelativeURI = "/";
		}
		strPath = ((document.location.protocol) ? document.location.protocol + "//" : "") 
				+ ((document.location.hostname) ? document.location.hostname : "")
				+ document.location.pathname;
	}
	p = strPath.lastIndexOf(CSSRelativeURI);
	strPath = (p>0) ? strPath.substr(0, p) + "/" : "";

	return strPath;
}

//
// Get the full IFRAME path to display a Facbook 'Like' button.
// Arguments:
//		none
//
//function LikeThis() {
//	var strSrc = document.location.href;
//	var strSrc = strSrc.replace(/:/g, '%3A'); 	/* ':' */
//	var strSrc = strSrc.replace(/\//g, '%2F');	/* '/' */
//	return "http://www.facebook.com/plugins/like.php?href=" + strSrc + "&layout=button_count&show_faces=false&width=130&action=like&colorscheme=light&height=21";
//}

// GLOBAL DEFINITIONS
var browser = new BrowserCheck();
//-->
