/*
SIFAS

Fonctions JavaScript
*/

//HP
function hpNewsFadeIn(post_ID)
{
			new Effect.Appear('hpNewsTxt_'+post_ID, {duration:1, fps:25, from:0.0, to:0.7});
			//$('hpNewsTxt_'+post_ID).style.display = '';
}
function hpNewsFadeOut(post_ID)
{
			$('hpNewsTxt_'+post_ID).style.display = 'none';
}
function hpNewsImgOnMouseOver(ID_img)
{
			$('hpNewsTxt_'+ID_img).src = '/img/hp_visunews_'+ID_img+'_omo.jpg';
}
function hpNewsImgOnMouseOut(ID_img)
{
			$('hpNewsTxt_'+ID_img).src = '/img/hp_visunews_'+ID_img+'.jpg';
}

//PANIER
function caddyAdd( ID_pdt, qte )
{
			new Ajax.Request('catalogue_caddy_bg.php?ID_produit='+ID_pdt+'&qte='+qte+'&act=add', {
				method: 'post',
				onSuccess: function(transport) {
					var json_datas = transport.responseText.evalJSON(false);
					caddyContentUpdate(json_datas['html'], json_datas['prix']);
				}
			});
}

function caddyDel( ID_pdt )
{
			new Ajax.Request('catalogue_caddy_bg.php?ID_produit='+ID_pdt+'&act=del', {
				method: 'post',
				onSuccess: function(transport) {
					var json_datas = transport.responseText.evalJSON(false);
					caddyContentUpdate(json_datas['html'], json_datas['prix']);
				}
			});
}

function caddyShow()
{
			new Ajax.Request('catalogue_caddy_bg.php', {
				method: 'post',
				onSuccess: function(transport) {
					var json_datas = transport.responseText.evalJSON(false);
					caddyContentUpdate(json_datas['html'], json_datas['prix']);
				}
			});
}

function caddyContentUpdate(html, prix)
{
	if($('pLstCaddyContent'))
	{
		$('pLstCaddyContent').update(html);					
		$('pLstCaddyRecapTotalContent').update(prix+' &euro;');					
	}
}

//COTATIONS
function cotationsDelete(ID_cotation)
{
	if(confirm("Etes vous sur de vouloir supprimer cette cotation ?"))
	{
		window.location.href = "moncompte_cotations.php?del="+ID_cotation;
	}
}

function cotationUpdate(ID_cotation, type, value)
{
			$('errStr').innerHTML = '';
			new Ajax.Request('moncompte_cotations_update_process.php?ID='+ID_cotation+'&type='+type+'&value='+encodeURI(value), {
				method: 'post',
				onSuccess: function(transport) {
					var json_datas = transport.responseText.evalJSON(false);
					
					if(json_datas['return'] == '-1')
					{
						$('errStr').innerHTML = 'Valeur incorrecte ou erreur dans la mise à jour';
					}
					else
					{
						switch(type)
						{
							case 'title':
								$('cotationTitreTxt'+ID_cotation).innerHTML     = json_datas['value'];
							break;
							
							case 'ristourne':
								$('cotationRistourneTxt'+ID_cotation).innerHTML = json_datas['value'];
								$('cotationPrice'+ID_cotation).innerHTML 		= json_datas['price'];
								
							break;					
						}
					}
				}
			});
}

function cotationRistourneEdit(ID_cotation) {
	$('cotationRistourneTxt'+ID_cotation).style.display = 'none';
	$('cotationRistourneInput'+ID_cotation).style.display = '';
}

function cotationRistourneEditProcess(ID_cotation) {
	cotationUpdate(ID_cotation, 'ristourne', $('cotationRistourneInput'+ID_cotation).value);
	$('cotationRistourneTxt'+ID_cotation).style.display = '';
	$('cotationRistourneInput'+ID_cotation).style.display = 'none';
	$('cotationRistourneTxt'+ID_cotation).innerHTML = '...';
}


function cotationTitreEdit(ID_cotation) {
	$('cotationTitreTxt'+ID_cotation).style.display = 'none';
	$('cotationTitreInput'+ID_cotation).style.display = '';
}

function cotationTitreEditProcess(ID_cotation) {
	cotationUpdate(ID_cotation, 'title', $('cotationTitreInput'+ID_cotation).value);
	$('cotationTitreTxt'+ID_cotation).style.display = '';
	$('cotationTitreInput'+ID_cotation).style.display = 'none';
	$('cotationTitreTxt'+ID_cotation).innerHTML = '...';
}

//TRI 
function tri(url, id_tri, tri_sens)
{
	window.location = url+'&tri='+id_tri+'&tri_sens='+tri_sens;
}

//USERS ADMIN

function userDelete(ID_user, query_string)
{
	if(confirm("Etes vous sur de vouloir supprimer cet utilisateur et toutes les donnees associées ? Vous ne pourrez plus restaurer ce profil."))
	{
		window.location.replace("users_lst.php?del="+ID_user+query_string);
	}
}

function userChangeType(ID_user, query_string)
{
	if(confirm("Etes vous sur de vouloir modifier le type (PRO/PART) de cet utilisateur ?"))
	{
		window.location.replace("users_lst.php?chtype="+ID_user+query_string);
	}
}

//ADMIN

function adminDelete(ID_user, query_string)
{
	if(confirm("Etes vous sur de vouloir supprimer cet utilisateur ? Il ne pourra plus accéder a l'administration du site."))
	{
		window.location.replace("admin_lst.php?del="+ID_user+query_string);
	}
}


//CONCOURS ADMIN

function concoursDelete(ID_concours, query_string)
{
	if(confirm("Etes vous sur de vouloir supprimer ce concours et la liste des participants ? Ils ne pourront être restaurés."))
	{
		window.location.replace("concours_lst.php?del="+ID_concours+query_string);
	}
}


//PROMO

function promoDelete(ID_promo, query_string)
{
	if(confirm("Etes vous sur de vouloir supprimer cet enregistrement ?"))
	{
		window.location.replace("promo_lst.php?del="+ID_promo+query_string);
	}
}

function promoSearchHelpHide()
{
	if(divOpen == 0)
	{
		$('promo_theme_select').style.visibility = 'hidden';
	}
}

function promoThemeSearch(search_div, search_str)
{
	$(search_div).style.visibility = 'visible';
	$(search_div).update('Recherche...');
	new Ajax.Updater(search_div, 'promo_edit_theme_search.php?txt='+encodeURI(search_str));		
}

function promoThemeSelect(promo_theme)
{
	$('theme').value = promo_theme;
	$('promo_theme_select').style.visibility = 'hidden';
}

//HOTEL

function hotelDelete(ID_hotel, query_string)
{
	if(confirm("Etes vous sur de vouloir supprimer cet hotel ?"))
	{
		window.location.replace("hotels_lst.php?del="+ID_hotel+'&'+query_string);
	}
}

function hotelPhoPrincipale(ID_hotel, filename)
{
	$('phoprinc').value = filename;
	new Ajax.Request('hotels_edit_pho_princ.php?filename='+encodeURI(filename)+'&ID_hotel='+ID_hotel);
}

function hotelPhoDel(ID_hotel, filename)
{
	//Verif si pas photo principale
	if(filename == $('phoprinc').value)
	{
		alert("Vous ne pouvez pas supprimer la photo principale. Merci de choisir une nouvelle photo principale puis de procéder à la suppression.");
	}
	else
	{
		if(confirm("Etes vous sur de vouloir supprimer cette photo ?"))
		{
			hotelPhoEdit(ID_hotel, filename);
		}
	}
}

//DOWNLOADS

function downloadDelete(ID_download, query_string)
{
	if(confirm("Etes vous sur de vouloir supprimer ce telechargement ?"))
	{
		window.location.replace("downloads_lst.php?del="+ID_download+'&'+query_string);
	}
}

function downloadUserRaz()
{
	$('ID_user').value = 0;
	$('user_name').update('<i>Aucune limitation</i>');
}

function downloadThemeSearch(search_div, search_str, search_type, search_filter)
{
	$(search_div).style.visibility = 'visible';
	$(search_div).update('Recherche...');
	new Ajax.Updater(search_div, 'downloads_edit_theme_search.php?type='+search_type+'&filter='+encodeURI(search_filter)+'&txt='+encodeURI(search_str));		
}

function downloadThemeSelect(download_theme)
{
	$('download_theme').value = download_theme;
	$('download_theme_select').style.visibility = 'hidden';
}

function downloadSsThemeSelect(download_sstheme)
{
	$('download_sstheme').value = download_sstheme;
	$('download_sstheme_select').style.visibility = 'hidden';
}

var divOpen = 0;
function downloadSearchHelpHide()
{
	if(divOpen == 0)
	{
		$('download_sstheme_select').style.visibility = 'hidden';
		$('download_theme_select').style.visibility = 'hidden';
		$('user_select').style.visibility = 'hidden';
	}
}

//PDT ADMIN
function pdtDelete (ID_pdt, query_string)
{
	if(confirm("Etes vous sur de vouloir supprimer définitivement ce produit du catalogue ? Attention, cette suppression peut avoir des conséquences sur les cotations des utilisateurs. Pour le conserver en base de données pour l'historique et ne plus l'afficher, modifiez le critère Affichage en édition produit."))
	{
		window.location.replace("produits_lst.php?del="+ID_pdt+'&'+query_string);
	}
}

//RVD ADMIN
function rvdDelete (ID_rvd, query_string)
{
	if(confirm("Etes vous sur de vouloir supprimer ce revendeur ?"))
	{
		window.location.replace("rvd_lst.php?del="+ID_rvd+'&'+query_string);
	}
}

//MENU AIDE SAISIE

function searchUser(search_div, nom, type)
{
	$(search_div).style.visibility = 'visible';
	$(search_div).update('Recherche...');
	new Ajax.Updater(search_div, 'downloads_edit_user_search.php?nom='+encodeURI(nom)+'&type='+type);		

}

function searchUserSelect(ID_user, user_name)
{
	$('ID_user').value = ID_user;
	$('user_name').update(user_name);
	$('user_select').style.visibility = 'hidden';

}

//FORM
function formInputKeyPress(field, defVal, classOri, classModif)
{
	/*
	if(field.value == defVal)
	{
		field.className = classOri;
	}
	else
	{
		field.className = classModif;
	}
	*/
	
}

function formFocusEmpty(field, defVal)
{
	if(field.value == defVal)
	{
		field.value = '';
	}
}

function formBlurEmpty(field, defVal, classOri)
{
	if(field.value == '')
	{
		field.value = defVal;
		//field.className = classOri;
	}
}

//DIVS MODAUX
function divModalShow (divUrl, nullVar, divW, divH)
{
	if(divW > 0 && divH > 0)
	{
	  	var modal = new Control.Modal.open(divUrl,{  
		    overlayOpacity: 0.75,  
		    className: 'modal', 
		    width:divW,
		    height:divH,
		    fade: true
		});
	}
	else
	{
	  	var modal = new Control.Modal.open(divUrl,{  
		    overlayOpacity: 0.75,  
		    className: 'modal', 
		    fade: true
		});	
	}
}

function divModalHide()
{
	Control.Modal.close();
}

function divTooltip(divId, txt)
{
	var tooltip = new Control.ToolTip($(divId),txt,{  
	    className: 'tooltip'  
	});  
}

function divShowSlide(ID_div)
{
	if($(ID_div).style.display == 'none')
	{
		Effect.SlideDown(ID_div);
		if($(ID_div+'_img'))
		{
			$(ID_div+'_img').src = 'images/btn_reduire.gif';
		}		
	}
	else
	{
		Effect.SlideUp(ID_div);
		
		if($(ID_div+'_img'))
		{
			$(ID_div+'_img').src = 'images/btn_developper.gif';
		}
	}
}

function pdtPhoZoom(ID_pdt)
{
	divModalShow ('/catalogue_produits_zoom.php?ID='+ID_pdt, '', 0, 0);
}

function loginForm(redirUrl)
{
	divModalShow ('/moncompte_login.php?rerout='+encodeURIComponent(redirUrl), '', 0, 0);
}

function account_pwd_lost()
{
	divModalShow ('/moncompte_pwd_lost.php', '', 0, 0);
}

function cotationsCreate()
{
	divModalShow ('/moncompte_cotations_create.php', '', 0, 0);
}

function cotationsAsk()
{
	divModalShow ('/catalogue_cotation_ask.php', '', 0, 0);
}

function concoursFormResult(resultat, ID_concours)
{
	divModalShow ('/concours_form_result.php?resultat='+resultat+'&ID='+ID_concours, '', 0, 0);
}

function userEdit(ID_user, user_type)
{
	divModalShow ('/admin/users_edit.php?ID='+ID_user+'&type='+user_type, '', 750, 630);
}

function adminEdit(ID_user)
{
	divModalShow ('/admin/admin_edit.php?ID='+ID_user, '', 750,550);
}

function downloadEdit(ID_download)
{
	divModalShow ('/admin/downloads_edit.php?ID='+ID_download, '', 750,550);
}

function rvdEdit(ID_rvd)
{
	divModalShow ('/admin/rvd_edit.php?ID='+ID_rvd, '', 750,550);
}

function promoEdit(ID_promo)
{
	divModalShow ('/admin/promo_edit.php?ID='+ID_promo, '', 750,550);
}

function stxtEdit(ID_stxt)
{
	divModalShow ('/admin/stxt_edit.php?ID='+ID_stxt, '', 750,550);
}

function pdtEdit(ID_pdt, ID_collec)
{
	divModalShow ('/admin/produits_edit.php?ID='+ID_pdt+'&ID_collec='+ID_collec, '', 750,550);
}

function concoursEdit(ID_pdt)
{
	divModalShow ('/admin/concours_edit.php?ID='+ID_pdt, '', 750,680);
}

function hotelPhoEdit(ID_hotel, del)
{
	divModalShow ('/admin/hotels_edit_pho.php?ID='+ID_hotel+'&del='+del, '', 700,680);
}

function hotelEdit(ID_hotel)
{
	divModalShow ('/admin/hotels_edit.php?ID='+ID_hotel, '', 750,280);
}
