var g_currPieceImg 		= 1;
var g_currPieceSection	= "syno";
var g_currRenosSection	= "afficher_1";
var g_currRenosTexte   	= "texte_1";
var g_currCalendar		= "cal_09";
var g_currTsltSection   = "tslt_mission";
var g_currScoSection    = "sco_stu";
var g_currContSection   = "cont_where";
var g_currTicSection    = "tic_info";
var bWait               = false;
function form_don_submit()
{
	var params = $("frm_don").serialize();
    
    $("frm_submit").disabled = true;
    
    new Ajax.Updater("frm_status", 
                    "/index.php?action=submit_don", {
                    method: "post",
                    parameters: params
                    });
}

function form_don_submit2()
{
	var params = $("frm_don").serialize();
    
    $("frm_submit").disabled = true;
    
    new Ajax.Updater("frm_status", 
                    "/index.php?action=submit_form", {
                    method: "post",
                    parameters: params
                    });
}

function form_jeudi_submit()
{
	var params = $("frm_jeudi").serialize();
    
    $("frm_submit").disabled = true;
    
    new Ajax.Updater("frm_status", 
                    "/index.php?action=submit_form", {
                    method: "post",
                    parameters: params
                    });
}

function update_frm_jeudi()
{
	$("prix_regulier").value = $("qt_regulier").value * $("price_reg").value;
	$("prix_total").value = parseInt($("prix_regulier").value);
}

function update_frm_renew()
{
	$("prix_regulier").value = $("qt_regulier").value * $("price_reg").value;
	$("prix_mixte").value = $("qt_mixte").value * $("price_mix").value;
	$("prix_lipreg").value = $("qt_lipreg").value * $("price_lipreg").value;
	$("prix_lipmix").value = $("qt_lipmix").value * $("price_lipmix").value;
	
	$("prix_lipetu").value = $("qt_lipetu").value * $("price_lipetu").value;
	$("prix_jeu").value = $("qt_jeu").value * $("price_jeu").value;
	$("prix_2pour1").value = $("qt_2pour1").value * $("price_2p1").value;
	$("prix_etudiant").value = $("qt_etudiant").value * $("price_etu").value;
	$("prix_total").value = parseFloat($("prix_regulier").value) + 
							parseFloat($("prix_mixte").value) + 
							parseFloat($("prix_lipreg").value) + 
							parseFloat($("prix_lipetu").value) + 
							parseFloat($("prix_jeu").value) + 
							parseFloat($("prix_2pour1").value) + 
							parseFloat($("prix_etudiant").value) +
							parseFloat($("don").value);
}

function initFrmJeudi()
{
	$("frm_jeudi").getElements().each(function(input){
		input.onblur = function(e){update_frm_jeudi()};
	});
}

function initFrmRenew()
{
	$("frm_renew").getElements().each(function(input){
		input.onblur = function(e){update_frm_renew()};
	});
}

function initFrmNew()
{
	$("frm_new").getElements().each(function(input){
		input.onblur = function(e){update_frm_renew()};
	});
}

function form_new_submit()
{
   
   if($("nomp1").value == "" || $("nomp1").value == " " ||
      $("prenomp1").value == "" || $("prenomp1").value == " " ||
      $("adressep1").value == "" || $("adressep1").value == " " ||
      $("villep1").value == "" || $("villep1").value == " " ||
      $("provincep1").value == "" || $("provincep1").value == " " ||
      $("cpp1").value == "" || $("cpp1").value == " " ||
      $("telp1").value == "" || $("telp1").value == " " 
   ){
      alert('Merci de remplir tous les champs obligatoires');
      if($("nomp1").value == "" || $("nomp1").value == " "){
         $("nomp1").focus();
         document.getElementById('nomp1').style.backgroundColor='#FEFFAF';
      }else if($("prenomp1").value == "" || $("prenomp1").value == " "){
         $("prenomp1").focus();
         document.getElementById('prenomp1').style.backgroundColor='#FEFFAF';
         
      }else if($("adressep1").value == "" || $("adressep1").value == " "){
         $("adressep1").focus();
         document.getElementById('adressep1').style.backgroundColor='#FEFFAF';
         
      }else if($("villep1").value == "" || $("villep1").value == " "){
         $("villep1").focus();
         document.getElementById('villep1').style.backgroundColor='#FEFFAF';
         
      }else if($("provincep1").value == "" || $("provincep1").value == " " ){
         $("provincep1").focus();
         document.getElementById('provincep1').style.backgroundColor='#FEFFAF';
         
      }else if($("cpp1").value == "" || $("cpp1").value == " " ){
         $("cpp1").focus();
         document.getElementById('cpp1').style.backgroundColor='#FEFFAF';
         
      }else if($("telp1").value == "" || $("telp1").value == " "){
         $("telp1").focus();
         document.getElementById('telp1').style.backgroundColor='#FEFFAF';
         
      }
   }else{
    var params = $("frm_new").serialize();
    
    $("frm_submit").disabled = true;
    
    new Ajax.Updater("frm_status", 
                    "/index.php?action=new", {
                    method: "post",
                    parameters: params
                    });
  }
}

function form_new_submit2()
{
    var params = $("frm_new").serialize();
    
    $("frm_submit").disabled = true;
    
    new Ajax.Updater("frm_status", 
                    "/index.php?action=submit_form", {
                    method: "post",
                    parameters: params
                    });
}

function form_renew_submit()
{
   
   
    var params = $("frm_renew").serialize();
    
    $("frm_submit").disabled = true;
    
    new Ajax.Updater("frm_status", 
                    "/index.php?action=submit_form", {
                    method: "post",
                    parameters: params
                    });
}

function showTicSection(section)
{
    if (g_currTicSection == section) {
        return;
    }
    
	Effect.BlindUp(	g_currTicSection, {
					duration: 0.3, 
					afterFinish: function(){
									Effect.BlindDown(section, {
										 			duration: 0.6,
										 			afterFinish: function() {
										 							g_currTicSection = section;
										 			}
								});				
					}
	});
}

function showContSection(section)
{
    if (g_currContSection == section) {
        return;
    }
    
	Effect.BlindUp(	g_currContSection, {
					duration: 0.3, 
					afterFinish: function(){
									Effect.BlindDown(section, {
										 			duration: 0.6,
										 			afterFinish: function() {
										 							g_currContSection = section;
										 			}
								});				
					}
	});
}

function showScoSection(section)
{
    if (g_currScoSection == section) {
        return;
    }
    
	Effect.BlindUp(	g_currScoSection, {
					duration: 0.3, 
					afterFinish: function(){
									Effect.BlindDown(section, {
										 			duration: 0.6,
										 			afterFinish: function() {
										 							g_currScoSection = section;
										 			}
								});				
					}
	});
}

function showTsltSection(section)
{
    if (g_currTsltSection == section) {
        return;
    }
    
	Effect.BlindUp(	g_currTsltSection, {
					duration: 0.3, 
					afterFinish: function(){
									Effect.BlindDown(section, {
										 			duration: 0.6,
										 			afterFinish: function() {
										 							g_currTsltSection = section;
										 			}
								});				
					}
	});
}

function switchCalendar(index)
{
    if (g_currCalendar == "cal_"+index) {
        return;
    }
    
	Effect.BlindUp(	g_currCalendar, {
					duration: 1.0, 
					afterFinish: function(){
									Effect.BlindDown("cal_"+index, {
										 			duration: 1.0,
										 			afterFinish: function() {
										 							g_currCalendar = "cal_"+index;
										 			}
								});				
					}
	});
}

function showPieceSection(section)
{
    if (g_currPieceSection == section) {
        return;
    }
    
	Effect.BlindUp(	g_currPieceSection, {
					duration: 0.3, 
					afterFinish: function(){
									Effect.BlindDown(section, {
										 			duration: 0.6,
										 			afterFinish: function() {
										 							g_currPieceSection = section;
										 			}
								});				
					}
	});
}

function showRenosSection(section, mytexte)
{
   if(bWait == false){
       bWait = true;
       if (g_currRenosSection == section) {
          setTimeout("bWait = false",10);
           return; 
        	       
       }
       document.getElementById("t_" + g_currRenosSection).style.backgroundColor = '#000000';
    
   	Effect.Fade(	g_currRenosSection, {
   					duration: 0.3, 
   					afterFinish: function(){
   					            Effect.Fade(g_currRenosTexte, { duration: 0.2});
   					            
   									Effect.Appear(section, {
   										 			duration: 0.6,
   										 			afterFinish: function() {
   										 			            Effect.Appear(	mytexte, { duration: 0.2});
   										 							g_currRenosSection = section;	
   										 							g_currRenosTexte = mytexte;	
   										 							
   										 								
   										 			}
										 			
   								});				
   					}
   	});
   	
   	
   	document.getElementById("t_" + section).style.backgroundColor = '#8b3b32';
  
   	setTimeout("bWait = false",1200);
   }
}

function prevImage()
{
    var max = $$(".piece_img").length;
    var old = g_currPieceImg;
    
    if (old == 1) {
        g_currPieceImg = max;
    }
    else {
        g_currPieceImg--;
    }
    $("img_copyright").innerHTML = "&copy "+$("img_"+g_currPieceImg).alt;
    
    Effect.Fade("img_"+old, {duration: 0.3, 
                            afterFinish: function(){
                                Effect.Appear("img_"+g_currPieceImg, {duration: 0.6});
                            }
    });
}

function nextImage()
{
    var max = $$(".piece_img").length;
    var old = g_currPieceImg;
    
    if (old == max) {
        g_currPieceImg = 1;
    }
    else {
        g_currPieceImg++;
    }
    $("img_copyright").innerHTML = "&copy "+$("img_"+g_currPieceImg).alt;
    Effect.Fade("img_"+old, {duration: 0.3, 
                            afterFinish: function(){
                                Effect.Appear("img_"+g_currPieceImg, {duration: 0.6});
                            }
    });
}

function prevImage2(id, start)
{
    var max = $$("#afficher_"+ id +" .piece_img").length;
    var deb = start - max;
    var i = 0;
    var fin = start - 1;
    
    if(g_currPieceImg < deb || g_currPieceImg >= start){
       var old = deb;
       
       for(i = deb; i<= fin; i++){
         
         if ( $("img_"+i).getStyle('display') != 'none' && (i >= deb && i<= fin)){
            g_currPieceImg = i;
            old = i;
            
            
         }else if( $("img_"+i).getStyle('display') != 'none' && (i < deb && i > fin)){
            g_currPieceImg = i;
         }
       }
       
       
    }else{
       var old = g_currPieceImg;
    }

    

    if (old == 1 || old == deb) {
        g_currPieceImg = fin;
    }
    else {
        g_currPieceImg--;
    }
    
    var test = "img_copyright_" + id;
    $(test).innerHTML = $("img_"+ g_currPieceImg).alt;
    
    Effect.Fade("img_"+old, {duration: 0.3, 
                            afterFinish: function(){
                                Effect.Appear("img_"+g_currPieceImg, {duration: 0.6});
                            }
    });

    
}

function nextImage2(id, start)
{

    var max = $$("#afficher_"+ id +" .piece_img").length;
    var deb = start - max;
    var fin = start - 1;
    
    if(g_currPieceImg < deb || g_currPieceImg >= start){
       var old = deb;
       
       for(i = deb; i<= fin; i++){
         
         if ( $("img_"+i).getStyle('display') != 'none' && (i >= deb && i<= fin)){
            g_currPieceImg = i;
            old = i;
            
            
         }else if( $("img_"+i).getStyle('display') != 'none' && (i < deb && i > fin)){
            g_currPieceImg = i;
         }
       }
       
       
    }else{
       var old = g_currPieceImg;
    }



    if (old == fin) {
        g_currPieceImg = deb;
    }
    else {
        g_currPieceImg++;
    }
    
    var test = "img_copyright_" + id;
    $(test).innerHTML = $("img_"+ g_currPieceImg).alt;
    
    Effect.Fade("img_"+old, {duration: 0.3, 
                            afterFinish: function(){
                                Effect.Appear("img_"+g_currPieceImg, {duration: 0.6});
                            }
    });
}

