/* 
iitd_validation.js: library of javascript for validating forms
    david.kelly@fanore.com (http://www.fanore.com/website_design.htm)
    
   validate_login: validates the login form that is presented to visitors 
   password_reminder: validates the password reminder dialogue (checking that user has entered an email address
   
    
*/


// iitd_login: validates the login form that is presented to visitors
function iitd_login(){
// check that username field has been populated
    var el=get_el("txt_username");
    
    if (el.value.length==0){
        alert("please enter your email address !");
        el.focus();
        return false;
    }
    if (el.value=="e-mail address"){
        alert("please enter your email address !");
        el.value="";
        el.focus();
        return false;
    
    }
    var s=el.value;
    if (!fixstring(s,true)){
        alert("the email address you have entered does not seem to be valid, please check your entry!");
        el.focus();
        return false;
    
    }
    
// check the password entry
    var el=get_el("txt_password");
    if (el.value.length==0){
        alert("please enter your password !");
        el.focus();
        return false;
    }
    var f=$('login_form')
    var your_details=f['your_details'];
    $(your_details).value='';
    $('login_form').submit();
    
}


//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();
}

//validate_registration: validate the registration form before posting
function validate_registration(param_context){
   // alert("here");
    switch(param_context){
        case 'apply':
            if (validate_terms()){
                $('registration_form').submit();
            }
            break;
        case 'start': // vaidate general information
            if (validate_general_input()){
                //alert(param_context);
                $('registration_form').submit();
            }
            break;
        case 'education':
            if (validate_education()){
                //alert(param_context);
                
            }
            break;
        case 'cpd':
            if (validate_cpd()){
                //alert(param_context);
                
            }
            break;
        case 'experience':
            if (validate_experience()){
                //alert(param_context);
                
            }
            break;
    
    }
}

//validate_general_input
function validate_general_input(){
    //organisation
        if ($F('reg_company').blank()){
            alert("Please enter your company or organisation name!");
            $('reg_company').focus();
            return false;
        }
    //salutation
        if ($F('reg_title').blank()){
            alert("Please enter your title (e.g. Mr. Ms. Dr.)!");
            $('reg_title').focus();
            return false;
        }
    //firstname
        if ($F('reg_firstname').blank()){
            alert("Please enter your first name!");
            $('reg_firstname').focus();
            return false;
        }
    //surname
        if ($F('reg_surname').blank()){
            alert("Please enter your surname!");
            $('reg_surname').focus();
            return false;
        }
    //job title
        if ($F('reg_jobtitle').blank()){
            alert("Please enter your job title!");
            $('reg_jobtitle').focus();
            return false;
        }
    //email address
        if ($F('reg_email').blank()){
            alert("Please enter your email address!");
            $('reg_email').focus();
            return false;
        }
        //validate email address format
        var email=$F('reg_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!");
             $('reg_email').focus();
            return false;
        }
    //telephone or mobile
        var telephone=fix_telephone($F('reg_telephone'));
                $('reg_telephone').value=telephone;

        var mobile=fix_telephone($F('reg_mobile'));
        $('reg_mobile').value=mobile;
        if (((telephone.blank())||(telephone.length<5))&&((mobile.blank())||(mobile.length<8))){
            alert("Please enter either a telephone or mobile number in numeric format (e.g. ##########)!");
            $('reg_telephone').value='';
            $('reg_mobile').value='';
            $('reg_telephone').focus();
            return false;
        }
        $('reg_telephone').value=telephone
        $('reg_mobile').value=mobile
    //if is attendee then we require the PPS  & DOB
        if ($F('is_attendee')=='True'){
                if ($F('pps').blank()){
                    alert("Please enter your PPS number !");
                    $('pps').focus();
                    return void[0];
                }
                
                //date_of_birth
                        var rule_day='01';
                        var rule_month='';
                        var rule_year='';
                        
                        var el_day=get_el("dob_day")
                        if (el_day.selectedIndex < 1){
                            alert("Please select the Day!");
                            el_day.focus();
                            return void[0];          }
                        else{
                            rule_day = el_day[el_day.selectedIndex].value;
                        }
            
                        var el_month=get_el("dob_month")
                        if (el_month.selectedIndex < 1){
                            alert("Please select the month!");
                            el_month.focus();
                            return void[0];      }
                        else{
                            rule_month = el_month[el_month.selectedIndex].value;
                        }
                        
                        var el_year=get_el("dob_year")
                        if (el_year.selectedIndex < 1){
                            alert("Please select the year!");        
                            el_year.focus();
                            return void[0]; }
                        else{
                            rule_year = el_year[el_year.selectedIndex].value;
                        }
                        var s_date=rule_day + " " + rule_month +  " " + rule_year 
                        if ((parseInt(rule_year)-17) > 1992){
                            alert("Please check your date of birth as our courses are for persons aged 18 and over!");
                            el_year.focus();
                            return void[0];
                        
                        }
                        $('reg_dob').value=s_date;
                        
        
        
        }    
        
    //address line 1 & 2
        if ($F('reg_address1').blank()){
            alert("Please enter at least a two line address!");
            $('reg_address1').focus();
            return false;
        }
        if ($F('reg_address2').blank()){
            alert("Please enter at least a two line address!");
            $('reg_address2').focus();
            return false;
        }
    //county
        if ($F('reg_locations').blank()){
            alert("Please select the county from the list provided!");
            $('reg_locations').focus();
            return false;
        }
    //preferred mailing address
    if ($F('reg_preferred')=='HOME'){
    //home address 1 & 2 
        if ($F('reg_haddress1').blank()){
            alert("Please enter at least a two line home address!");
            $('reg_haddress1').focus();
            return false;
        }
        if ($F('reg_haddress2').blank()){
            alert("Please enter at least a two line home address!");
            $('reg_haddress2').focus();
            return false;
        }
        
    //home county
        if ($F('reg_hlocations').blank()){
            alert("Please select the county from the list provided!");
            $('reg_hlocations').focus();
            return false;
        }
    //personal email
    //email address
//        if (!$F('reg_hemail').blank()){
        //validate email address format
   //         var email=$F('reg_hemail')
  //          if (!fixstring(email,true)){
   //             alert("The format of the personal email address you have entered is not supported on this system. Please check your entry!");
    //             $('reg_hemail').focus();
     //           return false;
      //      }
       // }
    }
    $('registration_details').value='';
return true;
}



//validate_education: check that all required fields have been populated
function validate_education(){
    //achievement / qualification
    if ($F('achievement_other').blank()){
        alert("Please select the qualification achieved or select 'other' if not listed!'");
        $('achievement').focus();
        return false;
    }
    //accreditation
    if ($F('accreditation_other').blank()){
        alert("Please select the accrediting body or select 'other' if not listed!'");
        $('accreditation').focus();
        return false;
    }
    //award_name
    if ($F('award_other').blank()){
        alert("Please select the name of the award achieved or select 'other' if not listed!'");
        $('award').focus();
        return false;
    }
    //award_date
            var rule_day='01';
            var rule_month='';
            var rule_year='';
            
            var el_month=get_el("education_month")
            if (el_month.selectedIndex < 1){
                alert("Please select the month value for the date achieved");
                el_month.focus();
                return false;                }
            else{
                rule_month = el_month[el_month.selectedIndex].value;
            }
           // alert(rule_month);
           // alert(el_month[el_month.selectedIndex].text);
            var el_year=get_el("education_year")
            if (el_year.selectedIndex < 1){
                alert("Please select the year value for the date achieved");        
                el_year.focus();
                return false;                }
            else{
                rule_year = el_year[el_year.selectedIndex].value;
            }
            var s_date=rule_day + " " + rule_month +  " " + rule_year 
            var d=new Date(s_date);
            //alert(s_date);
            //alert(d);
            //alert(d.getDate())
            //alert((parseInt(el_day.selectedIndex)));
            //we test the date is valid by checking the date value against the selectedIndex value (should always be 1 less than selectedIndex)
            
            $('date_achieved').value=s_date;
            
            var p=$F('main_subjects');
            if (p.length > 255) {
                alert("You may only enter up to 255 characters for the main subjects text box!");
                $('main_subjects').focus();
                return false;
            }
            var el=get_el("documentation");
            if (el){
                if ( ($F('attachment').blank()) && (!el.checked)){
                    alert("All educational qualifications must be validated, please upload a copy or select the option indicating that you will forward a copy by post!");
                    $('documentation').focus();
                    return false;
                }
                if ($F('attachment').blank()){
                    $('opt_post').value="1";
                }
                else{
                    $('opt_post').value="0";
                }
                if (!check_format('attachment', 'image')){
                    alert("Only images (jpg, gif, png, mdi or tif) or PDF files can be accepted!");
                    $('attachment').focus();
                    return false
                }
            }
            $('registration_details').value='';
            
    var progress_bar_url=$F('progress_bar_url');
    //$('registration_form').target='keyhole'; //window.open('../asp/ajax_2008.asp?action=none','media','width=380px,height=50', true);
// display a window indicating save progress 
            var w=380;
            var h=50;
            var winLeft=Math.round((screen.width - w)/2);
            var winTop=Math.round((screen.height - h)/2);
            var sVersion = navigator.appVersion;
             
           if (sVersion.indexOf('MSIE') != -1 && sVersion.substr(sVersion.indexOf('MSIE')+5,1) > 4)
          {
        		var settings="dialogWidth:380px; dialogHeight:50px; center:yes";
        		var x=window.showModelessDialog(progress_bar_url+ '&b=IE',null,settings);
                x.opener=window
                x.focus()
            }
           
            
   
   

            

    $('registration_form').submit();

}


//validate_cpd: check that all required fields have been populated
function validate_cpd(){
    //event / activity
    if ($F('cpd_title_other').blank()){
        alert("Please select the name of the CPD event or activity, alternatively choose \'Other\' if not listed!");
        $('cpd_title').focus();
        return false;
    }
    //cpd_date
            var rule_day='01';
            var rule_month='';
            var rule_year='';
            
            var el_month=get_el("cpd_month")
            if (el_month.selectedIndex < 1){
                alert("Please select the month value for the date");
                el_month.focus();
                return false;                }
            else{
                rule_month = el_month[el_month.selectedIndex].value;
            }
           // alert(rule_month);
           // alert(el_month[el_month.selectedIndex].text);
            var el_year=get_el("cpd_year")
            if (el_year.selectedIndex < 1){
                alert("Please select the year value for the date");        
                el_year.focus();
                return false;                }
            else{
                rule_year = el_year[el_year.selectedIndex].value;
            }
            var s_date=rule_day + " " + rule_month +  " " + rule_year 
            var d=new Date(s_date);
            //alert(s_date);
            //alert(d);
            //alert(d.getDate())
            //alert((parseInt(el_day.selectedIndex)));
            //we test the date is valid by checking the date value against the selectedIndex value (should always be 1 less than selectedIndex)
            $('date_created').value=s_date;
            
            var p=$F('cpd_detail');
            if (p.blank()){
                alert("Please enter some detail of this CPD event or activity!");
                $('cpd_detail').focus();
                return false;
            
            }
            if (p.length > 255) {
                alert("You may only enter up to 255 characters for the Detail text box!");
                $('cpd_detail').focus();
                return false;
            }

            var el=get_el("documentation");
            if (el){
                if (!$F('attachment').blank()){
                    if (!check_format('attachment', 'image')){
                        alert("Only images (jpg, gif, png, mdi or tif) or PDF files can be accepted!");
                        $('attachment').focus();
                        return false
                    }
                }
            }
            $('registration_details').value='';
            
    var progress_bar_url=$F('progress_bar_url');
    $('registration_form').target='keyhole'; //window.open('../asp/ajax_2008.asp?action=none','media','width=380px,height=50', true);
// display a window indicating save progress 
            var w=380;
            var h=50;
            var winLeft=Math.round((screen.width - w)/2);
            var winTop=Math.round((screen.height - h)/2);
            var sVersion = navigator.appVersion;
             
           if (sVersion.indexOf('MSIE') != -1 && sVersion.substr(sVersion.indexOf('MSIE')+5,1) > 4)
          {
        		var settings="dialogWidth:380px; dialogHeight:50px; center:yes";
        		var x=window.showModelessDialog(progress_bar_url+ '&b=IE',null,settings);
                x.opener=window
                x.focus()
            }
           
            
   
   

            

    $('registration_form').submit();

}


//validate_experience: check that all required fields have been populated
function validate_experience(){
    //date_from and to
            var rule_day='1';
            var rule_month='';
            var rule_year='';
            
            var el_month=get_el("from_month")
            if (el_month.selectedIndex < 1){
                alert("Please select the month value for the date");
                el_month.focus();
                return false;                }
            else{
                rule_month = el_month[el_month.selectedIndex].value;
            }
           // alert(rule_month);
           // alert(el_month[el_month.selectedIndex].text);
            var el_year=get_el("from_year")
            if (el_year.selectedIndex < 1){
                alert("Please select the year value for the date");        
                el_year.focus();
                return false;                }
            else{
                rule_year = el_year[el_year.selectedIndex].value;
            }
            var s_date=rule_day + " " + rule_month +  " " + rule_year 
            
            $('date_from').value=s_date;

            var el_month=get_el("to_month")
            if (el_month.selectedIndex < 1){
                alert("Please select the month value for the date");
                el_month.focus();
                return false;                }
            else{
                rule_month = el_month[el_month.selectedIndex].value;
            }
           // alert(rule_month);
           // alert(el_month[el_month.selectedIndex].text);
            var el_year=get_el("to_year")
            if (el_year.selectedIndex < 1){
                alert("Please select the year value for the date");        
                el_year.focus();
                return false;                }
            else{
                rule_year = el_year[el_year.selectedIndex].value;
            }
            var s_date=rule_day + " " + rule_month +  " " + rule_year 
            
            $('date_to').value=s_date;



    //organisation
    if ($F('organisation').blank()){
        alert("Please enter the name of the Organisation'");
        $('organisation').focus();
        return false;
    }

    //job_title
    if ($F('job_title').blank()){
        alert("Please enter the your Job Title'");
        $('job_title').focus();
        return false;
    }

            
            var p=$F('detail');
            if (p.blank()){
                alert("Please enter some details of this position!");
                $('detail').focus();
                return false;
            
            }
            if (p.length > 255) {
                alert("You may only enter up to 255 characters for the Details!");
                $('detail').focus();
                return false;
            }
            
            $('registration_details').value='';
            
    var progress_bar_url=$F('progress_bar_url');
    $('registration_form').target='keyhole'; //window.open('../asp/ajax_2008.asp?action=none','media','width=380px,height=50', true);
// display a window indicating save progress 
            var w=380;
            var h=50;
            var winLeft=Math.round((screen.width - w)/2);
            var winTop=Math.round((screen.height - h)/2);
            var sVersion = navigator.appVersion;
             
           if (sVersion.indexOf('MSIE') != -1 && sVersion.substr(sVersion.indexOf('MSIE')+5,1) > 4)
          {
        		var settings="dialogWidth:380px; dialogHeight:50px; center:yes";
        		var x=window.showModelessDialog(progress_bar_url+ '&b=IE',null,settings);
                x.opener=window
                x.focus()
            }
   
   

            

    $('registration_form').submit();

}


//password_reminder: validates the password reminder dialogue (checking that user has entered an email address
function password_reminder(){
// check that username field has been populated
    
	var el=get_el("txt_username")
	
	
    if (el.value.length==0){
        alert("please enter the email address you used before with this service!");
        el.focus();
        return false;
    }
    //var s=el.getValue(); 
    if (!fixstring(el.value,true)){
        alert("the email address you have entered is not supported on this system, please check your entry!");
        el.focus();
        return false;
    
    }
return true;
    
}

function directory_search(){
    var scope=false
    var loc=false
    var word=false
    
    
    var s_phrase=$F('phrase');
    if (!$F('phrase').empty()){
        word=true
    }
    //var el=get_el("opt_sector")
    //alert($F('opt_sector'));
    if ($F('opt_sector') > 0){
         scope=true;
            
    }
    var el=get_el("list_location");
    if (el.options[el.selectedIndex].value!=""){
        loc=true;
    }
    
    if ((loc==false)&&(scope==false)&&(word==false)){
        alert("please enter a phrase, speciality or location before searching!");
        return false;
    } 
    return true;

}

function directory_browse(){
    $('browse_directory').submit();

}


//check_format: of a file
function check_format(param_el, param_type){

            var el=get_el(param_el)
            if (el){
                if (el.value.blank()){
                    return true;
                }
                var s_file=el.value;
                //alert(s_file);
                if (s_file.length!=0){
                    //check for allowed file types
                    s_ext=s_file.substr(s_file.length-3,3).toLowerCase();
                    if (param_type=='image'){
                            switch(s_ext){
                                case "jpg": //ok
                                    return true;
                                    break;
                                case "gif":
                                    return true;
                                    break;
                                case "tif":
                                    return true;
                                    break;
                                case "pdf":
                                    return true;
                                    break;
                                case "mdi":
                                    return true;
                                    break;
                                case "png":
                                    return true;
                                    break;
                            }
                    }
                    //switch
                }
            }            

return false;
}

function validate_terms(){
    var el=get_el("terms");
    if (el){
        if (el.checked){
            return true;
        }
    }
    alert("Please tick the declaration to indicate that the information you are submitting is correct!");
    $('terms').focus();
return false;
}

// used to validate the "contact us" form
function validate_contact(){
// first ensure that required fields have been completed
    // is this form using presubmission validation ?
    


    //check the name
    var el=get_el("txt_name")
    if (el.value.length==0){
        alert("please enter your name !")
        el.focus();
        return void[0];    
    }
    
    //check the email address
    var el=get_el("txt_email")
    if (el.value.length==0){
        alert("please enter your email address !")
        el.focus();
        return  void[0];    
    }
    var sval=el.value
    // check email is correct format
	if (!fixstring(sval,true)){
		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
		el.focus();
		return  void[0];
	}
        var telephone=fix_telephone($F('txt_telephone'));
        $('txt_telephone').value=telephone;
        if ((telephone.blank())||(telephone.length<5)){
            alert("Please enter either a telephone or mobile number in numeric format (e.g. ##########)!");
            $('txt_telephone').value='';
            $('txt_telephone').focus();
            return void[0];
        }
	
    //check the comment
    var el=get_el("txt_comment")
    if (el.value.length==0){
        alert("please let us know how we can assist !")
        el.focus();
        return  void[0];    
    }
	else if (el.value.length>1024){
		alert("Your comment is limited to 1024 characters, please shorten your query.")
        el.focus();
        return  void[0];    
	}
     var f=$(form_contact_us)
    f["your_details"].value="";
    $('form_contact_us').submit();
}


//password_compliance: test the password entered by user to ensure compliance
function password_compliance(){
    if($F('current_password').blank()){
        alert("Please enter your current password!");
        $('current_password').focus();
        return void[0];
    }
    
    if($F('new_password').blank()){
        alert("Please enter your new password!");
        $('new_password').focus();
        return void[0];
    }
    
    if($F('new_password')!=$F('confirm_password')){
        alert("The passwords you have entered do not match, please ensure that you enter and confirm your new password!");
        $('new_password').focus();
        return void[0];
    }
    if (!password_conforms($F('new_password'))){
        return void[0];
    }
    $('password_details').value='';
    $('password_form').submit();   
}

//password_conforms: performs basic validation of the structure of the new password
function password_conforms(param_value){
    // we require that each password be at least 6 characters long and no longer than 10 characters
    // passwords must have a mix of alpha numerics
    var a_numbers="0123456789"
    var a_alphas="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!$^"
    var has_number=false
    var has_alpha=false;
    var allowed_chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!$^1234567890"
    var user_p=param_value;
    if (user_p.length < 6){
        alert("The password must be at least 6 characters long and be a mix of numbers and letters!");
        return false; 
    }
    if (user_p.length > 10){
        alert("The password must be no longer than 10 characters long and be a mix of numbers and letters!");
        return false; 
    }
    for (var i=0; i <= user_p.length; i++){
        //alert(allowed_chars.indexOf(user_p.charAt(i)));
        if (allowed_chars.indexOf(user_p.charAt(i))==-1){
            alert("The character \'" + user_p.charAt(i) + "\' may not be used in your password!");
            return false;
        }
        if (a_numbers.indexOf(user_p.charAt(i))> 0){
            has_number=true;
        }
        if (a_alphas.indexOf(user_p.charAt(i))> 0){
            has_alpha=true;
        }
        
    }
    //alert(has_number);
    if ((!has_number)||(!has_alpha)){
        alert("Passwords must be a contain at least one numeric value (e.g. 0 to 9) and one alphabetic character (e.g. 'a,b,d,etc.')");
        return false;
    }
    
    return true;
}



function switch_visibility(param_field,param_direction){
    var url=$F('fck_base_url') + "asp/ajax.asp"
    var new_image=$F('fck_base_url') + "images/"
    var new_prompt='';
    
    
    
    if (parseInt(param_direction)==0){
        // this implies that the user is switching an item on
        // however we should warn the user if the field is blank, that it will not be visible anyway
        new_image+='is_public_1.gif'
        $('a_' + param_field).href="javascript: switch_visibility('" + param_field + "',1);"
        new_prompt='click here to hide this item from members of the public'
    }
    else{
        new_image+='is_public_0.gif'
        $('a_' + param_field).href="javascript: switch_visibility('" + param_field + "',0);"
        new_prompt='click here to make this item visible to members of the public'
    }
        var params='action=updatepublication&element=' + param_field + '&direction=' + param_direction + '&recordid=' + $F('record_id')
        //window.location.href=url + "?" + params 
        ajax_get_url(url,params,'keyhole', '');
        $('img_' + param_field).src=new_image; 
        $('img_' + param_field).alt=new_prompt; 
  
  
}
//validate_business: validates the users information before posting form
function validate_business(){
    var progress_bar_url=$F('progress_bar_url');
    // organisation
    if ($('img_organisation').src.include('1.gif')&&$F('web_organisation').blank()){
        alert("please enter your organisation name if you are making this information public!");
        $('web_organisation').focus();
        return void[0];
    }
    // contact person
    if ($('img_contact').src.include('1.gif')&&$F('web_contact').blank()){
        alert("please enter your contact name if you are making this information public!");
        $('web_contact').focus();
        return void[0];
    }
    // email address
    if ($('img_email').src.include('1.gif')&&$F('web_email').blank()){
        alert("please enter your email address, this will not be made visible to the public, but will facilitate communication if you choose to activate this option!");
        $('web_email').focus();
        return void[0];
    }
    if ($('img_email').src.include('1.gif')){
        var e_mail=$F('web_email');
        if (!fixstring(e_mail,true)){
            alert("The format of the email address you have entered is not supported on this system. Please check your entry!");
             $('web_email').focus();
            return void[0];
        }
    }
    // telephone 1
    var telephone=fix_telephone($F('web_telephone1'));
    $('web_telephone1').value=telephone
    if ($('img_telephone1').src.include('1.gif') && $F('web_telephone1').blank()){
        alert("please enter your primary telephone number if choosing to make this visible to the public!");
        $('web_telephone1').focus();
        return void[0];
    }
    
    // telephone 2
    var telephone=fix_telephone($F('web_telephone1'));
    $('web_telephone1').value=telephone
    if ($('img_telephone1').src.include('1.gif') && $F('web_telephone1').blank()){
        alert("please enter your primary telephone number if choosing to make this visible to the public!");
        $('web_telephone1').focus();
        return void[0];
    }
    
    // mobile
    var telephone=fix_telephone($F('web_mobile'));
    $('web_mobile').value=telephone
    if ($('img_mobile').src.include('1.gif') && $F('web_mobile').blank()){
        alert("please enter your mobile number if choosing to make this visible to the public!");
        $('web_mobile').focus();
        return void[0];
    }
    
    // fax
    var telephone=fix_telephone($F('web_fax'));
    $('web_fax').value=telephone
    if ($('img_fax').src.include('1.gif') && $F('web_fax').blank()){
        alert("please enter your fax number if choosing to make this visible to the public!");
        $('web_fax').focus();
        return void[0];
    }
    
    // web
    var url=$F('web_web')
        
    if ($('img_web').src.include('1.gif') && $F('web_web').blank()){
        alert("please enter your website address if choosing to make this visible to the public!");
        $('web_web').focus();
        return void[0];
    }
    if (($('img_web').src.include('1.gif')) && (!url.include('http://') || !url.include('https://'))){
        url='http://' + url
        $('web_web').value=url;
        
    }
    
    // address 1, 2, 3, 4
    if ($('img_address').src.include('1.gif')){
        // need to check address
        if ($F('web_address1').blank()){
            alert("please enter your full address if choosing to make this visible to the public!");
            $('web_address1').focus();
            return void[0];
       }
        if ($F('web_address2').blank()){
            alert("please enter your full address if choosing to make this visible to the public!");
            $('web_address2').focus();
            return void[0];
       }
        if ($F('web_address4').blank()){
            alert("please select your county if choosing to make your address visible to the public!");
            $('web_address4').focus();
            return void[0];
       }
    }
    // abstract
    if ($('img_abstract').src.include('1.gif') && $F('web_abstract').blank()){
        alert("please enter a short description of your company if choosing to make this visible to the public!");
        $('web_abstract').focus();
        return void[0];
    }
    // narrative
    var el=get_el('FCKDATASOURCE');
    if (el){    
        var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
        var datasource_name = 'fd_' + el.value;
       $(datasource_name).value= oEditor.GetXHTML(true);  
    }       
    
    if ($('img_description').src.include('1.gif') && $F(datasource_name).blank()){
        alert("please enter a description of your business if choosing to make this visible to the public!");
        //$('web_web').focus();
        return void[0];
    }
    
    //we now need to examine the locations serviced selection
    var el=document.getElementsByName("opt_location")
    var locations=''
    for (i=0;i < el.length;i++){
        
        if(el[i].checked){
            if (locations.length!=0){
                locations+=','
            }
            locations+=el[i].value;
        }
    }
    $('locations').value=locations;
    
    //we now need to examine the 'areas of expertise' selection
    var el=document.getElementsByName("opt_expertise")
    var expertise=''
    for (i=0;i < el.length;i++){
        
        if(el[i].checked){
            if (expertise.length!=0){
                expertise+=','
            }
            expertise+=el[i].value;
        }
    }
    $('expertise').value=expertise;
    
    
    
    //get to here then ok to post this form
    $('business_details').value='';
    
    //$('business_form').target='keyhole'; 
// display a window indicating save progress 
            var w=380;
            var h=50;
            var winLeft=Math.round((screen.width - w)/2);
            var winTop=Math.round((screen.height - h)/2);
            var sVersion = navigator.appVersion;
             
           if (sVersion.indexOf('MSIE') != -1 && sVersion.substr(sVersion.indexOf('MSIE')+5,1) > 4)
          {
        		var settings="dialogWidth:380px; dialogHeight:50px; center:yes";
        		var x=window.showModelessDialog(progress_bar_url+ '&b=IE',null,settings);
                x.opener=window
                x.focus()
            }
   

            


    $('business_form').submit();
       // return void[0];
}


// member_changes: present member with T&C before submitting form
function member_changes(){

    $('member_terms').show();
}
//hide_terms: cancel submit
function hide_terms(){
    $('member_terms').hide();
}

//accept_terms: indicates member accepts terms displayed
function accept_terms(){
    $('terms_details').value='';
    $('m_changes').submit();
}

function payment_method(param_id){
    if (parseInt(param_id)==3){
        $('dd_details').show();   
    }
    else{
        $('dd_details').hide();   
    
    }
}
//validate users billing preferences before submitting form
function update_method(){
    if(parseInt($F('list_method'))==1){
        alert("please indicate your preferred payment method!");
        $('list_method').focus();
        return void[0];
    }
    switch(parseInt($F('list_method'))){
        case 2: // no further details required
            break;
        case 3://need additional information
            
            if ($F('ac_name').blank()){
                alert("please enter your name as it appears on the bank or building society account!");
                $('ac_name').focus();
                return void[0];
            }
            
            var s_value=fix_telephone($F('ac_number'));
            $('ac_number').value=s_value;
            if ($F('ac_number').blank()){
                alert("please enter your account number!");
                $('ac_number').focus();
                return void[0];
            }
            
            var s_value=fix_telephone($F('ac_sort'));
            $('ac_sort').value=s_value;
            if ($F('ac_sort').blank()){
                alert("please enter the sort code!");
                $('ac_sort').focus();
                return void[0];
            }
    }
    $('billing_preference').submit();
}


//validate_mcontact: validate member contact information
function validate_mcontact(){
    //organisation
        if ($F('reg_company').blank()){
            alert("Please enter your company or organisation name!");
            $('reg_company').focus();
            return void[0];
        }
    //salutation
        if ($F('reg_title').blank()){
            alert("Please enter your title (e.g. Mr. Ms. Dr.)!");
            $('reg_title').focus();
            return void[0];
        }
    //firstname
        if ($F('reg_firstname').blank()){
            alert("Please enter your first name!");
            $('reg_firstname').focus();
            return void[0];
        }
    //surname
        if ($F('reg_surname').blank()){
            alert("Please enter your surname!");
            $('reg_surname').focus();
            return void[0];
        }
    //job title
        if ($F('reg_jobtitle').blank()){
            alert("Please enter your job title!");
            $('reg_jobtitle').focus();
            return void[0];
        }
    //email address
        if ($F('reg_email').blank()){
            alert("Please enter your email address!");
            $('reg_email').focus();
            return void[0];
        }
        //validate email address format
        var email=$F('reg_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!");
             $('reg_email').focus();
            return void[0];
        }
    
        
    //address line 1 & 2
        if ($F('reg_address1').blank()){
            alert("Please enter at least a two line address!");
            $('reg_address1').focus();
            return void[0];
        }
        if ($F('reg_address2').blank()){
            alert("Please enter at least a two line address!");
            $('reg_address2').focus();
            return void[0];
        }
    //county
        if ($F('reg_locations').blank()){
            alert("Please select the county from the list provided!");
            $('reg_locations').focus();
            return void[0];
        }
    //telephone or mobile
        var telephone=fix_telephone($F('reg_telephone'));
                $('reg_telephone').value=telephone;

        var mobile=fix_telephone($F('reg_mobile'));
        $('reg_mobile').value=mobile;
        if (((telephone.blank())||(telephone.length<5))&&((mobile.blank())||(mobile.length<8))){
            alert("Please enter either a telephone or mobile number in numeric format (e.g. ##########)!");
            $('reg_telephone').value='';
            $('reg_mobile').value='';
            $('reg_telephone').focus();
           return void[0];
        }
        $('reg_telephone').value=telephone
        $('reg_mobile').value=mobile
    //preferred mailing address
    if ($F('reg_preferred')=='HOME'){
    //home address 1 & 2 
        if ($F('reg_haddress1').blank()){
            alert("Please enter at least a two line home address!");
            $('reg_haddress1').focus();
            return void[0];
        }
        if ($F('reg_haddress2').blank()){
            alert("Please enter at least a two line home address!");
            $('reg_haddress2').focus();
            return void[0];
        }
        
    //home county
        if ($F('reg_hlocations').blank()){
            alert("Please select the county from the list provided!");
            $('reg_hlocations').focus();
            return void[0];
        }
    }
    
    //now validate the industry sectors and interests
    //we now need to examine the sector selection
//    var el=get_el("opt_sector")
//    alert(el);
    var el=document.getElementsByName("opt_sector");
//    alert(x.length);
    var sectors=''
//    alert(el.length);
    
    for (i=0;i < el.length;i++){
        
        if(el[i].checked){
            if (sectors.length!=0){
                sectors+=','
            }
            sectors+=el[i].value;
        }
    }
    $('sectors').value=sectors;
//    alert(sectors);
//    return void[0];
    //we now need to examine the interests selection
    var el=document.getElementsByName("opt_interest")
    var interests=''
    for (i=0;i < el.length;i++){
        
        if(el[i].checked){
            if (interests.length!=0){
                interests+=','
            }
            interests+=el[i].value;
        }
    }
    $('interests').value=interests;
    var progress_bar_url=$F('progress_bar_url');
// display a window indicating save progress 
            var w=380;
            var h=50;
            var winLeft=Math.round((screen.width - w)/2);
            var winTop=Math.round((screen.height - h)/2);
            var sVersion = navigator.appVersion;
             
           if (sVersion.indexOf('MSIE') != -1 && sVersion.substr(sVersion.indexOf('MSIE')+5,1) > 4)
          {
        		var settings="dialogWidth:380px; dialogHeight:50px; center:yes";
        		var x=window.showModelessDialog(progress_bar_url+ '&b=IE',null,settings);
                x.opener=window
                x.focus()
            }
           
            
   
   

            


    
    
    $('contact_details').value='';
    $('contact_form').submit();
}


//delete_message: remove 
function delete_message(param_id){
    var url=$F('u_base') + "asp/ajax.asp"
    var params="itemid=" + param_id + "&action=deletemessage"
    var d=new Date();
    if (confirm("Are you sure you want to delete this message?")){
        var myAjax = new Ajax.Updater('', url, {method: 'get', parameters: params + '&d=' + d.toString()});  
        $('row_' + param_id).remove();
    }
    return void[0];
}


//validate_upgrade_form: validate the membership upgrade request before submitting
function validate_upgrade_form(){
    //your_name
        if ($F('your_name').blank()){
            alert("Please enter your name!");
            $('your_name').focus();
            return void[0];
        }
    //your_email
        if ($F('your_email').blank()){
            alert("Please enter your email address!");
            $('your_email').focus();
            return void[0];
        }
        var s=$F('your_email');
        if (!fixstring(s,true)){
            alert("the email address you have entered does not seem to be valid, please check your entry!");
            $('your_email').focus();
            return void[0];
        
        }
        
    //your_telephone
        var telephone=fix_telephone($F('your_telephone'));
        $('your_telephone').value=telephone;
        if (telephone.blank()){
            alert("Please enter a contact telephone number!");
            $('your_telephone').focus();
            return void[0];
        }
    //your_membernumber (optional)
    //your_memberdate (optional)
    //your_notes (required)
        if ($F('your_notes').blank()){
            alert("Please supply some background to your request!");
            $('your_notes').focus();
            return void[0];
        }
    
    var f=$('upgrade_form')
    var your_details=f['upgrade_details'];
    $(your_details).value='';
    $('upgrade_form').submit();

}


//search_member_directory: perform search operation via AJAX
function search_member_directory(){
    //first validate that something has been selected / entered as search criteria
    var b_valid=false;
    //name
    if (!$F('name').blank()){b_valid=true}
    //company
    if (!$F('company').blank()){b_valid=true}
    //sector
    if (!$F('sector').blank()){b_valid=true}
    //location
    if (!$F('location').blank()){b_valid=true}
    if (!b_valid==true){
        alert("Please enter a member name, company name or select an industry sector or location from the lists provided before searching!");
        return false;
    }
    
    var url='../asp/fanore.asp'
    var params='z=_results&name=' + $F('name') + '&company=' + $F('company') + '&sector=' + $F('sector') + '&location=' + $F('location')
     new Ajax.Updater('network_results', url, {
           method: 'get',
           parameters: params
     }); 
    
    return false;
}

//populate_locations: dynamically re-populate the search locations dialogue based on user selection
function populate_locations(){
    var sector_id=0;
     if (!$F('sector').blank()){sector_id=parseInt($F('sector'))}
     if (!$F('location').blank()){return void[0];}
     var url='../asp/fanore.asp'
     var params='z=_locations&sector=' + sector_id
     //window.location.href=url + '?' + params
     //return void[0];
     //alert(url)
     new Ajax.Updater('search_location', url, {
           method: 'get',
           parameters: params
     }); 
     
}
//populate_sectors: dynamically re-populate the search sectors dialogue based on user selection
function populate_sectors(){
    var location_id=0;
     if (!$F('location').blank()){location_id=parseInt($F('location'))}
     //alert($F('sector'));
     if (!$F('sector').blank()){return void[0];}
     var url='../asp/fanore.asp'
     var params='z=_sectors&location=' + location_id
     //window.location.href=url + '?' + params
     //return void[0];
     //alert(params)
     new Ajax.Updater('industry_sector', url, {
           method: 'get',
           parameters: params
     }); 
     
}
