



 function showLangForm(id){
	 	$$('div.field').each(function(fields){
	 		fields.style.display='none';
	 	}
	 	)
	 	$('field_'+id).style.display='';
 	}


 	function highlightDiv(id){
 		if ($('block_'+id).hasClassName('cat_item')==true){
 			$('block_'+id).className = 'cat_item_over';
 			$('check_'+id).checked = true;
 		}else{
 			$('block_'+id).className = 'cat_item';
 			$('check_'+id).checked = false;
 		}
 	}

 	function showHighlight(){
 		$$('input.check_invisible').each(function(checks){
 			if (checks.checked == true){
 				$('block_'+checks.value).className = 'cat_item_over';
 			}
 		}
 		)
 	}


 	function fileExt(fichier) // fonction de r�cup�ration extension fichier
   {
         if (fichier!="")// si le champ fihier n'est pas vide
         {
            nom_fichier=fichier;// on r�cupere le chemin complet du fichier
            nbchar = nom_fichier.length;// on compte le nombre de caractere que compose ce chemin
            extension = nom_fichier.substring(nbchar-4,nbchar); // on r�cupere les 4 derniers caracteres
            extension=extension.toLowerCase(); //on uniforme les caracteres en minuscules au cas ou cela aurait �t� �cris en majuscule...
            return extension; // on renvoi l'extension vers la fonction appelante
         }
   }


   function verifExt(file)
   {
   	var ext = fileExt(file);

   	if (ext == '.jpg' || ext == 'jpeg' || ext == '.gif' || ext == '.png' || ext == '.flv'){
   		return true;
   	}else{
   		return false;
   	}

   }


   function verifNumber(number){
   	var verif = /^-?\d+(\.\d+)?$/.test(number);
   	return verif;
   }



   function increase(id){
       $(id).value = parseFloat($(id).value) + 1;
   }


   function decrease(id){
       var value = parseFloat($(id).value);
       if (value <= 1){
           $(id).value = 1;
       }else{
           $(id).value = parseFloat($(id).value) - 1
       }
   }




   function addToCart(base_url,number,id,price,image){

       $('content_cart').innerHTML = '<img src="'+base_url+'images/ajax-load.gif">';

       var url	= base_url+'cart/addtocart/aid/'+id+'/price/'+price+'/number/'+number+'/';
       new Ajax.Request(url,{method:'get'
    		                    ,onSuccess:function priceSucceeded(t)
    		                               {
    		                                   $('content_cart').innerHTML = t.responseText;
                                               var url_cartinfo = base_url+'cart/updatecartinfo/';
                                               new Ajax.Request(url_cartinfo,{method:'get'
                                            		                    ,onSuccess:function priceSucceeded(t)
                                            		                               {
                                            		                                   $('cartinfo').innerHTML = t.responseText;
                                            		                                   $('cartinfo2').innerHTML = t.responseText;
                                            		                                   window.setTimeout('switchBackHeader(\''+base_url+'\')',3*1000);
                                            		                               }
                                            		                     ,onFailure:function  priceFailed()
                                            		                                {

                                            		                                }
                                            		                   }
                                                )

    		                               }
    		                     ,onFailure:function  priceFailed()
    		                                {

    		                                }
    		                   }
    		              )


/*       var url_cartinfo = base_url+'cart/updatecartinfo/';
       new Ajax.Request(url_cartinfo,{method:'get'
    		                    ,onSuccess:function priceSucceeded(t)
    		                               {
    		                                   $('cartinfo').innerHTML = t.responseText;
    		                                   $('cartinfo2').innerHTML = t.responseText;
    		                               }
    		                     ,onFailure:function  priceFailed()
    		                                {

    		                                }
    		                   }
        ) */

       var total = 100;

       $('fixed_cart').style.display='block';
       $('header-normal').style.visibility='hidden';

       $('picture_cart').innerHTML = '<img src="' + image + '">';

       //window.setTimeout('switchBackHeader(\''+base_url+'\')',7*1000);


   }


   function switchBackHeader(base_url){
       $('fixed_cart').style.display='none';
       $('header-normal').style.visibility='';

/*       var url_cartinfo = base_url+'cart/updatecartinfo/';
       new Ajax.Request(url_cartinfo,{method:'get'
    		                    ,onSuccess:function priceSucceeded(t)
    		                               {
    		                                   $('cartinfo2').innerHTML = t.responseText;

    		                               }
    		                     ,onFailure:function  priceFailed()
    		                                {

    		                                }
    		                   }
        ) */

   }



   function calculatePrice(quantity,price){
       var q = parseFloat(quantity);
       var p = parseFloat(price);
       price = q * p;
       newprice = Math.round(price*10)/10;


   }



   function increaseUpdate(id,price,base_url,article_id, price_id, shipping){

       $(id).value = parseFloat($(id).value) + 1;
       calculateSum(id, $(id).value,price,base_url,article_id, price_id, shipping);
   }


   function decreaseUpdate(id,price,base_url,article_id, price_id, shipping){

       var value = parseFloat($(id).value);

       if (value <= 1){
           $(id).value = 1;
       }else{
           $(id).value = parseFloat($(id).value) - 1;
       }
       calculateSum(id,$(id).value,price,base_url,article_id, price_id, shipping);
   }



    function addCommas( nStr )
    {
    	x = nStr.split('.');
    	x1 = x[0];
    	x2 = x[1];
    	return x1 + ',' + x2 + ' ';
    }


function number_format (number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands
    //
    // version: 906.1806
    // discuss at: http://phpjs.org/functions/number_format
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +     input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +     improved by: davook
    // +     improved by: Brett Zamir (http://brett-zamir.me)
    // +     input by: Jay Klehr
    // +     improved by: Brett Zamir (http://brett-zamir.me)
    // +     input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *     example 10: number_format('1.20', 2);
    // *     returns 10: '1.20'
    // *     example 11: number_format('1.20', 4);
    // *     returns 11: '1.2000'
    // *     example 12: number_format('1.2000', 3);
    // *     returns 12: '1.200'
    var n = number, prec = decimals;

    var toFixedFix = function (n,prec) {
        var k = Math.pow(10,prec);
        return (Math.round(n*k)/k).toString();
    };

    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
    var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;

    var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;

    var abs = toFixedFix(Math.abs(n), prec);
    var _, i;

    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;

        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }

    var decPos = s.indexOf(dec);
    if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
        s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
    }
    else if (prec >= 1 && decPos === -1) {
        s += dec+new Array(prec).join(0)+'0';
    }
    return s;
}


   function calculateSum(id, number,price,base_url,article_id, price_id, shipping){
       var new_sum = parseFloat(number) * parseFloat(price);
       var formated = new_sum.toFixed(2);
       formated = number_format (new_sum, 2, ',', "'")
       $('total_'+id).innerHTML = formated + CURRENCY_CODE;
       flash('total_'+id,'ded3bb','f7f4ee');
       var url_cart = base_url+'cart/updatetotal/id/'+article_id+'/price/'+price_id+'/number/'+number;
       new Ajax.Request(url_cart,{method:'get'
    		                    ,onSuccess:function priceSucceeded(t)
    		                               {
    		                                   $('grand_total').innerHTML = t.responseText;
    		                                   flash('grand_total','000000','686868');
    		                                   var url_ship_total = base_url+'cart/shippingtotal/id/'+article_id+'/price/'+price_id+'/number/'+number+'/shipping/'+shipping;
    		                                   new Ajax.Request(url_ship_total,{method:'get'
                        		                    ,onSuccess:function priceSucceeded(t)
                        		                               {
                        		                                   $('grand_total_shipping').innerHTML = t.responseText;
                        		                                   flash('grand_total_shipping','000000','686868');

                        		                                    var url_shipping = base_url+'cart/updateshipping/id/'+article_id+'/price/'+price_id+'/number/'+number+'/shipping/'+shipping;
                                                                    new Ajax.Request(url_shipping,{method:'get'
                                        		                    ,onSuccess:function priceSucceeded(t)
                                        		                               {

                                        		                                  $('total_shipping').innerHTML = t.responseText;
                                        		                               }

                                        		                   }
                                        		                 )


                        		                               }

                        		                   }
                        		                 )
    		                               }

    		                   }
    		                 )

   }





    function flash(id,color,end){
        new Effect.Highlight(id, { duration:0.5, startcolor: '#'+color+'', endcolor: '#'+end+'', queue: { position: 'end', scope: 'menuxscope', limit: 3 } }); // #2
    }


   function deleteProduct(base_url,id,price){


      if (confirm(CART_REMOVE_PRODUCT)){
          deleteProductAction(base_url,id,price);
      }


   }

   function deleteProductAction(base_url,id,price){
                  $('cart_container').innerHTML = '<img src="'+base_url+'images/ajax-load.gif">';

           var url_cart = base_url+'cart/deleteproduct/id/'+id+'/price/'+price;
           new Ajax.Request(url_cart,{method:'get'
        		                    ,onSuccess:function priceSucceeded(t)
        		                               {
        		                                   $('cart_container').innerHTML = t.responseText;
        		                               }
        		                     ,onFailure:function  priceFailed()
        		                                {

        		                                }
        		                   }
        		                 )
   }



	function verifForm(id){

		var error = false;

		$$('input.required').each(function(el)
		{
			if (el.value==''){
				error = true;
				el.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = MANDATORY_FIELD;
			}

		}
		)


		$$('select.required').each(function(el)
		{
			if (el.value==''){
				error = true;
				el.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = MANDATORY_FIELD;
			}

		}
		)


		$$('input.requiredEmail').each(function(email)
		{
			if (emailcheck(email.value)==false){
				error = true;
				email.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = WRONG_EMAIL_FORMAT;
			}

		}
		)


		$$('input.requiredPhone').each(function(phone)
		{
			if (checkPhone(phone.value)==false){
				error = true;
				phone.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = WRONG_PHONE_FORMAT;
			}

		}
		)

		if (error == false){
			$(id).submit();
		}


	}



	function displayMediaTitle(id){
		$$('span.first_media').each(function(el)
		{
            el.hide();
		}
		)

		$('first_media_'+id).show();
	}


	function nextMedia(url,array_js){
	    var current_pos = $('key_value').value;
	    var total = $('total_key_value').value;
	    var next_pos = 0;
	    if (current_pos == total-1){
	        next_pos = 0;
	    }else{
	        next_pos = parseFloat(current_pos) + 1;
	    }
	    $('key_value').value = next_pos;
	    txt = array_js[next_pos].split('_');
	    displayMediaTitle(txt[1]);
	    changeMedia(array_js[next_pos]);
	}


	function previousMedia(url,array_js){
	    var current_pos = $('key_value').value;
	    var total = $('total_key_value').value;
	    var next_pos = 0;
	    if (current_pos == 0){
	        next_pos = total-1;
	    }else{
	        next_pos = current_pos - 1;
	    }
	    $('key_value').value = next_pos;
	    txt = array_js[next_pos].split('_');
	    displayMediaTitle(txt[1]);
	    changeMedia(array_js[next_pos]);
	}



    function changeMedia(new_container){
        $(new_container).style.display = 'none';
        var mcenter_el_id = new_container;
        mcenter_el_id = mcenter_el_id.split('_');
        var mcenter_el_type_id = mcenter_el_id[2];
        mcenter_el_id = mcenter_el_id[1];
        loadMediaCenterElement(mcenter_el_id, mcenter_el_type_id);
    }


	function verifAdvForm(id){
		var error = false;
		$$('input.required').each(function(el)
		{
			if (el.value==''){
				error = true;
				el.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = MANDATORY_FIELD;
			}
		}
		)

		$$('input.requiredEmail').each(function(email)
		{
			if (emailcheck(email.value)==false){
				error = true;
				email.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = WRONG_EMAIL_FORMAT;
			}

		}
		)



		if ($('similar1')){
			if ($('similar1').value != $('similar2').value){
				error = true;
				$('similar1').style.border='2px #cc0000 solid';
				$('similar2').style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = PASSWORD_NOT_IDENTICAL;
			}
		}


		$$('input.requiredCheck').each(function(el)
		{
			if (!el.checked){
				error = true;
				el.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = ACCEPTANCE_GENERAL_CONDITIONS;
			}

		}
		)


		$$('input.requiredExpDate').each(function(expdate)
		{
		    var reg=new RegExp("[0-9][0-9]+/+[0-9][0-9]");
			if (!expdate.value.match(reg)){
				error = true;
				expdate.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = WRONG_EXPIRATION_DATE;
			}

		}
		)

		if (error == false){
			$(id).submit();
		}


	}


	function verifPaymentForm(id){
		var error = false;

		$$('input.requiredCheck').each(function(el)
		{
			if (!el.checked){
				error = true;
				el.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = ACCEPTANCE_GENERAL_CONDITIONS;
			}else{
			    el.style.border='2px #ac9056 solid';
			}

		}
		)


		$$('input.requiredExpDate').each(function(expdate)
		{
		    var reg=new RegExp("[0-9][0-9]");
			if (!expdate.value.match(reg)){
				error = true;
				expdate.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = WRONG_EXPIRATION_DATE;
			}else{
			    expdate.style.border='2px #ac9056 solid';
			}

		}
		)


		$$('input.required').each(function(el)
		{
			if (el.value==''){
				error = true;
				el.style.border='2px #cc0000 solid';
				$('message').style.display='';
				$('message').innerHTML = MANDATORY_FIELD;
			}else{
			    el.style.border='2px #ac9056 solid';
			}
		}
		)


		if (error == false){
		    Modalbox.show($('loading'), {title: '', overlayClose: false, width: 750, height: 130 });
			$(id).submit();
		}


	}


	function verifCartForm(id){
	    var error = false;
	    var test = '';

	    if (!document.getElementById('conditions').checked){
	    	error = true;
 			$('message').style.display='';
 			$('message').innerHTML = ACCEPTANCE_GENERAL_CONDITIONS;	    	
	    }    

	    if (error == false){
	        $('message').style.display='none';
	        Modalbox.hide()
			$(id).submit();
		}
	}


	function emailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        return false
        }

        if (str.indexOf(at,(lat+1))!=-1){
        return false
        }

        if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        return false
        }

        if (str.indexOf(dot,(lat+2))==-1){
        return false
        }

        if (str.indexOf(" ")!=-1){
        return false
        }

		return true
	}




function checkPhone(strPhone){
var re = new RegExp("^[+][0-9]", "g");
return re.test(strPhone);
}



function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/in_array
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
 
    return false;
}

