function showcart(){
       if($('cart').getStyle('display')=="none"){
    new Effect.SlideDown('cart', { duration:1 ,queue: { position: 'end', scope: 'menuxscope',
limit: 2 } });
       }
}

function hidecart(){
        new Effect.SlideUp('cart', { duration:1 ,queue: { position: 'end', scope: 'menuxscope',limit: 2 } });
}

 function closedisplaycart(){
             new Effect.Fade('shoppingcart1',{ duration: 0.5 });          
                                return false;
}


function setInsurance(){


 var myvalue = document.getElementById('order_form').insurance.checked;
 if(myvalue){
    myvalue="on";
 }
 else{
    myvalue="off"
 }
 var str = "../servlets/displaycart.php?action=insurance&value=" + myvalue;
var myAjax = new Ajax.Request(str,{onSuccess:function(response){}});

checkShipping();
}


function updatePickup(id){
var box = "pickupBox" + id;
var str = "../servlets/displaycart.php?action=localpickup&id=" + id;
var myAjax = new Ajax.Request(str,{onSuccess:function(response){}});
checkShipping();
$(box).fade();
}



function checkShipping(status){
    var parms = $('sForm').serialize();
  
   var myAjax = new Ajax.Updater({success: 'shippingCharges',failure: 'notice' },'../servlets/displaycart.php?action=shippingCharge',
                                    {method: 'get',
                                 onLoading: function(response){  $('cart_loader').setStyle({display:'block'}); },
                                 onSuccess: function(response){  $('cart_loader').setStyle({display:'none'});    
                                    if(status != ''){
                                            $('notice').setStyle({display:'block'});
                                            $('notice').update('Shipping charges updated.');                                    
                                        }
                                     },parameters: parms,evalScripts:true});
}



function displaycart(message){    
        var myAjax = new Ajax.Updater('content_cart_details','../servlets/displaycart.php?action=display&message='+message,
                                    {method: 'get',
                                    
                                    onLoading: function(response){
                                        $('cartloader').setStyle({display:'block'});                                  
                                   },
                                     onSuccess: function(response) {
                                        $('cartloader').setStyle({display:'none'});               
                                        
                                     }, 
                                    evalScripts:true

                                    });
}

function shippingcart(){    
    window.location = "?action=shipping";
}


function gotoshipping(ref){
    if(ref != ""){
        var str = '../servlets/displaycart.php?type=shipping&ref='+ref;
    }
    else{
        var str = '../servlets/displaycart.php?type=shipping';    
    }
        var myAjax = new Ajax.Updater({success: 'content_cart_details',failure: 'notice' },str,
                                    {method: 'get',
                                    onLoading: function(response){
                                        $('cartloader').setStyle({display:'block'}); 
                                     },
                                    onSuccess: function(response) {   
                                        $('cartloader').setStyle({display:'none'});
                                        //$('loginformbox').setStyle({display:'none'}); 
                                        
                                     },evalScripts:true             
            });
    }


function reviewcart(){
        
        //check shipping
        if(document.getElementById('sForm').sCountry.value == ""){ 
            $('notice').setStyle({display:'block'}); $('notice').update("Please select a country"); return false; 
        }

        //check form
        if(document.getElementById('s_form').sName.value == "" ){
            $('notice').setStyle({display:'block'});$('notice').update("Shipping name empty!");return false;
        }
        if(document.getElementById('s_form').sAdd1.value == "" ){
            $('notice').setStyle({display:'block'});$('notice').update("Shipping address empty!");return false;
        }
        if(document.getElementById('s_form').sPostal.value == "" ){
            $('notice').setStyle({display:'block'});$('notice').update("Shipping postal code empty!");return false;
        }        
        if(document.getElementById('s_form').sContact.value == "" ){
            $('notice').setStyle({display:'block'});$('notice').update("Shipping contact empty!");return false;
        }
        if(document.getElementById('s_form').sEmail.value == "" ){
            $('notice').setStyle({display:'block'});$('notice').update("Shipping email empty!");return false;
        }
        
        //check email valid
        var email1 = document.getElementById('s_form').sEmail.value;    
        if(email1 == ""){valid = false;}
        var at = email1.indexOf('@');
        var dot = email1.lastIndexOf('.');
        var valid = true;
        valid = (at && dot);
        if (at > dot) {valid = false;}    
        if(valid > 0){}else{ $('notice').setStyle({display:'block'}); $('notice').update("Invalid shipping email!"); return false;}
        
        
        //check if use billing address
        if(document.getElementById('billbutt').checked){
            //checking billing form 
            if(document.getElementById('s_form').bName.value == "" ){
                $('notice').setStyle({display:'block'});$('notice').update("Billig name empty!");return false;
            }
            if(document.getElementById('s_form').bAdd1.value == "" ){
                $('notice').setStyle({display:'block'});$('notice').update("Billing address empty!");return false;
            }
            if(document.getElementById('s_form').bCountry.value == "" ){
                $('notice').setStyle({display:'block'});$('notice').update("Billing country not selected!");return false;
            }            
            if(document.getElementById('s_form').bPostal.value == "" ){
                $('notice').setStyle({display:'block'});$('notice').update("Billing postal code empty!");return false;
            }        
            if(document.getElementById('s_form').bContact.value == "" ){
                $('notice').setStyle({display:'block'});$('notice').update("Billing contact empty!");return false;
            }
            if(document.getElementById('s_form').bEmail.value == "" ){
                $('notice').setStyle({display:'block'});$('notice').update("Billing email empty!");return false;
            }
            //check email valid
            var email = document.getElementById('s_form').bEmail.value;    
            if(email == ""){valid = false;}
            var at = email.indexOf('@');
            var dot = email.lastIndexOf('.');
            var valid = true;
            valid = (at && dot);
            if (at > dot) {valid = false;}    
            if(valid > 0){}else{ $('notice').setStyle({display:'block'}); $('notice').update("Invalid billing email!"); return false;}
            
            var str = '../servlets/calculatecart.php?action=shippingtopay&type=usebilling';        
        }
        else{
            var str = '../servlets/calculatecart.php?action=shippingtopay&type=useshipping';
        }
        
        
        //ready to go... 
        $('proceedpay').href = "javascript:void(0);";
        $('proceedpay').onclick = null;        
        $('cart_loader').setStyle({display:'block'});
        $('notice').setStyle({display:'block'});
        $('notice').update("Transferring to Secure Payments Page, please wait...");

        var parms = $('s_form').serialize(false);


        var myAjax = new Ajax.Request(str,
                                    {method: 'get',
                                    onLoading: function(response){  
                                    },
                                    onSuccess: function(response){  
                                        window.location = "https://projectmidas.com/cart/payment.php";
                                    },
                                    parameters: parms,evalScripts:true                                                          
        });

return false;
}


function updateshoppinghead1(){
                 new Ajax.Updater({success: 'shoppinghead',failure: 'notice' },'../servlets/checkitems.php',
                                    {method: 'get',
                                    onLoading: function(response){
                                   
                                    },
                                     onSuccess: function(response) {
                                   
                                     } 
                                   });
                                    
}


function checkTotal()
    {
    var myAjax = new Ajax.Updater({success: 'shippingTotal',failure: 'notice' },'../servlets/addshoppingcart.php?action=price',
            {method: 'get',
            onLoading: function(response){  $('cart_loader').setStyle({display:'block'});},
            onSuccess: function(response){  $('cart_loader').setStyle({display:'none'});}
            });
                                 
}



function changeQTY()
    {
     var parms=$('cart_form').serialize(false);
    
    var myAjax = new Ajax.Updater({success: 'shippingTotal',failure: 'notice' },'../servlets/displaycart.php?action=update',
                                    {method: 'get',
                                    onLoading: function(response){
                                   
                                    },
                                     onSuccess: function(response) {
                                        
                                        updateshoppinghead1();
                                       displaycart(response.responseText);

                                        //$('notice').setStyle({display:'block'});                                    
                                        //$('notice').update('Quantity updated.');
                                     } , parameters: parms,evalScripts:true

                                    
                                    });
                                 
}


function removeshoppingitem(id,attr,attr2){
        var myAjax = new Ajax.Updater({success: 'shippingCharges',failure: 'notice' },'../servlets/displaycart.php?action=remove&aID='+id+'&attr='+attr+"&attr2="+attr2,
                                    {method: 'get',
                                    onLoading: function(response){
                                        
                                   },
                                     onSuccess: function(response) {

                                       $('notice').setStyle({display:'block'});
                                       $('notice').update('Item(s) removed from shopping cart.');
                                        updateshoppinghead1();
                                       checkTotal();
                                       displaycart('Item(s) Removed');


                                     }
                                    });
        }

function clearcart(){
       var myAjax = new Ajax.Updater({success: 'notice',failure: 'notice' },'../servlets/displaycart.php?type=clear',
                                    {method: 'get',
                                    onLoading: function(response){
                                    
                                     $('cart_loader').setStyle({display:'block'});        
                                    },
                                    onSuccess: function(response) {
                                       $('notice').setStyle({display:'block'});        
                                      window.location = "?"; 
                                        
                                     } 
            });

}