YAHOO.namespace("cywalk.Pages");

YAHOO.cywalk.Pages.Default = function() {
	this.scrollBox = null;
	this.bildlaufFlash = null;
	this.tickerFlash = null;
	
	this.shopDialogHTML = null;
	this.shopDialog = null;
	
	this.shopDataList = [];
	
};

YAHOO.cywalk.Pages.Default.prototype.initialize = function() {
	
	// this.scrollBox = new YAHOO.cywalk.HTMLScroller("scrollbox", "content", "scrollbar", 474);
	 
	this.tickerFlash = new SWFObject("fileadmin/templates/layout/flash/whisky.swf", "flashPictures", "237", "641", "0", "#000000");
 	this.tickerFlash.write("flashPictures");
 	
 	this.shopDialogHTML = document.createElement("div");
 	this.shopDialogHTML.id = "ShopDialog";
 	YAHOO.util.Dom.setStyle(this.shopDialogHTML, "zIndex", "1000");
 	this.shopDialogHTML.innerHTML = '<div class="bd" style="450px;"></div><div class="ft" style="width:450px;"></div>';
 	YAHOO.util.Dom.addClass(this.shopDialogHTML, "shopDialog");
 	YAHOO.util.Dom.get("contentBox").appendChild(this.shopDialogHTML);
 	 	
 	this.shopDialog = new YAHOO.widget.Dialog(this.shopDialogHTML, {
 		visible: false,
 		close: false,
 		context: ["contentBox"],
 		effect: {effect: YAHOO.widget.ContainerEffect.FADE, duration:0.5 }
 	});
 	this.shopDialog.render();
 	
};

YAHOO.cywalk.Pages.Default.prototype.createFooterHTMLElement = function(showShopLink) {
	
	var footerHTML = document.createElement("span");
	
	if (showShopLink == true) {
		var  imageLink =  footerHTML.appendChild(document.createElement("img"));
		imageLink.src = "fileadmin/templates/layout/img/shop/shop_link.png";
		YAHOO.util.Dom.addClass(imageLink, "closeButton");
		if (YAHOO.env.ua.ie == 0) {
			YAHOO.util.Dom.setStyle(imageLink, "marginRight", "4px;");
		}
		YAHOO.util.Dom.addClass(imageLink, "goShop");
		YAHOO.util.Event.addListener(imageLink, "click", function(e) { 
			self.location.href="spirituosen-wein/whiskyshop/uebersicht.html";
		}, this, true);
	}
	
	var  imageLink =  footerHTML.appendChild(document.createElement("img"));
	imageLink.src = "fileadmin/templates/layout/img/shop/dialog/closebutton.png";
	YAHOO.util.Dom.addClass(imageLink, "closeButton");
	YAHOO.util.Event.addListener(imageLink, "click", function(e) { 
		this.shopDialog.hide();
	}, this, true);
	
	return footerHTML;
}

YAHOO.cywalk.Pages.Default.prototype.openShopDialog = function(articleID) {

	if (!YAHOO.lang.isUndefined(this.shopDataList[articleID])) {
		this.shopDialog.setBody(this.shopDataList[articleID]);		
	}
	else {
		this.shopDialog.setBody("");
		YAHOO.util.Connect.asyncRequest('GET', 'index.php?id='+articleID, {
			success: function(o) {
				this.shopDataList[articleID] = o.responseText;
				this.shopDialog.setBody(o.responseText);
				this.shopDialog.setFooter(this.createFooterHTMLElement(false));
			},
			scope: this
		});
	}

	this.shopDialog.bringToTop();
	this.shopDialog.show();

}; // Ende der Methode: openShopDialog()

/**
 * Öffnet den Dialog zur Darstellung der Detailseite
 */
YAHOO.cywalk.Pages.Default.prototype.openShopDetailDialog = function(url) {

		this.shopDialog.setBody("");
		YAHOO.util.Connect.asyncRequest('GET', url, {
			success: function(o) {
				this.shopDialog.setBody(o.responseText);
				this.shopDialog.setFooter(this.createFooterHTMLElement(false));
			},
			scope: this
	});

	this.shopDialog.bringToTop();
	this.shopDialog.show();

}; // Ende der Methode: openShopDialog()

YAHOO.cywalk.Pages.Default.prototype.FinalizeOrder = function(finalizeURL) {
	
	var errorMessages = [];
	
	var personinfo_first_name = YAHOO.util.Dom.get('personinfo_first_name');
	if (YAHOO.lang.isUndefined(personinfo_first_name) || (YAHOO.lang.trim(personinfo_first_name.value).length == 0)) {
		errorMessages[errorMessages.length] = "* Das Feld Vorname ist erforderlich!";
	}
	
	var personinfo_last_name = YAHOO.util.Dom.get('personinfo_last_name');
	if (YAHOO.lang.isUndefined(personinfo_last_name) || (YAHOO.lang.trim(personinfo_last_name.value).length == 0)) {
		errorMessages[errorMessages.length] = "* Das Feld Nachname ist erforderlich!";
	}
	
	var personinfo_address = YAHOO.util.Dom.get('personinfo_address');
	if (YAHOO.lang.isUndefined(personinfo_address) || (YAHOO.lang.trim(personinfo_address.value).length == 0)) {
		errorMessages[errorMessages.length] = "* Das Feld Adresse ist erforderlich!";
	}
	
	var personinfo_zip = YAHOO.util.Dom.get('personinfo_zip');
	if (YAHOO.lang.isUndefined(personinfo_zip) || (YAHOO.lang.trim(personinfo_zip.value).length == 0)) {
		errorMessages[errorMessages.length] = "* Das Feld PLZ ist erforderlich!";
	}
	
	var personinfo_city = YAHOO.util.Dom.get('personinfo_city');
	if (YAHOO.lang.isUndefined(personinfo_city) || (YAHOO.lang.trim(personinfo_city.value).length == 0)) {
		errorMessages[errorMessages.length] = "* Das Feld Ort ist erforderlich!";
	}
	
	var personinfo_telephone = YAHOO.util.Dom.get('personinfo_telephone');
	if (YAHOO.lang.isUndefined(personinfo_telephone) || (YAHOO.lang.trim(personinfo_telephone.value).length == 0)) {
		errorMessages[errorMessages.length] = "* Das Feld Telefon ist erforderlich!";
	}
	
	var personinfo_email = YAHOO.util.Dom.get('personinfo_email');
	if (YAHOO.lang.isUndefined(personinfo_email) || (YAHOO.lang.trim(personinfo_email.value).length == 0)) {
		errorMessages[errorMessages.length] = "* Das Feld E-Mail ist erforderlich!";
	}
	
	var personinfo_agb = YAHOO.util.Dom.get('personinfo_agb');
	if (YAHOO.lang.isUndefined(personinfo_agb) || (personinfo_agb.checked == false)) {
		errorMessages[errorMessages.length] = "* Best\u00e4tigen Sie bitte, dass sie \u00fcber 18 Jahre sind!";
	}
	
	if (errorMessages.length > 0) {
		alert("Korrigieren Sie bitte die folgenden Eingaben:\n" + errorMessages.join("\n"));
		return;
	}
	
	// Kommando setzen
	document.getElementById('products_payment').value = 1;
	
	// Action setzten und Formular senden
	var registrationForm = YAHOO.util.Dom.get('registrationForm');
	registrationForm.action = finalizeURL;
	registrationForm.submit();
}

YAHOO.cywalk.Pages.Default.Instance = new YAHOO.cywalk.Pages.Default();