/* 
agility_2010.js: library of javascript for animation / branding effects
    david.kelly@fanore.com (http://www.fanore.com/website_design.htm)
    
    
    
*/
var oEditor=false;


jQuery(document).ready(function($){workspace();});

function workspace(){
    //adjust the workspace to ensure that we are filling the screen (height)
    adjust_workspace();
    //animage_login?
    genericCSS();
    if ($('#default_params').length){
        //alert($('#default_params').val());
        //return void[0];
        eval("generic_populate_panel('', '" + $('#default_params').val() + "', 'ajax_results', '');");
    }
    //add tooltips
    $('a.icon').bind('mousemove', function(){
        $('.menuTips').html($(this).attr('title'));
    });
    //hide tooltips when mouse over menu bar
    $('#workspace').bind('mouseenter',function(){
        $('.menuTips').html('');
    });
}



/* adjust_workspace: ensure that workspace is filling height of page*/
function adjust_workspace(){
    var h=$(window).height()-105;
    var d=$(document).height()-105;
    //alert(h);
    //alert(d);
    //alert($('#workspace').height());
    if (h<d){h=d}
    if (($('#workspace').height()) < h){
       $('#workspace').height(h);
    }
    else{
       //$('#workspace').height('auto');    
    }
    //alert($('#workspace').height());
}


//setupCKEditor: loads the CKEditor control and attach user stylesheet (if valid)
function xsetupCKEditor(){
    var prefix=$('#fck_base_url').val();
    var css=$('#fck_css').val();
    var toolBar=$('#html_editor_to_use').val();
    $('#txtHTML').ckeditor(
     {
        toolbar : toolBar,
        bodyId : 'cms',
        contentsCss : css
     });

    $('#cancelButton').bind('click',function(e){
        e.preventDefault();
        cleanUpEditors();
        eval('generic_refresh_listing();');
    });
    return void[0];
}










//setup_editor: loads the fck editor control and attach user stylesheet (if valid)
function setup_editor(){
   
    var datasource_name = 'fd_' + $('#FCKDATASOURCE').val();
    var prefix=$('#fck_base_url').val();
    var sBasePath = prefix + 'fck/fckeditor/';
    
    //alert(sBasePath);
    oEditor = new FCKeditor('txtHTML') ;
//    oEditor = new FCKeditor('text_editor') ;
    oEditor.BasePath	= sBasePath ;
    oEditor.Height	= 300 ;
    
    var toolbar_set=$('#html_editor_to_use').val();
    if ($('#fck_css').length){
        buffer=$('#fck_css').val();
        if (buffer.length!=0){
            if (buffer.indexOf(',') > 0){
                var css=buffer.split(",");
                oEditor.Config['EditorAreaCSS'] = css;
            }
            else{
                oEditor.Config['EditorAreaCSS'] =buffer;
            }
        }        
    }
    
    if ($('#fck_css_body').length){
        buffer=$('#fck_css_body').val();
        oEditor.Config['BodyId'] = buffer;
    }
    oEditor.ToolbarSet = toolbar_set;
    //FCKConfig.DocType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' ;
    oEditor.Config['DocType'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' ;
    oEditor.Config['LinkUpload'] = false;
    //oEditor.Config['Debug'] = true;
    oEditor.Config['LinkBrowser'] = false;
    oEditor.ReplaceTextarea() ;
    $('#cancelButton').bind('click',function(e){
        e.preventDefault();
        //alert("here");
        eval('generic_refresh_listing();');
    });
}

//checkLogin: validate the customer login before proceeding
function checkLogin(){
    //minimum is username and password
            if (!agValidateInput($('#email'))){
                showError('Please enter your username!',$('#email'));
                return false;
            }
    
            if (!agValidateInput($('#password'))){
                showError('Please enter your password!',$('#password'));
                return false;
            }
            
            $('#loginDetails').val('');
            return true;

}
