function stopMusic()
{
	document.getElementById("radioplayer").stop();
}

function playMusic()
{
	document.getElementById("radioplayer").play();
}

function hoverImage(hoverCode)
{
	var oldSrc = E(hoverCode+'_n').src;

	E(hoverCode+'_n').src = E(hoverCode+'_h').src;
	E(hoverCode+'_h').src = oldSrc;
}

function ajax_encode(content)
{
	content = Base64.encode(content).replace(/\+/gi, "{F_PLUS}");

	return content;
}

var browserCheck = new RegExp('Microsoft', 'i'); // fuck microsoft and their stupid rules

if(browserCheck.test(navigator.appName))
{
	var app = "ie";
}
else
{
	var app = "moz";
}

var currentTarget;
var mouseX;
var mouseY;

function setTarget(event)
{
	if(!document.body)
	{
		return false;
	}

	var e = event || window.event;

	currentTarget = e.target || e.srcElement;

	if(app == "ie")
	{
		mouseX = event.clientX + parseInt((document.body.scrollLeft) ? document.body.scrollLeft : document.documentElement.scrollLeft);
		mouseY = event.clientY + parseInt((document.body.scrollTop) ? document.body.scrollTop : document.documentElement.scrollTop);
	}
	else
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
}

AttachEvent(document, 'mousemove', setTarget, false);

function getUserSelection()
{
	var cSelection;

	if (window.getSelection) {
		cSelection = String(window.getSelection());
	}
	else if (document.selection) { // should come last; Opera!
		cSelection = String(document.selection.createRange().text);
	}

	cSelection = cSelection.trim();

	return cSelection;
}

function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue)
{
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)", "i") : null;
    var oCurrent;
    var oAttribute;

    for(var i=0; i<arrElements.length; i++)
    {
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);

        if(typeof oAttribute == "string" && oAttribute.length > 0)
	{
            if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute)))
	    {
                arrReturnElements.push(oCurrent);
            }
        }
    }

    return arrReturnElements;
}

function Viewport()
{
	this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;
	this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
	this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
	this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
	this.pageX = (document.documentElement && document.documentElement.scrollWidth) 
		? document.documentElement.scrollWidth 
		: (document.body.scrollWidth > document.body.offsetWidth) 
			? document.body.scrollWidth 
			: document.body.offsetWidth; 
	this.pageY = (document.documentElement && document.documentElement.scrollHeight) 
		? document.documentElement.scrollHeight 
		: (document.body.scrollHeight > document.body.offsetHeight) 
			? document.body.scrollHeight 
			: document.body.offsetHeight;
}

function parent_found(elCode)
{
	if(!currentTarget)
	{
		return false;
	}

	//	if(currentTarget.id == 'globalBox_'+menuIndex || currentTarget.id == 'submenu_'+menuIndex || currentTarget.id == 'mainMenuholder_'+menuIndex)
	if(currentTarget.id == elCode)
	{
		return true;
	}
	else
	{
		// loop parents node:
		tempTarget = currentTarget.parentNode;

		while(tempTarget)
		{
			//if(tempTarget.id == 'globalBox_'+menuIndex || tempTarget.id == 'submenu_'+menuIndex || tempTarget.id == 'mainMenuholder_'+menuIndex)
			if(tempTarget.id == elCode)
			{
				return true
				break;
			}
			else
			{
				tempTarget = tempTarget.parentNode;
			}
		}
	}

	return false;
}

function validateURL(urlID)
{
	var urlElement = E(urlID);

	var urlValue = urlElement.value;
	var urlPrefix;

	var optionToSelect;

	if(!urlValue.trim())
	{
		return false
	}
	else
	{
		// I.E. Needs value assigned to var first :(
		if(urlValue.match(/^([a-z]*\:\/\/)/gi))
		{
			urlPrefix = /^([a-z]*\:\/\/)/gi.exec(urlValue)[0];

			urlValue = urlValue.replace(/^([a-z]*\:\/\/)/gi, "");
		}
		else
		{
			urlPrefix = "";
		}

		if(urlPrefix.trim())
		{
			switch(urlPrefix)
			{
				case "http://":
					optionToSelect = 0;
				break;

				case "https://":
					optionToSelect = 2;
				break;

				case "ftp://":
					optionToSelect = 1;
				break;

				case "ssl://":
					optionToSelect = 3;
				break;

				case "news://":
					optionToSelect = 4;
				break;
			}

			E('website_0_p').selectedIndex = optionToSelect;

			urlElement.value = urlValue;
		}

		return true;
	}
}

// use $ instead of getElementById
function E(obj)
{
	var newObj;

	if (arguments.length > 1)
	{
		for (var i = 0, objects = []; i < arguments.length; i++)
		{
			if(document.getElementById(arguments[i]) !== null)
			{
				objects.push(E(arguments[i]));
			}
		}
		return objects;
	}

	if (typeof obj == 'string')
	{
		newObj = document.getElementById(obj);
	}
	return newObj;
}

String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function()
{
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function()
{
	return this.replace(/\s+$/,"");
}

//***Cross browser attach event function. For 'evt' pass a string value with the leading "on" omitted
//***e.g. AttachEvent(window,'load',MyFunctionNameWithoutParenthesis,false);
function AttachEvent(obj,evt,fnc,useCapture)
{
	if (!useCapture) useCapture=false;
	if (obj.addEventListener){
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
	else{
		MyAttachEvent(obj,evt,fnc);
		obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
	}
} 

//The following are for browsers like NS4 or IE5Mac which don't support either
//attachEvent or addEventListener
function MyAttachEvent(obj,evt,fnc)
{
	if (!obj.myEvents) obj.myEvents={};
	if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
	var evts = obj.myEvents[evt];
	evts[evts.length]=fnc;
}

function MyFireEvent(obj,evt)
{
	if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
	var evts = obj.myEvents[evt];
	for (var i=0,len=evts.length;i<len;i++) evts[i]();
}


var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}

function getElementsByClassName(oElm, strTagName, strClassName)
{
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++)
	{
		oElement = arrElements[i];

		if(oRegExp.test(oElement.className))
		{
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function htmlentities (string, quote_style)
{
	// Convert all applicable characters to HTML entities  
	// version: 1004.2314
	// original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	var hash_map = {}, symbol = '', tmp_str = '', entity = '';
	tmp_str = string.toString();    
	if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
		return false;
	}
	hash_map["'"] = '&#039;';    for (symbol in hash_map) {
		entity = hash_map[symbol];
		tmp_str = tmp_str.split(symbol).join(entity);
	}
	return tmp_str;
}

function get_html_translation_table (table, quote_style)
{
	// Returns the internal translation table used by htmlspecialchars and htmlentities  
	// version: 1004.2314
	// original by: Philip Peterson

	var entities = {}, hash_map = {}, decimal = 0, symbol = '';    var constMappingTable = {}, constMappingQuoteStyle = {};
	var useTable = {}, useQuoteStyle = {};

	// Translate arguments
	constMappingTable[0]      = 'HTML_SPECIALCHARS';    constMappingTable[1]      = 'HTML_ENTITIES';
	constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
	constMappingQuoteStyle[2] = 'ENT_COMPAT';
	constMappingQuoteStyle[3] = 'ENT_QUOTES';
	 useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
	useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';

	if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
		throw new Error("Table: "+useTable+' not supported');        // return false;
	}

	entities['38'] = '&amp;';
	if (useTable === 'HTML_ENTITIES') {        entities['160'] = '&nbsp;';
		entities['161'] = '&iexcl;';
		entities['162'] = '&cent;';
		entities['163'] = '&pound;';
		entities['164'] = '&curren;';        entities['165'] = '&yen;';
		entities['166'] = '&brvbar;';
		entities['167'] = '&sect;';
		entities['168'] = '&uml;';
		entities['169'] = '&copy;';        entities['170'] = '&ordf;';
		entities['171'] = '&laquo;';
		entities['172'] = '&not;';
		entities['173'] = '&shy;';
		entities['174'] = '&reg;';        entities['175'] = '&macr;';
		entities['176'] = '&deg;';
		entities['177'] = '&plusmn;';
		entities['178'] = '&sup2;';
		entities['179'] = '&sup3;';        entities['180'] = '&acute;';
		entities['181'] = '&micro;';
		entities['182'] = '&para;';
		entities['183'] = '&middot;';
		entities['184'] = '&cedil;';        entities['185'] = '&sup1;';
		entities['186'] = '&ordm;';
		entities['187'] = '&raquo;';
		entities['188'] = '&frac14;';
		entities['189'] = '&frac12;';        entities['190'] = '&frac34;';
		entities['191'] = '&iquest;';
		entities['192'] = '&Agrave;';
		entities['193'] = '&Aacute;';
		entities['194'] = '&Acirc;';        entities['195'] = '&Atilde;';
		entities['196'] = '&Auml;';
		entities['197'] = '&Aring;';
		entities['198'] = '&AElig;';
		entities['199'] = '&Ccedil;';        entities['200'] = '&Egrave;';
		entities['201'] = '&Eacute;';
		entities['202'] = '&Ecirc;';
		entities['203'] = '&Euml;';
		entities['204'] = '&Igrave;';        entities['205'] = '&Iacute;';
		entities['206'] = '&Icirc;';
		entities['207'] = '&Iuml;';
		entities['208'] = '&ETH;';
		entities['209'] = '&Ntilde;';        entities['210'] = '&Ograve;';
		entities['211'] = '&Oacute;';
		entities['212'] = '&Ocirc;';
		entities['213'] = '&Otilde;';
		entities['214'] = '&Ouml;';        entities['215'] = '&times;';
		entities['216'] = '&Oslash;';
		entities['217'] = '&Ugrave;';
		entities['218'] = '&Uacute;';
		entities['219'] = '&Ucirc;';        entities['220'] = '&Uuml;';
		entities['221'] = '&Yacute;';
		entities['222'] = '&THORN;';
		entities['223'] = '&szlig;';
		entities['224'] = '&agrave;';        entities['225'] = '&aacute;';
		entities['226'] = '&acirc;';
		entities['227'] = '&atilde;';
		entities['228'] = '&auml;';
		entities['229'] = '&aring;';        entities['230'] = '&aelig;';
		entities['231'] = '&ccedil;';
		entities['232'] = '&egrave;';
		entities['233'] = '&eacute;';
		entities['234'] = '&ecirc;';        entities['235'] = '&euml;';
		entities['236'] = '&igrave;';
		entities['237'] = '&iacute;';
		entities['238'] = '&icirc;';
		entities['239'] = '&iuml;';        entities['240'] = '&eth;';
		entities['241'] = '&ntilde;';
		entities['242'] = '&ograve;';
		entities['243'] = '&oacute;';
		entities['244'] = '&ocirc;';        entities['245'] = '&otilde;';
		entities['246'] = '&ouml;';
		entities['247'] = '&divide;';
		entities['248'] = '&oslash;';
		entities['249'] = '&ugrave;';        entities['250'] = '&uacute;';
		entities['251'] = '&ucirc;';
		entities['252'] = '&uuml;';
		entities['253'] = '&yacute;';
		entities['254'] = '&thorn;';        entities['255'] = '&yuml;';
	}

	if (useQuoteStyle !== 'ENT_NOQUOTES') {
		entities['34'] = '&quot;';    }
	if (useQuoteStyle === 'ENT_QUOTES') {
		entities['39'] = '&#39;';
	}
	entities['60'] = '&lt;';    entities['62'] = '&gt;';


	// ascii decimals to real symbols
	for (decimal in entities) {        symbol = String.fromCharCode(decimal);
		hash_map[symbol] = entities[decimal];
	}

	return hash_map;
}

function html_entity_decode (string, quote_style) {
    // Convert all HTML entities to their applicable characters  
    // version: 1004.2314
    // +   original by: john (http://www.jd-tech.net)

	var hash_map = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {        return false;
    }
 
    // fix &amp; problem
    // http://phpjs.org/functions/get_html_translation_table:416#comment_97660    delete(hash_map['&']);
    hash_map['&'] = '&amp;';
 
    for (symbol in hash_map) {
        entity = hash_map[symbol];        tmp_str = tmp_str.split(entity).join(symbol);
    }
    tmp_str = tmp_str.split('&#039;').join("'");
    
    return tmp_str;
}


/*
	get anchor or return ""
*/

function retrieveAncor()
{
	var wAn = window.location.hash;

	if(wAn.match(/\#.+/gi))
	{
		var newCode = wAn.replace(/\#\!?(.*)/gi, "$1");

		return newCode;
	}
	else
	{
		return "";
	}
}

function parseScript(_source) {
	var source = _source;
	var scripts = new Array();
	
	// Strip out tags
	while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
		var s = source.indexOf("<script");
		var s_e = source.indexOf(">", s);
		var e = source.indexOf("</script", s);
		var e_e = source.indexOf(">", e);
		
		// Add to scripts array
		scripts.push(source.substring(s_e+1, e));
		// Strip from source
		source = source.substring(0, s) + source.substring(e_e+1);
	}
	
	// Loop through every script collected and eval it
	for(var i=0; i<scripts.length; i++) {
		try {
			eval(scripts[i]);
		}
		catch(ex) {
			// do what you want here when a script fails
		}
	}
	
	// Return the cleaned source
	return source;
}

function changePassword(changeBox, passMain)
{
	if(changeBox.checked)
	{
		E(passMain+'_js').value = "";
		E(passMain+'_r_js').value = "";

		E(passMain+'_js').disabled = false;
		E(passMain+'_r_js').disabled = false;
	}
	else
	{
		E(passMain+'_js').value = "*****";
		E(passMain+'_r_js').value = "*****";

		E(passMain+'_js').disabled = true;
		E(passMain+'_r_js').disabled = true;
	}
}

