function popupImage(img) {
    titre="Agrandissement";
    var top = (screen.height-400)/2;
    var left = (screen.width-400)/2;
    w = open('','image','top='+top+',left='+left+',width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');
    w.document.write('<html><head><title>'+titre+'</title><style>body { text-align: center; } p{ font: 12px arial; text-align: center; }</style></head>');
    w.document.write('<script language=javascript>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+10,document.images[0].height+50); window.focus();} else { setTimeout("checksize()",250) } }</'+'SCRIPT>');
    w.document.write('<script language=javascript>function fitsize() { document.images[0].height = document.body.clientHeight; if(document.images[0].width > document.body.clientWidth) { document.images[0].width = document.body.clientWidth; } }</'+'SCRIPT>');
    w.document.write('<body onload="checksize()" onresize="fitsize()" onblur="window.close()" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">');
    w.document.write('<IMG src="'+img+'" border="0" title="Redimensionner la fenêtre pour changer la taille de l\'image">');
    w.document.write('</body></html>');
    w.document.close();
}
function showOrder() {
    if($("#order").css("display") == "none") {
        $("#order").css("display", "block");
        $("#order_link").css("background", "url('/img/common/bottom_arrow.png') no-repeat 0 5px");
    } else {
        $("#order").css("display", "none");
        $("#order_link").css("background", "url('/img/common/right_arrow.png') no-repeat 3px 2px");
    }
}
function validForm() {
    var txt = $("#text").text();
    var reg = new RegExp("(<[br]+>)", "gi");
    var first = txt.replace(reg,' \r\n');
    var reg = new RegExp("(<[^>]+>)", "gi");
    document.translate.text.value = first.replace(reg,' ');
    document.translate.submit();
}
function modifyLotSelection(p_action, p_id,msg1,msg2) {
    if(p_action == 'add') {
        $("#details").before('<div id="alert'+p_id+'" class="alert">'+lotSelected+'</div>');
        $("#link"+p_id).html(msg1);
        $("#link"+p_id).attr("href", "javascript:modifyLotSelection('del', "+p_id+",'"+msg1+"','"+msg2+"');");
    } else {
        $("#details").before('<div id="alert'+p_id+'" class="alert">'+lotUnselected+'</div>');
        $("#link"+p_id).html(msg2);
        $("#link"+p_id).attr("href", "javascript:modifyLotSelection('add', "+p_id+",'"+msg1+"','"+msg2+"');");
    }
    $.getJSON("/lots_list.php",
        {action: p_action, type: "lot", id: p_id});
    setTimeout('deleteAlert('+p_id+')', 2000);
}
function deleteAlert(p_id) {
    $("#alert"+p_id).remove();
}

function addBid(lang) {
  vid = $("#vente_id").val();
    var phone = "off";
    if( ($("#bid_amount").val() == 'Montant' || $("#bid_amount").val() == 'Amount') && $("#bid_phone").is(":checked")){
      $("#bid_amount").val('');
    }
    if( ($("#bid_amount").val() != '' && ( $("#bid_amount").val()< 1 || isNaN($("#bid_amount").val()) )) || !$("#bid_phone").is(":checked") && ( $("#bid_amount").val()< 1 || isNaN($("#bid_amount").val()) )) {
        if(lang == 'UK')
          alert('Please enter a valid price without any space, coma, point or tick "by phone"');
        else
          alert('Vous devez rentrer un nombre valide sans espace, ni virgule ou cocher "Par téléphone" !');
    } else {
        $("#details").before('<div id="alert1" class="alert">'+bidAdded+'</div>');
        if($("#bid_phone").is(":checked")) {
           phone = "on";
           /*if($("#bid_amount").val() == 'Montant'){
             $("#bid_amount").val('');
           }*/
        }
        $.getJSON("/lot_details.php",
            {action: 'addBid', lid: $("#bid_lot_id").val(), vid: $("#vente_id").val(),amount: $("#bid_amount").val(), phone: phone}
        ,function(data) {
          res = data.added;
          if(res == 'true'){
            window.location='/'+lang+'/account/bids.php#'+vid;
          }else{
            alert('Veillez saisir le montant sans espace, ni virgule');
          }
          }
        );
        //setTimeout('deleteAlert(1)', 2000);
        $("#link"+$("#bid_lot_id").val()).remove();
        //window.location='/'+lang+'/account/bids.php#'+vid;
        if(!$("#bid_phone").is(":checked"))
           $("#order").html('<p>'+votreOrdreDachat+'<br/> '+$("#bid_amount").val()+' &euro;.<br/>'+validerAvantFax+' <a href="/'+lang+'/account/bids.php">'+cliquerIci+'</a>.</p>');
        else{
            // $("#order").html('<p>'+votreOrdreDachat+' : par tél.<br/>'+validerAvantFax+', <a href="/'+lang+'/account/bids.php">'+cliquerIci+'.</p>');
           $("#order").html('<p>'+votreOrdreDachat+'<br/> '+ $("#bid_amount").val() +'&euro; par tél.<br/>'+validerAvantFax+' <a href="/'+lang+'/account/bids.php">'+cliquerIci+'.</p>');
         }
    }
}
 $(document).ready(function() {
    /*$('#bid_phone').click( function(){
        if($('#bid_phone').is(':checked')){
        $('#bid_amount').val('0');
    }
    });*/
 });

