/* 

NOTES:

feature_set_name: replace this word to tailor standard functionality such as validation, delete, posting



project_management.js: library of javascript to support feature_set_name
    david.kelly@fanore.com (http://www.fanore.com/website_design.htm)
    check_project_management: validate the project editing dialogue
    check_project_user: validate the user editing dialogue
    
*/


//check_project_management: validate the feature_set_name editing dialogue
function check_project_management(){
    var progress_bar_url=$F('progress_bar_url');
    
    
//caption
    if ($F('txt_title').blank()){
         show_error_message("please enter a caption for this project!",'error_message_panel');
        $('txt_title').focus();
        return false;
    }
//context_id
    if ($F('context_id').blank()){
         show_error_message("please select the related web content applicable to this project!",'error_message_panel');
        $('context_id').focus();
        return false;
    }
//txt_seo_title
    if ($F('txt_seo_title').blank()){
         show_error_message("please enter a longer title for this project!",'error_message_panel');
        $('txt_seo_title').focus();
        return false;
    }
//txt_keywords
 //   if ($F('txt_keywords').blank()){
 //        show_error_message("please enter keyword tags for this project!",'error_message_panel');
 //       $('txt_keywords').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_project_user: validate the user editing dialogue
function check_project_user(){
    var progress_bar_url=$F('progress_bar_url');
    
//txt_organisation
    if ($F('txt_organisation').blank()){
         show_error_message("please enter the organisation name!",'error_message_panel');
        $('txt_organisation').focus();
        return false;
    }
//txt_name
    if ($F('txt_name').blank()){
         show_error_message("please the full name of the user!",'error_message_panel');
        $('txt_name').focus();
        return false;
    }
//txt_email
    if ($F('txt_email').blank()){
         show_error_message("please enter the 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;
	}
    

//txt_telephone
    if ($F('txt_telephone').blank()){
         show_error_message("please enter the telephone number!",'error_message_panel');
        $('txt_telephone').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_file_category: check the file category
function check_file_category(){
    var progress_bar_url=$F('progress_bar_url');
    
//txt_seo_title
    if ($F('txt_seo_title').blank()){
         show_error_message("please enter the category name!",'error_message_panel');
        $('txt_seo_title').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_file_item: validate the promotional_panels editing dialogue
function check_file_item(){
    var progress_bar_url=$F('progress_bar_url');
//project_id
    if ($F('project_id').blank()){
         show_error_message("please select a project!",'error_message_panel');
        $('project_id').focus();
        return false;
    }
//category_id    
    if ($F('category_id').blank()){
         show_error_message("please select a category!",'error_message_panel');
        $('category_id').focus();
        return false;
    }
//txt_seo_title: which website for the panel?
    if ($F('txt_seo_title').blank()){
         show_error_message("please enter a name for this file!",'error_message_panel');
        $('txt_seo_title').focus();
        return false;
    }
//  deal with image properties
    var has_picture=parseInt($F('has_picture')) //does this promotional panel 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='1'
    //must select a file for upload if there is no existing file
    if ((n_file.blank()) && (has_picture==0)){
        show_error_message("please select a file to upload !",'error_message_panel'); 
           $('picture').focus()
           return false;
        
    }
    
    //if file not blank then reset replace image
    if (!n_file.blank()){
        $('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 file previously uploaded!")){
                $('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);
         
    }       
    
    $('url_payload').value=$F('url_params')
    //return false;
    $('save').target='keyhole'; 
// display a window indicating save progress 
    progress_window(progress_bar_url)         
    $('save').submit();

}


//project_permit_access: make ajax call to add user to a project
function project_permit_access(param_project,param_user){
    var url="../asp/object_administration.asp"
    var params="?objectid=1201&mode=6&tag=_grant_project_access&projectid=" + param_project + "&userid=" + param_user 
    var d=new Date();
      var myAjax = new Ajax.Updater('', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  Element.remove('user_' + param_user);
                  params="?objectid=1201&mode=6&tag=_project_users_with_access&projectid=" + param_project 
                  generic_populate_panel(url, params, 'users_with_access', 'generic_null();')
                  
                }
            });       
}

//project_remove_access: make ajax call to add user to a project
function project_remove_access(param_project,param_id){
    var url="../asp/object_administration.asp"
    var params="?objectid=1201&mode=6&tag=_remove_project_access&projectid=" + param_project + "&permissionid=" + param_id 
    var d=new Date();
      var myAjax = new Ajax.Updater('', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  Element.remove('permit_' + param_id);
                  params="?objectid=1201&mode=6&tag=_project_users_no_access&projectid=" + param_project 
                  generic_populate_panel(url, params, 'users_no_access', 'generic_null();')
                  
                }
            });       
}

//file_permit_access: make ajax call to add user to a project
function file_permit_access(param_restriction,param_project,param_file){
    var url="../asp/object_administration.asp"
    var params="?objectid=1201&mode=6&tag=_grant_file_access&fileid=" + param_restriction 
    var d=new Date();
      var myAjax = new Ajax.Updater('', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  Element.remove('restriction_' + param_restriction);
                  params="?objectid=1201&mode=6&tag=_file_users_with_access&projectid=" + param_project + "&recordid=" + param_file
                  generic_populate_panel(url, params, 'users_with_access', 'generic_null();')
                  
                }
            });       
}

//file_remove_access: make ajax call to add user to a project
function file_remove_access(param_file,param_project,param_user){
    var url="../asp/object_administration.asp"
    var params="?objectid=1201&mode=6&tag=_remove_file_access&fileid=" + param_file + "&userid=" + param_user 
    var d=new Date();
      var myAjax = new Ajax.Updater('', 
            url, 
            {
                method: 'get', 
                parameters: params + '&d=' + d.toString(),
                onComplete: function(obj){
                  Element.remove('permit_' + param_user);
                  params="?objectid=1201&mode=6&tag=_file_users_no_access&projectid=" + param_project + "&recordid=" + param_file 
                  generic_populate_panel(url, params, 'users_no_access', 'generic_null();')
                  
                }
            });       
}

