var USER_AGENT = navigator.userAgent.toLowerCase();
var IS_OPERA = (USER_AGENT.indexOf('opera') != -1);
var IS_SAFARI = ((USER_AGENT.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var IS_IE = ((USER_AGENT.indexOf('msie') != -1) && !IS_OPERA && !IS_SAFARI);
var IS_IE7 = false;
var IS_IE6 = false;

if (IS_IE) {
	if (!IS_OPERA && window.XMLHttpRequest) {
		IS_IE7 = true;
	} else {
		IS_IE6 = true;
	}
}

var IS_MOZILLA	= ((navigator.product == 'Gecko') && !IS_SAFARI);
var IS_KONQUEROR = (USER_AGENT.indexOf('konqueror') != -1);

/**
 * Fixes a browser bug with relative URLs ignoring the <base> tag.
 * Thanks to microsoft and opera ;)
 */
function fixURL(url) {
	if (IS_IE || IS_OPERA) {
		if (url.indexOf("/") == -1 && document.getElementsByTagName('base').length > 0) {
			return document.getElementsByTagName('base')[0].href + url;
		}
	}
	
	return url;
}

// ************************************************************************ //

/**
 * JS EventHandler
 */
function addEvent(obj, eventType, f, useCapture) {
	if (obj.addEventListener) {
		// Gecko, KHTML, Opera
		obj.addEventListener(eventType, f, useCapture);
		return true;
	
	} else if (obj.attachEvent) {
		// IE
		return obj.attachEvent("on"+eventType, f);
	
	} else {
		alert("Fehler, Event konnte nicht gesetzt werden!");
		return false;
	}
}

// ************************************************************************ //

/**
 * Fügt ein Smilie in das Kommentarfeld ein
 */
function AddSmilie(tag) {
	
	var myField;
	
	if (document.getElementById('CommentMessage') && document.getElementById('CommentMessage').type == 'textarea') {
		myField = document.getElementById('CommentMessage');
	
	} else {
		return false;
	}
	
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = tag;
		myField.focus();
	
	} else if (myField.selectionStart || myField.selectionStart == '0') {
		
		var startPos 	= myField.selectionStart;
		var endPos 		= myField.selectionEnd;
		var cursorPos 	= endPos;
		
		myField.value = myField.value.substring(0, startPos) + tag + myField.value.substring(endPos, myField.value.length);
		cursorPos += tag.length;
	
		myField.focus();
		myField.selectionStart = cursorPos;
		myField.selectionEnd = cursorPos;
	
	} else {
		myField.value += tag;
		myField.focus();
	}
}

// ************************************************************************ //

function GetElementsWithClassName(elementName, className) {
	var allElements = document.getElementsByTagName(elementName);
	var elemColl = new Array();
	for (i = 0; i < allElements.length; i++) {
		if (allElements[i].className == className) {
			elemColl[elemColl.length] = allElements[i];
		}
	}
	return elemColl;
}

// ************************************************************************ //

function allCheckboxes() {
	
	if (jQuery('input.all').attr('checked') == true) { 
		var Status = 'checked';
	} else { 
		var Status = '';
	}
  	
	jQuery("input[type='checkbox']").attr('checked', Status); 
}

// ************************************************************************ //