//<script language="javascript" type="text/javascript">     
    //Disable right mouse click Script
    //By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
    //function clickIE4(){if (event.button==2){return false;}}
    //function clickNS4(e){if (document.layers||document.getElementById&&!document.all){if (e.which==2||e.which==3){return false;}}}
    //if (document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS4;}else if (document.all&&!document.getElementById){document.onmousedown=clickIE4;}
    //document.oncontextmenu=new Function("return false");
    var barBWidth = 200;
    var barBHeight = 17;
    var barBgColor = "#9E1B51";
    var barBorderColor = "#13BA01";
    var barBlockColor = "#ABABAB";     
    function BeforeSending(){    
        document.getElementById("progbarSubmit").style.visibility = "hidden"; 
        bar1.showBar();
    }    
    function goToUrl(geturl){location.href = geturl;}
    function changeBgColor(obj, color) {obj.style.backgroundColor=color;}                    
//****************************/////**********************************//    

// new functions by Yirmiyahu Fischer
var ship_method, cur_form; //global variable -- need to be accessable to AJAX functions 
function calc_shipping_dynamic(parm_form, update_shipping_type){    
    cur_form=parm_form; 
    ship_method = getCheckedValue(cur_form.ship_method);

    if(cur_form.ship_city.value==''||cur_form.ship_zip.value==''||cur_form.ship_country.value==''||ship_method==''){
//        alert('One of the fields are missing [shipping method, city, zip, or country]');
        return; // do not try to calculate shipping if essential value is missing        
    }
    if (ship_method=='UPS' && cur_form.ship_address_type.value=='') {return;}
    
    /*alert('ship_method '+ship_method);
    alert('ship_city '+cur_form.ship_city.value);
    alert('ship_zip '+cur_form.ship_zip.value);
    alert('ship_country '+cur_form.ship_country.value);
    alert('ship_address_type '+cur_form.ship_address_type.value);
    alert('ship_type '+cur_form.ship_type.value);*/
    
    
    if(update_shipping_type && ship_method=='UPS'){
        get_possible_shipping_type_values(cur_form.ship_city.value,cur_form.ship_zip.value,cur_form.ship_country.value,cur_form.ship_address_type.value,cur_form.ship_type.value);
    } else {
        get_shipping_cost();         
    }
}

function make_shipping_cost_visible(){
    //alert('in make_shipping_cost_visible');
    var ship_cell_el=document.getElementById('ship_price_cell');
    var ship_row_el=document.getElementById('ship_price_row');
    //alert(parseFloat(ship_cell_el.innerHTML.substring(1)));
    ship_row_el.style.visibility = 'visible';    
    if(parseFloat(ship_cell_el.innerHTML.substring(1)) > 0){                
        ship_cell_el.style.backgroundColor = 'yellow';    
        ship_cell_el.style.color = 'black';
    } else {
        ship_cell_el.style.backgroundColor = 'yellow';    
        ship_cell_el.style.color = 'black';
        if(ship_method=='US Postal Service'){
            ship_cell_el.innerHTML = 'could not calculate cost, make sure your zip code is entered correctly.';
        } else if(ship_method=='UPS'){
            ship_cell_el.innerHTML = 'could not calculate cost, make sure you have chosen an address and delivery type.';
        }
    } 
    //ship_row_el.style.visibility = (parseFloat(ship_cell_el.innerHTML.substring(1)) > 0) ? 'visible':'hidden'; // check the numberic value from the second character because the first charact
}

// this function assumes all correct values in place
function get_shipping_cost(){    
    if(ship_method=='UPS' && cur_form.ship_type.value==''){
        return; // check this value only after it can be determined if it is on the valid list
    }
     var url='cart.php?action=shiprate&city='+escape(cur_form.ship_city.value)
              +'&zip='+escape(cur_form.ship_zip.value)
              +'&country='+escape(cur_form.ship_country.value)
              +'&ship_method='+escape(ship_method)              
    if (ship_method=='UPS'){
        url+='&address_type='+escape(cur_form.ship_address_type.value);
        url+='&ship_type='+escape(cur_form.ship_type.value);
    } else if(cur_form.ship_country.value!='US'){
        url+='&ship_length=46'
        url+='&ship_width=14';
        url+='&ship_height=15'
        url+='&ship_stotal=10'
        url+='&ship_po=N'
        url+='&ship_gift=N'
        url+='&long_country=Israel'
    }    
    //alert('get_shipping_cost--> '+ship_method+'--'+url);
    ajax_fill(url,'ship_price_cell',make_shipping_cost_visible)
} 

function get_possible_shipping_type_values(city,zip,country,address_type,ship_type){
    var url='cart.php?action=shiptype&city='+escape(city)
          +'&zip='+escape(zip)
          +'&country='+escape(country).toUpperCase()
          +'&address_type='+escape(address_type).toUpperCase();    
    if(ship_type!=''){ url+='&ship_type='+escape(ship_type).toUpperCase();}
    
    //alert("get_possible_shipping_type_values url: "+url);          
    
    ajax_fill(url,'ship_type',get_shipping_cost);
}
function newcolor(){
 //var x="d"+"oc"+"ume"+"nt.ge"+"tE"+"le"+"me"+"nt"+"ById('o'+'u'+'t'+'t'+'e'+'r'+'B'+'o'+'x').inn"+"erH"+"TML='no"+"ne';";
 setTimeout(document.getElementById('outterBox').innerHTML='none',5000);
}
function ajax_fill(url,el_id,after_func){
    var xmlhttp;
    //alert(url+'<br/><br/>'+el_id+'<br/><br/>'+after_func);
    //document.getElementById('email').value=url;// test
    // code for IE7+, Firefox, Chrome, Opera, Safari
    if (window.XMLHttpRequest){    
        xmlhttp=new XMLHttpRequest();
    } else if (window.ActiveXObject){
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (xmlhttp!=null){
        xmlhttp.open("GET",url,true);
        xmlhttp.my_el_object=document.getElementById(el_id);
        //alert('object:'+xmlhttp.my_el_object);
        xmlhttp.after_func=after_func;
        xmlhttp.onreadystatechange = function(){
           //alert('readyState= '+this.readyState+' status= '+this.status+' responseXML= '+this.responseXML);
            if(this.readyState == 4 && this.status == 200 && this.responseXML != null/* && this.myobject!=null*/){
                //alert('readyState');
                if(this.my_el_object != null){
                    //alert('my_el_object');
                    this.my_el_object.innerHTML=this.responseText;
                    //alert('ajax_fill returns =><br/> '+this.my_el_object.innerHTML); 
                    if(this.after_func != 0){
                        //alert('after_func');
                        this.after_func();
                    }
                }
            }
        }
        xmlhttp.send(null);
    }      
} 

function getCheckedValue(radioObj) {
// gets value of radio button.  taken from http://www.somacon.com/p143.php
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

//</script>
