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);
    }
    //setIframeHeight('calendar_frame');
};             

    function setIframeHeight(iframeName) {
      //var iframeWin = window.frames[iframeName];
      var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
      if (iframeEl) {
      iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
      //var docHt = getDocHeight(iframeWin.document);
      // need to add to height to be sure it will all show
      var h = alertSize();
      var new_h = (h+148);
      iframeEl.style.height = new_h + "px";
      //alertSize();
      }
    }

    function alertSize() {
      var myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
      }
      //window.alert( 'Height = ' + myHeight );
      return myHeight;
    }

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