// JavaScript Document
var load_method = (window.ie?'load':'domready');// fix for IE cannot open internet site
var accordion;
window.addEvent(load_method, function()
{
    //resize text
   $("li-small").addEvent("click", function() {resizeText(1);});  
   $("li-medium").addEvent("click", function() {resizeText(2);});     
   $("li-large").addEvent("click", function() {resizeText(3);});     

    //add rollover effect
    $$('.button').each(function(el) {
            el.addEvent('mouseenter', function() {            
                el.setStyle('opacity','0.8');            
            });
            el.addEvent('mouseleave', function() {            
                el.setStyle('opacity','1');            
            });
    });
    if ($('accordion')){
        openIndex = -1;
    	if(location.hash){
    	   i = 0;
    	   openId = location.hash.substr(1);    	   
    	   $$('a.acc-title').each(function(e) {    	       
    	      if (e.id && e.id==openId){                
                openIndex = i; 
              }
              i ++;
    	   });
    	   
        }
        
        accordion = new Accordion('a.acc-title', 'div.acc-content', {
    		opacity: false,alwaysHide: true,display:openIndex,
    		onActive: function(toggler){
    			toggler.addClass('active-title');  
                			
    		},
    	 
    		onBackground: function(toggler){
    			toggler.removeClass('active-title');    			
    		},
            onComplete: function(toggler,elements, options){ 
                if($('sub-accordion')){
                    var el = this.elements[this.previous]; //- retrieve current element 
                    if( el == null ) return; if( el.offsetHeight > 0 ){ //- element is displayed height property should be fixed        to auto to allow auto-resize 
                    el.setStyle('height', 'auto'); }
                } 
                
            }
    	},  $('accordion'));        
                    	
    }
     if ($('sub-accordion')){
    	subaccordion = new Accordion('h4.acc-title2', 'div.acc-content2', {
    		opacity: false,alwaysHide: true,display:-1,
    		onActive: function(toggler){
    			toggler.addClass('active-title');  
                			
    		},
    	 
    		onBackground: function(toggler){
    			toggler.removeClass('active-title');    			
    		}
    	},  $('sub-accordion'));    
     } 
    if($('linkspan')){
        accordion = new Accordion('a.a-span', 'div.span-content', {
            opacity: false,alwaysHide: true,display:-1,
    		onActive: function(toggler){
    			toggler.addClass('active-title');
                toggler.innerHTML = "Hide";  
                			
    		},
    	 
    		onBackground: function(toggler){
    			toggler.removeClass('active-title');
                toggler.innerHTML = "View more";    			
    		}
    	},  $('linkspan'));     

    }

    if ($('accordion-region')){
    	var accordion1 = new MultipleOpenAccordion($$('#accordion-region a.filter-region'), $$('#accordion-region .filterSlide'), {
    		opacity: true,alwaysHide: true,openAll:false,firstElementsOpen:[],allowMultipleOpen:false,start:'0'
    	});
    }

    // tips
	var Tips2 = new Tips($$('.Tips'), {
	    className: 'custom',
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
   //tabs
   if($('tabs-financials')){
    var myTabs1 = new mootabs('tabs-financials', {height: 'auto', width: '562px', changeTransition: 'none',mouseOverClass:'tab'});
   }
   if($('tabs-block')){
    var myTabs1 = new mootabs('tabs-block', {height: '406px', width: '562px', changeTransition: 'none',mouseOverClass:'tab'});        
   }
   
   loadTextsize();
});

function loadTextsize(){
      fontsize = '14px';
      footersize = '11px';
      if (readCookie('fontsize')) {
        fontsize =readCookie('fontsize');
      }  
      if (readCookie('footersize')) {
        footersize =readCookie('footersize');
     }  
      
      document.body.setStyle('font-size',fontsize);           
      $('footer').setStyle('font-size',footersize);             


   } 

    
   function resizeText(font_size) {
     switch(font_size){
        case 1: 
        fontsize="14px";
        footersize = "11px";
        break;
        case 2: fontsize="16px";footersize = "13px";break;
        case 3: fontsize="18px";footersize = "15px";break;
     }  
	 
	 createCookie('fontsize', fontsize,1);      
      createCookie('footersize', footersize,1);

	 
      document.body.style.fontSize = fontsize;
      $('footer').setStyle('font-size',footersize);        
   }  
   
   function checkConditions(obj){
        if(!document.getElementById(obj).checked){
            alert('Please ensure you meet the conditions.');
            return false;
        }    
        else
        {
            location.href = 'BecomeSubcontractor2.aspx'
        }
   }

   function checkTerms(obj){
        if(!document.getElementById(obj).checked){
            alert('Please ensure you agree to the terms and conditions.');
            return false;
        }    
   }
   function checkContact(){
        if(document.enquiry_form.name.value=='Name' || document.enquiry_form.name.value==''){
            alert('Name is missing.');
            document.enquiry_form.name.focus();
            return false;
        }    
        if(document.enquiry_form.company.value=='Company' || document.enquiry_form.company.value==''){
            alert('Company is missing.');
            document.enquiry_form.company.focus();
            return false;
        }    
        if(document.enquiry_form.email.value.indexOf("@", 0) < 0){
            alert('Email is missing or not valid.');
            document.enquiry_form.email.focus();
            return false;
        }    
        if(document.enquiry_form.phone.value=='Telephone' || document.enquiry_form.phone.value==''){
            alert('Telephone is missing.');
            document.enquiry_form.phone.focus();
            return false;
        }    
        if(document.enquiry_form.postcode.value=='Post code' || document.enquiry_form.postcode.value==''){
            alert('Post code is missing.');
            document.enquiry_form.postcode.focus();
            return false;
        }    
        if(document.enquiry_form.comments.value=='Comments' || document.enquiry_form.comments.value==''){
            alert('Comment is missing.');
            document.enquiry_form.comments.focus();
            return false;
        }    
        if(document.enquiry_form.spam.value=='Spam filter' || document.enquiry_form.spam.value==''){
            alert('Please input spam filter code.');
            document.enquiry_form.spam.focus();
            return false;
        }    
   
   }
   
   function checkApply(){
        if(document.apply_form.title.value==''){
            alert('Title is missing.');
            document.apply_form.title.focus();
            return false;
        }    
        if(document.apply_form.name.value==''){
            alert('Name is missing.');
            document.apply_form.name.focus();
            return false;
        }    
        
        check = checkContact();        
        if (!check) return false;
        
         if(!document.apply_form.eligible[0].checked && !document.apply_form.eligible[1].checked){            
            alert('Please check if you are eligible to work in UK');            
            return false;
        }    
        if(document.apply_form.cv.value==''){
            alert('Please upload your CV.');
            document.apply_form.cv.focus();
            return false;
        }
        return true;    
   }
   
   function checkContact(){        

       if(document.apply_form.address1.value==''){
            alert('Address is missing.');
            document.apply_form.address1.focus();
            return false;
        }    
        if(document.apply_form.city.value==''){
            alert('Town/City is missing.');
            document.apply_form.city.focus();
            return false;
        }    
        if(document.apply_form.county.value==''){
            alert('County is missing.');
            document.apply_form.county.focus();
            return false;
        }    
        if(document.apply_form.postcode.value==''){
            alert('Post code is missing.');
            document.apply_form.postcode.focus();
            return false;
        }    
        if(document.apply_form.email.value.indexOf("@", 0) < 0){
            alert('Email is missing or not valid.');
            document.apply_form.email.focus();
            return false;
        }    
        if(document.apply_form.phone.value==''){
            alert('Telephone is missing.');
            document.apply_form.phone.focus();
            return false;
        }   
        return true; 
         
        
        
   }
   function checkGraduate(){
        
        check = checkApply();
        
        if (!check) return false;
        
        if(document.apply_form.location.value==''){
            alert('Please select a preferred work location.');
            document.apply_form.location.focus();
            return false;
        }    

        if(document.apply_form.area.value==''){
            alert('Please select an area of interest.');
            document.apply_form.area.focus();
            return false;
        }    
        
   }
   
    function checkGraduate2(){
    
        if(document.apply_form.education.value==''){
            alert('Please fill in educational establishment you are studying at.');
            document.apply_form.education.focus();
            return false;
        }    
        
        if(document.apply_form.qualification.value==''){
            alert('Please select type of qualification.');
            document.apply_form.qualification.focus();
            return false;
        }    
    
        if(document.apply_form.degree.value==''){
            alert('Please select title of degree course.');
            document.apply_form.degree.focus();
            return false;
        }    
        if(document.apply_form.year.value==''){
            alert('Please select year of graduation.');
            document.apply_form.year.focus();
            return false;
        }    
        if(document.apply_form.reason1.value==''){
            alert('Please explain why you would like to work for BAM.');
            document.apply_form.reason1.focus();
            return false;
        }    
        if(document.apply_form.reason2.value==''){
            alert('Please explain why you wish to pursue a career in construction.');
            document.apply_form.reason2.focus();
            return false;
        }    
    }
    
    function checkCopyfomr(){
    
        if(document.copyform.email.value.indexOf("@", 0) < 0){
            alert('Your email is missing or not valid.');
            document.copyform.email.focus();
            return false;
        }    
    }
    
    function checkSupply(){
        if(document.apply_form.company_name.value==''){
            alert('Company name is missing.');
            document.apply_form.company_name.focus();
            return false;
        }    
		
		if(document.apply_form.job_title.value==''){
            alert('Job Title is missing.');
            document.apply_form.job_title.focus();
            return false;
        }    
        
        check = checkContact();        
        
        
    }

    function checkSupply2(){
                
        if(document.apply_form2.region.value=='' && document.apply_form2.county.value=='' && !(document.apply_form2.nationwide.checked)){
            alert('Please select geographic area of work.');            
            return false;
        
        }
        if(document.apply_form2.discipline.value=='' || document.apply_form2.discipline.value=='Please describe your field(s) of work?'){
            alert('Please describe your field(s) of work.');
            document.apply_form2.discipline.focus();
            return false;
        }    
        
    }
	
	function createCookie(name,value,days) {
                if (days) {
                                var date = new Date();
                                date.setTime(date.getTime()+(days*24*60*60*1000));
                                var expires = "; expires="+date.toGMTString();
                }
                else var expires = "";
                document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
                var nameEQ = name + "=";
                var ca = document.cookie.split(';');
                for(var i=0;i < ca.length;i++) {
                                var c = ca[i];
                                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
                }
                return null;
}

function eraseCookie(name) {
                createCookie(name,"",-1);
}

