function autoHeight(left, right, height){

	var l = document.getElementById(left);
	var r = document.getElementById(right);
	
	var lh = l.offsetHeight;
	var rh = r.offsetHeight;
	
	height == '' ? (height=0) : (height = height);
	
	if(lh>=rh) {
		r.style.height=( l.offsetHeight-height ) +'px' ;
		l.style.height=r.style.height ;
	}else{
		l.style.height=r.offsetHeight+'px';
	}
}

function check_num(obj)
{
 if(event.keyCode == 13)
  return true;
 if(event.keyCode <48 || event.keyCode >57)
  return false;
 else
  return true;
}

function frm_city_submit(){
	var frm = document.getElementById( "country_city_frm" );
	frm.submit();
}

function frm_country_submit(){
	var city = document.getElementById( "city_select" );
	var frm = document.getElementById( "country_city_frm" );
	city.value = '';
	frm.submit();
}

function autoHeight_three(left, mid, right,hgt){
	var l = document.getElementById(left);
	var m = document.getElementById(mid);
	var r = document.getElementById(right);
	
	var lh = l.offsetHeight + hgt ;
	var mh = m.offsetHeight + hgt ;
	var rh = r.offsetHeight + hgt ;
	
	var len = lh >= mh ? lh : mh;
	var len_02 = len >= rh ? len : rh;
	
	l.style.height = len_02 + 'px';
	m.style.height = len_02 + 'px';
	r.style.height = len_02 + 'px';
	
}


function checkCOL(strDivs, splitchar )
{
if(strDivs != ''){
	var DIVs = strDivs.split(splitchar);
	var objDiv = 0;
	var strlen = DIVs.length-1;
switch(strlen){
  case 1:
    document.getElementById(DIVs[0]).className = 'mid-onecolumn';
  break;
  case 2:
    document.getElementById(DIVs[0]).className = 'left-twocolumn';
    document.getElementById(DIVs[1]).className = 'mid-twocolumn';
  break;
  case 3:
  break;
  }
}
}

function setDivHeight(strDivs, splitchar,reduce )
{
if(strDivs != ''){
	var DIVs = strDivs.split(splitchar);
	var objDiv = 0;
	var strlen = DIVs.length-1;
	//get get the max height
	for( i=0; i < strlen; i++){
		if(objDiv < document.getElementById(DIVs[i]).scrollHeight )
			objDiv = document.getElementById(DIVs[i]).scrollHeight;
	}
	//set height
  objDiv = objDiv - reduce;
	for( i=0; i < strlen; i++){
		document.getElementById(DIVs[i]).style.height = objDiv+"px";
		//document.getElementById(DIVs[i]).style.borderBottom='1px solid red' ;
	}
}
}

//add by sam

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_plan( 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_plan( 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 setDivHeight_plan(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++ ){
					if( document.getElementById(DIVs[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++ ){
						if( document.getElementById(DIVs[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' && objDiv > 24 ){
				for( k=i-3;k<i+1;k++ ){
					if( document.getElementById(DIVs[k]) )
					document.getElementById(DIVs[k]).style.height = objDiv+"px";
				}
				objDiv = 0;
			}
			
			if( strlen%4 != 0 && objDiv > 24) {
				if( i == ( strlen - 1 ) ){
					for( k=(strlen - strlen%4 );k<strlen;k++ ){
						if( document.getElementById(DIVs[k]) )
						document.getElementById(DIVs[k]).style.height = objDiv+"px";
					}
					objDiv = 0;
				}
			}
		}
	}
}

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 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 change_doc( id, page ){
	if( page == 'download' ){
		var id_art = document.getElementById('tous').value;
		if( id_art != '' ){
			window.location = 'spip.php?page='+page+'&id_rubrique='+id+'&id_article='+id_art;
		}else{
			window.location = 'spip.php?page='+page+'&id_rubrique='+id;
		}
	}else{
		var id_mot = document.getElementById('question').value;
		if( id_mot != '' ){
			window.location = 'spip.php?page='+page+'&id_rubrique='+id+'&id_mot='+id_mot;
		}else{
			window.location = 'spip.php?page='+page+'&id_rubrique='+id;
		}
	}
}

function change_doc( id, page ){
	if( page == 'download' ){
		var id_art = document.getElementById('tous').value;
		if( id_art != '' ){
			window.location = 'spip.php?page='+page+'&id_rubrique='+id+'&id_article='+id_art;
		}else{
			window.location = 'spip.php?page='+page+'&id_rubrique='+id;
		}
	}else{
		var id_mot = document.getElementById('question').value;
		if( id_mot != '' ){
			window.location = 'spip.php?page='+page+'&id_rubrique='+id+'&id_mot='+id_mot;
		}else{
			window.location = 'spip.php?page='+page+'&id_rubrique='+id;
		}
	}
}


function frm_search_check(){
	frm = document.getElementById('frm_search');
	key = document.getElementById('search').value;
	if( key == '' || key == 'Entrez vos mots clés' ){
		alert( 'Entrez vos mots clés' );
		return false;
	}else{
		frm.submit();
	}
	
}

function login_frm_check(){
	frm = document.getElementById('login_frm');
	login = document.getElementById('login').value;
	if( login == '' ){
		alert( "input your Identification" );
		return false;
	}else{
		frm.submit();
		return true;
	}
}

function lists_submit(){
	frm = document.getElementById('regist_frm');
	mail = document.getElementById('email_newsletter').value;
	user_profil = document.getElementById('user_profil_type').value;
	
	if( mail == '' ){
		alert( "Merci de saisir une adresse courriel valide." );
		return false;
	}else{
		if( !isEmail( mail ) ){
			alert( "Votre adresse courriel n'est pas valide." );
			return false;
		}
	}
	
	if( user_profil == '' ){
		alert( "Merci de sélectionner un profil." );
		return false;
	}
	
	var list_tmp = document.getElementsByName( "list_all[]" );
	var list_select = false;
	for( var i=0;i<list_tmp.length;i++  ){
		if(list_tmp[i].checked )   
			list_select = true;
	}
	
	// var comfire_select = false;
	// var comfire_tmp = document.getElementsByName( "confirm[]" );
	// for( var i=0;i<comfire_tmp.length;i++  ){
		// if(comfire_tmp[i].checked )   
			// comfire_select = true;
	// }
	
	if( !list_select ){
		alert( "Merci de choisir au moins une lettre d'information." );
		return false;
	// }else if( !comfire_select ){
		// alert( "Merci de confirmer votre choix." );
		// return false;
	}
	
	frm.submit();
}

function unsub_check(){
	frm = document.getElementById('unsub_frm');
	mail = document.getElementById('email_newsletter').value;
	if( mail == '' ){
		alert( "Merci de saisir une adresse courriel valide." );
		return false;
	}else{
		if( !isEmail( mail ) ){
			alert( "Votre adresse courriel n'est pas valide." );
			return false;
		}
	}
	
	var list_tmp = document.getElementsByName( "list_all[]" );
	var list_select = false;
	for( var i=0;i<list_tmp.length;i++  ){
		if(list_tmp[i].checked )   
			list_select = true;
	}
	
	if( !list_select ){
		alert( "Merci de choisir au moins une liste de diffusion." );
		return false;
	}
	frm.submit();
	
}

function home_newsletter_check(){
	frm = document.getElementById('newsletter_frm');
	mail = document.getElementById('email_newsletter').value;
	
	if( mail == '' || mail == 'votre adresse courriel' ){
		alert( "Merci de saisir une adresse courriel valide." );
		return false;
	}else{
		if( !isEmail( mail ) ){
			alert( "Merci de saisir une adresse courriel valide." );
			return false;
		}
	}
	
	frm.submit();
	
}

function log_out(){
	frm = document.getElementById('regist_frm');
	document.getElementById('log_out_value').value = 'log_out';
	frm.submit();
}

//end by sam
/*
function selectArea( id, page ){
	window.location = 'spip.php?page='+page+'&id_rubrique='+id;
}
*/
function selectArea( url ){
    window.location = url;
}
