function submit_rating(id,rating) {
	if ( rating == '' ) alert('Please enter a rating.');
	else  content('_action.htm?rate_confirm='+id+'&rating='+rating, 'you_say_'+id);
}






function get_related(id) {




	if ($('related_'+id).style.display == 'none' ) {


		/*
		var dim = page_dimensions();
		$('drop_sheet').style.width = dim[0] + 'px';
		$('drop_sheet').style.height = dim[1] + 'px';
		Element.show('drop_sheet');
		*/

		var view = viewport_size();
		var position = scroll_position();


		var spinner_top =  position[1] + parseInt(view[1] / 2) - (32/2);
		var spinner_left =  position[0] + parseInt(view[0] / 2) - (32/2);
		$('spinner').style.top = spinner_top + 'px';
		$('spinner').style.height = spinner_left + 'px';
		Element.show('spinner');



		new Ajax.Updater ('related_'+id+'_content', '_action.htm', {
			postBody: 'related='+id,
			evalScripts: true ,
			onComplete: function () {
				Effect.toggle('related_'+id, 'blind', { duration: 0.3} );
				Effect.Appear('related_'+id);

				//alert(spinner_top+' '+spinner_left);


				//Element.hide('drop_sheet');
				Element.hide('spinner');
			}
		}
		);

	}

	else {
		Effect.toggle('related_'+id, 'blind', { duration: 0.3} );
	}



}







function trim(s)
{
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	{ s = s.substring(1,s.length); }
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	{ s = s.substring(0,s.length-1); }
	return s;
}




function content (url, divname, style) {

	$(divname).innerHTML = 'Loading ...';

	var style = (style == null) ? "none" : style;

	if (divname != null) {
		if (style == 'highlight') {
			new Ajax.Updater(divname, url, { onComplete: function() { new Effect.Highlight(divname, { startcolor: '#f1caab' } ); }, evalScripts: true } );
		}

		if (style == 'none') {
			new Ajax.Updater(divname, url, { evalScripts: true } );
		}
	}


	else {
		new Ajax.Request( url );
	}

}



















function page_dimensions()
{
	var body = document.getElementsByTagName("body")[0];
	var bodyOffsetWidth = 0;
	var bodyOffsetHeight = 0;
	var bodyScrollWidth = 0;
	var bodyScrollHeight = 0;
	var pageDimensions = [0, 0];

	if (typeof document.documentElement != "undefined" &&
	typeof document.documentElement.scrollWidth != "undefined")
	{
		pageDimensions[0] = document.documentElement.scrollWidth;
		pageDimensions[1] = document.documentElement.scrollHeight;
	}

	bodyOffsetWidth = body.offsetWidth;
	bodyOffsetHeight = body.offsetHeight;
	bodyScrollWidth = body.scrollWidth;
	bodyScrollHeight = body.scrollHeight;

	if (bodyOffsetWidth > pageDimensions[0])
	{
		pageDimensions[0] = bodyOffsetWidth;
	}

	if (bodyOffsetHeight > pageDimensions[1])
	{
		pageDimensions[1] = bodyOffsetHeight;
	}

	if (bodyScrollWidth > pageDimensions[0])
	{
		pageDimensions[0] = bodyScrollWidth;
	}

	if (bodyScrollHeight > pageDimensions[1])
	{
		pageDimensions[1] = bodyScrollHeight;
	}

	return pageDimensions;
}




function viewport_size()
{
	var size = [0,0];

	if (typeof window.innerWidth != 'undefined')
	{
		size = [
		window.innerWidth,
		window.innerHeight
		];
	}
	else if (typeof document.documentElement != 'undefined'
	&& typeof document.documentElement.clientWidth != 'undefined'
	&& document.documentElement.clientWidth != 0)
	{
		size = [
		document.documentElement.clientWidth,
		document.documentElement.clientHeight
		];
	}
	else
	{
		size = [
		document.getElementsByTagName('body')[0].clientWidth,
		document.getElementsByTagName('body')[0].clientHeight
		];
	}

	return size;
}




function scroll_position()
{
	var position = [0, 0];

	if (typeof window.pageYOffset != 'undefined')
	{
		position = [
		window.pageXOffset,
		window.pageYOffset
		];
	}

	if (typeof document.documentElement.scrollTop != 'undefined'
	&& document.documentElement.scrollTop > 0)
	{
		position = [
		document.documentElement.scrollLeft,
		document.documentElement.scrollTop
		];
	}

	else if(typeof document.body.scrollTop != 'undefined')
	{
		position = [
		document.body.scrollLeft,
		document.body.scrollTop
		];
	}

	return position;
}











/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="images/spacer.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e){
	if (enabletip){
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
			nondefaultpos=true
		}
		else if (curX<leftedge)
		tipobj.style.left="5px"
		else{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			pointerobj.style.left=curX+offsetfromcursorX+"px"
		}

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight){
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			nondefaultpos=true
		}
		else{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
		}
		tipobj.style.visibility="visible"
		if (!nondefaultpos)
		pointerobj.style.visibility="visible"
		else
		pointerobj.style.visibility="hidden"
	}
}

function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		pointerobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove=positiontip













/*
* Copyright (c) 2006 Jonathan Weiss <jw@innerewut.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


/* tooltip-0.1.js - Small tooltip library on top of Prototype
* by Jonathan Weiss <jw@innerewut.de> distributed under the BSD license.
*
* Unlike other libraries it does not declare its own tooltip
* div or window. It relies on an already existing div or element defined by you to display as
* the tooltip. This element will be placed (and shown) near the mouse pointer when a trigger-element is moused-over.
*
*
* Usage:
*   <script src="/javascripts/prototype.js" type="text/javascript"></script>
*   <script src="/javascripts/tooltip.js" type="text/javascript"></script>
*   <script type="text/javascript">
*     var my_tooltip = new Tooltip('id_of_trigger_element', 'id_of_tooltip_to_show_element')
*   </script>
*
* Now whenever you trigger a mouseOver on the `trigger` element, the tooltip element will
* be shown. On o mouseOut the tooltip disappears.
*
* Example:
*
*   <script src="/javascripts/prototype.js" type="text/javascript"></script>
*   <script src="/javascripts/scriptaculous.js" type="text/javascript"></script>
*   <script src="/javascripts/tooltip.js" type="text/javascript"></script>
*
*   <div id='tooltip' style="display:none; margin: 5px; background-color: red;">
*     Detail infos on product 1....<br />
*   </div>
*
*   <div id='product_1'>
*     This is product 1
*   </div>
*
*   <script type="text/javascript">
*     var my_tooltip = new Tooltip('product_1', 'tooltip')
*   </script>
*
* You can use my_tooltip.destroy() to remove the event observers and thereby the tooltip.
*/

var Tooltip = Class.create();
Tooltip.prototype = {
	initialize: function(element, tool_tip) {
		var options = Object.extend({
			default_css: false,
			margin: "0px",
			padding: "5px",
			backgroundColor: "#d6d6fc",
			delta_x: 5,
			delta_y: 5,
			zindex: 1000
		}, arguments[1] || {});

		this.element      = $(element);
		this.tool_tip     = $(tool_tip);

		this.options      = options;

		// hide the tool-tip by default
		this.tool_tip.hide();

		this.eventMouseOver = this.showTooltip.bindAsEventListener(this);
		this.eventMouseOut   = this.hideTooltip.bindAsEventListener(this);

		this.registerEvents();
	},

	destroy: function() {
		Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
		Event.stopObserving(this.element, "mouseout", this.eventMouseOut);
	},

	registerEvents: function() {
		Event.observe(this.element, "mouseover", this.eventMouseOver);
		Event.observe(this.element, "mouseout", this.eventMouseOut);
	},

	showTooltip: function(event){
		Event.stop(event);
		// get Mouse position
		var mouse_x = Event.pointerX(event);
		var mouse_y = Event.pointerY(event);


		// decide if wee need to switch sides for the tooltip
		var dimensions = Element.getDimensions( this.tool_tip );
		var element_width = dimensions.width;
		var element_height = dimensions.height;

		if ( (element_width + mouse_x) >= ( this.getWindowWidth() - this.options.delta_x) ){ // too big for X
			mouse_x = mouse_x - element_width;
			// apply delta to make sure that the mouse is not on the tool-tip
			mouse_x = mouse_x - this.options.delta_x;
		} else {
			mouse_x = mouse_x + this.options.delta_x;
		}

		if ( (element_height + mouse_y) >= ( this.getWindowHeight() - this.options.delta_y) ){ // too big for Y
			mouse_y = mouse_y - element_height;
			// apply delta to make sure that the mouse is not on the tool-tip
			mouse_y = mouse_y - this.options.delta_y;
		} else {
			mouse_y = mouse_y + this.options.delta_y;
		}

		// now set the right styles
		this.setStyles(mouse_x, mouse_y);


		// finally show the Tooltip
		//new Effect.Appear(this.tool_tip);
		new Element.show(this.tool_tip);

	},

	setStyles: function(x, y){
		// set the right styles to position the tool tip
		Element.setStyle(this.tool_tip, { position:'absolute',
		top:y + "px",
		left:x + "px",
		zindex:this.options.zindex
		});

		// apply default theme if wanted
		if (this.options.default_css){
			Element.setStyle(this.tool_tip, { margin:this.options.margin,
			padding:this.options.padding,
			backgroundColor:this.options.backgroundColor,
			zindex:this.options.zindex
			});
		}
	},

	hideTooltip: function(event){
		//new Effect.Fade(this.tool_tip);
		new Element.hide(this.tool_tip);
	},

	getWindowHeight: function(){
		var innerHeight;
		if (navigator.appVersion.indexOf('MSIE')>0) {
			innerHeight = document.body.clientHeight;
		} else {
			innerHeight = window.innerHeight;
		}
		return innerHeight;
	},

	getWindowWidth: function(){
		var innerWidth;
		if (navigator.appVersion.indexOf('MSIE')>0) {
			innerWidth = document.body.clientWidth;
		} else {
			innerWidth = window.innerWidth;
		}
		return innerWidth;
	}

}