function same_height(idToBeSet, idSetBy){
	document.getElementById(idToBeSet).style.height = (document.getElementById(idSetBy).offsetHeight ) + 'px';
}

function autoHeight(left, right, height, more){

	var l = document.getElementById(left);
	var r = document.getElementById(right);
	var lh = l.offsetHeight;
	var rh = r.offsetHeight;
	height == '' ? (height=0) : (height = height-250);
	more == '' ? (more=0) : (more = more);
	if(lh>=rh) {
		r.style.height=( l.offsetHeight+height ) +'px' ;
		l.style.height=r.style.height ;
	}else{
	   l.style.height=(r.offsetHeight + more)+'px';
	}
}

function popupWindow(w,h) {
	var frm = document.getElementById("show_picture");
	var link = frm.src;
	var width = w;
	var height = h;
	
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	
    window.open('spip.php?page=show_picture&img='+link,'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 check_advance_engine( form )
{
	
	if( form.auteur.value=='' && form.mot_cle.value=='' && form.titre.value=='' && form.editeur.value=='' &&
	form.isbn.value=='' && form.collection.value=='' && form.langue.value==''  &&
	form.debut.value=='' && form.fin.value==''){
		alert( '  Entrer au moins un texte à rechercher !' );
		form.auteur.focus();
		return false;
	}
	
	if( trim( form.debut.value ) != '' && !isValidDate( trim( form.debut.value ) ) ){
			alert( "Format de date est invalide" );
			form.debut.focus();
			return false;
	}	 						
	
	
	if( trim( form.fin.value ) != '' && !isValidDate( trim( form.fin.value ) ) ){
		alert( "Format de date est invalide" );
		form.fin.focus();
		return false;
	}

	return true;

}

function isValidDate(str){					
var expr = /^([0-3]{0,1}[0-9]{1,1})\/([0-1]{0,1}[0-9]{1,1})\/([1-2]{1,1}[0-9]{3,3})$/;

var str_org = str;
if(!expr.test(str_org))
	return false;
else {
	
	var date_array = str.split("/");
	
	
	if(date_array[0] <=0 || date_array[0] > 31)
		return false;
	else if(date_array[1] <=0 || date_array[1]>12)
		return false;
	else if(date_array[2] <=0)
		return false;
	else if(date_array[1] == 2 && date_array[0] > 29)
		return false;
	else{
			if( date_array[1] == 4 && date_array[0] > 30 ) return false;
			else if( date_array[1] == 6 && date_array[0] > 30 ) return false;
			else if( date_array[1] == 9 && date_array[0] > 30 ) return false;
			else if( date_array[1] == 11 && date_array[0] > 30 ) return false;
			else return true;
	}
}
		

}

function change_image( id_rubrique,current_index,page,div_name,show_connecting_div )
{
	
	var current_radom_image_div = $( div_name );
	if( show_connecting_div != '' ){
		var show_connecting_div = $( show_connecting_div );
		show_connecting_div.style.display = '';
	}
	current_radom_image_div.style.display = 'none';
	
	
	update_radom_image_div( id_rubrique,current_index,page,div_name );
	current_radom_image_div.style.display = '';
	
	if( show_connecting_div != '' )
		show_connecting_div.style.display = 'none';
	return false;
}

function update_radom_image_div( id_rubrique,current_index,page,div_name )
{	
	var url = 'spip.php';
	 
	 
    var pars = 'page=inc_random_image_ajax&id_rubrique='+id_rubrique+'&hash=<?=md5( time() )?>&current_image_index='+current_index+'&my_page='+page;
    
	
    var myAjax = new Ajax.Updater(div_name, url, {method: 'get', parameters: pars});
	return;
}

function popup_noticle_photo(image,w,h) {
	
	var link = image;
	var width = w;
	var height = h;
	
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	
    popup_window = window.open('spip.php?page=show_museum_picture&img='+link,'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);
   	if( popup_window ){
   		popup_window.focus();
   	}
    return false;
}



