function recherche_prod(pObject)
{
	var action=true;
	var cible=document.getElementById('dd_prod_filter2_selecta');
	var aSelect=document.getElementsByTagName('select');
	var aReference=new Array('format', 'medium', 'print', 'coating');
	var get="?";
	var html_cible='product_search_result';
	for (var select in aSelect)
	{
		for (var i=0; i<aReference.length; i++)
		{
			if(aSelect[select].name==aReference[i])
			{
				
				if(aSelect[select].value==-1)
				{
					action=false;
				}
				get+=aSelect[select].name+'='+aSelect[select].value+'&';
				action = true;
			}
		}
	}
		var ajax_page='../ajax/getSearchResults.php'+get;
		var requeteAjax=makerequest(ajax_page, html_cible);
		
		if (action == true)
		{
			fade('product_search_result');	
		}
}

function select_option(pObject)
{
	var action=true;
	var cible=document.getElementById('prod_options');
	var aSelect=cible.getElementsByTagName('select');
	var aReference=new Array('paper', 'format', 'print', 'making', 'coating', 'cutting', 'folding', 'gluing', 'holing', 'shaping');
	var get="?";
	
	for (var select in aSelect)
	{
		for (var i=0; i<aReference.length; i++)
		{
			if(aSelect[select].name==aReference[i])
			{
				
				if(aSelect[select].value==-1)
				{
					action=false;
				}
				get+=aSelect[select].name+'='+aSelect[select].value+'&';
			}
		}
	}
	if(action)
	{
		var chpUidRubrique=document.getElementById('chp_uid_rubrique');
		var uidRubrique=chpUidRubrique.value;
		get+='uid='+uidRubrique;
		var ajax_page='../ajax/getQty.php'+get;
		var html_cible='prod_qty';
		var requeteAjax=makerequest(ajax_page, html_cible);
		var div_erase=document.getElementById('prod_price');
		div_erase.innerHTML='';
	}
}


function select_qty(pObject)
{
	var product_qty=pObject.value;
	//alert(product_qty);
	var chp_product_uid=document.getElementById('product_uid');
	var product_uid=chp_product_uid.value;
	//alert(product_uid);
	var get='?product_uid='+product_uid+'&product_qty='+product_qty;
	if(product_qty == -255){
		document.location.href = '../commandes/demande_devis.php';
		}
	else {
	var ajax_page='../ajax/getPrice.php'+get;
	var html_cible='prod_price';
	makerequest(ajax_page, html_cible);
	}
}


function select_ship_addr(pObject,iIncrement)
{	
	var indexCart=iIncrement;
	var cible=document.getElementById('prod_adress_selected_'+indexCart);
	if(pObject.value!=0)
	{
		cible.style.display="block";
		var form_new_adress=document.getElementById("prod_adress_new_"+iIncrement);
		form_new_adress.style.display="none";
		
	}
	else
	{
		cible.style.display="none";
	}
	var get='uid='+pObject.value+'&index='+indexCart;
	var ajax_page='../ajax/getShipAddr.php?'+get;
	var html_cible=cible.id;
	makerequest(ajax_page, html_cible);
	
	var ajax_page='../ajax/setShipAddrControl.php';
	var html_cible='prod_foot';
	makerequest(ajax_page, html_cible);
}

function select_justif_addr(pObject,iIncrement)
{	
	var indexCart=iIncrement;
	//alert('justif_adress_selected_'+indexCart);
	var cible=document.getElementById('justif_adress_selected_'+indexCart);
	if(pObject.value!=0)
	{
		cible.style.display="block";
		var form_new_adress=document.getElementById("prod_adress_new_"+iIncrement);
		form_new_adress.style.display="none";
	}
	else
	{
		cible.style.display="none";
	}
	var get='uid='+pObject.value+'&index='+indexCart;
	var ajax_page='../ajax/getShipSampleAddr.php?'+get;
	var html_cible=cible.id;
	makerequest(ajax_page, html_cible);
	
	var ajax_page='../ajax/setShipAddrControl.php';
	var html_cible='prod_foot';
	makerequest(ajax_page, html_cible);
}

function setItemName(cartItemUID)
{
	var value_item =  document.getElementById(cartItemUID).value;
	
	var get='?name='+value_item+'&index='+cartItemUID;
	var ajax_page='../ajax/renameNickname.php'+get;
	
	makesimplerequest(ajax_page,0);	
}

function setProof(pObject, pId)
{
	/*
	 * met a jour le bat dans la session
	 * met a jour le prix de l'item
	 * met à jour le total du panier
	 */
	
	var proof=pObject.checked;
	
	var indexCart=pId;
	var get='?proof='+proof+'&index='+indexCart;
	
	// mise à jour dans de proof dans la session
	var ajax_page='../ajax/setProof.php'+get;
	var html_cible='tmp_ajax';
	makesimplerequest(ajax_page);
	
	//contrôle des adresses avant étape 2
	var ajax_page='../ajax/setShipAddrControl.php';
	var html_cible='prod_foot';
	makerequest(ajax_page, html_cible);	
	
	// mise à jour du prix de l'item
	ajax_page='../ajax/setItemPriceIncludingProof.php'+get;
	html_cible='itemPrice_'+indexCart;
	makerequest(ajax_page, html_cible);
	
	// mise à jour du total panier
	ajax_page='../ajax/setTotalPanier.php';
	html_cible='total_tarif';
	makerequest(ajax_page, html_cible);
	
	
}

function setSample(pObject, pId)
{
	/*
	 * met a jour le justif dans la session
	 * met a jour le prix de l'item
	 * met à jour le total du panier
	 */
	var sample=pObject.checked;
	var indexCart=pId;
	
	if(pObject.checked==false){
		sample = false;
		html_cible='sample_adress_'+indexCart;
		document.getElementById(html_cible).style.display='none';
		}
	else{
		sample = true;
		html_cible='sample_adress_'+indexCart;
		document.getElementById(html_cible).style.display='block';
		}
		
		var get='?sample='+sample+'&index='+indexCart;
		
		// mise à jour de sample dans la session
		var ajax_page='../ajax/setSample.php'+get;
		var html_cible='tmp_ajax';
		makesimplerequest(ajax_page);
		
		// apparition de l'adresse du justificatif
		ajax_page='../ajax/setSampleAdress.php'+get;
		html_cible='sample_adress_'+indexCart;
		makerequest(ajax_page, html_cible);
		
		/*//contrôle des adresses avant étape 2
		var ajax_page='../ajax/setShipAddrControl.php';
		var html_cible='prod_foot';
		makerequest(ajax_page, html_cible);*/
		
		// mise à jour du prix de l'item
		ajax_page='../ajax/setItemPriceIncludingSample.php'+get;
		html_cible='itemPrice_'+indexCart;
		makerequest(ajax_page, html_cible);
		
		// mise à jour du total panier
		ajax_page='../ajax/setTotalPanier.php';
		html_cible='total_tarif';
		makerequest(ajax_page, html_cible);
}

function newAdresse(pObject)
{
	var cible=document.getElementById("prod_adress_new_"+pObject);
	cible.style.display='block';
	cible.style.opacity='1';
	
	var cible=document.getElementById("prod_adress_selected_"+pObject);
	cible.style.display='none';
}

function newAdresse2()
{	
	var ajax_page='../ajax/epNewAdress.php';
	var html_cible='prod_adress_new';
	
	makerequest(ajax_page, html_cible);
}
function newAdresse2_close()
{
	var ajax_page='';
	var html_cible='prod_adress_new';
	
	makerequest(ajax_page, html_cible);
	
	var cible = document.getElementById(html_cible);
	document.getElementById('ep_add_adress').style.display='block';
}

function devis_addShippAddr()
{
	
	var aShip_qty=new Array();
	var aPostCode=new Array();
	var aCountry=new Array();
	var chpCount=document.getElementById('ship_count');
	var increment=0;
	increment=parseInt(chpCount.value);
	//alert('increment='+increment);
	
	for(j=0; j<increment; j++)
	{
		//alert('j='+j);
		var chp_qty=document.getElementById("ship_qty_"+j);
		aShip_qty.push(chp_qty.value);
		
		var chp_postcode=document.getElementById("postcode_"+j);
		aPostCode.push(chp_postcode.value);
		
		var chp_country=document.getElementById("country_"+j);
		aCountry.push(chp_country.value);
	}
	
	var get="?count="+increment;
	for (var i=0; i<aShip_qty.length; i++)
	{
		get+="&ship_qty_"+i+"="+aShip_qty[i];
	}
	
	for (var i=0; i<aPostCode.length; i++)
	{
		get+="&postcode_"+i+"="+aPostCode[i];
	}
	
	for (var i=0; i<aCountry.length; i++)
	{
		get+="&country_"+i+"="+aCountry[i];
	}
	
	var ajax_page='../ajax/devis_SetShippAddr.php'+get;
	var html_cible='dd2_dest';
	
	makerequest(ajax_page, html_cible);
}

function PanierNext() 
{
	if(document.getElementById('panier_final_btn').style.display=='none')
	{
	document.getElementById('panier_final_btn').style.display='block';
	}
	else{
	document.getElementById('panier_final_btn').style.display='none';
	}
}

function product_finder(pObject)
{
	
	alert(pObject.name+' '+pObject.value);
	
}

function other_product_finder(pObject)
{
	window.location.replace("http://www.printexpress.fr/produits/fiche_produit.php?uid="+pObject.value);
}

/*Espace Pro : Modification adresse perso*/
function epContact()
{	
	var ajax_page='../ajax/epContact.php';
	var html_cible='ep_profil1';
	
	makerequest(ajax_page, html_cible);
}
function epModContact()
{	
	var ajax_page='../ajax/epModContact.php';
	var html_cible='ep_profil1';
	
	makerequest(ajax_page, html_cible);
}

/*Espace Pro : Modification adresse de société*/
function epOrg()
{	
	var ajax_page='../ajax/epOrg.php';
	var html_cible='ep_profil2';
	
	makerequest(ajax_page, html_cible);
}
function epModOrg()
{	
	var ajax_page='../ajax/epModOrg.php';
	var html_cible='ep_profil2';
	
	makerequest(ajax_page, html_cible);
}

/*Espace Pro : Modification adresse de facturation*/
function epFac()
{	
	var ajax_page='../ajax/epFac.php';
	var html_cible='ep_content3';
	
	makerequest(ajax_page, html_cible);
}
function epModFac()
{	
	var ajax_page='../ajax/epModFac.php';
	var html_cible='ep_content3';
	
	makerequest(ajax_page, html_cible);
}
function epCollabAdd() 
{
	var ajax_page='../ajax/epCollabAdd.php';
	var html_cible='ep_contact_new';
	
	makerequest(ajax_page, html_cible);
}

function ep2ComDetails(comid)
{
	if(document.getElementById(comid).style.display=='none'){
		document.getElementById(comid).style.display='table-row';
	}
	else{
		document.getElementById(comid).style.display='none';
	}
}

function ep2BatVal(id, comid)
{	
	var ajax_page='../ajax/ep2BatVal.php'+'?id='+id+'&comid='+comid;
	var html_cible='ep_bat_validator';
	
	makerequest(ajax_page, html_cible, id, comid);
	
	var cible = document.getElementById(html_cible);
	cible.style.display='block';
}

function ep2BoxClose()
{	
	var ajax_page='';
	var html_cible='ep_bat_validator';
	
	makerequest(ajax_page, html_cible);
	
	var cible = document.getElementById(html_cible);
	cible.style.display='none';
}

/*OLD POP-UP METHOD*/
/*function ep2FileTransfer()
{	
	var ajax_page='../ajax/ep2FileTransfer.php';
	var html_cible='ep_bat_validator';
	
	makerequest(ajax_page, html_cible);
	
	var cible = document.getElementById(html_cible);
	cible.style.display='block';
}*/

function ftpShowMtd1(id, comid)
{
	var ajax_page='../ajax/ftpMethod1.php'+'?id='+id +'&comid='+comid;
	var html_cible='ftp_method';
	
	makerequest(ajax_page, html_cible);
	
	var cible = document.getElementById(html_cible);
	if (html_cible != null){
		cible.style.display='block';
		fade(html_cible);
	}
}

function ftpShowMtd2(id, comid)
{
	var ajax_page='../ajax/ftpMethod2.php'+'?id='+id+'&comid='+comid;
	var html_cible='ftp_method';
	
	makerequest(ajax_page, html_cible);
	
	var cible = document.getElementById(html_cible);
	if (html_cible != null){
		cible.style.display='block';
		fade(html_cible);
	}
}

function ftpWait() 
{
	document.getElementById('file_picker').style.display='none';
	document.getElementById('ftp_upload_wait').style.display='block';
}

function MailBox(page)
{
	get = '?';
	get+='page=';
	get+= page;
	var ajax_page='../ajax/mailerBox.php'+get;
	var html_cible='cat_form';
	
	makerequest(ajax_page, html_cible);
	
	var cible = document.getElementById(html_cible);
	
	if (html_cible != null){
		cible.style.display='block';
		fade(html_cible);
	}
}


var fadeTime = 800.0;

function fade(id)
{	
	cible = document.getElementById(id);
	var fadestate = cible.style.opacity;
	if(fadestate == null){
		if(cible.style.opacity==null||cible.style.opacity==''||cible.style.opacity=='1'){
			cible.fadestate = 2;
			}
		else {
			cible.fadestate = -2;
			}
		}
	if(cible.fadestate == 1||cible.fadestate == -1)
		{
		cible.fadestate = cible.fadestate == 1 ? - 1 : 1;
		cible.fadeTimeleft = fadeTime - cible.fadeTimeleft;
		}
	else {
		cible.fadestate = cible.fadestate == 2 ? -1 : 1;
		cible.fadeTimeleft = fadeTime;
		setTimeout("fademotion(" + new Date().getTime() + ",'" + id + "')", 33);
		}
}

function fademotion(last, id)
{  
  var cur = new Date().getTime();
  var elapsed = cur - last;
 
  var element = document.getElementById(id);
 
  if(element.fadeTimeleft <= elapsed)
  {
    element.style.opacity = element.fadestate == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '+ (element.fadestate == 1 ? '100' : '0') + ')';
    element.fadestate = element.fadestate == 2;
    return;
  }
 
  element.fadeTimeleft -= elapsed;
  var newOpVal = element.fadeTimeleft/fadeTime;
  if(element.fadestate == 1)
  newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("fademotion(" + cur + ",'" + id + "')", 33);
}

function controlNickName()
{
	var valid = true;
	var element = document.getElementsByClassName('nickname');
	
	for(var i=0 ; i<element.length; i++){
		if(element[i].value == '' || element[i].value == 'Nommez votre dossier'){
			valid = false;	
		}
	}
	
	if(valid == false){
		alert("Veuillez saisir un nom de dossier pour chaque produit.");
	}
	
	return valid;
}

function files_list(item,compteur)
{
	var get ='?itemUID=' + item + '&cpt=' + compteur;
	var ajax_page = 'files_list.php'+get;
	var html_cible = 'fichier-envoyes';
	
	//alert(get + '||' + ajax_page + '||' + html_cible);
	makerequest(ajax_page,html_cible,0);	
}

function help(cartItem, fonction){
	if(fonction != 0){
		$('#infosBAT-'+cartItem).fadeIn('def');
	} else {
		$('#infosBAT-'+cartItem).fadeOut('def');
	}	
}

function help2(cartItem, fonction){
	if(fonction != 0){
		$('#infosJustif-'+cartItem).fadeIn('def');
	} else {
		$('#infosJustif-'+cartItem).fadeOut('def');
	}
}


