/* 
bni.js: library of javascript for working with BNI application
    david.kelly@fanore.com (http://www.fanore.com/website_design.htm)
    
    
    
*/

//check_bni_account:validate that member account dialogue has been populated properly
function check_bni_account(){

    var progress_bar_url=$F('progress_bar_url');

//profession
    if ($F('profession').blank()){
         show_error_message("please enter the member\'s profession!",'error_message_panel');
        $('profession').focus();
        return false;
    }
//organisation
    if ($F('organisation').blank()){
         show_error_message("please enter the member\'s organisation name!",'error_message_panel');
        $('organisation').focus();
        return false;
    }
//firstname
    if ($F('firstname').blank()){
         show_error_message("please enter the member\'s firstname!",'error_message_panel');
        $('firstname').focus();
        return false;
    }
//surname
    if ($F('surname').blank()){
         show_error_message("please enter the member\'s surname!",'error_message_panel');
        $('surname').focus();
        return false;
    }
//email
    if ($F('email').blank()){
         show_error_message("please enter the member\'s email address!",'error_message_panel');
        $('email').focus();
        return false;
    }
//validate email address
    var e=$F('email')
	if (!fixstring(e,true)){
		alert("The email address is invalid - this system only supports the format 'anything@address.com' !");
        $('email').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();
    
    
} 


function check_bni_profile(){
    var progress_bar_url=$F('progress_bar_url');

//profession
    if ($F('profession').blank()){
         show_error_message("please enter the member\'s profession!",'error_message_panel');
        $('profession').focus();
        return false;
    }
//organisation
    if ($F('organisation').blank()){
         show_error_message("please enter the member\'s organisation name!",'error_message_panel');
        $('organisation').focus();
        return false;
    }
//firstname
    if ($F('firstname').blank()){
         show_error_message("please enter the member\'s firstname!",'error_message_panel');
        $('firstname').focus();
        return false;
    }
//surname
    if ($F('surname').blank()){
         show_error_message("please enter the member\'s surname!",'error_message_panel');
        $('surname').focus();
        return false;
    }
//email
    if ($F('email').blank()){
         show_error_message("please enter the member\'s email address!",'error_message_panel');
        $('email').focus();
        return false;
    }
//validate email address
    var e=$F('email')
	if (!fixstring(e,true)){
		alert("The email address is invalid - this system only supports the format 'anything@address.com' !");
        $('email').focus();
		return false;
	}

//  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'); 
           $('picture').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 profile!")){
                $('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);
         //alert($(datasource_name).value);
    }       


    $('url_payload').value=$F('url_params')
    //return false;
    $('save').target='keyhole'; 
// display a window indicating save progress 
    progress_window(progress_bar_url)         
    $('save').submit();
    

}


