function submit_search(){
	if(document.forms['search_form'].elements['search'].text!=""){
		//alert('Search launched !');
		document.forms['search_form'].submit();
	}	
}

// Function that clear search text
function empty_search(){
	if(document.forms['search_form'].elements['search'].text=="search..."){
		alert('pareil');
		document.forms['search_form'].elements['search'].value="";
	}
}
// Function which catches the ENTER keyboard entry
function getKey(form,e)
{
	if(e.keyCode==13) window.document.forms[form].submit();
}
// Function which catches the ENTER keyboard entry for lightbox creation
function getKeyCreateLB(form,e)
{
	if(e.keyCode==13) {
		if(lightbox_create_form.lightbox_create.value!='' && lightbox_create_form.lightbox_create.value!='Or create a new one...' && lightbox_create_form.lightbox_create.value!='Give me a name please !'){
			lightbox_create_form.submit();
		}else{
			lightbox_create_form.lightbox_create.value='Give me a name please !';
			lightbox_create_form.lightbox_create.select();
		}
	}
}
// Submit a photo to the selected lightbox
function addToLB(img,fromPage)
{
	lightbox = document.lightbox_select_form.elements['lightbox_select'].value;
	//alert(lightbox);
	if(lightbox == ''){
		alert('Please select a lightbox first');
	}else{
		//alert('Yeah that\'s it !');
		scriptAddPhotoToLB = "lib/_scriptAddPhotoToLB.php?img="+img+"&lb="+lightbox+"&referer="+fromPage;
		//alert(scriptAddPhotoToLB);
		window.location = scriptAddPhotoToLB;
	}
}
function popupcentree(page,largeur,hauteur,options)
{
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,'',"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
function delLightbox(lb,urlFrom){
	if(lightbox_select_form.selectedLightbox.value!=''){
		if(confirm('Really delete this lightbox ?')==true){
			window.location="lib/_scriptDelLightbox.php?lb2del="+lb+"&urlFrom="+urlFrom;
		}
	}else{
		alert('You must choose which lightbox you want to delete');
	}
}

// Fonction qui sélectionne toutes les images affichées de la lightbox
function selectAll(item){
	if(item.checked==true){
		//alert('checkée !');
		for (i=0; i<document.lightbox_form.chkImg.length; i++) {
    	document.lightbox_form.chkImg[i].checked=true; 
		}
	}else{
		//alert('pas checkée !');
		for (i=0; i<document.lightbox_form.chkImg.length; i++) {
    	document.lightbox_form.chkImg[i].checked=false; 
		}
	}
}
// Fonction qui sélectionne toutes les newsletter affichées dans la page registration
function selectAllNl(item){
	if(item.checked==true){
		//alert('checkée !');
		for (i=0; i<document.register.chkNl.length; i++) {
    	document.register.chkNl[i].checked=true; 
		}
	}else{
		//alert('pas checkée !');
		for (i=0; i<document.register.chkNl.length; i++) {
    	document.register.chkNl[i].checked=false; 
		}
	}
}
// Fonction qui sélectionne la check-box principale
function selectMain(){
	if(document.register.mainNewsLetter.checked==false){
		document.register.mainNewsLetter.checked=true;
	}
	oneChecked=false;
	for (i=0; i<document.register.chkNl.length; i++) {
    	if(document.register.chkNl[i].checked==true){
    		oneChecked=true;
    	} 
	}
	if(oneChecked==false){
		document.register.mainNewsLetter.checked=false;
	}
}

// Fonction qui récupère l'id des toutes les catégories sélectionnées et les
// mets dans le champ caché "hdSltCat" pour le passer en POST
function catchCat(){
	document.register.hdSltCat.value="";
	for (i=0; i<document.register.chkNl.length; i++) {
    	if(document.register.chkNl[i].checked==true){
    		document.register.hdSltCat.value+=" "+document.register.chkNl[i].value;
    	} 
	}
}
// Fonction qui supprime toutes les images sélectionnées dans la lightbox
function deleteSelected(lb){
	//alert('delete');
	toDel="";
		for (i=0; i<document.lightbox_form.chkImg.length; i++) {
    	if(document.lightbox_form.chkImg[i].checked){
    		toDel=toDel+"_"+document.lightbox_form.chkImg[i].value;
    	}
		}
		if(toDel!=""){
			if(confirm('Really delete selected photos ?')==true){
				window.location="lib/_scriptDelImgs.php?lb="+lb+"&toDel="+toDel;
			}
		}else{
			alert('No selected photo');
		}
}
// Fonction qui supprime la photo sélectionnée
function deletePhoto(lb,toDel){
	//alert('delete');
			if(confirm('Really delete this photo from your lightbox ?')==true){
				window.location="lib/_scriptDelImg.php?id="+lb+"&img="+toDel;
			}
}
// Fonction qui download la photo
function downloadPhoto(image){
	window.location="lib/downloadImage.php?image="+image;
}
function downloadSelected(lb){
	//alert('delete');
	toDown="";
		for (i=0; i<document.lightbox_form.chkImg.length; i++) {
    	if(document.lightbox_form.chkImg[i].checked){
    		toDown=toDown+"_"+document.lightbox_form.chkImg[i].value;
    	}
		}
		if(toDown!=""){
			window.location="lib/downloadZip.php?lb="+lb+"&toDown="+toDown;
		}else{
			alert('No selected photo');
		}
}
function renameLb(lb){
	//alert(document.all.txtLightbox.value);
	window.location="lib/_scriptRenameLb.php?lb="+lb+"&newName="+window.document.all['txtLightbox'].value;
}