function setup_page(){
    var el=get_el("map");
    if (el){
        eval('load_map();');
    }
    //small_login
    var el=get_el('small_login');
    if (el){eval('enable_tab_tracking(\'small_login\');');}
    //form_reminder
    var el=get_el('form_reminder');
    if (el){eval('enable_tab_tracking(\'form_reminder\');');}
    //form_register
    var el=get_el('form_register');
    if (el){eval('enable_tab_tracking(\'form_register\');');}
    fix_height();
}


// fix_height; ensure that the main panel and footer fill screen
function fix_height(){
    var h=(document.viewport.getHeight()-170).toString() + 'px';
    var b=$('main_panel').getStyle('height')
    if (parseInt(b.toString().replace('px',''))< parseInt(h.replace('px',''))){
        $('main_panel').setStyle({height: h});
    }
    else{
        $('main_panel').setStyle({height: 'auto'});
    }
}
//submit_form: utility that will perform client side validation of the passed form id and allow validator to post it 
function submit_form(param_form){
    var el=get_el("cs_validation");
    //alert("here");
    if (el){
        var f=$(param_form)
        var cs_validation=f['cs_validation'];
        if (eval($(cs_validation).getValue())!=true){
            return void[0];
        }
    }
    else{
        $(param_form).submit();
    }
}

function open_link(url){
 var settings='Height=' + screen.height + ',Width=' + screen.width + ',Top=0,left=0,scrollbars=yes,resizable=1, location=1,status=1'
 var w=window.open(url,'clarity',settings);    
}

function validate_search(){
    if ($F('txt_keywords').blank()){
        alert("please enter one or more keywords to perform a search!");
        $('txt_keywords').focus();
        return void[0];
    }
    $('search_details').value="";
    $('search_form').submit();
}


function fix_telephone(param_value){
    var ret_value='';
    var wip_value=param_value;
    var a_values='1234567890'
    //alert(wip_value.length);
    for (var i=0;i<=wip_value.length;i++){
    //alert(wip_value.charAt(i))
        for (var x=0;x<=a_values.length;x++){
            
            if (wip_value.charAt(i)==a_values.charAt(x)){
                ret_value+=wip_value.charAt(i)
            }
        }
    } 
    //alert(ret_value);
    return ret_value;   
}

//enable_tab_tracking: when displaying a form we set a highlight to indicate which 'line' a user has moved focus to
function enable_tab_tracking(param_el){
    var v=navigator.appVersion;
    if (v.toString().include('MSIE 6.0')){
        return void[0];
    }

    var cls_highlight='highlighted';
    var el=get_el('cls_highlight');
    if (el){
        cls_highlight=$('cls_highlight').value;
    }
    var children=$A($(param_el).select('input.input_element','select.input_element','textarea.input_element'));
   // alert(children.length);
    var evfocus=function(el)
    {   
        //alert(Rico);
         Event.observe(el,'focus',function(){
            var row_name='row_' + el.id;
            var r=get_el(row_name);
            if (r){
                if (!$(row_name).hasClassName(cls_highlight)){
                    $(row_name).toggleClassName(cls_highlight);
                }
            }
         });
         Event.observe(el,'blur',function(){
            var row_name='row_' + el.id;
            var r=get_el(row_name);
            if (r){
                $(row_name).toggleClassName(cls_highlight);
            }
         });
         //Rico.Corner.round(el.id);
    }
    children.each(evfocus);
   // $('save').focusFirstElement();
    
}

//check_reminder: validate
function check_reminder(){
    if ($F('txt_username').blank()){
        alert("please enter your email address!");
        $('txt_username').focus();
        return false;
    }
        var email=$F('txt_username')
        if (!fixstring(email,true)){
            alert("The format of the email address you have entered is not supported on this system. Please check your entry!");
             $('txt_username').focus();
            return false;
        }
        
    var f=$('form_reminder')
    var your_details=f['your_details'];
    $(your_details).value='';
    $('form_reminder').submit();
}

//check_register: validate the registration form detail
function check_register(){
    //your_name
    if ($F('your_name').blank()){
        alert("please enter your name!");
        $('your_name').focus();
        return false;
    }
    //email
    if ($F('email').blank()){
        alert("please enter your email address!");
        $('email').focus();
        return false;
    }
    var email=$F('email')
    if (!fixstring(email,true)){
        alert("The format of the email address you have entered is not supported on this system. Please check your entry!");
         $('email').focus();
        return false;
    }
    
    //your_telephone
    var your_telephone=$F('your_telephone')
    your_telephone=fix_telephone(your_telephone);
    $('your_telephone').value=your_telephone
    if ($F('your_telephone').blank()){
        alert("please enter your telephone number!");
        $('your_telephone').focus();
        return false;
    }
    //your_origin
    if ($F('your_origin').blank()){
        alert("please let us know how you found our site - it's appreciated!");
        $('your_origin').focus();
        return false;
    }
    
    var f=$('form_register')
    var your_details=f['your_details'];
    $(your_details).value='';
    $('form_register').submit();
        

}


