YAHOO.util.Event.addListener(window, "load", function(){  

/*
	Deadline=new function() {
		this.dateFormatter=function(htmlElement, record, column, data) {
			var dateString=record.getData("date");
			////			
			var day=dateString.substring(8, 10);
			var month=dateString.substring(5, 7);
			var year=dateString.substring(0, 4);
			////
			htmlElement.innerHTML=day+"."+month+"."+year;
		}
		////
		this.locationFormatter=function(elCell, oRecord, oColumn, oData) {  	
	        YAHOO.util.Dom.addClass(elCell, "entf");  	
            ////
            elCell.innerHTML="<span title='Mehr Info' style='color: #333; text-decoration: underline; font-weight: bold'>"+
								oRecord.getData("locationName")+
								"</span>";
		};		
		////
		this.myGoFormatter=function(elCell, oRecord, oColumn, oData) {  	
	        YAHOO.util.Dom.addClass(elCell, "entf");  	
            ////
            if ( oRecord.getData("hasRes")=="0" ) {elCell.innerHTML="<img src='images/icon/go.gif'>";}
            else {elCell.innerHTML="<span style='color:#007700; font-weight: bold;text-decoration: underline;'>angemeldet</span>";}
		};		
		////
		var columnDefs= 
		[  	
			{key: "date", width: "80px", label: "Datum", sortable: true, resizeable: false, formatter: this.dateFormatter},  	
			{key: "locationName", label: "Location", sortable: true, resizeable: false, formatter: this.locationFormatter},  	
			{key: "locationCity", label: "Stadt", sortable: true, resizeable: false},
            {key: "begin", label: "Beginn", width: "40px"},          
			{label: "Anmelden", formatter:this.myGoFormatter, width: "70px"}
		];
		////
		this.myDataSource=new YAHOO.util.DataSource(base_site_path + "reservation/view10?");
		this.myDataSource.responseType=YAHOO.util.DataSource.TYPE_JSON;  
		this.myDataSource.connXhrMode="queueRequests"; 	
		this.myDataSource.responseSchema={  	
            resultsList: "resultSet",   	
			fields: ["id", "date", "begin", 
						"eventID", "eventName",
						"buyIn", "checkIn", 
						"happyCheckIn", "happyBuyIn", 
						"earlyBookingDiscount", "earlyOpenDiscount", "twoForOneDiscount", "twoFriends",
						"happyBuyInCount", "earlyBookingDiscountCount", "earlyOpenDiscountCount", 
						"twoForOneDiscountCount", "twoFriendsCount",
						"awardCategoryID",  
						"locationID", "locationName", "categoryID", "locationCity", "hasRes"
					]  	
		};  
		////
		var configs={  	
			sortedBy: {key: "date", dir: "asc"},  	
			paginated: false,  	
			paginator: {  	
				rowsPerPage: 7,  	
				//dropdownOptions: [10, 25, 50, 100],  	
				pageLinks: 5  	
			}  	
	    }  	
		////
	    this.onEventSelectRow=function(args) {
			var record=this.getRecord(args.target);
			////
			if ( args.target.cellIndex==1 ) {
				$("locationID").value=record.getData("locationID");
				$("location").value=record.getData("locationName");
				$("locationForm").submit();
				return;
			}
			////
			if ( (args.target.cellIndex==4) && (record.getData("hasRes")==0) ) {
				$("deadlineID").value=record.getData("id");
				$("reservationForm").submit();
				return;
			}
	    }
		////
		this.myDataTable=new YAHOO.widget.DataTable("datatable", columnDefs, this.myDataSource, configs);
        ////
		this.myDataTable.subscribe("cellClickEvent", this.onEventSelectRow);
        this.myDataTable.subscribe("rowMouseoverEvent", this.myDataTable.onEventHighlightRow); 
        this.myDataTable.subscribe("rowMouseoutEvent", this.myDataTable.onEventUnhighlightRow); 
        this.myDataTable.subscribe("rowClickEvent", this.myDataTable.onEventSelectRow)
	}
   */
       Deadline=new function() {
        this.dateFormatter=function(htmlElement, record, column, data) {
            var dateString=record.getData("date");
            ////            
            var day=dateString.substring(8, 10);
            var month=dateString.substring(5, 7);
            var year=dateString.substring(0, 4);
            ////
            htmlElement.innerHTML=day+"."+month+"."+year;
        }
        ////
        this.myCustomFormatter=function(elCell, oRecord, oColumn, oData) {      
            YAHOO.util.Dom.addClass(elCell, "entf");      
            ////
           switch ( oRecord.getData("categoryID")*1 ) {
                case 1:
                    elCell.innerHTML="<img src='images/icon/loc-cat-1.gif'>";      
                    break;
                case 2:
                    elCell.innerHTML="<img src='images/icon/loc-cat-2.gif'>";      
                    break;
                case 3:
                    elCell.innerHTML="<img src='images/icon/loc-cat-3.gif'>";      
                    break;
            }
        };        
        ////
        this.myDiscountFormatter=function(elCell, oRecord, oColumn, oData) {      
            YAHOO.util.Dom.addClass(elCell, "entf");      
            ////
            elCell.innerHTML="";
            if ( oRecord.getData("happyBuyInCount")*1>0 ) {elCell.innerHTML+="<img src='images/icon/promo-1.gif'>";}
            if ( oRecord.getData("earlyBookingDiscountCount")*1>0 ) {
                elCell.innerHTML+="<img src='images/icon/promo-2.gif'>";
            }
            if ( oRecord.getData("earlyOpenDiscountCount")*1>0 ) {
                elCell.innerHTML+="<img src='images/icon/promo-3.gif'>";
            }
            if ( oRecord.getData("twoForOneDiscountCount")*1>0 ) {
                elCell.innerHTML+="<img src='images/icon/promo-4.gif'>";
            }
            if ( oRecord.getData("twoFriendsCount")*1>0 ) {elCell.innerHTML+="<img src='images/icon/promo-5.gif'>";}
        };        
        ////
        this.myGoFormatter=function(elCell, oRecord, oColumn, oData) {      
            YAHOO.util.Dom.addClass(elCell, "entf");      
            ////
            if ( oRecord.getData("hasRes")=="0" ) {elCell.innerHTML="<img src='images/icon/go.gif' title='Anmelden'>";}
            else {elCell.innerHTML="<span style='color:#007700; font-weight: bold;text-decoration: underline;'>angemeldet</span>";}
        };        
        ////
        this.locationFormatter=function(elCell, oRecord, oColumn, oData) {      
            YAHOO.util.Dom.addClass(elCell, "entf");      
            ////
            var locName = oRecord.getData("locationName");
            if(locName.length > 15) {
                locName = locName.substring(0, 13) + "...";
            }
            elCell.innerHTML="<span title='Mehr Info' style='color: #333; text-decoration: underline; font-weight: bold'>"+ locName +"</span>";
        };        
        ////
        this.myPlayerFormatter=function(elCell, oRecord, oColumn, oData) {      
            YAHOO.util.Dom.addClass(elCell, "entf");      
            ////
            elCell.innerHTML="<span title='Mehr Info' style='color: #333; text-decoration: underline; font-weight: bold'>"+
                                "Spieler"+
                                "</span>";
        };        
        ////
        this.googleFormatter=function(elCell, oRecord, oColumn, oData) {      
            YAHOO.util.Dom.addClass(elCell, "entf");      
            ////
            elCell.innerHTML="<span title='Google Map' style='color: #333; text-decoration: underline; font-weight: bold'>"+
                                oRecord.getData("locationCity")+
                                "</span>";
        };        
        ////
        var columnDefs= 
        [      
            {key: "date", width: "70px", label: "Datum", sortable: true, resizeable: false, formatter: this.dateFormatter},      
            //{key: "eventName", label: "Event", sortable: true, resizeable: false}, 
            //{label: "", width: "16px",  formatter:this.myCustomFormatter},
            {key: "begin", label: "Beginn", width: "40px"},       
            {key: "locationName", label: "Location", sortable: true, resizeable: false, formatter: this.locationFormatter},      
            {key: "locationCity", width: "70px", label: "Stadt", sortable: true, resizeable: false, formatter: this.googleFormatter},
            {label: "Promo", formatter:this.myDiscountFormatter, width: "40px"},
            {label: "Spieler", formatter:this.myPlayerFormatter, width: "40px"},          
            {label: "Anmelden", formatter:this.myGoFormatter, width: "70px"}
        ];
        ////
        //var params=(locationName=="")?"":"locationName="+locationName;
        this.myDataSource=new YAHOO.util.DataSource(base_site_path + "reservation/view10");
        this.myDataSource.responseType=YAHOO.util.DataSource.TYPE_JSON;  
        this.myDataSource.connXhrMode="queueRequests";     
        this.myDataSource.responseSchema={      
            resultsList: "resultSet",       
            fields: ["id", "date", "begin", 
                        "eventID", "eventName",
                        "buyIn", "checkIn", 
                        "happyCheckIn", "happyBuyIn", 
                        "earlyBookingDiscount", "earlyOpenDiscount", "twoForOneDiscount", "twoFriends",
                        "happyBuyInCount", "earlyBookingDiscountCount", "earlyOpenDiscountCount", 
                        "twoForOneDiscountCount", "twoFriendsCount",
                        "awardCategoryID",  
                        "locationID", "locationName", "categoryID", "locationCity", "hasRes"
                    ]      
        };  
        ////
        var configs={      
            sortedBy: {key: "date", dir: "asc"},      
            paginated: true,      
            paginator: {      
                rowsPerPage: 10,      
                //dropdownOptions: [10, 25, 50, 100],      
                pageLinks: 20      
            }      
        }      
        ////
        this.onEventSelectRow=function(args) {
            var record=this.getRecord(args.target);
            ////
            if ( args.target.cellIndex==2 ) {
                $("locationID").value=record.getData("locationID");
                $("location").value=record.getData("locationName");
                $("locationForm").submit();
                return;
            }
            ////
            if ( args.target.cellIndex==3 ) {
                var attributes="toolbar=no, location=no, status=yes, menubar=0, scrollbars=0, resizable=yes, ";
                attributes+="left=50, top=200, height=300, width=500";
                window.open(base_site_path + "google?id="+record.getData("locationID"), "Search", attributes);
                return;
            }
            if ( args.target.cellIndex==5 ) {
                $("userDeadlineID").value=record.getData("id");
                $("playerForm").submit();
                return;
            }
            if ( (args.target.cellIndex==6) && (record.getData("hasRes") == 0) ) {
                $("deadlineID").value=record.getData("id");
                $("reservationForm").submit();
                return;
            }
        }
        ////
        this.myDataTable=new YAHOO.widget.DataTable("datatable", columnDefs, this.myDataSource, configs);
        ////
        this.myDataTable.subscribe("cellClickEvent", this.onEventSelectRow);
        this.myDataTable.subscribe("rowMouseoverEvent", this.myDataTable.onEventHighlightRow); 
        this.myDataTable.subscribe("rowMouseoutEvent", this.myDataTable.onEventUnhighlightRow); 
        this.myDataTable.subscribe("rowClickEvent", this.myDataTable.onEventSelectRow)
    } 
	//**********************************
    calendarInit();

}); 


//**********************************
function search(){
    var requestSearchParams=getRequest("search");  
	if ( $("searchDate").value!="" ) {requestSearchParams+="&date="+getEnglishDate("searchDate");}
    ////
    $("request").value=requestSearchParams;
    $("toReservation").submit();
}
//**********************************

