/* 
highlyrecommended.js: library of javascript for animation / branding effects
    david.kelly@fanore.com (http://www.fanore.com/website_design.htm)
    
    
    
*/

//check_recommended_item_group
function check_recommended_item_group(){
  var progress_bar_url=$F('progress_bar_url');
//        caption=""
    if ($F('txt_title').blank()){
         show_error_message("please enter the group name!",'error_message_panel');
        $('txt_title').focus();
        return false;
    }
    var el=get_el('FCKDATASOURCE');
    if (el){    
        var cEditor = FCKeditorAPI.GetInstance('txtHTML');
        var datasource_name = 'fd_description';
        //alert(datasource_name);
       $(datasource_name).value= cEditor.GetXHTML(true);
         
    }       
    $('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_recommended_item
function check_recommended_item(){

    var progress_bar_url=$F('progress_bar_url');
    
//        caption=""
    if ($F('caption').blank()){
         show_error_message("please enter the caption!",'error_message_panel');
        $('caption').focus();
        return false;
    }
//        strap_line=""
//        seo_title=""
//        seo_keywords=""
//        seo_description=""
//        contact_name=""
//        address1=""
//        address2=""
//        address3=""
//        address4=""
//        telephone=""
//        fax=""
//        email=""
//        web=""
//        twitter=""
//        latitude=""
//        longtitude=""
//        description=""
//        picture=session("userurl") & "images/recommended_item_placeholder.jpg"
//        has_picture=0
//        change_picture=0
//  deal with image properties
    var has_picture=parseInt($F('has_picture')) //does this product already have an image ?
    var n_file=$F('picture') // has user selected an image
    
    //default value for replacing an image is NO
    $('change_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;
        }
        $('change_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 record!")){
                $('change_picture').value=0
            }
        }
    }
    

    var el=get_el('FCKDATASOURCE');
    if (el){    
        var cEditor = FCKeditorAPI.GetInstance('txtHTML');
        var datasource_name = 'fd_description';
        //alert(datasource_name);
       $(datasource_name).value= cEditor.GetXHTML(true);
         
    }       
    var el=get_el("optGroups");
    var buffer="0"
    for (var i=0;i<el.length;i++){
        
        if (el[i].checked){
            buffer+=',' + el[i].value;
        }
    }
    $('groups').value=buffer
    $('url_payload').value=$F('url_params')
    //return false;
    $('save').target='keyhole'; 
// display a window indicating save progress 
    progress_window(progress_bar_url)         
    $('save').submit();


    
}

//recommendedIcon: populate the 'picture' value with selected image
function recommendedIcon(paramID,paramImage){
    $('icon').value=paramImage;
    if ($('icon1').hasClassName('currentIcon')){
        $('icon1').removeClassName('currentIcon');
        $('icon1').addClassName('normalIcon');
    }
    if ($('icon2').hasClassName('currentIcon')){
        $('icon2').removeClassName('currentIcon');
        $('icon2').addClassName('normalIcon');
    }
    if ($('icon3').hasClassName('currentIcon')){
        $('icon3').removeClassName('currentIcon');
        $('icon3').addClassName('normalIcon');
    }
    if ($('icon4').hasClassName('currentIcon')){
        $('icon4').removeClassName('currentIcon');
        $('icon4').addClassName('normalIcon');
    }
    if ($('icon5').hasClassName('currentIcon')){
        $('icon5').removeClassName('currentIcon');
        $('icon5').addClassName('normalIcon');
    }
    if ($('icon6').hasClassName('currentIcon')){
        $('icon6').removeClassName('currentIcon');
        $('icon6').addClassName('normalIcon');
    }
    $(paramID).addClassName('currentIcon');
}
