var calObject = {
	init : function(){
		this.overLayContainer 	= document.getElementById("overlayBox");
		this.calendarContainer 	= document.getElementById("calendarContainer");
	},

	hideOverlay : function(){
		this.overLayContainer.style.display = "none";
	},

	showEvent : function(eStr){
		this.overLayContainer.innerHTML = eStr;
		this.overLayContainer.style.display = "block";
	},

	getEvent : function(itemID, bgImageOpened){
		this.sItem 			= document.getElementById(itemID);
		this.sItem.newImage = bgImageOpened;
		this.sItem.itemID   = itemID;
		this.sItem.axEvent  = "getEvent";
		this.sItem.cbEvent  = "setEvent";

		if(this.getCookieValueByName("calendarItemSet") == itemID){
			//itemID = "alreadyOpened";
		}

		this.ax_callMethod(this.sItem.axEvent, itemID, this.sItem.cbEvent);
	},

	recallLastEvent : function(){
		this.ax_callMethod(this.sItem.axEvent, this.sItem.itemID, this.sItem.cbEvent);
	},

	alreadyOpened : function(){
		this.ax_callMethod("getEvent", "alreadyOpened", "setEvent");
	},

	thanksForTakingPart : function(){
		this.ax_callMethod("getEvent", "thanksForTakingPart", "setEvent");
	},

	notYetOpened : function(daysLeft){
		this.ax_callMethod("getNotYetOpened", "notYetOpened,"+daysLeft, "setEvent");
	},

	showInfoScreen : function(){
		this.ax_callMethod("getEvent", "infoScreen", "setEvent");
	},

	activateDoor : function(){
		this.sItem.style.backgroundImage 	= "url("+this.sItem.newImage+")";
		anchor 								= this.sItem.getElementsByTagName("a");
		anchor[0].className 				= "disabled";
		document.cookie 					= "calendarItemSet="+this.sItem.id+";expires=Tue, 30 Nov 2010 13:58:23 GMT";

		this.thanksForTakingPart();
	},

	e_addUser : function(uData){
		uString = "";
		fError = false;
		for(var i = 0;i < uData.length; i++){
			if(uData.elements[i].value != undefined){
				if(uData.elements[i].type == "checkbox"){
					uData.elements[i].value = uData.elements[i].checked;
				}

				if(uData.elements[i].type == "text" && (uData.elements[i].value == "" || uData.elements[i].value == "Vorname*" || uData.elements[i].value == "Nachname*"  || uData.elements[i].value == "E-Mail Adresse*")){
					fError = true;
				}

				uString += uData.elements[i].value+";";
			}
		}

		if(fError == false)
			this.ax_callMethod("addUser", uString, "activateDoor");
		else
			alert("Bitte tragen Sie Ihre Daten in das Formular ein.");

	},

	ac_setEvent : function(r){
		this.showEvent(r);
	},

	ax_callMethod : function(axMethod, param, callBack){
		pAjaxCallMethod("dp_christmasCalendarEventHolder", axMethod, param, callBack);
	},

	getCookieValueByName : function(strName){
		if(!document.cookie){
			return false;
		}

		var c   = document.cookie;
		var tmp = c.split(";")
		for(var i in tmp){
			var cookieDesc = tmp[i].split("=");
			if(strName == cookieDesc[0].replace(" ", "")){
				return cookieDesc[1];
			}
		}

		return false;
	}
}



/**
 * function openWindow
 * opens window with defined parameters
 *
 * @param windowUrl
 * @param width window width
 * @param height window height
 * @param left left position
 * @param top top position
 * @param windowName
 */
function openWindow(windowUrl, width , height , left , top , windowName, scrollbars){
	if(width == undefined || width == 0)
		width = 680;

	if(height == undefined || height == 0)
		height = 480;

	if(top == undefined)
		top = 100;

	if(left == undefined)
		left = 100;

	if(scrollbars == undefined)
		scrollbars = "yes";


	var windowOpener = window.open(windowUrl, windowName, "resizable=yes,width="+width+",height="+height+",left="+left+",top="+top+",toolbar=no,menubar=no,scrollbars="+scrollbars+"");

	windowOpener.focus();
	return windowOpener;
}

