var size = 100;
function doZoom( strDiv )
{ 
	
	if( strDiv == "plan" ){
		
		var id_string = "R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16,R17,";
		var id_string_title = "R_021,R_022,R_023,R_024,R_025,R_026,R_027,R_028,R_029,R_0210,R_0211,R_0212,R_0213,R_0214,R_0215,R_0216,R_0217,";
		
		var DIVs_01 = id_string.split(",");
		var DIVs_02 = id_string_title.split(",");
		var strlen = DIVs_01.length-1;
		
		if(size<129)
		{ 
		for( i=0; i < strlen; i++){
			if(  document.getElementById(DIVs_01[i]) )
				$( "#"+ DIVs_01[i]).removeAttr ("style");
				
			if(  document.getElementById(DIVs_02[i]) )
				$( "#"+ DIVs_02[i]).removeAttr ("style");
			
		}
				
	 	var font_size = document.getElementById("pgcontent").style.fontSize
	 	if(font_size=="")
	 		size = 110;     	
	 	else     	
	 		size+=10;
	 	
	 	document.getElementById("pgcontent").style.fontSize=size+'%'; 
	 	
	 	setDivHeight( id_string,"," );
		setDivHeight_title	( id_string_title,"," );
		}	
		
	}else{
	
		if(size<129)
		{ 
	 	var font_size = document.getElementById("pgcontent").style.fontSize
	 	if(font_size=="")
	 		size = 110;     	
	 	else     	
	 		size+=10;
	 	
	 	document.getElementById("pgcontent").style.fontSize=size+'%'; 
		}
	
	}
} 
function doNarrow( strDiv )
{ 
	
	if( strDiv == "plan" ){
		
		var id_string = "R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16,R17,";
		var id_string_title = "R_021,R_022,R_023,R_024,R_025,R_026,R_027,R_028,R_029,R_0210,R_0211,R_0212,R_0213,R_0214,R_0215,R_0216,R_0217,";
		
		var DIVs_01 = id_string.split(",");
		var DIVs_02 = id_string_title.split(",");
		var strlen = DIVs_01.length-1;
		
		if(size>71)
		{
			
		for( i=0; i < strlen; i++){
			if(  document.getElementById(DIVs_01[i]) )
				$( "#"+ DIVs_01[i]).removeAttr ("style");
				
			if(  document.getElementById(DIVs_02[i]) )
				$( "#"+ DIVs_02[i]).removeAttr ("style");
		}
				
	 	var font_size = document.getElementById("pgcontent").style.fontSize
	 	if(font_size=="")
	 		size = 90;     	
	 	else     	
	 		size-=10;	     	
	 	document.getElementById("pgcontent").style.fontSize=size+'%'; 
	 	
	 	setDivHeight( id_string,"," );
		setDivHeight_title	( id_string_title,"," );
		}	
		
	}else{
	
		if(size>71)
		{
	 	var font_size = document.getElementById("pgcontent").style.fontSize
	 	if(font_size=="")
	 		size = 90;     	
	 	else     	
	 		size-=10;	     	
	 	document.getElementById("pgcontent").style.fontSize=size+'%'; 
		}
	
	}
	
}


function popupWindow( page,id, site, comePage , title) {

	var mail_page = "email"+id;
	var link = "&url="+page;
    var title = "&pass_title=" + title; 
    //alert(title);
	var site = site.replace('$_$', 'http://');
    var comePage = window.location.href;
    comePage = comePage.replace('&', '!');
    comePage = "&comepage=" + comePage;
    //alert(comePage);
	var width = 630;
	var height = 520;
	
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	
    window.open( site + '/spip.php?page=' + mail_page + link + comePage + title, 'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=yes,copyhistory=no,width='+ width +',height='+ height +',top='+TopPosition+',left='+LeftPosition)
}

function validation(){
	var myName = document.getElementById('yourName').value;
	var myEmail = document.getElementById('yourEmail').value;
	var friendEmail = document.getElementById('recipientEmail').value;
	var mail_array = friendEmail.split(";");
	
	if( myName=="" ){
		document.getElementById('frm_check_text_01').style.display="block";
		document.getElementById('frm_check_text_02').style.display="none";
		return false;
	}else if(myEmail==""){
		document.getElementById('frm_check_text_01').style.display="block";
		document.getElementById('frm_check_text_02').style.display="none";
		return false;
	}else if(!isEmail(myEmail)){
		document.getElementById('frm_check_text_02').style.display="block";
		document.getElementById('frm_check_text_01').style.display="none";
		return false;
	}
	if(friendEmail==""){
		document.getElementById('frm_check_text_01').style.display="block";
		document.getElementById('frm_check_text_02').style.display="none";
		return false;
	}else{
		for(i=0;i<mail_array.length;i++){
			if(!isEmail(mail_array[i])){
				document.getElementById('frm_check_text_02').style.display="block";
				document.getElementById('frm_check_text_01').style.display="none";
				return false;
			}
		}
	}
	
	return true;
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function load_calendar( div_id,year,month,day )
{
	var timestamp = Date.parse(new Date());
	$.ajax({ url: "spip.php",
             type:"get",           
             dataType:"html",
             data: "page=calendar_event&year="+year + '&month=' + month + '&day=' + day + '&hash=' + timestamp,
             success:function(msg){
								
                                 $( "#"+div_id ).html(msg);
                              } 
     });

	return false;
}



function setDivHeight(strDivs, splitchar )
{
	var DIVs = strDivs.split(splitchar);
	var objDiv = 0;
	var strlen = DIVs.length-1; //because the strDivs is like "id1,id2,id3,", use split the array DIVs has 4 element, the last one is null, DIVs.length-1 get the right quantity of you div

	for( i=0; i < strlen; i++){
		if( document.getElementById(DIVs[i]) ){
			if(objDiv < document.getElementById(DIVs[i]).scrollHeight ){
				objDiv = document.getElementById(DIVs[i]).scrollHeight;
			}
			
			if( (i+1)%4 == 0 ){
				for( k=i-3;k<i+1;k++ ){
					document.getElementById(DIVs[k]).style.height = objDiv+"px";
				}
				objDiv = 0;
			}
			
			if( strlen%4 != 0) {
				if( i == ( strlen - 1 ) ){
					for( k=(strlen - strlen%4 );k<strlen;k++ ){
						document.getElementById(DIVs[k]).style.height = objDiv+"px";
					}
					objDiv = 0;
				}
			}
			
		}
	}
}

function setDivHeight_title(strDivs, splitchar )
{
	var DIVs = strDivs.split(splitchar);
	var objDiv = 0;
	var strlen = DIVs.length-1; //because the strDivs is like "id1,id2,id3,", use split the array DIVs has 4 element, the last one is null, DIVs.length-1 get the right quantity of you div

	for( i=0; i < strlen; i++){
		if( document.getElementById(DIVs[i]) ){
			if(objDiv < document.getElementById(DIVs[i]).scrollHeight ){
				objDiv = document.getElementById(DIVs[i]).scrollHeight;
			}
			
			if( (i+1)%4 == 0 ){
				for( k=i-3;k<i+1;k++ ){
					document.getElementById(DIVs[k]).style.height = objDiv+"px";
				}
				objDiv = 0;
			}
			
			if( strlen%4 != 0) {
				if( i == ( strlen - 1 ) ){
					for( k=(strlen - strlen%4 );k<strlen;k++ ){
						document.getElementById(DIVs[k]).style.height = objDiv+"px";
					}
					objDiv = 0;
				}
			}
		}
	}
}

function print_page( url ){
	var font_size = document.getElementById("pgcontent").style.fontSize;
	url = url+"&size="+font_size;
	
	var width = 1030;
	var height = 720;
	
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	
	window.open(url,'popupWindow','toolbar=yes,location=yes,directories=no,status=no,menubar=no,scrollbars=yes, resizable=yes,copyhistory=no,width='+ width +',height='+ height +',top='+TopPosition+',left='+LeftPosition)
}


function contact_frm_submit(id_form){
	var id = document.getElementById(id_form);
	id.submit();
}


function location_to(par_order, id_rub, id_mot){
    /*switch( par_order ){
        case 'nom':
            window.location.href='spip.php?page=contact_list&id_rubrique='+id_rub+'&id_mot='+id_mot+'&par=nom';
        break;
        case 'fonction':
            window.location.href='spip.php?page=contact_list&id_rubrique='+id_rub+'&id_mot='+id_mot+'&par=fonction';
        break;
        case 'service':
            window.location.href='spip.php?page=contact_list&id_rubrique='+id_rub+'&id_mot='+id_mot+'&par=service';
        break;
        default :
            //alert(par_order)
            window.location.href='spip.php?page=contact_list&id_rubrique='+id_rub+'&id_mot='+id_mot+'&par=service&filter_service='+par_order;
        break;
    }*/
    //alert(document.getElementById(par_order));
    link = document.getElementById(par_order);// = document.getElementById(par_order).href;
    window.location.href = link;
    //var link;
    //link = $(par_order).attr("href");
    //link = link.replace('&amp;', '&');
    //alert(link);
    //window.location.href = link;
}

function showFlash(time){
    $('#home_flash').css("visibility", 'visible');
}

function search_frm_check()
{
    var recherche = document.getElementById('recherche');
    var frm_search = document.getElementById('frm_search');
    var search_page_url = document.getElementById('search_page_url');
    
    if( recherche.value != '' && recherche.value != 'Recherche' ){					
        document.location = search_page_url.href + "&recherche="+document.frm_search.recherche.value;
        return false;
    }else{
        alert( "Merci de saisir un mot clé" );
        return false;
    }
}

function setDivHeight_home(left , right)
{
	objDiv = document.getElementById( left ).scrollHeight;
	if(document.getElementById(left).scrollHeight < document.getElementById( right ).scrollHeight ){
		objDiv = document.getElementById( right ).scrollHeight - 34 ;
	}
	document.getElementById( left ).style.height = objDiv+"px";	
}
