var g_intUnAvailable = new Array();
var g_datStart = new Date();
var g_datEnd = new Date();
var g_strSeasons = new Array();
var g_strStart = new Array('',0,0,0,0);
var g_strEnd = new Array('',0,0,0,0);
var g_strSelectedDayId = '';
var g_strCalc = new Array();
var g_strMonthLong = new Array('Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December');
var g_strMonth = new Array('jan','feb','mrt','apr','mei','jun','jul','aug','sep','okt','nov','dec');
var g_srtReserved = '';

function SetUnAvailableDay(p_intDay)
{
    var l_intCounter = g_intUnAvailable.length;
    g_intUnAvailable[l_intCounter] = p_intDay;
}

function SetSeason(p_strSeason, p_intFromYear, p_intFromMonth, p_intFromDay, p_intTillYear, p_intTillMonth, p_intTillDay, p_intPrice, p_intSecPrice)
{
    //alert(p_strSeason);
    if(p_intSecPrice == 0)
        p_intSecPrice = p_intPrice;
    var l_intCounter = g_strSeasons.length;
    g_strSeasons[l_intCounter] = new Array();
    g_strSeasons[l_intCounter][0] = p_strSeason;
    g_strSeasons[l_intCounter][1] = new Date(p_intFromYear,p_intFromMonth-1,p_intFromDay, 00,00,00);
    g_strSeasons[l_intCounter][2] = new Date(p_intTillYear,p_intTillMonth-1,p_intTillDay, 00,00,00);
    g_strSeasons[l_intCounter][3] = p_intPrice;
    g_strSeasons[l_intCounter][4] = p_intSecPrice;
}

function IsAvailable()
{
    var l_blnOutput = true;
    var l_intCounter = 0;
    var l_strStart =  g_strStart;
    var l_strEnd =  g_strEnd;
    if(l_strStart[1] > l_strEnd[1])
    {
        var l_strTemp = l_strEnd;
        l_strEnd = l_strStart;
        l_strStart = l_strTemp;
    }
    while(l_intCounter < g_intUnAvailable.length)
    {
    //alert(g_intUnAvailable[l_intCounter] + ' - ' + l_strStart[1] + ' - ' + l_strEnd[1])
        if(g_intUnAvailable[l_intCounter] >= l_strStart[1] && g_intUnAvailable[l_intCounter] < l_strEnd[1])
            l_blnOutput = false;
        l_intCounter++;
    }
    if(!l_blnOutput)
    {
        g_strEnd = new Array('',0,0,0,0,0);
        alert('Door u gemaakte selectie is niet mogelijk!');
    }
}

function DaySelect(p_objDiv, p_intDayId, p_intYear, p_intMonth, p_intDay)
{
    var l_strId = p_objDiv.getAttribute('id');
    var l_strPosition = p_objDiv.getAttribute('position');
    var l_datDate = new Date();
    l_datDate.setFullYear(p_intYear,p_intMonth-1,p_intDay, 00,00,00);
/*
    if(l_strId == g_strStart[0])
    {
        DeleteDates();
        g_strStart = new Array('',0,0,0,0,0);
    }
    else if(l_strId == g_strEnd[0])
    {
        DeleteDates();
        g_strEnd = new Array('',0,0,0,0,0);
    }
    else
    {
        if(g_strStart[0] == '')
        {
            g_strStart[0] = l_strId;
            g_strStart[1] = p_intDayId;
            g_strStart[2] = p_intYear;
            g_strStart[3] = p_intMonth;
            g_strStart[4] = p_intDay;
            g_strStart[5] = l_datDate;
        }
        else if(g_strEnd[0] == '')
        {
            g_strEnd[0] = l_strId;
            g_strEnd[1] = p_intDayId;
            g_strEnd[2] = p_intYear;
            g_strEnd[3] = p_intMonth;
            g_strEnd[4] = p_intDay;
            g_strEnd[5] = l_datDate;
            IsAvailable();
        }
    }
*/
    if(g_strStart[0] == '')
    {
        g_strStart[0] = l_strId;
        g_strStart[1] = p_intDayId;
        g_strStart[2] = p_intYear;
        g_strStart[3] = p_intMonth;
        g_strStart[4] = p_intDay;
        g_strStart[5] = l_datDate;
    }
    else if(g_strEnd[0] == '')
    {
        if(l_strId == g_strStart[0])
        {
            DeleteDates();
            g_strStart = new Array('',0,0,0,0,0);
            g_strEnd = new Array('',0,0,0,0,0);         
        }
        else
        {
            g_strEnd[0] = l_strId;
            g_strEnd[1] = p_intDayId;
            g_strEnd[2] = p_intYear;
            g_strEnd[3] = p_intMonth;
            g_strEnd[4] = p_intDay;
            g_strEnd[5] = l_datDate;
            IsAvailable();
        }
    }
    else
    {
        DeleteDates();
        g_strStart = new Array('',0,0,0,0,0);
        g_strEnd = new Array('',0,0,0,0,0);
        g_strStart[0] = l_strId;
        g_strStart[1] = p_intDayId;
        g_strStart[2] = p_intYear;
        g_strStart[3] = p_intMonth;
        g_strStart[4] = p_intDay;
        g_strStart[5] = l_datDate;
    }
        
    SetDates();
    SetSelectedDates();
}

function DeleteDates()
{
    var l_intCounter = 0;
    while(l_intCounter < g_strSelectedDayId.length)
    {
        document.getElementById(g_strSelectedDayId[l_intCounter][0]).style.backgroundPosition = g_strSelectedDayId[l_intCounter][1];
        l_intCounter++;
    }
}

function SetDates()
{
    if(g_strEnd[0] != '' && g_strStart[0] != '')
    {
        if(g_strEnd[1] < g_strStart[1])
        {
            var l_strDates = g_strStart;
            g_strStart = g_strEnd;
            g_strEnd = l_strDates;
        }
    }
    else if(g_strEnd[0] != '' && g_strStart[0] == '')
    {
        g_strStart = g_strEnd;
        g_strEnd = new Array('',0,0,0,0,0);
    }
}

function CalculateForm()
{
    if(g_strEnd[0] != '' && g_strStart[0] != '')
    {
        var l_intCounter = 0;
        var l_strOldSeason = '';
        var l_intSeasonCounter = 0;
        var l_strOutput = '<div id="CalculateDiv">';
        var l_strOutput2 = '';
        var l_datDate = new Date();
        var l_datDate2 = new Date();
        var l_datStart = g_strStart[5];
        var l_datEnd = g_strEnd[5];
        var l_intPrice = 0;
        while(l_intCounter < g_strCalc.length)
        {
            l_datDate = g_strCalc[l_intCounter][1];
            //l_datDate2 = g_strCalc[l_intCounter][1];
            if(l_intCounter+1 < g_strCalc.length)
                l_datDate2 = g_strCalc[l_intCounter+1][1];
            else
                l_datDate2 = g_strEnd[5];
            if(l_intCounter == 0)
            {
                l_strOutput += '<div class="TitleOrangeBold2"><div class="CalendarBtn" id="CalendarBtn" onclick="ReserveForm()"></div>Reservering van ' + l_datStart.getDate() + ' ' + g_strMonth[l_datStart.getMonth()] + ' ' + l_datStart.getFullYear() + ' tot ' + l_datEnd.getDate() + ' ' + g_strMonth[l_datEnd.getMonth()] + ' ' + l_datEnd.getFullYear() + '</div>';
                l_strOutput += '<div style="position:relative; float:left; width:300px; padding-bottom:5px;"><b>Periode</b></div><div style="position:relative; float:left; width:60px;"><b>Prijs</b></div><div style="clear:both;"></div>';
                l_strOutput += '<div style="font-size:0px; width:350px; border-bottom: solid 1px Black;"></div>';
                l_strOutput2 += '<table border=0 cellspacing=0><tr><td style="width:300px; font-weight:bold; border-bottom: solid 1px Black;">Periode</td><td style="width:60px; font-weight:bold; border-bottom: solid 1px Black;">Prijs</td></tr>'
            }
            
            l_strOutput2 += '<tr><td style="width:300px;">' + l_datDate.getDate() + ' ' + g_strMonth[l_datDate.getMonth()] + ' ' + l_datDate.getFullYear() + ' tot ' + l_datDate2.getDate() + ' ' + g_strMonth[l_datDate2.getMonth()] + ' ' + l_datDate2.getFullYear() + '</td><td style="width:60px;">&euro; ' + g_strCalc[l_intCounter][2] + ',-</td></tr>';
            
            l_strOutput += '<div style="position:relative; float:left; width:300px; padding-bottom:5px;">' + l_datDate.getDate() + ' ' + g_strMonth[l_datDate.getMonth()] + ' ' + l_datDate.getFullYear() + ' tot ' + l_datDate2.getDate() + ' ' + g_strMonth[l_datDate2.getMonth()] + ' ' + l_datDate2.getFullYear() + '</div><div style="position:relative; float:left; width:60px;">&euro; ' + g_strCalc[l_intCounter][2] + ',-</div><div style="clear:both;"></div>';
            l_intPrice += g_strCalc[l_intCounter][2];
            l_strOutput += '';
            l_intCounter++;
        }
        l_strOutput2 += '<tr><td style="width:300px; font-weight:bold; text-align:right;">Totaal&nbsp;&nbsp;&nbsp;</td><td style="width:50px; font-weight:bold; border-top: solid 1px Black; ">&euro; ' + l_intPrice + ',-</td></tr>'
        l_strOutput2 += '</table>';
        l_strOutput += '<div style="clear:both; height:10px;"></div>';
        l_strOutput += '<div style="position:relative; float:left; width:300px; padding-bottom:5px; text-align:right;">Totaal&nbsp;&nbsp;&nbsp;</div><div style="position:relative; float:left; width:60px; border-top: solid 1px Black">&euro; ' + l_intPrice + ',-</div><div style="clear:both;"></div>';
        l_strOutput += '</div>';
        var l_objTarget = document.getElementById('CalculateFrom');
        l_objTarget.innerHTML = l_strOutput;
        document.getElementById('BerekeningDiv').innerHTML = l_strOutput2;
        
        document.getElementById('BerekeningInput').value = l_strOutput2.replace(/</g, "#<#").replace(/>/g, "#>#");
        document.getElementById('BerekeningPrice').value = l_intPrice + ',-';
        //document.getElementById('CalculateDiv').style.display = 'none';
        document.getElementById('GenCalendar').style.display = 'none';
        document.getElementById('GoToCalendarBtn').style.display = 'block'; 
        l_objTarget.style.display = 'block';
    }
    else
    {
        alert('Om een berekening te maken moeten er twee datum geselecteerd zijn!');
    }
}

function ReserveForm()
{
    if(g_strStart[0] != '' && g_strEnd[0] != '')
    {
        document.getElementById('HouseFrom').value = g_strStart[3] + '-' + g_strStart[4] + '-' + g_strStart[2];
        document.getElementById('HouseTill').value = g_strEnd[3] + '-' + g_strEnd[4] + '-' + g_strEnd[2];
        document.getElementById('HouseFrom2').value = g_strStart[4] + '-' + g_strStart[3] + '-' + g_strStart[2];
        document.getElementById('HouseTill2').value = g_strEnd[4] + '-' + g_strEnd[3] + '-' + g_strEnd[2];
        document.getElementById('HouseFrom3').value = g_strStart[4] + '-' + g_strStart[3] + '-' + g_strStart[2];
        document.getElementById('HouseTill3').value = g_strEnd[4] + '-' + g_strEnd[3] + '-' + g_strEnd[2];
        //CloseDiv('Huis_');BerekeningDiv
        document.getElementById('CalculateDiv').style.display = 'none';
        document.getElementById('HouseForm').style.display = 'block';
        document.getElementById('GoToCalendarBtn').style.display = 'block';
    }
    else
    {
        alert('U moet eerste een selectie maken van de gewenste periode');
    }
    
}

function GoToCalendar()
{
    document.getElementById('CalculateDiv').style.display = 'none';
    document.getElementById('HouseForm').style.display = 'none';
    document.getElementById('GoToCalendarBtn').style.display = 'none';
    document.getElementById('GenCalendar').style.display = 'block';
}

function ShowExtraGasten()
{
    ShowExtraGasten2();
    document.getElementById('FooterContainer').style.bottom = '2px';
}


function ShowExtraGasten2()
{
    var l_intValue = document.getElementById('AantalGasten').value;
    var l_intCounter = 0;
    var l_objGuest = document.getElementById('Gast_' + l_intCounter);
    while(l_objGuest)
    {
        if(l_intCounter < l_intValue)
            l_objGuest.style.display = 'block';
        else
            l_objGuest.style.display = 'none';
        l_intCounter++;
        l_objGuest = document.getElementById('Gast_' + l_intCounter);
    }
    //alert(0%3);
}

function SetSelectedDates()
{
    var l_intCounter = 0;
    var l_intCounter2 = 0;
    var l_strId = '';
    var l_intStart = l_strId[1];
    var l_objDay = '';
    var l_intSubCounter = 0;
    var l_strLastWeek = '';
    var l_intCalc = 0;
        l_strId = g_strEnd[0].split('_');
    
    var l_strOldSeason = '';
    if(g_strStart[0] != '' && g_strEnd[0] != '')
    {
        l_strId = g_strEnd[0].split('_');
        l_intCounter2 = g_strStart[1];
        g_strSelectedDayId = new Array();
        g_strCalc = new Array();
        while(l_intCounter2 < g_strEnd[1])
        {
            l_intSubCounter = 0;
            l_objDay = document.getElementById('Day_'+l_intCounter2);
            g_strSelectedDayId[l_intCounter] = new Array();
            g_strSelectedDayId[l_intCounter][0] = l_objDay.getAttribute('id');
            g_strSelectedDayId[l_intCounter][1] = l_objDay.getAttribute('position');
            g_strSelectedDayId[l_intCounter][2] = l_objDay.getAttribute('switch');

            if(g_strSelectedDayId[l_intCounter][2])
            {
                g_strSelectedDayId[l_intCounter][3] = new Date(l_objDay.getAttribute('year'),l_objDay.getAttribute('month')-1,l_objDay.getAttribute('day'), 00,00,00);
                while(l_intSubCounter < g_strSeasons.length)
                {
                    if(g_strSelectedDayId[l_intCounter][3] >= g_strSeasons[l_intSubCounter][1] && g_strSelectedDayId[l_intCounter][3] < g_strSeasons[l_intSubCounter][2])
                    {
                        l_intCalc = g_strCalc.length;
                        g_strCalc[l_intCalc] = new Array();
                        g_strCalc[l_intCalc][0] = g_strSeasons[l_intSubCounter][0];
                        g_strCalc[l_intCalc][1] = g_strSelectedDayId[l_intCounter][3];
                        if(l_strOldSeason == g_strSeasons[l_intSubCounter][0])
                        {
                            g_strCalc[l_intCalc][0] = '';
                            g_strCalc[l_intCalc][2] = g_strSeasons[l_intSubCounter][4];
                        }
                        else
                        {
                            g_strCalc[l_intCalc][2] = g_strSeasons[l_intSubCounter][3];
                        }
                        l_strOldSeason = g_strSeasons[l_intSubCounter][0];
                    }
                    l_intSubCounter++;
                }
            
            }

            if(l_intCounter2 == g_strStart[1])
                l_objDay.style.backgroundPosition= GetSelectedStyle((g_strSelectedDayId[l_intCounter][1]), 0, true);
            else
                l_objDay.style.backgroundPosition= GetSelectedStyle((g_strSelectedDayId[l_intCounter][1]), 1, true);
            l_intCounter++;
            l_intCounter2++;
        }
        //document.getElementById('Calc').innerHTML = g_strCalc;
        l_objDay = document.getElementById('Day_'+l_intCounter2);
        g_strSelectedDayId[l_intCounter] = new Array();
        g_strSelectedDayId[l_intCounter][0] = l_objDay.getAttribute('id');
        g_strSelectedDayId[l_intCounter][1] = l_objDay.getAttribute('position');
        g_strSelectedDayId[l_intCounter][2] = l_objDay.getAttribute('switch'); 

        l_objDay.style.backgroundPosition= GetSelectedStyle(g_strSelectedDayId[l_intCounter][1], 2, true);
    }
    else if(g_strStart[0] != '')
    {
        l_strId = g_strStart[0].split('_');
        l_intCounter2 = g_strStart[1];
        l_objDay = document.getElementById('Day_'+l_intCounter2)
        g_strSelectedDayId = new Array();
        g_strSelectedDayId[l_intCounter] = new Array();
        g_strSelectedDayId[l_intCounter][0] = l_objDay.getAttribute('id');
        g_strSelectedDayId[l_intCounter][1] = l_objDay.getAttribute('position');
        g_strSelectedDayId[l_intCounter][2] = l_objDay.getAttribute('switch');

        l_objDay.style.backgroundPosition= GetSelectedStyle(g_strSelectedDayId[l_intCounter][1], 0, false);
    }
}

function RedirectSelect(p_objObject)
{
window.location=p_objObject.value;
}

function GetSelectedStyle(p_intStyle, p_intSwitch, p_blnAlphaOmega)
{
    switch(p_intSwitch)
    {
        case 0:
            switch(p_blnAlphaOmega)
            {
                case true:
                    switch(p_intStyle)
                    {
                    case '-207px -48px':
                        return '-276px -192px';
                        break;
                    case '-69px -240px':
                        return '-276px -240px';
                        break;
                    case '-69px -48px':
                        return '-276px -48px';
                        break;
                    case '-69px -144px':
                        return '-276px -144px';
                        break;
                    }
                    break;
                default:
                    switch(p_intStyle)
                    {
                    case '-345px -48px':
                        return '-345px -192px';
                        break;
                    case '-207px -48px':
                        return '-207px -192px';
                        break;
                    case '-69px -144px':
                        return '-276px -144px';
                        break;
                    case '-69px -240px':
                        return '-276px -240px';
                        break;
                    case '-69px -48px':
                        return '-276px -192px';
                        break;
                    }
                    break;
            }
            break;
        case 1:
            switch(p_intStyle)
            {
                default:
                    return '-276px -192px';
                    break;
            }
            break;
        case 2:
            switch(p_intStyle)
            {
                case '-345px -48px':
                    return '-345px -192px';
                    break;
                case '-207px -48px':
                    return '-207px -192px';
                    break;
                default:
                    return '-69px -192px';
                    break;
            }
            break;
    }
}