/**
	Script d'Euro8Securite
	Copyright e-leos
	Octobre 2006
**/

function	saveProductAjax()
{
	//	Get the parameters of the form
	parameters = Form.serializeURI( $("productform") );
	//	Create the URL
	url = "/produits/enregisterproduitajax.html";
	//	Create the options
	options = {
         method   : 'post',
         postBody : parameters
		 };
	//	Request the updater
	new	Ajax.Updater( "maincontent", url, options );
	/*url = url+"?"+parameters;
	new	Ajax.Updater( "maincontent", url );*/
	//	Finished
	return false;
}

function	deleteProduct()
{
	if( window.confirm("Etes-vous sûr de vouloir supprimer ce produit ?") ){
		return	true;
	}else{
		return	false;
	}
	
}

function	updateDetailledDisplay(){
	var	ck = $('layoutcomplete');
	if( ck.checked ){
		ShowElement($("detailtable"), "block");
		ShowElement($("divtechnic"), "block");
		$("productdetailled1").disabled = false;
		$("productdetailled2").disabled = false;
	}else{
		HideElement($("detailtable"));
		HideElement($("divtechnic"));
		$("productdetailled1").disabled = true;
		$("productdetailled2").disabled = true;
	}
}

function	initeditor(){
	new MyAjax.TextEditor( $('productdescription'), { boldbutton: $('descboldbutton'), italicbutton: $('descitalicbutton'), underlinebutton: $('descunderlinebutton'), biggerbutton: $('descbiggerbutton'), smallerbutton: $('descsmallerbutton'), centerbutton: $('desccenterbutton') } );
	new MyAjax.TextEditor( $('productdetailled1'), { boldbutton: $('det1boldbutton'), italicbutton: $('det1italicbutton'), underlinebutton: $('det1underlinebutton'), biggerbutton: $('det1biggerbutton'), smallerbutton: $('det1smallerbutton'), centerbutton: $('det1centerbutton') } );
	new MyAjax.TextEditor( $('productdetailled2'), { boldbutton: $('det2boldbutton'), italicbutton: $('det2italicbutton'), underlinebutton: $('det2underlinebutton'), biggerbutton: $('det2biggerbutton'), smallerbutton: $('det2smallerbutton'), centerbutton: $('det2centerbutton') } );
}

function	openProductMainPhotoUpload( productid, purpose )
{
	var	url = "/produits/showproductuploadajax.html?productid="+productid+"&purpose="+purpose;
	window.open( url, "", "width=400,height=100,resizable,scrollbars" );
}

function	openProductSecondaryPhotoUpload( productid, purpose )
{
	var	url = "/produits/showproductuploadajax.html?productid="+productid+"&purpose="+purpose;
	window.open( url, "", "width=400,height=100,resizable,scrollbars" );
}

function	onUpdateFinished()
{
	window.close();
}

function	refreshParentImage( productid, purpose )
{
	if( window.opener == null )
	{
		alert("Une erreur s'est produite dans l'application, veuillez fermer la fenêtre manuellement");
		return;
	}
	
	target = window.opener.document.getElementById( "imagepurpose"+purpose );
	if( target == null )
	{
		alert("Erreur: cible de la mise à jour non trouvée");
		return;
	}
	
	//	Create the URL
	var	url = "/produits/produitimage"+purpose+"ajax.html?productid="+productid;
	//alert(url);
	//	Create the options
	options = {
         method   : 'get',
		 onSuccess : onUpdateFinished
		 };
	//	Request the updater
	new	Ajax.Updater( target, url, options );
	//	Finished
	return;
	
}

function	deleteImage( productid, fileid, purpose )
{
	if( !window.confirm("Etes-vous sûr de vouloir supprimer cette image ?") ){
		return;
	}
	
	var	url = "/produits/produitsupprimage"+purpose+"ajax.html?productid="+productid+"&fileid="+fileid;
	DoUpdate('imagepurpose'+purpose, url);
}

function	submitGamme( button, value )
{
	//	Get the parameters of the form
	var	parameters = Form.serializeURI( $("gammeform") );
	//	Add the button
	parameters = parameters+"&"+button+"="+value
	//	Create the URL
	url = "/produits/gammeajax.html";
	//	Create the options
	options = {
         method   : 'post',
         postBody : parameters
		 };
	//	Request the updater
	new	Ajax.Updater( "gammearray", url, options );
	//	Finished
	return false;
}

function	upDirectory()
{
	var	idx = $('childsselect').selectedIndex;
	if( idx < 0 )
	{
		return;
	}
	if( idx == 0 )
	{
		return;
	}
	var	tempText = $('childsselect').options[idx].text;
	var	tempValue = $('childsselect').options[idx].value;
	
	$('childsselect').options[idx].text = $('childsselect').options[idx-1].text;
	$('childsselect').options[idx].value = $('childsselect').options[idx-1].value;
	$('childsselect').options[idx-1].text = tempText;
	$('childsselect').options[idx-1].value = tempValue;
	$('childsselect').selectedIndex = idx-1;
	return;
	
}

function	downDirectory()
{
	var	idx = $('childsselect').selectedIndex;
	if( idx < 0 )
	{
		return;
	}
	var	count = $('childsselect').options.length;
	if( idx >= count-1 ){
		return;
	}
	var	tempText = $('childsselect').options[idx].text;
	var	tempValue = $('childsselect').options[idx].value;
	
	$('childsselect').options[idx].text = $('childsselect').options[idx+1].text;
	$('childsselect').options[idx].value = $('childsselect').options[idx+1].value;
	$('childsselect').options[idx+1].text = tempText;
	$('childsselect').options[idx+1].value = tempValue;
	$('childsselect').selectedIndex = idx+1;
	return;
}

function	SubmitDirectoryOrder()
{
	var	count = $('childsselect').options.length;
	if( count <=1 ){
		alert("L'application ne peut pas tier des sous-répertoires qui n'existent pas ou un répertoire unique")
		return false;
	}
	var	tempS = "";
	for( i=0 ; i<count ; i++ )
	{
		if( tempS == ""){
			tempS = $('childsselect').options[i].value;
		}else{
			tempS = tempS+";"+$('childsselect').options[i].value;
		}
	}
	$('folderorder').value = tempS;
	return	true;
}