// changes the calendar
function change_calendar(iMonth, iYear)
{
    // if the xmlHttp is ready to accept commands
    if (ready_to_accept())
    {
        // open the GET
        xmlHttp.open('GET', '/ajax_commands/change_calendar.php?day=01&month=' + iMonth + '&year=' + iYear);
        // trigger a function when the state changes
        xmlHttp.onreadystatechange = function myFunction()
        {
            // if the xmlHttp is ready to process
            if (ready_to_process())
            {
                // take the code and put inside the division
                document.getElementById('calendar').innerHTML = xmlHttp.responseText;
                refresh_tips();
            }
        };
        // send the command
        xmlHttp.send(null);
    }
    else
    {
        // set the time out to recall the function after 250ms
        setTimeout('change_calendar(' + iMonth + ',' + iYear + ')', 250);
    }
}

function refresh_tips()
{
	$$('tr.weeks td a.tips_ovascene').each(function(element) {  
	    if (element.get('title'))
	    {
		    var content = element.get('title').split('::');  
		    element.store('tip:title', content[0]);  
		    element.store('tip:text', content[1]);  
		}
	});
	var tipsOvascene = new Tips($$('tr.weeks td a.tips_ovascene'), {
		fixed: true,
		offsets: {'x': -249, 'y': -9},
		className: 'tipsOvascene'
	});

	$$('tr.weeks td a.tips_regional').each(function(element) {  
	    if (element.get('title'))
	    {
		    var content = element.get('title').split('::');  
		    element.store('tip:title', content[0]);  
		    element.store('tip:text', content[1]);  
		}
	});
	var tipsRegional = new Tips($$('tr.weeks td a.tips_regional'), {
		fixed: true,
		offsets: {'x': -249, 'y': -9},
		className: 'tipsRegional'
	});
}

function onLoadHandler()
{
    setTimeout('refresh_tips()', 1000);
}

window.onload = onLoadHandler;

window.addEvent('domready',function(){
	var menu = new Openmoomenu ('ul.nav',{
		delay: 400,
		animate: {
		props: ['opacity', 'width', 'height'],
		options: {
			duration:500,
				fps: 100,
				transition: Fx.Transitions.Sine.easeOut
			}
		}
	});	
});

$jquery(document).ready(function()
{
    $jquery("a[rel^='prettyPhoto']").prettyPhoto(
    {
        animationSpeed: 'normal', /* fast/slow/normal */
        padding: 40, /* padding for each side of the picture */
        opacity: 0.35, /* Value betwee 0 and 1 */
        showTitle: true, /* true/false */
        allowresize: false, /* true/false */
        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
        theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
    });
    
    setTimeout('refresh_tips()', 1000);
    
});

function get_extra_person(iExtraTicket)
{
    if (ready_to_accept())
    {
        xmlHttp.open('GET', '/ajax_commands/get_extra_person.php?supplement_ticket=' + iExtraTicket);
        
        xmlHttp.onreadystatechange = function myFunction()
        {
            if (ready_to_process())
            {
                document.getElementById('number_' + iExtraTicket).value = xmlHttp.responseText;
            }
        }
        
        xmlHttp.send(null);
    }
    else
    {
        setTimeout('get_extra_person(' + iExtraTicket + ')', 250);
    }
}

// get the regular price for an event
function get_regular_price(iEventId, iExtraTicket, iTotalExtras)
{
    // if ready to accept
    if (ready_to_accept())
    {
        // open the xml feed
        xmlHttp.open('GET', '/ajax_commands/get_regular_price.php?events_id=' + iEventId);
        
        // when the status changes
        xmlHttp.onreadystatechange = function myFunction()
        {
            // if ready to process
            if (ready_to_process())
            {
                // get the price and place it into the html zone
                document.getElementById('regular_price_' + iExtraTicket).innerHTML = Math.abs(xmlHttp.responseText).toFixed(2);
                
                // if the extra ticket is different than the total
                if ((iExtraTicket + 1) != iTotalExtras)
                {
                    if (document.getElementById('row_supplement_' + (iExtraTicket + 1)) !== null)
                    {
                        // set the next droplist to show
                        document.getElementById('row_supplement_' + (iExtraTicket + 1)).style.display = '';
                    }
                }
                // get_extra_person(iExtraTicket);
                
                setTimeout('calculate_extra_price(' + iExtraTicket + ')', 250);
            }
        }
        
        // send the feed
        xmlHttp.send(null);
    }
    // if not ready
    else
    {
        // retry after 250 ms
        setTimeout('get_regular_price(' + iEventId + ', ' + iExtraTicket + ', ' + iTotalExtras + ')', 250);
    }
}

// inscription infolettre
function inscription_infolettre(sType)
{
    // if ready to accept
    if (ready_to_accept())
    {
        if (sType == '')
        {
            // build the command string
            sCommand = '/ajax_commands/inscription_infolettre.php?email=' + document.getElementById('infolettre_adresse').value;
            sCommand += '&first_name=' + document.getElementById('infolettre_prenom').value;
            sCommand += '&last_name=' + document.getElementById('infolettre_nom').value;
        }
        else
        {
            sCommand = '/ajax_commands/inscription_infolettre.php?email=' + sType.email.value;
            sCommand += '&groups=' + sType.groups.value;
        }

        // open XML feed
        xmlHttp.open('GET', sCommand);
        
        // when changes are occuring in status
        xmlHttp.onreadystatechange = function myFunction()
        {
            if (ready_to_process())
            {
                if (sType == '')
                {
                    document.getElementById('infolettre_division').innerHTML = 'Inscription Effectuée avec succès';
                }
                else
                {
                    sEventId = sType.events_id.value;
                    document.getElementById('supplement_' + sEventId).innerHTML = 'Inscription Effectuée avec succès';
                    document.getElementById('form_supplement_' + sEventId).style.display = 'none';
                }
            }
        }
        
        // send the xml feed
        xmlHttp.send(null);
    }
    // if not ready
    else
    {
        // attempt after 250ms
        setTimeout('inscription_infolettre(' + sType + ')', 250);
    }
}

function resetNews(iNumber)
{
    if (iNumber > 2)
    {
        iNumber = 0;
    }
    
    aNumber = newsIds.split(',');
    
    iNewsId = aNumber[iNumber];
    
    xmlHttp.open('GET', '/ajax_commands/get_news_content.php?news_id=' + iNewsId, false);
    xmlHttp.send(null);
    
    document.getElementById('news_container').innerHTML = xmlHttp.responseText;
    
    iNextNews = iNumber + 1;
    
    setTimeout('resetNews(' + iNextNews + ')', 10000); 
}
