function getCook(nom) {
  deb = document.cookie.indexOf(nom + "=")
  if (deb >= 0) {
    deb += nom.length + 1
    fin = document.cookie.indexOf(";",deb)
    if (fin < 0) fin = document.cookie.length
    return unescape(document.cookie.substring(deb,fin))
  }
  return ""
}
        
function checkOut(){


i=1;

if(orderNum  <= 0 ){ setCookie('curcook','',-1);return panierVide();}
dejaSoumis=false ;
var c=[bandeau()];
 

var d=[bandeau()];


out = true ;
grandTotal = 0;
c.push('<div style="width: 574px;margin: 10px;text-align:center;">') ;
c.push('<p class="rouge13"  style="margin:20px"> Mon panier achat</p>');
//Titre de la table
c.push("<table width='554' id='checkout' cellspacing='0' summary='Mon panier'>");
c.push( "<thead><tr><td>" ) ;
c.push([ s_q, "Reference", s_P, s_T, s_C, s_Px+_dse, s_Tot, 'Annuler' ].join("</td><td>") );
c.push("</td></tr></thead><tbody>");
//Lignes de tables
for(var i = 1; i <= orderNum; i++){
	c.push("<tr><td>");
c.push("<table><tr><td>");
	c.push("<input type='text' value='"+order[i].totQ+"' id='i_"+i+"' class='' size='2'/>") ;

c.push("</td><td width=9 valign='top'>");
c.push("<img src='images/boutique/More.gif' alt='Plus' id='plus_"+i+"' />");
c.push("<img src='images/commun/spacer.gif' width='9' height='3'>");
c.push("<img src='images/boutique/Less.gif' alt='Moins' id='moins_"+i+"' />");

c.push("</td></tr></table>");
	
	c.push("</td>");
	c.push("<td>"+order[i].ref+"</td>");
	c.push("<td>"+order[i].Indx+"</b></td>");
	c.push("<td>"+order[i].taille+"</td>");
	c.push("<td>"+order[i].couleur+"</td>");
	c.push("<td>"+currency(order[i].totSum/order[i].totQ)+"</td>");
	c.push("<td>"+currency(order[i].totSum)+_dse+"</td>");
	c.push("<td><img src='images/boutique/supprimer.gif' id='s_"+i+"' /></td>");
	c.push("</tr>");
	grandTotal += parseFloat(order[i].totSum);
}

finalSum = currency((grandTotal * 0) + grandTotal);
c.push("<tr><td colspan='8' align='right'>"); 
if( coef < 1.5) ttc= 'HT' ;
c.push(" Total "+ttc+" de votre commande: " + finalSum + _dse+" &nbsp;&nbsp;</td>");
c.push("</tr></tbody></table>");
c.push("<img src='images/commun/spacer.gif' width='20' height='20'> <br/>");


url_order ="<form name='orderSecure'  method='post' action='https://ssl6.ovh.net/~derhy/secure/paiement.cgi' target='_self' >";
//var url_order ="<form name='orderSecure'  method='post' action='secure_.cgi'>";

c.push( url_order); //form action... suivant french ou english.js
//c.push("<form action='javascript:void%200' onsubmit='return false;' >"); 
c.push(
"<INPUT TYPE='hidden' NAME='devise'"+" VALUE='"+_dse+"'>",
"<INPUT TYPE='hidden' NAME='coef'"+" VALUE='"+coef+"'>",
"<INPUT TYPE='hidden' NAME='order'"+" VALUE=''>",
"<input type='submit' class='submit160' value='Passer commande' id='valider' />",
'<input type="button" id="poursuivre" value="Poursuivre" class="submit160"/>',
"</form>",
"<center><span>",
"Ren&eacute; Derhy , 6 rue du Faubourg Poissonni&egrave;re , 75010 Paris , France.<br/>",
"Tel: 331 47705690 , Fax : 331 45233547</span></center><br/>",
"</div>" ) ;




d.push(
'          <div id="doublepage"> '
,'			<div id="panier_titre"><h2><img src="a/cart.png" alt="panier" width="16" height="16" /> mon '
,'              panier</h2></div> '
,'			<div id="panier_aide"><a href="faq.html#livraison" target="_blank">Livraison</a><span class="pipe">|</span><a href="faq.html#echange" target="_blank">Echange</a><span class="pipe">|</span><a href="http://www.derhy.com/suivi/index.php" target="_blank">Suivi '
,'              de la commande</a><span class="pipe">|</span><a href="login.html" target="_blank">Première '
,'              visite</a></div>  '
,'			  <hr class="separation" />'
,'			<p>Vérifier votre commande, puis valider pour acheter. '
,'              Pour supprimer un article, indiquer quantité puis '
,'              cliquer sur modifier</p>'
,'			  <div class="filetpanier">&nbsp;</div>'
,'            <div>               '
,'              <table width="760" border="0" cellpadding="4" cellspacing="0">'
,'                <tr>            '
,'                  <td class="td-article">&nbsp;</td>'
,'                  <td class="td-taille">Taille . <a href="mesures_popup.html" target="_blank" class="small">Calculer '
,'                    sa taille</a></td>'
,'                  <td class="td-couleur">Couleur</td>'
,'                  <td class="td-quant">Quantité<td>'
,'                  <td class="td-prix">Prix</td>'
,'                  <td class="td-sup">Supprimer</td>'
,'                </tr>           '
,'              </table>          '
,'			</div>                     '
,'<form name="orderSecure"  method="post" action="http://www.derhy.com/adresse_livraison_kids.php" target="_self" id="derhy_form">'
,'					<INPUT TYPE="hidden" NAME="devise" VALUE="'+_dse+'">'
,'					<INPUT TYPE="hidden" NAME="coef"  VALUE="'+coef+'">'
,'					<INPUT TYPE="hidden" NAME="order" VALUE="">'
);


for(var i = 1; i <= orderNum; i++){
	if(i%2) {
d.push('			<div class="lignecolor">   ');
	}
	else {
d.push('			<div>   ');
	}	

d.push(
'			  <table width="760" border="0" cellpadding="4" cellspacing="0">'
,'                <tr>            '
,'                  <td class="td-article"><a href="page_article.html">',order[i].Indx
,'                    </a> - Ref:'+order[i].ref+'</td>'
,'                  <td class="td-taille">'+order[i].taille+' - '+currency(order[i].totSum/order[i].totQ)+' €</td>'
,'				  <td class="td-couleur">'+order[i].couleur+'</td>'
,'				  <td class="td-quant">'
,'                      <input name="textfield" type="text" id="i_'+i+'" value="'+order[i].totQ+'" size="2" maxlength="2" />'
,'                    </td>'
,'                  <td class="td-prix">'+currency(order[i].totSum)+'€</td>'
,'				  <td class="td-sup"><a href="#"><img src="a/sup.gif"  id="s_'+i+'" alt="x" border="0" /></a></td>'
,'              </tr>'
,'            </table>'
,'			</div>'
);
}


d.push(
'			</form>'
,'									<div>'
,'              <table width="760" border="0" cellpadding="4" cellspacing="0">'
,'                <tr> '
,'                  <td class="td-article">&nbsp;</td>'
,'                  <td class="td-taille">&nbsp;</td>'
,'                  <td class="td-zone">Zone de livraison: '
,'                    <SELECT onChange="document.basket.submit()" size="1" name="frais">'
,'                      <OPTION value="0" selected>France métropolitaine</OPTION>'
,'                      <OPTION value="1" >CEE</OPTION>'
,'                      <OPTION value="2" >Europe hors CEE</OPTION>'
,'                      <OPTION value="3" >Reste du monde</OPTION>'
,'                    </SELECT></td>'
,'                  <td class="td-prix-zone">+ 6 €</td>'
,'                </tr>'
,'              </table>'
,'            </div>'
,'				<div><table width="760" border="0" cellpadding="4" cellspacing="0">'
,'                <tr> '
,'                  <td class="td-article">&nbsp;</td>'
,'                  <td class="td-taille">&nbsp;</td>'
,'                  <td class="td-total">Total</td>'
,'                  <td class="td-quant-total">&nbsp;</td>'
,'                  <td class="td-prix-total">'+finalSum+' €</td>'
,'              </tr>'
,'            </table></div>'
,'			<div class="filetpanier">&nbsp;</div>'
,'							<div><table width="760" border="0" cellpadding="4" cellspacing="0">'
,'                <tr> '
,'                  <td class="td-article"><a href=# onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image17\',\'\',\'a/retour-on.gif\',1)"><img src="a/retour.gif" id="poursuivre" alt="continuer mes achats" name="Image17" width="120" height="26" border="0" id="Image17" /></a></td>'
,'                  <td class="td-taille">&nbsp;</td>'
,'                  <td class="td-couleur">&nbsp;</td>'
,'                  <td valign="top" class="td-quant"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image14\',\'\',\'a/modifier-on.gif\',1)"><img src="a/modifier.gif" alt="modifier" name="Image14" width="120" height="26" border="0" id="Image14" /></a></td>'
,'                  <td valign="top" class="td-prix"><a href=# onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image15\',\'\',\'a/valider-on.gif\',1)"><img src="a/valider.gif" alt="valider"  id="valider" name="Image15" width="120" height="26" border="0" /></a> '
,'                  </td>'
,'              </tr>'
,'            </table></div>'
,'			<div class="filetpanier">&nbsp;</div>'
,'			<p>Si vous êtes un revendeur, n\'oubliez pas de vous <a href="login.html">identifier</a></p>'
,'			<div class="filetpanier">&nbsp;</div>'
,'			<div>'
)
















modalDialog(d.join(''));


for(var i=1 ; i<=  orderNum ;i++){
	$('s_'+i).onclick = function(){ rm(this.id);};	
	$('i_'+i).onchange= $('i_'+i).onblur=$('i_'+i).onkeyup=function(){ change_q(this.id);}
	$('i_'+i).onfocus= function(){ this.select();}
//	$('plus_'+i).onclick =function(){ moreless(this.id,1); }
//	$('moins_'+i).onclick =function(){ moreless(this.id,-1);}
}
//$('valider').onclick = validerCommande;


$('valider').onclick = function(e){formData($('derhy_form')); return false;}
$('close').onclick=$('poursuivre').onclick=toggleModal;
	setCookie('curcook',serier());
}// Fin de checkOut() ;

function moreless(id , q) {

	 var i=id.split('_')[1] ;
	$('i_'+i).value = parseInt($('i_'+i).value) + q ;
	change_q('i_'+i) ;
}
/* **************************************************************/
function rm(prod){
	var item= prod.split('_')[1];
	for(var i = (parseInt(item)+1); i <= orderNum; i++) order[i-1] = order[i] ;
	order[orderNum--]=null ;
	calculTotal();
	checkOut();
}// FIN DE REMOVE(item )
/* **************************************************************/
function change_q(prod){
	var newval = currency( $(prod).value);


	if( newval==0) return rm(prod);
	var item= order[prod.split('_')[1]];
	var prix =  item.totSum/item.totQ;

	item.totQ= newval;
	item.totSum= newval*prix;
	calculTotal();
	checkOut();
}// FIN DE REMOVE(item )



/****************************************************************/
function panierVide(){
	modalDialog( [ bandeau() ,
	'<p class="rouge13"  style="margin:20px">',
	'Le panier est vide ! </p>',
	'<p><input type="submit" id="poursuivre" value="Poursuivre" class="submit"/>',
	'</p>'].join('')) ;
	$('close').onclick= $('poursuivre').onclick= toggleModal ;
}// FIN de panierVide()

