var hwCallback = {
    
    contact: function(result) {
        
        if(result[0]==false)
            alert(result[1]);
        else {
            document.getElementById('contact_mesaj').innerHTML=result[1];    
        }    
    },
    
    adauga: function(result) {
        if(result[0]==false)
            alert(result[1]);
        else {
            document.location="/mycart/";   
        }    
    },
    
    login: function(result) {
        if(result[0]===false) {
            alert(result[1]);
        } else if(result[0]===true) {
            document.location = ruri1;
        } else {
            document.getElementById('login').innerHTML=result;  
            loginForm = new VarienForm('login-form', true); 
            
            $j.delay(0.4, function () { $j("#email").focus() } );
        }
    },
    
    forgot: function(result) {
        if(result[0]===false) {
            alert(result[1]);
        } else if(result[0]===true) {
            do_login(false, result[1]);
        } else {
            document.getElementById('login').innerHTML=result;  
            forgotForm = new VarienForm('forgot-form', true); 
            $j.delay(0.4, function () { $j("#email_address").focus() } );
        }
    },    
    
    checkouttransport: function(result) {
        if(result[0]==false)
            alert(result[1]);
        else {
            
            $j('#checkouttransport').html(result[1]);
            $j('#checkouttransportrow').effect('highlight');

            $j('#checkouttotal').html(result[2]);
            $j('#checkouttotalrow').effect('highlight');
        }   
    },    
    
    checkout: function(result) {
        if(result[0]==false)
            alert(result[1]);
        else if(result[0]==true) {
            document.location = "/confirmation/"+result[1];
        } else  {
            document.getElementById('checkout').innerHTML=result;  
            $j('#checkout').show('blind');
            //$j('#checkout').html(result).show('blind');
            
            dataForm = new VarienForm('forma', true);  
            $j('#cosulmeusubtotal').html($j('#cartsubtotal').html());
            
            $j("#login").dialog({ 
                    bgiframe: true, 
                    autoOpen: false, 
                    width: 410, 
                    
                    modal: false,
                    closeOnEscape: true,
                    
                    show: 'blind', 
                    hide: 'blind' 
                });
            Init();    
        }    
    },
    
    cart: function(result) {
        if(result[0]==false)
            alert(result[1]);
        else {
            //document.getElementById('cart').innerHTML=result;
            $j('#cart').html(result).show('blind');  
            dataForm = new VarienForm('forma', true);  
            $j('#cosulmeunr').html($j('#cartnr').val());
            newaddtocart = " (" + $j('#cartnr').val() + ")";
            $j('#addtocosulmeu').html(newaddtocart);
        }    
    },
    
    sterge: function(result) {
        if(result[0]==false)
            alert(result[1]);
        else {
            $j('#MainMessage').hide();
            //document.getElementById('cart').innerHTML=result; 
            $j('#cart').html(result).show('blind');
            dataForm = new VarienForm('forma', true); 
            $j('#cosulmeusubtotal').html($j('#cartsubtotal').html());  
            $j('#cosulmeunr').html($j('#cartnr').val());   
            newaddtocart = " (" + $j('#cartnr').val() + ")";
            $j('#addtocosulmeu').html(newaddtocart);
        }    
    },
    
    update: function(result) {
        if(result[0]==false) {
            alert(result[1]);
            $j('#cart').show();
        } else {
            $j('#MainMessage').hide(); 
            //document.getElementById('cart').innerHTML=result; 
            $j('#cart').html(result).show('blind');
            dataForm = new VarienForm('forma', true);
            $j('#cosulmeusubtotal').html($j('#cartsubtotal').html());   
            $j('#cosulmeunr').html($j('#cartnr').val());   
            newaddtocart = " (" + $j('#cartnr').val() + ")";
            $j('#addtocosulmeu').html(newaddtocart);
        }    
    },
    
    informatii: function(result) {
        
        if(result[0]==false)
            alert(result[1]);
        else {
            document.getElementById('informatii_mesaj').innerHTML=result[1]+document.getElementById('informatii_mesaj').innerHTML;    
        }    
    },
    
    recomanda: function(result) {
        
        if(result[0]==false)
            alert(result[1]);
        else {
            document.getElementById('recomanda_mesaj').innerHTML=result[1];    
        }    
    },
    
    favorite: function(result) {
        
        if(result[0]===false) { 
            
            if(result[1]=='AUTENTIFICA-TE') {
                $j("#dialogautentifica").dialog('open');
                
            } else {
                alert(result[1]);
            }

        } else {
            $j("#dialogresult").html(result);
            
            $j("#dialogresult").dialog('open');
            
            
        }    
    },
    
    favoritele: function(result) {
        if(result[0]==false)
            alert(result[1]);
        else {
            document.getElementById('favorite').innerHTML=result;  
            dataForm = new VarienForm('forma', true); 
            $j('#actualizeaza').focus(); 
        }    
    },
    
    stergefavorit: function(result) {
        if(result[0]==false)
            alert(result[1]);
        else {
            $j('#MainMessage').hide();
            document.getElementById('favorite').innerHTML=result; 
            dataForm = new VarienForm('forma', true); 
            $j('#actualizeaza').focus();     
        }    
    },
    
    updatefavorite: function(result) {
        if(result[0]==false)
            alert(result[1]);
        else {
            $j('#MainMessage').hide(); 
            document.getElementById('favorite').innerHTML=result; 
            dataForm = new VarienForm('forma', true); 
            $j('#actualizeaza').focus();     
        }    
    },
    
    test: function(result) {
        alert(result);
    }
}

function CloseResult()
{
    $j("#dialogresult").dialog("close");
}


function do_login(submit)
{
    if(submit==true) {
        data = $j('#login-form').serialize();
    } else {
        data = false;
    }
    
    if(arguments.length==2) {
        mesaj = arguments[1];
    } else {
        mesaj = "";
    }
    
    remoteHW.login(data, mesaj);
}

function do_forgot(submit)
{
    if(submit==true) {
        data = $j('#forgot-form').serialize();
    } else {
        data = false;
    }
    
    remoteHW.forgot(data);
}

function do_checkouttransport(submit) {
    if(submit==true) {
        data = $j('#forma').serialize();
    } else {
        data = false;
    }
    //$j('#checkout').hide('blind');
    remoteHW.checkouttransport(data);
}
function do_checkout(submit) {
    if(submit==true) {
        data = $j('#forma').serialize();
    } else {
        data = false;
    }
    $j('#checkout').hide('blind');
    remoteHW.checkout(data);
}
function do_cart() {
    $j('#cart').hide('blind');
    remoteHW.cart();
}
function do_sterge(spec_id) {
    $j('#cart').hide('blind');
    remoteHW.sterge(spec_id);
}
function do_update() {
    //valorinoi
    
    var nrtot = $j('#nrtot').attr('value');
    
    var valori = new Array(); 
    
    for(var i=1;i<=nrtot;i++) {
        elul = "#qty_"+i;
        valoare = $j(elul).attr('value');
        valori[i] = valoare;
    }
    $j('#cart').hide('blind');
    remoteHW.update(valori);
}
function do_adauga(produs_id, spec_id) {
    remoteHW.adauga(produs_id, spec_id);
}
function do_contact() {
    nume = document.getElementById('nume').value;
    email = document.getElementById('email').value;    
    telefon = document.getElementById('telefon').value;    
    mesaj = document.getElementById('mesaj').value;    
    
    remoteHW.contact(nume, email, telefon, mesaj);
    return false;
}

function do_informatii() {
    nume = document.getElementById('inume').value;
    email = document.getElementById('iemail').value;    
    telefon = document.getElementById('itelefon').value; 
    product_id = document.getElementById('iproduct_id').value;       
    mesaj = document.getElementById('imesaj').value;    
    
    remoteHW.informatii(nume, email, telefon, mesaj, product_id);
    return false;
}

function do_recomanda() {
    delanume = document.getElementById('rnume').value;
    delaemail = document.getElementById('remail').value;    
    pentruemail = document.getElementById('remailf').value;    
    product_id = document.getElementById('rproduct_id').value;    
    mesaj = document.getElementById('rmesaj').value;    
    
    remoteHW.recomanda(delanume, delaemail, pentruemail, mesaj, product_id);
    return false;
}

function do_favoritele() {
    remoteHW.favoritele();
}
function do_stergefavorit(favorit_id) {
    remoteHW.stergefavorit(favorit_id);
}
function do_updatefavorite() {
    var nrtot = $j('#nrtot').attr('value');
    
    var valori = new Array(); 
    var iduri = new Array();  
    
    for(var i=1;i<=nrtot;i++) {
        elul = "#description_"+i;
        
        idul = $j(elul).attr('name');
        
        valoare = $j(elul).val();
        
        valori[i] = valoare;
        iduri[i] = idul;
    }
    remoteHW.updatefavorite(iduri, valori);
}
function do_favorite(product_id) {
    remoteHW.favorite(product_id);
    return false;
}


function do_test(input) {
    remoteHW.test(input);
}
function do_LoadingString() {
    return "Loading ...";
}

function fireEvent(obj,evt){
    
    var fireOnThis = obj;
    if( document.createEvent ) {
      var evObj = document.createEvent('MouseEvents');
      evObj.initEvent( evt, true, false );
      fireOnThis.dispatchEvent(evObj);
    } else if( document.createEventObject ) {
      fireOnThis.fireEvent('on'+evt);
    }
}
function firmapersoana()
{
    if($j("#forma input[name=cumparator#firmapersoana]:checked").val() == 'firma') {
        $j('.fppersoana').hide('');
        //$j.delay(0.5, function () { $j('.fpfirma').show('blind'); } ); 
        $j('.fpfirma').show('blind');
    } else {
        $j('.fpfirma').hide('');
        //$j.delay(0.5, function () { $j('.fppersoana').show('blind'); } ); 
        $j('.fppersoana').show('blind');
    }
}

function inregistrare()
{
    if($j("#forma input[name=cont#inregistrare]:checked").val() == 'DA') {
        $j('.inregistrareda').show('blind');
    } else {
        $j('.inregistrareda').hide('blind');
    }
}

function livrare()
{
    if($j("#forma input[name=livrare#tip]:checked").val() == 'magazin') {
        $j('.livrareadresa').hide('blind');
        
        /*
        $j('#plata_op').attr('checked', 'checked');
        $j('#plata_ramburs').attr('disabled', 'disabled');
        
        $j('#plata').effect('highlight');
        */
        $j.delay(0.4, function () { 
            $j('#plata_op').attr('checked', 'checked');
            $j('#plata_ramburs').attr('disabled', 'disabled');
        
            $j('#platagrup').effect('highlight');
        } );
    } else {
        $j('.livrareadresa').show('blind');
        
        $j.delay(0.4, function () { 
            //$j('#plata_op').attr('checked', 'checked');
            $j('#plata_ramburs').removeAttr('disabled');
        
            $j('#platagrup').effect('highlight');
        } );
    }
}

function plata()
{
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


