function was_rated(jokes_key, jokes_rate, returned_average){

	dom_toggle_element("ratemenu" + jokes_key, false);
	dom_toggle_element("hide_rate" + jokes_key, true);

	jokes_rating_pic = document.getElementById("jokes_rating_pic" + jokes_key);

	jokes_rating_pic.src = PATH + "/img/site/rating/bar_" + Math.ceil(returned_average) + ".gif";
}

// LOADING BAR v1.1 ---------------------------------------------------------------------------------------------------------------------
// display a loading bar at given coordinates
function loadingBar(position, loadMsg, endLoadMsg, useCSS, type, gradient, dimensions) {

	// R - this variable can only be read
	// R/W - this variable can be read and also overwritten

	this.loadBand = null;				// referrence to the colored loading bar that displays progress - R
	this.ldBar = null;				// referrence to the loading bar element - R
	this.locationHandle = null;			// id of the element where the loadingBar is parsed, if any - R/W
	this.position = position;			// position of loading bar is formed as "top position, left position"(eg: "middle,right") or as "left coord, top Coord"(eg: "300px,200px" or "50%,100%"), top positions can be "top, middle, bottom", left positions can be "left, middle, right" - R/W
	this.loadMsg = loadMsg; 			// message displayed while the loading is in progress - R/W
	this.endLoadMsg = endLoadMsg; 			// message displayed after the loading has finished - R/W
	this.useCSS = useCSS;				// css to use for the loading bar - R/W
	this.loadBarStyle = null;			// core style of the loader - R
	this.loadBarContent = null;			// text currently displayed inside the loading bar - R/W
	this.callErrors = false;			// prototype displays help if this is set as true - R
	this.stylePosition = null;			// can be absolute, relative and fixed, it is used in loading bar container style - R
	this.width = 200;				// default load bar width
	this.height = 50;				// default load bar height
	this.left = 0;					// default load bar left coordinate
	this.top = 0;					// default load bar top coordinate
	this.coord = [0,0];				// current coordinates of loader if position is not relative - R
	this.intRefresher = null;			// refresher interval referrence - R
	this.intFinisher = null;			// finisher interval referrence - R
	this.refreshSpeed = 0;				// interval in miliseconds at which the refresher runs - R
	this.runningTime = 0;				// miliseconds from the moment the loading process started - R
	this.loadingInterval = 0;			// number of miliseconds since the start and the end of the loading progress animation - R
	this.loadBandWidth = 0;				// current width(pixels) of the loading band - R
	this.progressRate = 0;				// progress rate in percent for refresher
	this.progressRateWidth = 0;			// progress rate in width for refresher
	this.progressPercent = 0;			// howmuch of the loading bar is filled (percent)
	this.startColor = [0,0,0];			// gradient start color
	this.endColor = [0,0,0];			// gradient end color
	this.globalAux = "";				// gobal aux variable used for different purposes during development and testing

	// detect microsoft IE - R
	this.isMSIE = (navigator.appName.toLowerCase().indexOf("microsoft") >= 0) ? true : false;

	// set lower loader refresh speed for IE as it is slower and does not manage to finish the loading
	this.refreshSpeed = this.isMSIE ? 100 : 50;

	// extract width and height
	if (dimensions) {
		var aux = dimensions.split("x");
		this.width = aux[0];
		this.height = aux[1];
	}

	// set type to "temporary" (default) or "persistent" to hide the loading bar after loading ended or to keep displaing it. - R/W
	this.type = (type=="temporary") ? "temporary" : "persistent";

	// loading effect gradient - R/W
	this.gradient = gradient ? ((gradient.replace("#","")).replace("#","")).split("-") : "FF0000-0000FF".split("-");

	// create unique id for this instance of the loading bar - R
	this.loadBarId = ("loadBar" + Math.random(2000)).replace("0.","");

	// set errors
	this.callErrors = position ? false : true;

	// DISPLAY LOADING BAR -----------------------------------------------------------------------------------------------------
	this.display = function () {
		this.ldBar.style.display = "";

		this.loadBand.style.width = "1px";
		this.loadBand.style.display = "";
	};

	// HIDE LOADING BAR ----------------------------------------------------------------------------------------------------------
	this.hide = function () {
		// unset onscroll event to prevent useless processing
		if(!this.locationHandle){
			window.onscroll = null;
		}

		// one last refresh to display full bar
		this.refresh("last");

		clearInterval(this.intRefresher);
		clearInterval(this.intFinisher);

		this.intFinisher = null;
		this.intRefresher = null;

		this.runningTime = 0;
		this.loadingInterval = 0;
		this.loadBandWidth = 0;
		this.progressRate = 0;
	};

	// START LOADING ----------------------------------------------------------------------------------------------------------
	// set loading interval (milliseconds) and start loading
	this.start = function (interval) {
		this.loadingInterval = interval;

		// if no bar has been created, create it now
		if (!this.ldBar) {
			this.createBar();
		}

		// if it is IE, set the onScroll event to drag the element after it so it is kept in it's initial position on the screen
		if (this.isMSIE && !this.locationHandle) {
			window.onscroll = this.tune4IE;
			// tune it up one time to make sure the element is correctly positioned
			this.tune4IE();
		}

		this.display();

		// run first refresh to prepare bar
		this.refresh("first");

		this.intRefresher = setInterval("loadBar.refresh();", this.refreshSpeed);
		this.intFinisher = setInterval("loadBar.hide();", this.loadingInterval);
	};

	// REFRESHER ---------------------------------------------------------------------------------------------------------------
	// display loading progress on loadBar
	this.refresh = function (refreshMoment) {

		// get progress rate
		if (!this.progressRate && this.loadingInterval) {
			this.progressRate = this.refreshSpeed / (this.loadingInterval / 1000);
			this.progressPercent = this.progressRate;
			this.progressRateWidth = (this.width / 1000) * this.progressRate;
		}

		// if finisher has not triggered yet
		if (this.intFinisher || refreshMoment) {
			if (refreshMoment == "last") {
				this.loadBand.style.backgroundColor = "#" + this.gradient[1];
				this.loadBand.style.width = this.width;
			}
			else {
				this.globalAux += " | " + this.getGradientColor(this.progressPercent, 1000, this.gradient[0], this.gradient[1]);
				this.loadBand.style.backgroundColor = this.getGradientColor(this.progressPercent, 1000, this.gradient[0], this.gradient[1]);

				this.runningTime += this.refreshSpeed;
				this.loadBandWidth += this.progressRateWidth;
				this.loadBand.style.width = this.loadBandWidth;
				this.progressPercent += this.progressRate;
			}
		}

		// if this is the last refresh, hide the bar
		if (refreshMoment == "last") {
			setTimeout('loadBar.ldBar.style.display = "none";loadBar.loadBand.style.display = "none";', 100);
		}
	};

	// FINISHED LOADING ----------------------------------------------------------------------------------------------------------
	// this event must occur when the content has finished loading so that the bar will quickly end it's progress
	this.finished = function () {
		if (this.type == "temporary") {
			this.hide();
		}
	};

	// GET GRADIENT COLOR ----------------------------------------------------------------------------------------------------------
	// get color positioned at the color location ("position" on given scale from 1 to "scale" 0 beeing the "startColor" and "scale" + 1 beeing the endColor) between the "startColor" and "endColor" (HEX with no #)
	this.getGradientColor = function (position, scale, startcolor, endcolor) {

		// get numeric RGB values for startColor
		if (!this.startColor[0]) {
			this.startColor[0] = hexToDec(startcolor.substring(0,2));
		}
		if (!this.startColor[1]) {
			this.startColor[1] = hexToDec(startcolor.substring(2,4));
		}
		if (!this.startColor[2]) {
			this.startColor[2] = hexToDec(startcolor.substring(4,6));
		}

		// get numeric RGB values for endColor
		if (!this.endColor[0]) {
			this.endColor[0] = hexToDec(endcolor.substring(0,2));
		}
		if (!this.endColor[1]) {
			this.endColor[1] = hexToDec(endcolor.substring(2,4));
		}
		if (!this.endColor[2]) {
			this.endColor[2] = hexToDec(endcolor.substring(4,6));
		}

		var thisColor = [0,0,0];

		// calculate red for current color
		if ((this.endColor[0] - this.startColor[0]) != 0) {
			thisColor[0] = Math.round(this.startColor[0] + (position * ((this.endColor[0] - this.startColor[0])/scale)));
		}

		// calculate blue for current color
		if ((this.endColor[1] - this.startColor[1]) != 0) {
			thisColor[1] = Math.round(this.startColor[1] + (position * ((this.endColor[1] - this.startColor[1])/scale)));
		}

		// calculate green for current color
		if ((this.endColor[2] - this.startColor[2]) != 0) {
			thisColor[2] = Math.round(this.startColor[2] + (position * ((this.endColor[2] - this.startColor[2])/scale)));
		}

		thisColor[0] = (thisColor[0] > 255) ? 255 : (thisColor[0] < 0) ? 0 : thisColor[0];
		thisColor[1] = (thisColor[1] > 255) ? 255 : (thisColor[1] < 0) ? 0 : thisColor[1];
		thisColor[2] = (thisColor[2] > 255) ? 255 : (thisColor[2] < 0) ? 0 : thisColor[2];

		return "#" + decToHex(thisColor[0]) + decToHex(thisColor[1]) + decToHex(thisColor[2]);
	};

	// HEX TO DECIMAL ----------------------------------------------------------------------------------------------------------
	// convert from hexadecimal to decimal
	function hexToDec(hex) {
		return parseInt(hex.toUpperCase(),16);
	};

	// DECIMAL TO HEX ----------------------------------------------------------------------------------------------------------
	// convert from decimal to hexadecimal
	function decToHex(dec)
	{
		var hexStr = "0123456789ABCDEF";
		var low = dec % 16;
		var high = (dec - low)/16;
		return "" + hexStr.charAt(high) + hexStr.charAt(low);
	};

	// PROCESS LOCATION DATA ----------------------------------------------------------------------------------------------------------
	// process the data in the position param and fill-in global object configuration params
	// the position param can be formed as "center" or "top position, left position"(eg: "middle,right") or as "left coord, top Coord"(eg: "300px,200px" or "50%,100%"), top positions can be "top, middle, bottom", left positions can be "left, middle, right"
	// if top position exists and does not match any of the above formats it will be considered as location handle for relative positioning
	this.processLocation = function (position) {

		// position test samples
		// this.position = "top,right";
		// this.position = "300px,400px";
		// this.position = "70%,20%";
		// this.position = "center";

		// check position format
		var locationReg = /((top|middle|bottom),(left|middle|right))|([0-9]+(px|\%),[0-9]+(px|\%))|center/;
		var posMatch = locationReg.exec(this.position);

		// if found coordinates
		if (posMatch) {

			var screenWidth = window.innerWidth ? window.innerWidth : document.body.offsetWidth;
			var screenHeight = window.innerHeight ? window.innerHeight : document.body.offsetHeight;

			// set location to center
			if(posMatch[0] == "center"){
				this.coord = [Math.round(screenHeight/2), Math.round(screenWidth/2)];
			}
			// set location to percent
			else if(posMatch[5] == "%" && posMatch[6] == "%"){
				var aux = this.position.split(",");
				aux[0] = aux[0].replace("%","");
				aux[1] = aux[1].replace("%","");

				this.coord = [Math.round((screenHeight/100) * aux[0]), Math.round((screenWidth/100) * aux[1])];
			}
			// set location to pixels
			else if(posMatch[5] == "px" && posMatch[6] == "px"){
				var aux = this.position.split(",");
				this.coord = [aux[0].replace("px",""),aux[1].replace("px","")];
			}
			// set verbal coordinate posMatch[2], posMatch[3]
			else {
				var aux = this.position.split(",");

				if (aux[0] == "top") {
					this.coord[0] = Math.round(this.height/2) + 4;
				}
				else if (aux[0] == "middle") {
					this.coord[0] = Math.round(screenHeight/2);
				}
				else if (aux[0] == "bottom") {
					this.coord[0] = screenHeight - Math.round(this.height/2) - 4;
				}

				if (aux[1] == "left") {
					this.coord[1] = Math.round(this.width/2) + 4;
				}
				else if (aux[1] == "middle") {
					this.coord[1] = Math.round(screenWidth/2);
				}
				else if (aux[1] == "right") {
					this.coord[1] = screenWidth - Math.round(this.width/2) - 20;
				}
			}
		}
		// else, it must be a element handle
		else {
			this.locationHandle = document.getElementById(this.position);
		}
	};

	// CREATE LOADING BAR ELEMENT ----------------------------------------------------------------------------------------------------------
	// creates actual loading bar element and returns a referrence to it
	this.createBar = function () {

		// process data from the position param
		this.processLocation();

		// save initial position
		this.top = this.coord[0];
		this.left = this.coord[1];

		// set append location to document's body
		var appendLocation = document.body;

		// if position is made on a location handle
		if (this.locationHandle) {
			// set append position on the location handle
			var appendLocation = this.locationHandle;

			// set style for relative positioning
			this.loadBarStyle = "position: relative; display: none; width: " + this.width + "px; height: " + this.height + "px;";
		}
		else {
			// if position is fixed and this is IE, set position as absolute and onscroll event
			if (this.isMSIE) {
				this.stylePosition = "absolute";

				this.coord[0] = this.coord[0]*1 + document.body.scrollTop;
				this.coord[1] = this.coord[1]*1 + document.body.scrollLeft;
			}
			// else set W3C compliant "fixed" position
			else{
				this.stylePosition = "fixed";
			}

			this.coord[0] = this.coord[0]*1 - Math.round(this.height/2);
			this.coord[1] = this.coord[1]*1 - Math.round(this.width/2);

			// set style for absolute positioning
			this.loadBarStyle = "position: " + this.stylePosition + "; top: " + this.coord[0] + "px; left: " + this.coord[1] + "px; width: " + this.width + "px; height: " + this.height + "px; display: none;";
		}

		// build bar html
		this.loadBarHtml = '<table class="' + this.useCSS + '" cellpadding="0" cellspacing="0" width="' + this.width + '" height="' + this.height + '"><tr><td valign="middle"> </td></tr></table>';

		// create for IE
		if (this.isMSIE) {
			// create loader container
			this.ldBar = document.createElement("div");
			appendLocation.appendChild(this.ldBar);

			// create loader as inner html on it's container
			this.ldBar.innerHTML = '<div id="' + this.loadBarId + '" style="' + this.loadBarStyle + '">' + this.loadBarHtml + '</div>';
		}
		// create for W3C standards
		else {
			this.ldBar = document.createElement("div");
			this.ldBar.setAttribute("id", this.loadBarId);
			this.ldBar.setAttribute("style", this.loadBarStyle);
			appendLocation.appendChild(this.ldBar);

			// append inner html to loader
			this.ldBar.innerHTML = this.loadBarHtml;
		}

		// get referrence to loadBar element using it's ID to ensure the this.ldBar is pointed right
		this.ldBar = document.getElementById(this.loadBarId);

		// set zIndex for loading bar
		this.ldBar.style.zIndex = 10;

		// create loading band element and get referrence to it by id
		this.loadBand = document.createElement("div");
		this.loadBand.setAttribute("id", this.loadBarId + "Band");
		document.body.appendChild(this.loadBand);
		this.loadBand = document.getElementById(this.loadBarId + "Band");
		this.ldBar.style.zIndex = this.ldBar.style.zIndex - 1;

		// get coordinates of locationHandle if loadBar is in relative positioning
		if (this.locationHandle) {
			var loadBandPos = this.getRecurCoord(this.locationHandle);
		}
		else {
			var loadBandPos = [this.ldBar.style.left, this.ldBar.style.top];
		}

		// position and prepare the loading band under the loadBar
		this.loadBand.innerHTML = "";
		this.loadBand.style.position = (this.stylePosition == "fixed") ? "fixed" : "absolute";
		this.loadBand.style.backgroundColor = "#dddddd";
		this.loadBand.style.left = loadBandPos[0];
		this.loadBand.style.top = loadBandPos[1];
		this.loadBand.style.width = "1px";
		this.loadBand.style.height = this.height + "px";

		// get referrence to loadBar content container td
		this.loadBarContent = this.ldBar.childNodes[0].childNodes[0].childNodes[0].childNodes[0];

		// write text
		this.loadBarContent.innerHTML = loadMsg;
	};

	// GET RECUR COORD ------------------------------------------------------------------------------------------------------------
	// recursively get coordinates of relatively positioned element
	this.getRecurCoord = function (el){
		var left = 0;
		var top = 0;
		if (el.offsetParent) {
			while (el.offsetParent) {
				left += el.offsetLeft;
				top += el.offsetTop;
				el = el.offsetParent;
			}
		}

		return [left,top];
	};

	// TUNE FOR IE ------------------------------------------------------------------------------------------------------------
	// tune absolute position for Internet Explorer, this. cannot be used because in IE the event will point the this. referrence to the event triggering element
	this.tune4IE = function (){
		// calculate new position
		loadBar.coord[0] = document.body.scrollTop + loadBar.top * 1 - Math.round(loadBar.height/2);
		loadBar.coord[1] = document.body.scrollLeft + loadBar.left * 1 - Math.round(loadBar.width/2);

		// reposition msgBox
		loadBar.ldBar.style.top = loadBar.coord[0];
		loadBar.ldBar.style.left = loadBar.coord[1];

		// reposition loading band
		loadBar.loadBand.style.top = loadBar.coord[0];
		loadBar.loadBand.style.left = loadBar.coord[1];
	};

	// SHOW HELP INFO ----------------------------------------------------------------------------------------------------------
	// when called, this function displays help about the loadingBar object
	this.help = function(){
		var helpMsg = 'LOADING BAR OBJECT HELP #####################################\n\n';
		helpMsg += 'OBJECT INSTANCING ========================================\n';
		helpMsg += '\nSyntax ---------------------------------------------------------------------------------------\n';
		helpMsg += 'var loadBar = new loadingBar(bar_position, load_message, end_of_load_message, css_class_to_use, loader_type, loading_effect_gradient, dimensions);\n';
		helpMsg += '\nExample ---------------------------------------------------------------------------------------\n';
		helpMsg += 'var loadBar = new loadingBar("middle,top", "Data is loading, please wait...", "Loading Finished!", "loadBarCSS", "persistent", "#FF0000-#0000FF");';
		helpMsg += '\n\nPARAMETERS ============================================\n';
		helpMsg += '\n1. bar_position (required): position of the bar(examples: "middle,top", "right,bottom", "100%,40%", "200px,300px", "center", "id_of_container_element"). The "id_of_container_element" represents the id of the html element where you want the loading bar to be parsed, if used the bar will be relatively positioned.';
		helpMsg += '\n\n2. load_message (optional): message that will be shown on the loading bar while the loading is in progress';
		helpMsg += '\n\n3. end_of_load_message (optional): message that will be shown on the loading bar after the loading is finished';
		helpMsg += '\n\n4. css_class_to_use (optional): css class used by the loading bar, default is loadBarCSS with sub levels loadBarCSS table and loadBarCSS td';
		helpMsg += '\n\n5. loader_type (optional): can be "temporary"(will hide after loading) or "persistent"(will remain after loading)';
		helpMsg += '\n\n6. loading_effect_gradient (optional): as "start_color-end_color" both in hexa format, loadbar color will progress thru this gradient while loading';
		helpMsg += '\n\n7. dimensions (optional): as "widthxheight" example: "200x300", if not given default is used';
		helpMsg += '\n\nUSAGE =================================================\n\n';
		helpMsg += 'after creating an instance with loadBar = new loadingBar() as explained above, the loading process cand be started by using the loadBar.start(total_duration_in_milliseconds) function. If the loading finished event can be caught then the loadBar.finished() function should be called so that the loading bar ends the progress exactly the same time as the loaded element finished loading';
		helpMsg += '\n\nNOTIFICATION ==========================================\n\n';
		helpMsg += 'this help message is either displayed as a result of calling the loadBar.help() function or by making a wrong call to the prototype function when trying to create an instance of the loading bar.';
		helpMsg += '\n\nWARNING ===============================================\n\n';
		helpMsg += 'loadingBar cannot function in multiple instances and it is required that the used instance be named "loadBar"';

		alert(helpMsg);
	};

	if (this.callErrors) {
		// display help if call errors
		this.help();
	}
}


function form_set_select_id(sel_id, form_name, sel_index) {
	var obj = dom_get_element(sel_id);

	var sel_length = obj.length;

	for (optionCounter = 0; optionCounter < sel_length; optionCounter++) {
		if (obj.options[optionCounter].value == sel_index){
			obj.selectedIndex = optionCounter;
		}
	}
}

function CounterText(field, cntfield, maxlimit) {
	var obj_field = dom_get_element(field);
	var obj_cntfield = dom_get_element(cntfield);
	if (obj_field.value.length > maxlimit){
        		obj_field.value = obj_field.value.substring(0, maxlimit);
	}
   	else {
       		obj_cntfield.value = maxlimit - obj_field.value.length;
   	}
}

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(){ //v3.0
        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];
                   }
        }
}


