/* 
tomorrowcms.js: library of javascript for managing tomorrows office validation
    david.kelly@fanore.com (http://www.fanore.com/website_design.htm)
    
    
    
*/

function boss(params, param_target,param_clear){
    var u = '../asp/ajax_2008.asp'
    var p=params
    $(param_clear).innerHTML='';
    ajax_get_url(u,p, param_target,'');
    

}

/* 
product_catalogue.js: library of javascript for product catalogue management
    david.kelly@fanore.com (http://www.fanore.com/website_design.htm)
    
    
    
*/

//apply_catalogue_filters: captures the selected filters and passes them as ajax params to target
function apply_office_filters(){
    var url="../asp/object_administration.asp"
    var params="objectid=1182&mode=6&tag=products&category=" + $F('category') + "&brand=" + $F('brand') + "&supplier=" + $F('supplier') 
    //alert(params)
    var d=new Date();
      var myAjax = new Ajax.Updater('ajax_results', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  eval('tickle_session();')
                }
            });   

}

//setup the product editor
function tm_product_editor(){
        
        setup_editor();
        setup_tab_tracking('database_editor');
        if (parseInt($F('product_type'))==0){
            $('bundle_contents_workspace').hide();
        };


}
//toggle_product_contents: toggle display of 'bundle_contents_workspace'
function toggle_product_contents(param_type){
    if (parseInt(param_type)==0){
      $('bundle_contents_workspace').hide();
    }
    else
    {   
      $('bundle_contents_workspace').show();
    }
}
//add_to_bundle: perform ajax query for a product id, if not zero then append to the members collection {current}
function add_to_bundle(){
    var current=$F('members');
    
    //check that product code has been entered
    if ($F('bundle_code').blank()){
        show_error_message("please enter a product code to add to this bundle!",'error_message_panel');
        $('bundle_code').focus();
        return void[0];
    }
    //perform ajax lookup using the product code
    var url="../asp/object_administration.asp?objectid=1189&mode=6&tag=_lookupcode&code=" + $F('bundle_code') 
    //window.location.href=url
    //return void[0];
      var myAjax = new Ajax.Request(url, 
            {
                method: 'get', 
                onComplete: function(transport){
                   eval('tickle_session();')
                  var uid=parseInt(transport.responseText);
                  if (uid==0){
                    show_error_message("No product with a code of '" + $F('bundle_code') + "' was found!",'error_message_panel');
                    $('bundle_code').value='';
                    $('bundle_code').focus();
                     return void[0];
                  }
                  //other wise product uid was found, append to current
                  var current=$F('members');
                  current+=',' + uid
                  //alert(current);
                  $('members').value=current
                  var d=new Date();
                  var nAjax = new Ajax.Updater('list_bundle_members',"../asp/object_administration.asp", 
                    {
                        method: 'get', 
                        parameters: "objectid=1189&mode=6&tag=_list_bundle_members&recordid=" + $F('uid') + "&members=" + $F('members') + "&d=" + d.toString(),
                        onComplete: function(transport){
                           eval('tickle_session();')
                        }
                    });  
                }
            });   

    
    

}
//remove_bundle_member: remove an item from bundle contents
function remove_bundle_member(param_parent,param_product){
    return void[0];
}


function check_office_catalogue_item(){

    //var main_image=$F('header_image');
    var progress_bar_url=$F('progress_bar_url');
    
    var product_type=parseInt($F('product_type'))
    //product_supplier
    if ($F('product_supplier').blank()){
        show_error_message("Please select a valid supplier!",'error_message_panel');
        $('product_supplier').focus();
        return false;
    }
    //product_category
    if ($F('product_category').blank()){
        show_error_message("Please select a valid category!",'error_message_panel');
        $('product_category').focus();
        return false;
    }
    
//product_code
    if ($F('product_code').blank()){
         show_error_message("please enter a product code!",'error_message_panel');
        $('product_code').focus();
        return false;
    }
//product_name
    if ($F('product_name').blank()){
         show_error_message("please enter a product name!",'error_message_panel');
        $('product_name').focus();
        return false;
    }
//product_rrp
    if ($F('product_rrp').blank()){
         show_error_message("please enter the RRP for this product!",'error_message_panel');
        $('product_rrp').focus();
        return false;
    }
    var p=$F('product_rrp')
    
    if (isNaN(p)){
         show_error_message("please enter only numberic values for the RRP!",'error_message_panel');
        $('product_rrp').focus();
        return false;
    }
    if (p==0){
         show_error_message("please enter a value greater than zero for the RRP!",'error_message_panel');
        $('product_rrp').focus();
        return false;
    
    }
//product_price
    if ($F('product_price').blank()){
         show_error_message("please enter a price for this product!",'error_message_panel');
        $('product_price').focus();
        return false;
    }
    var p=$F('product_price')
    
    if (isNaN(p)){
         show_error_message("please enter only numberic values for the price!",'error_message_panel');
        $('product_price').focus();
        return false;
    }
    if (p==0){
        show_error_message("please enter a value greater than zero for the price!",'error_message_panel');
        $('product_price').focus();
        return false;
    }

//is this a bundle?
    if (product_type=1){
    
        //check if any items selected for the bundle
        var m=$F('members');
        if (m.length > 1){
            var a_members=m.split(',');
            var quantities='0'
            for (var i=0; i<a_members.length;i++){
                var x=parseInt(a_members[i])
                if (x!=0){
                    // validate quantity of member entered
                    var q='quantity' + x.toString()
                    if ($F(q).blank()){
                        show_error_message("please enter a quantity for each bundled item!",'error_message_panel');
                        $(q).focus();
                        return false;
                    }
                    var p=$F(q)
                    
                    if (isNaN(p)){
                         show_error_message("please enter only a numeric quantity for each bundled item!",'error_message_panel');
                        $(q).focus();
                        return false;
                    }
                    if (p==0){
                        show_error_message("please enter a quantity greater than zero for each bundled item !",'error_message_panel');
                        $(q).focus();
                        return false;
                    }
                    quantities+=',' + p
                    
                }
            }
        }
        $('member_quantities').value=quantities;
    }    
    
//  deal with image properties
    var has_picture=parseInt($F('has_picture')) //does this product already have an image ?
    var n_file=$F('product_image') // has user selected an image
    
    //default value for replacing an image is NO
    $('replace_picture').value=0 
    //if file not blank then reset replace image
    if (!n_file.blank()){
        //check that file is a JPG
        var m=n_file.toString().toLowerCase();
        var c=m.lastIndexOf(".")
        m=m.substr((c+1),4)
        if (m !='jpg'){
           show_error_message("please select a JPG for the picture !",'error_message_panel'); 
           $('product_image').focus()
           return false;
        }
        $('replace_picture').value=1
        //double check that user wants to perform this action
        if (has_picture==1){
            if (!confirm("Please confirm that you wish to replace the picture used for this product!")){
                $('replace_picture').value=0
            }
        }
    }

    var el=get_el('FCKDATASOURCE');
    if (el){    
        var oEditor = FCKeditorAPI.GetInstance('txtHTML');
        var datasource_name = 'fd_description';
        //alert(datasource_name);
       $(datasource_name).value= oEditor.GetXHTML(true);
         
    }       
    $('url_payload').value='refresh_catalogue_view();'
    //return false;
    $('save').target='keyhole'; 
// display a window indicating save progress 
    progress_window(progress_bar_url)         
    $('save').submit();
 }
 
 //refresh_catalogue_view
 function refresh_catalogue_view(){
    //get the params used for most recent listing
    //alert("refresh_catalogue_view");
    var view_params=$('url_params').value;
    var url="../asp/object_administration.asp"
    var params="objectid=1189&mode=6&tag=_dashboard"
    var target="catalogue_dashboard"
    ajax_get_url(url,params, target,'');
    generic_populate_panel(url, view_params, "ajax_results", generic_tracking(view_params)) 
    return void[0];
 }

//sales_category: function triggered by change to 'list_sales_categories' form element
function sales_category(){
    if (parseInt($F('list_sales_categories'))==-1){
        alert("please select a sub-category!");
        return void[0];
    }
    var url="../asp/object_administration.asp"
    var params="objectid=1184&mode=6&tag=category&category=" + $F('list_sales_categories')
    var d=new Date();
      var myAjax = new Ajax.Updater('ajax_results', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  eval('tickle_session();')
                }
            });   

    
}
//refresh_category: refreshes the products listing for a given category (triggered by a category update)
function refresh_category(){
    var url="../asp/object_administration.asp"
    var params="objectid=1184&mode=6&tag=_refreshcategory&category=" + $F('list_sales_categories')
    var d=new Date();
      var myAjax = new Ajax.Updater('assigned_products', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  eval('tickle_session();')
                }
            });   


}
//populate_boss_two: triggered when user selects a main group from listbox 'list_boss_groups'
function populate_boss_two(){
    if ($F('list_boss_groups')==""){
        alert("please select a BOSS category!");
        return void[0];
    }
    $('available_products').innerHTML='';
    var url="../asp/object_administration.asp"
    var params="objectid=1184&mode=6&tag=_bosstwo&mainid=" + $F('list_boss_groups')
    var d=new Date();
      var myAjax = new Ajax.Updater('boss_secondary', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  eval('tickle_session();')
                }
            });   
}

//populate_boss_three: triggered when user selects a second level group from listbox 'list_boss_secondaries'
function populate_boss_three(){
    if ($F('list_boss_secondaries')==""){
        alert("please select a BOSS sub-category!");
        return void[0];
    }
    $('available_products').innerHTML='';
    var url="../asp/object_administration.asp"
    var params="objectid=1184&mode=6&tag=_bossthree&secondid=" + $F('list_boss_secondaries')
    var d=new Date();
      var myAjax = new Ajax.Updater('boss_three', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  eval('tickle_session();')
                }
            });   
}

//populate_available_products: triggered either by keyword search (param_boss==false) or by selection from boss classifications (param_boss==true)
function populate_available_products(param_boss){
    if (param_boss==true){
        if ($F('list_boss_thirds')==""){
            alert("please select a BOSS sub-category!");
            return void[0];
        }
        var url="../asp/object_administration.asp"
        var params="objectid=1184&mode=6&tag=_catalogue&bossid=" + $F('list_boss_thirds') + "&category=" + $F('list_sales_categories') + "&kw="
        //alert(params)
        //ajax_get_url(url ,params, 'available_products', '');
    var d=new Date();
      var myAjax = new Ajax.Updater('available_products', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  eval('tickle_session();')
                }
            });   
    
    
    }

}
//add_to_category: adds product to a sales category
function update_category(param_product,param_category){
        var url="../asp/object_administration.asp"
        var params="objectid=1184&mode=6&tag=_addtocatalogue" + "&productid=" + param_product + "&categoryid=" + param_category + "&bossid=" + $F('list_boss_thirds') + "&category=" + $F('list_sales_categories') + "&kw="
        //alert(params)
        //window.location.href=url + "?" + params
        //return void[0];
    var d=new Date();
      var myAjax = new Ajax.Updater('available_products', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  eval('refresh_category();')
                  eval('tickle_session();')
                }
            });   




    
}


//update_sales_group: adds product to a sales group
function update_sales_group(param_product,param_group){
        var url="../asp/object_administration.asp"
        var params="objectid=1187&mode=6&productid=" + param_product + "&groupid=" + param_group + "&tag=_add_to_group"
        //alert(params)
        //window.location.href=url + "?" + params
        //return void[0];
    var d=new Date();
      var myAjax = new Ajax.Updater('in_sales_group', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  //eval('refresh_category();')
                  eval('tickle_session();')
                }
            });   
}
function remove_from_sales_group(param_product,param_group){
        var url="../asp/object_administration.asp"
        var params="objectid=1187&mode=6&productid=" + param_product + "&groupid=" + param_group + "&tag=_remove_from_group"
        //alert(params)
        //window.location.href=url + "?" + params
        //return void[0];
    var d=new Date();
      var myAjax = new Ajax.Updater('in_sales_group', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  //eval('refresh_category();')
                  eval('tickle_session();')
                }
            });   
}


function update_freight_settings(param_function){
        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_dashboard"
        var d=new Date();
          var myAjax = new Ajax.Updater('dashboardpanel', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      
                      eval('tickle_session();')
                    }
                });   
         eval(param_function);
    
}
/* freight_services: list all freight services*/
function freight_services(){
        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_list_freight_services"
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      
                      eval('tickle_session();')
                    }
                });   


}
/* edit_freight_service: enable edit/new freight service dialogue*/
function edit_freight_service(param_record){
        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_edit_freight_service&recordid=" + param_record
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      setup_tab_tracking('database_editor');
                      eval('tickle_session();')
                    }
                });   

}
/* validate_freight_service: check that form filled in correctly before saving*/
function validate_freight_service(){
    var progress_bar_url=$F('progress_bar_url');
//service name
    if ($F('txt_title').blank()){
         show_error_message("please enter a name for this freight service!",'error_message_panel');
        $('txt_title').focus();
        return false;
    }
    $('save').target='keyhole'; 
// display a window indicating save progress 
    progress_window(progress_bar_url)     
   

            

    $('save').submit();
}
/* delete_freight_service: deletes a freight service*/
function delete_freight_service(param_record){
alert("This feature disabled for now");
return void[0];
}



/* freight_zones: list all freight zones */
function freight_zones(){

        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_list_freight_zones"
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      
                      eval('tickle_session();')
                    }
                });   
}
/* edit_freight_zone: enable edit/new freight zone dialogue*/
function edit_freight_zone(param_record){
        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_edit_freight_zone&recordid=" + param_record
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      setup_tab_tracking('database_editor');
                      eval('tickle_session();')
                    }
                });   

}

/* validate_freight_zone: check that form filled in correctly before saving*/
function validate_freight_zone(){
    var progress_bar_url=$F('progress_bar_url');
//service name
    if ($F('txt_title').blank()){
         show_error_message("please enter a name for this freight zone!",'error_message_panel');
        $('txt_title').focus();
        return false;
    }
    $('save').target='keyhole'; 
// display a window indicating save progress 
            var w=380;
            var h=50;
            var winLeft=Math.round((screen.width - w)/2);
            var winTop=Math.round((screen.height - h)/2);
            var sVersion = navigator.appVersion;
             
           if (sVersion.indexOf('MSIE') != -1 && sVersion.substr(sVersion.indexOf('MSIE')+5,1) > 4)
          {
        		var settings="dialogWidth:380px; dialogHeight:50px; center:yes";
        		var x=window.showModelessDialog(progress_bar_url+ '&b=IE',null,settings);
                x.opener=window
            }
            else
            {
        		//var x=window.open(progress_bar_url+ '&b=NN','','width=370,height=115', true);
                var x=window.open(progress_bar_url+ '&b=NN','','width=380px,height=50', true);
        
           }
           
            x.focus()
   
   

            

    $('save').submit();
}
/* */
/* */
/* freight_charges: list all freight charges */
function freight_charges(){

        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_list_freight_charges"
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      
                      eval('tickle_session();')
                    }
                });   
}
/* freight_service_charges: displays a list of freight charges associates with selected service */
function freight_service_charges(){
    if ($F('list_freight_services').blank()){
        alert("please select a freight service !");
        return void[0];
    }
        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_service_freight_charges&freightserviceid=" + $F('list_freight_services')
        var d=new Date();
          var myAjax = new Ajax.Updater('showfreightservicecharges', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      
                      eval('tickle_session();')
                    }
                });   
}
/* edit_freight_charge: edit freight charge*/
function edit_freight_charge(param_service,param_record){
        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_edit_freight_charge&freightserviceid=" + param_service + "&recordid=" + param_record
        //window.location.href=url + "?" + params
        //return void[0];
        //alert($('displayfreightservicecharges').innerHTML);
        var d=new Date();
          var myAjax = new Ajax.Updater('displayfreightservicecharges', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      //  alert("here")
                      setup_tab_tracking('database_editor');
                      eval('tickle_session();')
                    }
                });   

}
/* validate_freight_charge: test that freight charge form completed correctly */
function validate_freight_charge(){
    var progress_bar_url=$F('progress_bar_url');
//zone name
    if (parseInt($F('zone_id'))==0){
         show_error_message("please select a freight zone!",'error_message_panel');
        $('txt_title').focus();
        return false;
    }
//range_start
    if ($F('range_start').blank()){
         show_error_message("please enter the starting weight for this charge!",'error_message_panel');
        $('range_start').focus();
        return false;
    }
    if (isNaN($F('range_start'))){
         show_error_message("please enter only numeric values for the starting weight (e.g. 0.05)!",'error_message_panel');
        $('range_start').focus();
        return false;
    
    }
//range_end
    if ($F('range_end').blank()){
         show_error_message("please enter the end weight for this charge!",'error_message_panel');
        $('range_end').focus();
        return false;
    }
    if (isNaN($F('range_end'))){
         show_error_message("please enter only numeric values for the end weight (e.g. 0.05)!",'error_message_panel');
        $('range_end').focus();
        return false;
    }
    if (($F('range_start')==$F('range_end'))||($F('range_start') > $F('range_end'))){
         show_error_message("The end weight range must be great than the start weight!",'error_message_panel');
        $('range_end').focus();
        return false;
    }
//euro_price    
    if ($F('euro_price').blank()){
         show_error_message("please enter a price for this charge!",'error_message_panel');
        $('euro_price').focus();
        return false;
    }
    if (isNaN($F('euro_price'))){
         show_error_message("please enter only numeric values for the price (e.g. 9.99)!",'error_message_panel');
        $('euro_price').focus();
        return false;
    
    }
    
    $('save').target='keyhole'; 
// display a window indicating save progress 
            var w=380;
            var h=50;
            var winLeft=Math.round((screen.width - w)/2);
            var winTop=Math.round((screen.height - h)/2);
            var sVersion = navigator.appVersion;
             
           if (sVersion.indexOf('MSIE') != -1 && sVersion.substr(sVersion.indexOf('MSIE')+5,1) > 4)
          {
        		var settings="dialogWidth:380px; dialogHeight:50px; center:yes";
        		var x=window.showModelessDialog(progress_bar_url+ '&b=IE',null,settings);
                x.opener=window
            }
            else
            {
        		//var x=window.open(progress_bar_url+ '&b=NN','','width=370,height=115', true);
                var x=window.open(progress_bar_url+ '&b=NN','','width=380px,height=50', true);
        
           }
           
            x.focus()
   
   

            

    $('save').submit();

}
/* freight_groups: list freight groups */
function freight_groups(){
        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_list_freight_groups"
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      
                      eval('tickle_session();')
                    }
                });   
}
/* */
/* edit_freight_group: edit freight group*/
function edit_freight_group(param_record){
        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=_edit_freight_group&recordid=" + param_record
        //window.location.href=url + "?" + params
        //return void[0];
        //alert($('displayfreightservicecharges').innerHTML);
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      //  alert("here")
                      setup_tab_tracking('database_editor');
                      eval('tickle_session();')
                    }
                });   

}
/* validate_freight_group: test that freight group form completed correctly */
function validate_freight_group(){
    var progress_bar_url=$F('progress_bar_url');
//group name
    if ($F('txt_title').blank()){
         show_error_message("please enter the group name!",'error_message_panel');
        $('txt_title').focus();
        return false;
    }
//weight
    if ($F('weight').blank()){
         show_error_message("please enter the weight!",'error_message_panel');
        $('weight').focus();
        return false;
    }
    if (isNaN($F('weight'))){
         show_error_message("please enter only numeric values for the weight (e.g. 0.05)!",'error_message_panel');
        $('weight').focus();
        return false;
    }
    $('save').target='keyhole'; 
// display a window indicating save progress 
            var w=380;
            var h=50;
            var winLeft=Math.round((screen.width - w)/2);
            var winTop=Math.round((screen.height - h)/2);
            var sVersion = navigator.appVersion;
             
           if (sVersion.indexOf('MSIE') != -1 && sVersion.substr(sVersion.indexOf('MSIE')+5,1) > 4)
          {
        		var settings="dialogWidth:380px; dialogHeight:50px; center:yes";
        		var x=window.showModelessDialog(progress_bar_url+ '&b=IE',null,settings);
                x.opener=window
            }
            else
            {
        		//var x=window.open(progress_bar_url+ '&b=NN','','width=370,height=115', true);
                var x=window.open(progress_bar_url+ '&b=NN','','width=380px,height=50', true);
        
           }
           
            x.focus()
   
   

            

    $('save').submit();

}
/* */
/* freight_products: list products with / without valid weight (param_state=0 ==> none, param_state==1 ==> yes)*/
function freight_products(param_state){
        var url="../asp/object_administration.asp"
        var params="objectid=1185&mode=6&tag=product_weights"
        window.location.href=url + "?" + params
}
/*populate_freight_group: using ajax, we populate dialogue to enable assignment of products to a freight / weight group */
function populate_freight_group(){
    if ($F('list_freight_groups').blank()){
        alert("please select a freight group!");
        return void[0];
    }
    var url="../asp/object_administration.asp"
    var params="objectid=1185&mode=6&tag=_freight_group_workspace&recordid=" + $F('list_freight_groups')
    var d=new Date();
      var myAjax = new Ajax.Updater('ajax_results', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  eval('tickle_session();')
                }
            });   

    
    
}

/* tm_manage_customers: refresh summary and list of customers*/
function tm_manage_customers(){
        var url="../asp/object_administration.asp"
        var params="objectid=1186&mode=6&tag=_overview"
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      eval('tm_list_customers();')
                    }
                });   

}

/* tm_list_customers: present a list of customers */
function tm_list_customers(){
        var url="../asp/object_administration.asp"
        var params="objectid=1186&mode=6&tag=_listcustomers"
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      
                      eval('tickle_session();')
                    }
                });   

}
/* tm_edit_customer: open a customer record for editing*/
function tm_edit_customer(param_customer){
        var url="../asp/object_administration.asp"
        var params="objectid=1186&mode=6&tag=_edit_customer&recordid=" + param_customer
        $('url_params').value='tm_list_customers();'
        //window.location.href=url + "?" + params
        //return void[0];
        //alert($('displayfreightservicecharges').innerHTML);
        var d=new Date();
          var myAjax = new Ajax.Updater('ajax_results', 
                url, 
                {
                    method: 'get', 
                    parameters: params + '&d=' + d.toString(),
                    onComplete: function(obj){
                      //  alert("here")
                      setup_tab_tracking('database_editor');
                      eval('tickle_session();')
                    }
                });   


}
/*check_tm_customer_account: validate the customer account form before posting*/
function check_tm_customer_account(){
    var progress_bar_url=$F('progress_bar_url');
//organisation
    if ($F('txt_organisation').blank()){
         show_error_message("please enter the organisation name!",'error_message_panel');
        $('txt_organisation').focus();
        return false;
    }
//title
   // if ($F('txt_title').blank()){
   //      show_error_message("please enter the contact title (e.g. Mr. / Ms.)!",'error_message_panel');
   //     $('txt_title').focus();
   //     return false;
   // }
//firstname
/*
    if ($F('txt_firstname').blank()){
         show_error_message("please enter the contact's first name!",'error_message_panel');
        $('txt_firstname').focus();
        return false;
    }
 */
/*
//surname
    if ($F('txt_surname').blank()){
         show_error_message("please enter the contact's surname!",'error_message_panel');
        $('txt_surname').focus();
        return false;
    }
*/
//email
    if ($F('txt_email').blank()){
         show_error_message("please enter the customer's email address!",'error_message_panel');
        $('txt_email').focus();
        return false;
    }
//validate email address
    var e=$F('txt_email')
	if (!fixstring(e,true)){
		alert("The email address is invalid - this system only supports the format 'yourname@address.com' !");
        $('txt_email').focus();
		return false;
	}
    
//address 1
/*
    if ($F('txt_address1').blank()){
         show_error_message("please enter at least two lines for the address!",'error_message_panel');
        $('txt_address1').focus();
        return false;
    }
//address 2
    if ($F('txt_address1').blank()){
         show_error_message("please enter at least two lines for the address!",'error_message_panel');
        $('txt_address1').focus();
        return false;
    }
 */
//address 3
//    if ($F('txt_address3').blank()){
//         show_error_message("please enter at least two lines for the address!",'error_message_panel');
//        $('txt_address3').focus();
//        return false;
//    }
//address 4 (county)

    if ($F('txt_address4').blank()){
         show_error_message("please select the county!",'error_message_panel');
        $('txt_address4').focus();
        return false;
    }
//telephone
//    if ($F('txt_telephone').blank()){
//         show_error_message("please enter a contact telephone number!",'error_message_panel');
//        $('txt_telephone').focus();
//        return false;
//    }
//mobile
//    if ($F('txt_mobile').blank()){
//         show_error_message("please enter a mobile number!",'error_message_panel');
//        $('txt_mobile').focus();
//        return false;
//    }
//fax
//    if ($F('txt_fax').blank()){
//         show_error_message("please enter a fax number!",'error_message_panel');
//        $('txt_fax').focus();
//        return false;
//    }
//vat number
//    if ($F('txt_vat').blank()){
//         show_error_message("please enter a vat number!",'error_message_panel');
//        $('txt_vat').focus();
//        return false;
//    }
//credit limit
    if ($F('txt_credit_limit').blank()){
        $('txt_credit_limit').value="0";
    }
    var e=$F('txt_credit_limit')
    if (isNaN(e)){
         show_error_message("please enter only numeric values (e.g. 10000)!",'error_message_panel');
        $('txt_credit_limit').focus();
        return false;
    
    }    
    
    $('url_payload').value=$F('url_params')
    //return false;
    $('save').target='keyhole'; 
// display a window indicating save progress
    progress_window(progress_bar_url) 
    $('save').submit();

}

//check_tm_customer_discount: validate a customer discount before saving
function check_tm_customer_discount(){
    var progress_bar_url=$F('progress_bar_url');

//txt_price
    if ($F('txt_price').blank()){
         show_error_message("please enter the customer discount!",'error_message_panel');
        $('txt_price').focus();
        return false;
    }
    var e=$F('txt_price')
    if (isNaN(e)){
         show_error_message("please enter only numeric values (e.g. 10000)!",'error_message_panel');
        $('txt_price').focus();
        return false;
    }    
    if (parseInt(e)==0){
        if (!confirm("Are you sure you want to sell this product for free ?")){
        $('txt_price').focus();
        return false;
        }
    }
//txt_min
    if ($F('txt_min').blank()){
        $('txt_min').value="0";
    }
    var e=$F('txt_min')
    if (isNaN(e)){
         show_error_message("please enter only numeric values (e.g. 10000)!",'error_message_panel');
        $('txt_min').focus();
        return false;
    }    
//txt_max    
    if ($F('txt_max').blank()){
        $('txt_max').value="0";
    }
    var e=$F('txt_max')
    if (isNaN(e)){
         show_error_message("please enter only numeric values (e.g. 10000)!",'error_message_panel');
        $('txt_max').focus();
        return false;
    }    
            

    $('url_params').value=$F('url_payload')
    //alert($F('url_payload'));
    //return false;
    $('save').target='keyhole'; 
    progress_window(progress_bar_url) 
    $('save').submit();

    
}

//tm_delete_discount: delete a customer discount
function tm_delete_discount(param_id){
    var url="../asp/object_Administration.asp?objectid=1186&mode=6&tag=_delete_discount&recordid=" + param_id
    var text='Are you sure you want to delete this record ?'
    if (!confirm(text)){
        return void[0];
    }
    var row_id='listing_' + param_id
    new Ajax.Request(url, {  
         onSuccess: function(transport) { 
        Element.remove(row_id);     
         } 
         }); 
    return void[0];
}

//tm_delete_customer: delete a customer account
function tm_delete_customer(param_id){
    var url="../asp/object_Administration.asp?objectid=1186&mode=6&tag=_delete_customer&recordid=" + param_id
    var text='Are you sure you want to delete this customer (warning! this is irreversible) ?'
    if (!confirm(text)){
        return void[0];
    }
    var row_id='listing_' + param_id
    new Ajax.Request(url, {  
         onSuccess: function(transport) { 
        Element.remove(row_id);
             
         } 
         }); 
    return void[0];
}

//check_discount_spreadsheet: check that a valid spreadsheet file has been selected
function check_discount_spreadsheet(){
    var progress_bar_url=$F('progress_bar_url');
    if ($F('customer_discount_file').blank()){
        alert("you must select a valid spreadsheet first!");
        return false;
    }
    $('url_params').value=$F('url_payload')
    $('uploadingform').target='keyhole'; 
    progress_window(progress_bar_url) 
    $('uploadingform').submit();

}
//confirm_reset_discounts: confirm that user wants to reset the last updated value for customer discounts
function confirm_reset_discounts(){
    var progress_bar_url=$F('resetprogress_bar_url');
    if (!confirm("Are you sure you want to reset the date on this customers discounts?")){
        
        return void[0];
    }
    $('url_params').value=$F('url_payload')
    $('resetform').target='keyhole'; 
    progress_window(progress_bar_url) 
    $('resetform').submit();

}

//tm_promo_editor: prepares dialogue for editing a promotional panel
function tm_promo_editor(){

        setup_editor();

        setup_tab_tracking('database_editor');
        var css = document.createElement("link");
        css.setAttribute("href",$F("fck_css"));
        css.setAttribute("rel","stylesheet");
        css.setAttribute("type","text/css");
        setCSS(css);
        css = null;
    return void[0];
}

// clones text (up to a limit) into two spaces, seo_description & summary narrative
function promo_narrative(editorInstance){
        var alreadyRun = false;
        var promoeditor = FCKeditorAPI.GetInstance('txtHTML') ;
    	var oDOM = promoeditor.EditorDocument ;
    	var iLength ;
        iLength = oDOM.body.innerText.length ;
        //alert(iLength)
        var buffer=oDOM.body.innerText;
        //get value of seo auto fill 
        //alert(oDOM.body.innerHTML)
        $('div_preview').innerHTML=oDOM.body.innerHTML;


}


//tm_salesgroup_editor: prepares dialogue for editing a sales group
function tm_salesgroup_editor(){
   // alert('tm_salesgroup_editor')
        setup_editor();
        setup_tab_tracking('database_editor');
    return void[0];
}


//toggle_promo_contents: display options based on the type of promotional panel
function toggle_promo_contents(param_type){
    if (param_type=='category'){
        //populate 'context_settings' with tick box list of categories
        
    }
    return void[0];
}

//toggle_promo_links: present list of links 
function toggle_promo_links(param_id,param_type){
    var url="../asp/object_administration.asp"
    var params="objectid=1190&mode=6&tag=_promo_link_options&linktype=" + param_type + "&recordid=" + param_id
    var target="promo_link_options"
    ajax_get_url(url,params, target,'');
     $('promo_link_options').show();
}

 //refresh_promotion_view
 function refresh_promotion_view(){
    //get the params used for most recent listing
    var view_params=$('url_params').value;
    var url="../asp/object_administration.asp"
    var params="objectid=1190&mode=6&tag=_dashboard"
    var target="promotions_dashboard"
    ajax_get_url(url,params, target,'');
    generic_populate_panel(url, view_params, "ajax_results", generic_tracking(view_params)) 
    return void[0];
 }
 
 //refresh_group_view
 function refresh_group_view(){
    //alert('refresh_group_view')
    //get the params used for most recent listing
    var view_params=$('url_params').value;
    var url="../asp/object_administration.asp"
    var params="objectid=1187&mode=6&tag=_dashboard"
    var target="sales_group_dashboard"
    ajax_get_url(url,params, target,'');
    generic_populate_panel(url, view_params, "ajax_results", generic_tracking(view_params)) 
    return void[0];
 }
 
 
// check_tm_promotion: validate form for creating promotion
function check_tm_promotion(){
    //
    var progress_bar_url=$F('progress_bar_url');
    //promo_name
    if ($F('promo_name').blank()){
        show_error_message("Please enter name for this promotion!",'error_message_panel');
        $('promo_name').focus();
        return false;
    }

    
    var start_date=0;
    var end_date=0;
// date validation  
    start_date= validate_dmyhm('start')
    if (start_date==false){
        return false
    }
    //alert(start_date);
    end_date=validate_dmyhm('end')
    if (end_date==false){
        return false
    }
    if (js_date('start')>=js_date('end')){
        show_error_message("You have selected an invalid start date, please check your entry!",'error_message_panel');
        $('start_day').focus();
        return false;
    }
    $('start_date').value=start_date;
    $('end_date').value=end_date;
    if ($F('promo_link').blank()){
        show_error_message("Please select the type of link to create!",'error_message_panel');
        $('promo_link').focus();
        return false;
        
    }
    var promo_link_type=$F('promo_link')
    //alert(promo_link_type);
    switch (promo_link_type){
        case 'sales': // implies that a sales group has been selected
            break;
        case 'product': //implies that product has been selected
            if ($F('promo_context').blank()){
                show_error_message("Please select the product to link to!",'error_message_panel');
                $('item_code').focus();
                return false;
            }
            if ($F('promo_context_id').blank()){
                show_error_message("Please select the product to link to!",'error_message_panel');
                $('item_code').focus();
                return false;
            }
            
            break;
        
    
    }
    
    var promo_image=$F('promo_image')
    var has_picture=parseInt($F('has_picture'));
    //if no picture
    $('replace_picture').value='0'
    
    if ((parseInt(has_picture)==0)&&($F('promo_image').blank())){
        show_error_message("Please select a picture to use!",'error_message_panel');
        $('promo_image').focus();
        return false;
    }
    
    //if already has picture - confirm replacement
    if ((parseInt(has_picture)==1)&&(!$F('promo_image').blank())){
        if (confirm('Please click ok to confirm you want to replace the exising image!')){
            $('replace_picture').value='1'
        }
    }
    if ((parseInt(has_picture)==0)&&(!$F('promo_image').blank())){
         $('replace_picture').value='1'
    }
    //promo_type
    var promo_type=$F('promo_type');
    switch (promo_type){
        case 'pooled'://implies it is part of a pool
            break;
        case 'home': //implies it used on the home page
            break;
        case 'category': // implies it is used on one or more category pages
            break;
    
    }
    var el=get_el('FCKDATASOURCE');
    if (el){    
        var oEditor = FCKeditorAPI.GetInstance('txtHTML');
        var datasource_name = 'fd_description';
        //alert(datasource_name);
       $(datasource_name).value= oEditor.GetXHTML(true);
         
    }       
    
    
    $('save').target='keyhole'; 
    progress_window(progress_bar_url)         
    $('save').submit();
    

}

//check_tm_salesgroup: validate sales group before posting
function check_tm_salesgroup(){
    var progress_bar_url=$F('progress_bar_url');
    //group_name
    if ($F('group_name').blank()){
        show_error_message("Please enter name for this sales group!",'error_message_panel');
        $('group_name').focus();
        return false;
    }

    //group_seo_title
    if ($F('group_seo_title').blank()){
        show_error_message("Please enter the seo title for this sales group!",'error_message_panel');
        $('group_seo_title').focus();
        return false;
    }

    var group_image=$F('group_image')
    var has_picture=parseInt($F('has_picture'));
    //if no picture
    $('replace_picture').value='0'
    
    //if ((parseInt(has_picture)==0)&&($F('group_image').blank())){
    //    show_error_message("Please select a picture to use!",'error_message_panel');
    //    $('group_image').focus();
    //    return false;
    //}
    
    //if already has picture - confirm replacement
    if ((parseInt(has_picture)==1)&&(!$F('group_image').blank())){
        if (confirm('Please click ok to confirm you want to replace the exising image!')){
            $('replace_picture').value='1'
        }
    }
    if ((parseInt(has_picture)==0)&&(!$F('group_image').blank())){
         $('replace_picture').value='1'
    }
    
    var el=get_el('FCKDATASOURCE');
    if (el){    
        var oEditor = FCKeditorAPI.GetInstance('txtHTML');
        var datasource_name = 'fd_description';
        //alert(datasource_name);
       $(datasource_name).value= oEditor.GetXHTML(true);
         
    }       
    
    
    $('save').target='keyhole'; 
    progress_window(progress_bar_url)         
    $('save').submit();
}


//find_catalogue_item: facility to search for a product using product code
function find_catalogue_item(param_context, param_contextid){
    var url="../asp/object_administration.asp"
    
    //alert(param_context)
    switch (param_context){
        case '1184':
            if ($F('item_code').blank()){
                show_error_message("please enter part of a product code!",'error_message_panel');
                $('item_code').focus();
                return void[0];
                }
            var params="objectid=1190&mode=6&tag=_items_found&code=" + $F('item_code') + '&context=' + param_context + '&contextid=' + param_contextid;
            var target='list_items_found';
            break;
        case '1185':
            if ($F('item_code').blank()){
                show_error_message("please enter part of a product code!",'error_message_panel');
                $('item_code').focus();
                return void[0];
                }
            var params="objectid=1185&mode=6&tag=_items_found&code=" + $F('item_code') + '&context=' + param_context + '&contextid=' + param_contextid;
            var target='list_items_found';
            break;
        case '1186':
            if ($F('item_code').blank()){
                show_error_message("please enter part of a product code!",'error_message_panel');
                $('item_code').focus();
                return void[0];
                }
            var params="objectid=1186&mode=6&tag=_items_found&code=" + $F('item_code') + '&context=' + param_context + '&contextid=' + param_contextid;
            var target='list_items_found';
            break;
        case '1187':
            if ($F('item_code').blank()){
                show_error_message("please enter part of a product code!",'error_message_panel');
                $('item_code').focus();
                return void[0];
                }
            var params="objectid=1187&mode=6&tag=_sales_group_available&code=" + $F('item_code') + '&context=' + param_context + '&groupid=' + param_contextid;
            var target='sales_group_available';
            break;
        case '1189':
            if ($F('item_code').blank()){
                show_error_message("please enter part of a product code!",'error_message_panel');
                $('item_code').focus();
                return void[0];
                }
            var params="objectid=1189&mode=6&tag=_list_all_products&report=search&code=" + $F('item_code') 
            var target='ajax_results';
            break;
        case '1190':
            if ($F('item_code').blank()){
                show_error_message("please enter part of a product code!",'error_message_panel');
                $('item_code').focus();
                return void[0];
                }
            var params="objectid=1190&mode=6&tag=_items_found&code=" + $F('item_code') + '&context=' + param_context;
            var target='list_items_found';
            $('promo_link_options').show();
            break;
        case '1111':
            break;
    }
    generic_populate_panel(url, params,target, '');
    return void[0];
}

//tm_select_this: generic function to select 'an item'
function tm_select_this(param_id,param_context, param_code, param_name, param_payload){
    var uid=param_id
    var url="../asp/object_administration.asp"
    var params=""
    //alert(param_context)
    switch(param_context){
        case '1184': //selecting an item to add to a category
            $('promo_context').value=param_payload // context of the promotion link (product or sales group)
            $('promo_context_id').value=param_id // context id of the particular product or group
            $('promo_current_link').innerHTML='<span style="margin: 0 10px 0 0;">'  + param_code  + '</span><span>' + param_name + '</span>'
            $('promo_link_options').hide();
            break;
        case '1185'://selecting an item to be added as a freight exception
            var target="list_freight_exceptions"
            var oncomplete="generic_refresh_dashboard();"            
            params="objectid=1185&mode=6&tag=_list_freight_exceptions&action=add&productid=" + param_id 
            if (param_payload=="remove"){
                params="objectid=1185&mode=6&tag=_list_freight_exceptions&action=remove&productid=" + param_id 
            }
            //alert(params)
            generic_populate_panel(url,params,target,oncomplete);
            break;
        case '1186': //selecting an item to add to a category
            var target="display_discounts"
            var oncomplete="setup_tab_tracking(\'database_editor\');"            
            params="objectid=1186&mode=6&tag=_edit_customer_discount&accountid=" + param_payload + "&recordid=0&step=2&productid=" + param_id + "&code=" + $F('item_code')
            //alert(params)
            generic_populate_panel(url,params,target,oncomplete);
            break;
        case '1190': //selecting an item to link to in shop promotions dialogue
            $('promo_context').value=param_payload // context of the promotion link (product or sales group)
            $('promo_context_id').value=param_id // context id of the particular product or group
            
            $('promo_current_link').innerHTML='<span style="margin: 0 10px 0 0;">'  + param_code  + '</span><span>' + param_name + '</span>'
            //$('promo_link_options').hide();
            break;
    }
    return void[0];
}
//display_sales_group: triggered when user selects a sales group from list (to manage contents)
function display_sales_group(param_id){
    if ($F('list_sales_groups').blank()){return void[0]}//exit if nothing selected
    var url="../asp/object_administration.asp"
    var params="objectid=1187&mode=6&tag=_sales_group_contents&groupid=" + $F('list_sales_groups')
    var target='sales_group_contents'
    var oncomplete='generic_null();'
    generic_populate_panel(url, params,  target, oncomplete );
}

//tm_delete_order: delete an order from the database
function tm_delete_order(param_id){
    var url="../asp/object_Administration.asp?objectid=1191&mode=6&tag=_delete_order&recordid=" + param_id
    var text='Are you sure you want to delete this order (warning! this is irreversible) ?'
    if (!confirm(text)){
        return void[0];
    }
    var row_id='listing_' + param_id
    new Ajax.Request(url, {  
         onSuccess: function(transport) { 
        Element.remove(row_id);
             
         } 
         }); 
    return void[0];

}

//tm_order_options: validate options
function tm_order_options(param_context,param_id){
var url="../asp/object_administration.asp"
var oncomplete='generic_null();'
var target='sales_order_options'
    switch(param_context){
        case 'MARK_AS_PAID': // flag the order as paid and set payment date (check date is valid)
           var input_date= validate_dmy('payment')
            if (input_date==false){
                return false
            }
    
        var params="objectid=1191&mode=6&tag=_update_options&type=MARK_AS_PAID&recordid=" + param_id + "&date=" + input_date
        //window.location.href=url + "?" + params
        //return false;
    
                   var d=new Date();
                      var myAjax = new Ajax.Updater('sales_order_options', 
                            url, 
                            {
                                method: 'get', 
                                parameters: params + '&d=' + d.toString(),
                                onComplete: function(obj){
                                  eval('update_online_sales_dashboard();');
                                  //update various other values
                                }
                            });
                            
                        
            break;
        case 'MARK_AS_DESPATCHED': // flag order as despatched
            var input_date= validate_dmyhm('despatch')
            if (input_date==false){
                return false
            }
    
        var params="objectid=1191&mode=6&tag=_update_options&type=MARK_AS_DESPATCHED&recordid=" + param_id + "&date=" + input_date + "&ref=" + $F('despatch_reference')
        //window.location.href=url + "?" + params
        //return false;
    
                   var d=new Date();
                      var myAjax = new Ajax.Updater('sales_order_options', 
                            url, 
                            {
                                method: 'get', 
                                parameters: params + '&d=' + d.toString(),
                                onComplete: function(obj){
                                  eval('update_online_sales_dashboard();');
                                  //update various other values
                                }
                            });
                            
                        
            break;
        case 'MARK_AS_CLOSED': // flag order status as 'closed'
        
        var params="objectid=1191&mode=6&tag=_update_options&type=MARK_AS_CLOSED&recordid=" + param_id 
        //window.location.href=url + "?" + params
        //return false;
    
                   var d=new Date();
                      var myAjax = new Ajax.Updater('sales_order_options', 
                            url, 
                            {
                                method: 'get', 
                                parameters: params + '&d=' + d.toString(),
                                onComplete: function(obj){
                                  eval('update_online_sales_dashboard();');
                                  //update various other values
                                }
                            });
                            
                        
            break;
        case 'MARK_AS_ARCHIVED': // flag order status as 'archived'
        
        var params="objectid=1191&mode=6&tag=_update_options&type=MARK_AS_ARCHIVED&recordid=" + param_id 
        //window.location.href=url + "?" + params
        //return false;
    
                   var d=new Date();
                      var myAjax = new Ajax.Updater('sales_order_options', 
                            url, 
                            {
                                method: 'get', 
                                parameters: params + '&d=' + d.toString(),
                                onComplete: function(obj){
                                  eval('update_online_sales_dashboard();');
                                  //update various other values
                                }
                            });
                            
                        
            break;
        case 'MARK_CC_AS_PAID'://was failed cc payment, flag as paid    
           var input_date= validate_dmy('payment')
            if (input_date==false){
                return false
            }
    
        var params="objectid=1191&mode=6&tag=_update_options&type=MARK_CC_AS_PAID&recordid=" + param_id + "&date=" + input_date + "&ref=" + $F('payment_reference')
        //window.location.href=url + "?" + params
        //return false;
    
                   var d=new Date();
                      var myAjax = new Ajax.Updater('sales_order_options', 
                            url, 
                            {
                                method: 'get', 
                                parameters: params + '&d=' + d.toString(),
                                onComplete: function(obj){
                                  eval('update_online_sales_dashboard();');
                                  
                                  //update various other values
                                }
                            });
                            
                        
            break;
        case 'MARK_AS_ARRANGE'://take incomplete order back into main stream workflow
        var params="objectid=1191&mode=6&tag=_update_options&type=MARK_AS_ARRANGE&recordid=" + param_id 
        //window.location.href=url + "?" + params
        //return false;
    
                   var d=new Date();
                      var myAjax = new Ajax.Updater('sales_order_options', 
                            url, 
                            {
                                method: 'get', 
                                parameters: params + '&d=' + d.toString(),
                                onComplete: function(obj){
                                  eval('update_online_sales_dashboard();');
                                  
                                  //update various other values
                                }
                            });
                            
                        
            break;
        default:
    }
    return false;
}

function update_online_sales_dashboard(){
//alert('update_online_sales_dashboard')
        var params="objectid=1191&mode=6&tag=_dashboard"
        //window.location.href=url + "?" + params
        //return false;
    
                   var d=new Date();
                      var myAjax = new Ajax.Updater('overview', 
                            url, 
                            {
                                method: 'get', 
                                parameters: params + '&d=' + d.toString(),
                                onComplete: function(obj){
                                  eval('tickle_session();');
                                  //update various other values
                                }
                            });

}


//customer_search: validate then execute customer search
function customer_search(){
    if ($F('customer_email').blank()){
        show_error_message("please enter some or all of the customers email address!",'error_message_panel');
        return false;
    }
    var params='objectid=1186&mode=6&tag=_listcustomers&report=search&email=' + $F('customer_email')
    generic_populate_panel('../asp/object_administration.asp', params, 'ajax_results', 'generic_null();');
    return false;
}

//reset_customer_password: confirm if administrator wishes to reset customer password
function reset_customer_password(url,params,counter){
    var target='ajax_results'
    var complete="setup_editor();setup_tab_tracking('database_editor');"
    var p=params
    if (counter==0){
        if (!confirm('Are you sure you want to send this customer a message, you have not setup any discounts for them!')){
            return void[0];
        }
    }
    
    if (!confirm('Click on "OK" if you want to create a NEW password for this customer, otherwise click on "CANCEL"')){
        p+='&reset=false'
    }
    
    generic_populate_panel(url,p, target,complete);
    
}

//send_reset_customer_message: validate and send the customer message
function send_reset_customer_message(){
   var oEditor = FCKeditorAPI.GetInstance('txtHTML'); 
   var buffer=oEditor.GetXHTML(true);
   var progress_bar_url=$F('progress_bar_url');
   
   if ($F('txt_subject').blank()){
        show_error_message("please enter a subject line before sending!",'error_message_panel');
        return false;    
   }
   
   var datasource_name = 'fd_description';
   if (buffer==null){
        show_error_message("please click somewhere on the message before sending!",'error_message_panel');
        return false;    
    
   }
   //buffer=oEditor.GetXHTML(true);
   if (buffer.indexOf('runtime')!=-1){
        show_error_message("please replace any variables in the message before sending!",'error_message_panel');
        return false;    
   }
   
   $(datasource_name).value= buffer;
   
   
    $('url_payload').value='tm_list_customers();'
    //return false;
    $('save').target='keyhole'; 
// display a window indicating save progress 
    progress_window(progress_bar_url)         
    $('save').submit();
//    alert("message has been sent to customer");
}

function check_default_shipping_parameters(){
var progress_bar_url=$F('progress_bar_url');
//default_shipping_threshold
    if ($F('default_shipping_threshold').blank()){
        $('default_shipping_threshold').value="0";
    }
    var e=$F('default_shipping_threshold')
    if (isNaN(e)){
         show_error_message("please enter only numeric values (e.g. 75)!",'error_message_panel');
        $('default_shipping_threshold').focus();
        return false;
    }    

//default_shipping_cost
    if ($F('default_shipping_cost').blank()){
        $('default_shipping_cost').value="0";
    }
    var e=$F('default_shipping_cost')
    if (isNaN(e)){
         show_error_message("please enter only numeric values (e.g. 100)!",'error_message_panel');
        $('default_shipping_cost').focus();
        return false;
    }    
    
    //return false;
    $('save').target='keyhole'; 
// display a window indicating save progress 
    progress_window(progress_bar_url)         
    $('save').submit();

}

