function rollblock() {

	if (document.getElementById('rollblock').style.display=="none") {
			document.getElementById('rollblock').style.display="block";
	}else{
		document.getElementById('rollblock').style.display="none";
	}
}

function rollnewsletter() {

	if (document.getElementById('rollnewsletter').style.display=="none") {
			document.getElementById('rollnewsletter').style.display="block";
	}else{
		document.getElementById('rollnewsletter').style.display="none";
	}
}

function rollamis() {
	$$('.rollamis').setStyles({display: 'none' });

	if (document.getElementById('rollamis').style.display=="none") {
			document.getElementById('rollamis').style.display="block";
	}else{
		document.getElementById('rollamis').style.display="none";
	}
}

function encadre(obj,num) {
	
	$$('#bloc_droit_possoft img').removeClass('active');
	$(obj).addClass('active');
	document.getElementById('soft_nom_ill').innerHTML = obj.title;
	
	document.forms['majimage'].position.value=num;
	submitForm($('majimage'));
	
}

function updatestyle(num)
{
	document.forms['majimage'].style.value=num;
	submitForm($('majimage'),1);	
}

function updatetexte(txt)
{
	document.forms['majimage'].message.value=txt;
	submitFormTxt($('majimage'));	
}

function updatetexteweight(po)
{
	if(document.forms['majimage'].weight.value==po)
		po=0;
	document.forms['majimage'].weight.value=po;
	submitFormTxt($('majimage'));
}

function updatetextetransform(po)
{
	if(document.forms['majimage'].transform.value==po)
		po=0;
		
	document.forms['majimage'].transform.value=po;
	submitFormTxt($('majimage'));
}

function updatetaille(sel)
{
	document.forms['majimage'].taille.value=sel.options[sel.selectedIndex].value;
	submitFormTxt($('majimage'));
}

function updatepolice(sel)
{
	document.forms['majimage'].police.value=sel.options[sel.selectedIndex].value;
	submitFormTxt($('majimage'));	
}

function updatetextealign(ind)
{
	document.forms['majimage'].align.value=ind;
	submitFormTxt($('majimage'));	
}

function changeOnglet(id) {

if(id<=3)	{
	for(i=1;i<=3;i++) {
			document.getElementById("soft_onglet_contenu_"+i).style.display = "none";
			document.getElementById("onglet_etat_"+i).className = "onglet_inactif";
	}
}
if(id>3 && id<=6)	{
	for(i=4;i<=6;i++) {
			document.getElementById("soft_onglet_contenu_"+i).style.display = "none";
			document.getElementById("onglet_etat_"+i).className = "onglet_inactif";
	}
}
	document.getElementById("onglet_etat_"+id).className = "onglet_actif";
	document.getElementById("soft_onglet_contenu_"+id).style.display = "block";	
}

function persoDelImage()
{
	document.forms['majimage'].image_url.value='';
	submitForm($('majimage'));
	document.forms['produit'].perso.value='';
	updateTarif();		
	removeDivPanier();
}

function persoDelMotif()
{
	document.forms['majimage'].motif_url.value='';
	submitForm($('majimage'));
	removeDivPanier();
}

function persoUpdateImage(img, what)
{
	cacheAide();

	document.forms['majimage'].image_url.value=img;
	submitForm($('majimage'));
	
	if(what == 'perso')
		document.forms['produit'].perso.value=1;
	else
	{
		addHitDeco(img);
		document.forms['produit'].perso.value='';
	}
		
	updateTarif();		
	removeDivPanier();
}

function persoUpdateMotif(img, what)
{
	cacheAide();
	
	document.forms['majimage'].motif_url.value=img;
	submitForm($('majimage'));
	addHitDeco(img);
	removeDivPanier();
}

function addHitDeco(url_image)
{
	new Ajax(
		'/ajax/personalisation/hitImage.php',
		{
			method: 'post',
			data:'url='+url_image
		}
	).request();
}

function submitForm(obj,spin)
{
	if(spin==1)
	{
		if(!dataDiv){
			dataDiv = document.createElement('div');
			dataDiv.style.position = 'absolute';
			document.getElementById('bloc_centre_contenu').appendChild(dataDiv);
		}
	
		$(dataDiv).setStyles({
		   backgroundColor: '#000000',
		   width: '270px',
		   height: '270px',
		   position: 'absolute',
		   border: '1px solid #000',
		   top: '34px',
		   left: '34px',	   
	   	 zIndex: '1600',
		   visibility: 'hidden'
		});
	
		new Ajax(
			'/ajax/spinner.php',
			{
				method: 'get',
				update: dataDiv,
				evalScripts: true
			}
		).request();	
	}	
	
		new Ajax(
		'/ajax/personalisation/updateImage.php',
		{
			method: 'get',
			update: $('personnalisation'),
			data:$(obj).toQueryString(),
			onRequest: function(req) {
				if(spin==1)
					$$(dataDiv).setStyles({visibility: 'visible' });
			},
			onComplete: function() {
				if(spin==1)
					setTimeout('removeDivPanier()',500);
					
				$('zoomcrea').style.display='block';
			},			
			evalScripts: true
		}
	).request();
}

function spinner()
{
		if(!dataDiv){
			dataDiv = document.createElement('div');
			dataDiv.style.position = 'absolute';
			document.getElementById('bloc_centre_contenu').appendChild(dataDiv);
		}
	
		$(dataDiv).setStyles({
		   backgroundColor: '#000000',
		   width: '270px',
		   height: '270px',
		   position: 'absolute',
		   border: '1px solid #000',
		   top: '34px',
		   left: '34px',	   
	   	 zIndex: '1600',
		   visibility: 'hidden'
		});
	
		new Ajax(
			'/ajax/spinner.php?up=1',
			{
				method: 'get',
				update: dataDiv,
				evalScripts: true
			}
		).request();	
	
	
	$$(dataDiv).setStyles({visibility: 'visible' });
}

function submitFormTxt(obj)
{
		new Ajax(
		'/ajax/personalisation/updateTexte.php',
		{
			method: 'get',
			update: $('personnalisationtxt'),
			data:$(obj).toQueryString(),
			evalScripts: true
		}
	).request();
	$('zoomcrea').style.display='block';
}



// Upload de photo
function checkModif()
{
	//if(!dataDiv)
		spinner();
		
	var contenu = "";
	if(navigator.appName=="Microsoft Internet Explorer")
		contenu = document.frames["iframePhoto"].document.body.innerHTML;
	else
		contenu =document.getElementById('iframePhoto').contentDocument.body.innerHTML;
	
	if(contenu == "")
		setTimeout("checkModif()",1000);
	else
	{
		if(contenu.indexOf("err")!=-1)
		{
			//Erreur d'Upload
			new Ajax(
				'/ajax/personalisation/err_upload.php',
				{
					method: 'get',
					update: dataDiv,
					evalScripts: true
				}
			).request();				
		}
		else
		{
			persoUpdateImage(contenu,'perso');
		}
		
		document.forms['uploadimage'].reset();
		if(navigator.appName=="Microsoft Internet Explorer")
			document.frames["iframePhoto"].document.body.innerHTML="";
		else
			document.getElementById('iframePhoto').contentDocument.body.innerHTML="";		
	}

}

function saveCreation(obj)
{
		new Ajax(
		'/ajax/personalisation/saveCreation.php',
		{
			method: 'get',
			data:$(obj).toQueryString()+ '&' +$('produit').toQueryString(),
			evalScripts: true,
			onComplete: function (req) {
				alert(req);
			}
		}
	).request();
}



function rollcreate() {

	$$('.rollamis').setStyles({display: 'none' });
	//$$('.rollamis').setStyles().display = 'none';

	if (document.getElementById('rollcreate').style.display=="none") {
			document.getElementById('rollcreate').style.display="block";
	}else{
		document.getElementById('rollcreate').style.display="none";
	}
}

function createcreation(obj)
{
	if(document.forms['send_create'].tmp_client_creation_nom.value != '')
	{
		document.forms['majimage'].creation_nom.value=document.forms['send_create'].tmp_client_creation_nom.value;
		saveCreation($('majimage'));
		$('rollcreate').style.display = 'none';
	}
	else
	{
		alert('Merci de saisir un nom!');
	}
}


var move=0;
function cachemove()
{
	if($('positionmain'))
		$('positionmain').style.display="none";
}

function affichemove()
{
	if($('positionmain'))
		$('positionmain').style.display="block";
}

function updateTarif()
{
	
		new Ajax(
		'/ajax/personalisation/updateTarif.php',
		{
			method: 'get',
			data:$('produit').toQueryString(),
			onComplete: function(req) {
				var arr = req.split('|');
				document.forms['produit'].produit_attribut_id.value=arr[0];
				$('vdvc_prix').innerHTML=arr[1];
			},
			evalScripts: true
		}
	).request();
}


var stepOne = false;

function selectTaille(obj,load)
{
	//alert(obj.options[obj.selectedIndex].value);
	if(obj.options[obj.selectedIndex].value != '')
	{
		$('select_matiere').disabled = false;
		$('select_matiere').removeClass('disable');

		compat = obj.options[obj.selectedIndex].className;
		arrCompat = compat.split(' ');
		
		arrArt2 = $$('#select_matiere option.tocheck').setStyle('display', 'none');
		arrArt = $$('#select_matiere .'+obj.options[obj.selectedIndex].value).setStyle('display', 'block');
		
		document.forms['produit'].produit_option_valeur_id.value=obj.options[obj.selectedIndex].value;
		document.forms['produit'].produit_option_valeur_id_bis.value="";
		
	if(load=="undefined")
		updateTarif();
		
	}
	else
	{
		document.forms['produit'].produit_option_valeur_id_bis.value="";
		stepOne = false;
	}

	if(load=="undefined")
		$('select_matiere').selectedIndex = 0;
		
	selectMatiere($('select_matiere'));
}

function selectMatiere(obj)
{
	if(obj.options[obj.selectedIndex].value != '' && $('select_matiere').options[$('select_matiere').selectedIndex].value != '')
	{
		$('select_couleur').setStyle('display', 'none');
		$('noselect_couleur').setStyle('display', 'none');
		
		if(obj.options[obj.selectedIndex].value == '2')
		{
			$('personnalisation').setStyle('background', 'none');
			$('myInput').value='-1';
			$('noselect_couleur').setStyle('display', 'block');
		}
		else
		{
			if($('myInput').value == '-1' || $('myInput').value == 'null') $('myInput').value='Couleurs';
			$('select_couleur').setStyle('display', 'block');			
		}

		document.forms['produit'].produit_option_valeur_id_bis.value=obj.options[obj.selectedIndex].value;

		updateTarif();
		
		stepOne = true;
		activateOtherStep();
	}
	else
	{
		$('personnalisation').setStyle('background', 'none');
		$('myInput').value='null';
		$('select_couleur').setStyle('display', 'none');
		$('noselect_couleur').setStyle('display', 'none');		
		document.forms['produit'].produit_option_valeur_id_bis.value="";
		stepOne = false;
	}
}

var effect2 = false;
var effect3 = false;



var fx = false;

function activateOtherStep()
{
	$('bloc_droit_3onh').removeClass('disable');
	$('bloc_droit_2onh').removeClass('disable');

	effect2 = $('bloc_droit_2onh').effect('opacity', {duration: 800});
	effect3 = $('bloc_droit_3onh').effect('opacity', {duration: 800});
	
	
	
	fx = function() {
		effect2.start('1').chain(function() {
			effect2.start('0.5');
		});
		effect3.start('1').chain(function() {
			effect3.start('0.5');
		});				
	}

	fx();
	periodical = fx.periodical(1700);		
	boulechat=false;		
}

function load_deco(obj, where)
{
	new Ajax(
		'/ajax/load_deco.php',
		{
			method: 'get',
			update: where,
			data:'theme_id='+obj.options[obj.selectedIndex].value,
			evalScripts: true
		}
	).request();
}
var periodical;
function show_hide_soft(id,obj) {
	
	if(id != 1 && stepOne == false)
	{
		alert('Vous devez choisir une taille ainsi qu\'une matiere avant de poursuivre.');
	}
	else
	{
		cacheAide();
		$clear(periodical);


		$$('.stepcontent').setStyle('display', 'none');
		document.getElementById("bloc_droit_1onh").className="bloc_droit_1off";
		document.getElementById("bloc_droit_2onh").className="bloc_droit_2off";
		document.getElementById("bloc_droit_3onh").className="bloc_droit_3off";						

		$(obj).removeClass("bloc_droit_"+id+"off");
		$(obj).addClass("bloc_droit_"+id+"onh");
		document.getElementById("bloc_droit_"+id+"onc").style.display="block";
		document.getElementById("imgetat_"+id).src="/charte/soft/agrandir.png";
		setTimeout("$('bloc_droit_2onh').setStyle('opacity', 1)",950);
		setTimeout("$('bloc_droit_3onh').setStyle('opacity', 1)",950);
	}
	/*
	if (document.getElementById("bloc_droit_"+id+"onh").className=="bloc_droit_"+id+"onh") {	
			document.getElementById("bloc_droit_"+id+"onh").className="bloc_droit_"+id+"off";
			document.getElementById("bloc_droit_"+id+"onc").style.display="none";
			document.getElementById("imgetat_"+id).src="/charte/soft/agrandir.png";
	}else{
			document.getElementById("bloc_droit_"+id+"onh").className="bloc_droit_"+id+"onh";
			document.getElementById("bloc_droit_"+id+"onc").style.display="block";
			document.getElementById("imgetat_"+id).src="/charte/soft/retraicir.png";	
	}	
	*/
}

function effacercreation(idcreation)
{
	a = confirm("Etes-vous sur de vouloir supprimer votre Creation ?");
	if(a)
		document.location.href="/account_checkout.html?action=del&client_creation_id=" + idcreation;
}

function utiliseCreation(idcrea)
{
	if($('produit_id' + idcrea).selectedIndex==0)
		alert("Merci de choisir le produit sur lequel vous souhaitez appliquer votre Creation");
	else
	{
		document.location.href=$('produit_id' + idcrea).options[$('produit_id' + idcrea).selectedIndex].value + "?load=" + idcrea;
	}
}

function cacheAide()
{

	$('soft_centre_etape1').style.display='none';
	$('personnalisation').style.display='block';
	$('personnalisationtxt').style.display='block';
}

var imgDiv = false;

function overPhoto(obj,img,w,h)
{
	if($('iframebla'))
	{
		$('iframebla').remove();
		blaaFrame = false;
		
	}
	
	$$('.image_div').setStyles({display: 'none' });
	
	if(!imgDiv){
		imgDiv = document.createElement('img');
		imgDiv.style.position = 'absolute';
		document.body.appendChild(imgDiv);
	}

	
	imgDiv.src = img;
	imgDiv.id = 'imageDiv';	
	imgDiv.className = 'image_div png';
	Pos = $(obj).getPosition();
	
	imgDiv.style.height = h + 'px';
	imgDiv.style.width = w + 'px';
	imgDiv.style.left = Pos.x + 17 - w/2 + 'px';
	imgDiv.style.top = Pos.y - 7 - h + 'px';
	putFrame('imageDiv');
	imgDiv.style.display = 'block';

		/*
	$(dataDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '500px',
	   height: '250px',
	   position: 'absolute',
	   border: '1px solid #000',
	   top: '50%',
	   left: '50%',	   
	   marginLeft: '-250px',	   
	   marginTop: (getScrollTop()-125) + 'px',	   	   	   
	   zIndex: '1600',
	   visibility: 'hidden'
	});*/

}

var blaaFrame = false;

function putFrame(obj){
	if($('iframebla'))
	{
		$('iframebla').remove();
		blaaFrame = false;
		
	}
		
	blaaFrame   = document.createElement("iframe");
	var d    = $(obj);
//alert(d+' '+d.offsetTop+' '+d.offsetLeft);
	blaaFrame.id = "iframebla";
	with(blaaFrame.style){
		position	= "absolute";
	 	width    	= d.offsetWidth+"px";
	  height		= d.offsetHeight+"px";
	 	top			= d.offsetTop+"px";
	  	left		= d.offsetLeft+"px";
	   	zIndex		= "1";
	   	border = "none";
	   	margin = "0";
	   	padding = "0";	   	
	}

	document.body.appendChild(blaaFrame);
}

function outPhoto()
{
	if(imgDiv){
		$(imgDiv).remove();
		imgDiv = false;
	}	
	
	if($('iframebla'))
	{
		$('iframebla').remove();
		blaaFrame = false;
		
	}
	
	if(blaaFrame){
		$(blaaFrame).remove();
		blaaFrame = false;
	}	
	
}

function razCrea()
{
	$('image_url').value="";
	
	$('personnalisation').setStyle('background', 'none');
	$('myInput').value='Couleur';	
	document.forms['produit'].perso.value="";
	
	document.forms['majimage'].position.value="";
	document.forms['majimage'].couleur_fond.value="";
	document.forms['majimage'].motif_url.value="";
	document.forms['majimage'].creation_nom.value="";
	document.forms['majimage'].style.value="";
	document.forms['majimage'].message.value="";
	document.forms['majimage'].police.value="";
	document.forms['majimage'].taille.value="36";
	document.forms['majimage'].couleur.value="";
	document.forms['majimage'].top.value="";
	document.forms['majimage'].left.value="";
	document.forms['majimage'].align.value="";
	document.forms['majimage'].weight.value="";
	document.forms['majimage'].transform.value="";

	submitForm($('majimage'));
	submitFormTxt($('majimage'));
	updateTarif();	
}

function tagPad(action_id, produit_id, track_id)
{
	new Ajax(
		'/ajax/tagPad.php',
		{
			method: 'get',
			data:'tag_pad_action_id='+action_id+'&produit_id='+produit_id+'&tag_pad_track_id='+track_id,
			evalScripts: true
		}
	).request();
}