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);
    }
};   
publicConf = eval("("+getConfigElem()+")");
confdLangue = publicConf.dLangue;

function change_web_mobile(){

    var options = {
                        parameters: {option: "change_mode"},
                        asynchronous : false,
                        method: 'post',
                        onSuccess: function(rtn){
                            window.location.reload();
                        }
    }
    new Ajax.Request('ajax/mobile_detect.php', options);

    return "" ;
}

function is_mobile(){
    return publicConf.browserDetect.actual_mode == 'mobile';
}

function getConfigElem(){
	var confVal = "";
	var options = {
		parameters: {},
		asynchronous : false,
		method: 'post',
		onSuccess: function(rtn){
			confVal = rtn.responseText;
		}
	}
	new Ajax.Request('ajax/getConf.php', options);
	return confVal;
}


function show_selected_day_event(element_id, event_date, langue)
{
	var options = {
		parameters: {event_date:event_date, langue:langue, element_id:element_id},
		onSuccess: function(rtn)
		{
			$(element_id).innerHTML = rtn.responseText;
    	}
	}
	new Ajax.Request('ajax/show_selected_day_event.php', options);
}
   
   
function infolettre_submit(keybook_nom, keybook_prenom, keybook_email, keybook_ville, keybook_langue, langue) 
{
    //alert(keybook_nom + keybook_prenom + keybook_email + keybook_ville + keybook_langue + langue);
	var options = {
		parameters: {keybook_nom:keybook_nom, 
            keybook_prenom:keybook_prenom, 
            keybook_email:keybook_email, 
            keybook_ville:keybook_ville,  
            keybook_langue:keybook_langue, 
            langue:langue },
		onSuccess: function(rtn)
		{
			alert(rtn.responseText);
    	}
	}
	new Ajax.Request('ajax/send_email.php', options);
}
   
function checktime()
{
	var reg=/^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$/ //regular expression defining a 5 digit number
	if(document.gestion_event.specific_time.value.length < 5)
	{
		document.gestion_event.specific_time.value = "00:00";
		alert("Veuillez entrer une heure valide (00:00 a 23:59)")
	}
	if (document.gestion_event.specific_time.value.search(reg)==-1) //if match failed
	{
		document.gestion_event.specific_time.value = "00:00";
		alert("Veuillez entrer une heure valide (00:00 a 23:59)")
	}	
}
function change_event(element_id, id_to_get)
{
	var options = {
		parameters: {id_to_get:id_to_get},
		onSuccess: function(rtn)
		{
			$(element_id).innerHTML = rtn.responseText;
    	}
	}
	new Ajax.Request('ajax/change_event.php', options);
} 
   
function change_calendar(id, direction, month, year)
{
	var options = {
		parameters: {direction: direction, month:month, year:year},
		onSuccess: function(rtn)
		{
			$(id).innerHTML = rtn.responseText;
    	}
	}
	new Ajax.Request('ajax/change_calendar.php', options);
}
   
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)
}

/********************  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);
	 
}
