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



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