window.onload=function(){    
    var viewport=document.viewport.getDimensions();
    var width=viewport.width;
    var height=viewport.height;
    if(width < 1024 && screen.width>=1024){
        window.resizeTo(1024,height);
        width = 1024;
    }

    if(height < 400 && screen.height>=768){
        window.resizeTo(width,768);
    }
};             

function change_group(child_id, parent_id)
{
	var options = {
		parameters: {child_id: child_id},
		onSuccess: function(rtn)
		{
			document.getElementById('group_container_'+parent_id).innerHTML = rtn.responseText;
			mainOpts();
    	}
	}
	new Ajax.Request('ajax/change_group.php', options);
}

function add_script (uri) {
  var fileref=document.createElement('script')
  script.setAttribute("type","text/javascript")
  script.setAttribute("src", uri)
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(script)
  
}

function add_css(uri){
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", uri)
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

/********* Email de réservation *********/
function send_mail(nom, tel, date, courriel, note, group, prenom, newsletter)
{
  var reg = /([0-9]{3})-([0-9]{3})-([0-9]{4})/;
  if(!nom || !tel || !date || !group || !prenom)
  {
    alert("Vous devez remplir les champs obligatoire.\nYou must fill all the required fields.");
  }
  else if(tel.match(reg) == null)
  {
    alert("Veuillez utilisez un # de téléphone selon le format :\n555-555-5555\n\nPlease use a phone # following this format :\n555-555-5555");
  }
  else
  {
    var options = {
      parameters: {nom: nom, tel: tel, date: date, courriel: courriel, note: note, group: group, prenom: prenom, newsletter: newsletter},
      onSuccess: function(rtn)
      {
        //alert(rtn.responseText);
        alert("Votre réservation a été envoyée avec succès!\n\nYour reservation has been successfully sent!");
        window.location.reload();
      }
    }
    new Ajax.Request('ajax/ajax.reservation.php', options);
  }
}
/****************************************/



/********************  DO NOT TOUCH THIS PART BELOW :) *************************/

/**
 * This function will display or not a div
 * if fiv is already displayed function will be hide and vice-versa
 */
function show_do_comment(id){

    var form = document.getElementById(id);
    if(form.style.display=='block'){
        form.style.display='none';
    }
    else{
        form.style.display='block';
    }

}// end function show_do_comment


/****** TESTIMONIAL FUNCTIONS *******/
var nb_div_testimony = 0;
var var_actual = 0;
var time_tem = 5000;
var id_time_out = 0;

/**
 * This function will hidden all div that are linked to testimony
 */
function disable_all_but_one(id_not_disable){
    for(i = 0; i < nb_div_testimony;i++){
        if(i != id_not_disable){
            document.getElementById('tem_'+i).style.display = 'none';
        }
    }
}// end function disable_all_but_one

//this function will display a div
function enable_one(id_to_enable){
    document.getElementById('tem_'+id_to_enable).style.display = 'block';
}// end function enable_one

/**
 * This function will show next testimony all hidden all others
 */
function active_next(){

    // first we stop counter
    if(id_time_out != 0){
        window.clearTimeout(id_time_out);
    }

    var next = var_actual;

    if(document.getElementById('tem_'+next)){

       enable_one(next);
        disable_all_but_one(next)
        var_actual += 1;
    }
    else{

        var_actual = 0;
        enable_one(var_actual);
        disable_all_but_one(var_actual);
    }
    
    id_time_out = window.setTimeout(active_next, time_tem);
    
}// end function active_next

function ini_testimony(nb_testimony){    

    nb_div_testimony = nb_testimony;

    active_next()
    id_time_out = window.setTimeout(active_next, time_tem);
}// end function ini_testimony


function intelLoc(lat,lng,id){
	 var options = {
		parameters: {lat: lat, lng: lng},
		asynchronous : false,
		onSuccess: function(rtn){
      		$(id).innerHTML = rtn.responseText;
    	}
	}
	new Ajax.Request('ajax/actuLoc.php', options);
	 
}
