/**
 * Javascript Form Utils
 */

if ( HP == null ) var HP = {};
if ( HP.Screen == null ) HP.Screen = {};
if ( HP.Screen.Utils == null ) HP.Screen.Utils = {};



HP.Screen.Utils.Slide = function(toSlide, itemToChange, classOnActive) {
	if ( toSlide != '') $(toSlide).slide();
	
	if ( itemToChange != '' && classOnActive != "") {
		itemToChange = $(itemToChange);
		itemToChange.toggleClass(classOnActive);
	}
}

HP.Screen.Utils.GetPraemien = function(Abo, Language, Container, Form, Bestellbar) {
	$(Form).products_id.value = Abo;
	
	var myRequest = new Request.JSON({
		"url"		: "/AJAXRequest",
		"method"	: "post",
		"data"		: {
			"namespace" : "Frontend.Praemien",
			"Abo" 		: Abo,
			"Language"	: Language
		},
		"onSuccess" : function(responseJSON, responseText) {
			//alert(responseText);
			var C = $(Container);
			
	        var PictureWindow;
	        var Button;
	        var AdditionalInfoButton;
	        var item;
	        
	        C.empty();
	        //alert(responseJSON.length);
	        for(i=0; i < responseJSON.length; i++) {
	        	item = responseJSON[i];

	        	if (Bestellbar) {
		        	Button = new Element("a", {
		        		"href"  : "#",
		        		"html" 	: item.linkname,
		        		"ref"	: item.products_id, 
		        		"class"	: "AboKaufenButton",
		                "events" : {
		        			"click" : function() {
		        				$('products_form').praemien_id.value = this.getAttribute("ref");
	                			$('products_form').submit();
	                			
	                			return false;
	                		}
		        		}
		        	});
	        	}
	        	
	        	AdditionalInfoButton = new Element("a", {
	        		"href"  	: "#",
	        		"styles"	: {
	        			"width":120,"height":110,"top":0
	        			
	        		},
	        		/*"class"	: "AdditionalInfoButton",*/
	        		"rel"	: "<b>" + item.products_name + "</b><br />" + item.products_description
/*	        		
	                "events" : {
	        			"mouseover" : function() {
	        				alert(item.products_description);
                		}
	        		}
*/
	        	});

	            PictureWindow = new Element("div", {
	                "class"   : "left small bold AdditionalInfoButton",
	                "rel"	: "<b>" + item.products_name + "</b><br />" + item.products_description,
	            	"styles"    : {
	                    "background"    : "url('"+item.products_image+"') top center no-repeat",
	                    "width"			: 120,
	                    "height"		: 150,
	                    "opacity"		: 0,
	                    "text-align"	: "center",
	                    "padding"		: "5px 0px 0px 0px",
	                    "margin"		: "0px 4px 0px 0px"
	                },
	                "html"	: ""/*item.products_name*/
	            }); 
	            
	            if (Bestellbar) { Button.inject(PictureWindow); }
	            AdditionalInfoButton.inject(PictureWindow);
	            PictureWindow.inject(C);
	            PictureWindow.tween("opacity",1);
	        }
	        
	        
        	// Tooltips erzeugen    
			window.addEvent("domready", function() {
				var Labeltips = new Tips($$('.AdditionalInfoButton'),{
					onShow: function(toolTipElement){
				    	toolTipElement.fade(1);
					},
					onHide: function(toolTipElement){
				    	toolTipElement.fade(0);
					}				
				});
			});   
	        
		}
	});
	
	myRequest.send();	
	
}
