String.prototype.trim = function() { return this.replace(/^\s+|\s+$/gi, ''); }
function is_email(v){ return v.match(/^[a-z0-9\.\-\+_]+@[a-z0-9\-_]+\.[a-z\.\-_]{1,}[a-z\-_]+/); }

function AfficheImage(photo){
	if(photo == null){
		$('PreviewPhoto').style.display = 'none';
		$$('#PreviewPhoto img')[0].src = null;
	}else{
		var arXY = Position.realOffset($('PreviewPhoto'));
		$$('#PreviewPhoto img')[0].src = "/images/photos/"+photo;
		$('PreviewPhoto').style.top = arXY[1]+'px';
		timer = setTimeout(function(){$('PreviewPhoto').style.display = 'block'; clearTimeout(timer);}, 1000);
	}
}

function isState(i){
	if (i == 1){
		var arXY = $('animLoad').cumulativeScrollOffset();
		$('animLoad').style.top = arXY[1]+'px';
	}	else
		$('animLoad').style.top = "-100px";
}
function AfficheInfoProduit(idProd){
	isState(1);
	if($('infoProduit')) $('infoProduit').remove();
	// A Décommenter en production
	//new Ajax.Updater('conteneur', 'http://www.serticlos.com/web2/service.php', {
    // A commenter en production
	  new Ajax.Updater('conteneur', '/service.php', {
		parameters: { 'p_id': idProd, 'p_action':'infoProduit'},
		insertion: Insertion.Top,
		onComplete: function(t){
									isState(0);
									var arXY = $('infoProduit').cumulativeScrollOffset();
									$('infoProduit').style.top = (arXY[1]+15)+'px';
									$('infoProduit').style.display = 'block';
								}
	});
}

function addPanier(id, popupInfo){
	isState(1);
	var taille = null;
	var qt = null;

	if(popupInfo){
		var qt = $$('#infoProduit #p_quantite')[0].value;
		if( $$('#infoProduit #p_taille')[0] ) taille = $$('#infoProduit #p_taille')[0].value;
	}else{
		if($('taille_'+id)) var taille = $F('taille_'+id);
		var qt = $F('quantite_'+id);
		if( $('taille_'+id) ) taille = $F('taille_'+id);
	}
	new Ajax.Request('/service.php', {
		parameters: { 'p_id': id, 'page':'addPanier', 'p_qt':qt, 'p_option':taille},
		onComplete: function(t){
									isState(0);
									if(t.responseText == 'Ok') alert('le produit sélectionné a bien été ajouté au panier');
									else  alert("le produit sélectionné n'a pu être ajouté au panier");
								}
	});
}

function chiffres(event)
{
	// Compatibilit IE / Firefox
	if(!event&&window.event) {
		event=window.event;
	}
	if(event.keyCode == 8 || event.which == 8) return;
	// IE
	if(event.keyCode < 48 || event.keyCode > 57) {
		event.returnValue = false;
		event.cancelBubble = true;
	}
	// DOM
	if(event.which < 48 || event.which > 57) {
		event.preventDefault();
		event.stopPropagation();
	}
}

function popPhoto(w,h,dest){
	winPopPhoto = open(dest, 'photo', 'width='+(w+20)+', height='+(h+20)+', scrollbar=false');
	if(winPopPhoto) winPopPhoto.focus();
}

function swapProduitActive(elBox, id){
	if(elBox.checked) $('p_produit_'+id).disabled = 'disabled';
	else  $('p_produit_'+id).removeAttribute('disabled');

}
/*
function printBon(){
	new Ajax.Updater('cadreBonReduction', '/service.php?page=gestBonReduc',
										{ onComplete:function(t){
												if(t.responseText=='ok') alert('Vous ne disposez plus de bon de réduction.');
												//else if(t.responseText=='ko') alert('Vous ne disposez plus de bon de réduction.');
											}
										});
}

function addBon(){
	$('sBob').selectedIndex;
}
*/
