function contactChecker(errorDivId)
{
	var ok = true;
	var errors = '';

	document.getElementById(errorDivId).innerHTML = '<p>&nbsp;</p>';
	
    	if(document.getElementById('ddlTitle'))
		{
			var title = document.getElementById('ddlTitle').value;
		
			if(title == "Please select")
			{
				ok = false;
				errors += '<p>Please Enter your title in step 1.</p>';
			}				
    	}  	
    	if(document.getElementById('txtFirstname'))
		{
			var first = document.getElementById('txtFirstname').value;
		
			if(first.length == 0)
			{
				ok = false;
				errors += '<p>Please enter your first name</p>';
			}
    	}
    	if(document.getElementById('txtLastname'))
		{
			var last = document.getElementById('txtLastname').value;
			
			if(last.length == 0)
			{
				ok = false;
				errors += '<p>Please enter your last name</p>';
			}	
    	}
    	if(document.getElementById('txtPhone'))
	{
		var val = document.getElementById('txtPhone').value;
		   		
    		val = onlyNumbersPhone(val);
    		
    		document.getElementById('txtPhone').value = val;
		
		if(val.length < 10 || val.length > 15)
			ok = false;
    	}
    	if(document.getElementById('txtEmail'))
	{
		var email = document.getElementById('txtEmail').value;
		
		var lastAt = email.lastIndexOf("@");
		var lastDot = email.lastIndexOf(".");

		if(email.length < 5)
		{
		    errors += '<p>Your email address appears to be invalid.</p>';
		    ok = false;
		}
		else if(email.length > 40)
		{
		    errors += '<p>Your email address is too long.</p>';
		    ok = false;
		}
		else if((lastAt > lastDot) || lastAt == -1 || lastDot == -1 || 
		    (!email.toLowerCase().search('.com') && !email.toLowerCase().search('.uk') && !email.toLowerCase().search('.org')
		     && !email.toLowerCase().search('.biz') && !email.toLowerCase().search('.net') && !email.toLowerCase().search('.gov')
		     && !email.toLowerCase().search('.eu') ))
		{
		    errors += '<p>Your email address appears to be invalid.</p>';
		    ok = false;
        	}
		

    	}
    	if(document.getElementById('txtFirstLineOfAddress'))
		{
			var address1 = document.getElementById('txtFirstLineOfAddress').value;
		
			if(address1.length == 0)
			{
				ok = false;
				errors += '<p>Please enter your address</p>';
			}
		}	
    	if(document.getElementById('txtPostCode'))
		{
			var postcode = document.getElementById('txtPostCode').value;
		
			if(postcode.length == 0)
			{	
				ok = false;
				errors += '<p>Please enter your post code</p>';
			}	
		}
    	
    	if(document.getElementById(errorDivId))
    	{
    		document.getElementById(errorDivId).innerHTML += errors;
    	}
    	    	
    	return ok;    	
}

function phoneVal(val)
{
    var newVal="";
    for(var i=0; i<val.length; i++)
    {
        switch(val.charAt(i))
        {
            case "0":newVal+="0";break;
            case "1":newVal+="1";break;
            case "2":newVal+="2";break;
            case "3":newVal+="3";break;
            case "4":newVal+="4";break;
            case "5":newVal+="5";break;
            case "6":newVal+="6";break;
            case "7":newVal+="7";break;
            case "8":newVal+="8";break;
            case "9":newVal+="9";break;
        }
    }

    return newVal;
}

function onlyNumbers(val)
{

    var newVal="0";
    for(var i=0; i<val.length; i++)
    {
        switch(val.charAt(i))
        {
            case "0":newVal+="0";break;
            case "1":newVal+="1";break;
            case "2":newVal+="2";break;
            case "3":newVal+="3";break;
            case "4":newVal+="4";break;
            case "5":newVal+="5";break;
            case "6":newVal+="6";break;case "7":newVal+="7";break;
            case "8":newVal+="8";break;case "9":newVal+="9";break;
        }
    }
    for(var i=0; i<newVal.length; i++)
    {
        if(newVal.charAt(i) == "0")
        {
            newVal=newVal.substring(1);
            i--;
        }
        else 
            break;
    }
    if(newVal=="")
        newVal="0";
    return parseInt(newVal);
}

function xreplace(checkMe,toberep,repwith)
{
    var temp = checkMe;
    var i = temp.indexOf(toberep);
    while(i > -1)
    {
        temp = temp.replace(toberep, repwith);
        i = temp.indexOf(toberep);
    }
    return temp;
}

function FormatNumberBy3(num, decpoint, sep) 
{
    if (arguments.length == 2) 
    {
        sep = ',';
    }
    if (arguments.length == 1) 
    {
        sep = ',';
        decpoint = '.';
    }
                
    num = num.toString();
    num = xreplace(num, ',', '');
    a = num.split(decpoint);
    x = a[0]; 
    y = a[1]; 
    z = '';
    if (typeof(x) != 'undefined') 
    {
        for (i=x.length-1;i>=0;i--)
            z += x.charAt(i);
        z = z.replace(/(\d{3})/g, '$1' + sep);
    
        if (z.slice(-sep.length) == sep)
            z = z.slice(0, -sep.length);
        x = '';
        for (i=z.length-1;i>=0;i--)
            x += z.charAt(i);
            
        if (typeof(y) != 'undefined' && y.length > 0)
            x += decpoint + y;
    }
    x = xreplace(x, ',,', ',');
    return x;
}

function onlyNumbersPhone(val)
{
    var newVal="";
    for(var i=0; i<val.length; i++)
    {
        switch(val.charAt(i))
        {
            case "0":newVal+="0";break;
            case "1":newVal+="1";break;
            case "2":newVal+="2";break;
            case "3":newVal+="3";break;
            case "4":newVal+="4";break;
            case "5":newVal+="5";break;
            case "6":newVal+="6";break;
            case "7":newVal+="7";break;
            case "8":newVal+="8";break;
            case "9":newVal+="9";break;
        }
    }
    
    if(newVal=="")newVal="0";
    return (newVal);
}



function arcTurnover()
{
    var running = 0;
    running += parseInt(document.getElementById('txtResidential').value);
    running += parseInt(document.getElementById('txtRetail').value);
    running += parseInt(document.getElementById('txtOffice').value);
    running += parseInt(document.getElementById('txtIndustrial').value);
    running += parseInt(document.getElementById('txtOther').value);
    
    if(parseInt(document.getElementById('txtOther').value) > 0)
    {
        document.getElementById('rowTurnoverSpecify').style.display = '';
    }
    else
    {
        document.getElementById('rowTurnoverSpecify').style.display = 'none';
    }
    
    document.getElementById('txtTotal').value = running;
}

function arcActivities()
{
    var running = 0;
    
    running += parseInt(document.getElementById('txtArchitecturalservices').value);
    running += parseInt(document.getElementById('txtProjectcoordination').value);
    running += parseInt(document.getElementById('txtProjectmanagement').value);
    running += parseInt(document.getElementById('txtInteriordesign').value);
    running += parseInt(document.getElementById('txtFeasibilitystudies').value);
    
    //if the arc surveyors form
    if(document.getElementById('txtValuations'))
    {
    	running += parseInt(document.getElementById('txtValuations').value);
    	
    	if(parseInt(document.getElementById('txtValuations').value) > 0)
	{
		document.getElementById('ValuationDetailsLabel').style.display = '';
		document.getElementById('ValuationDetailsText').style.display = '';
	}
	else
	{
		document.getElementById('ValuationDetailsLabel').style.display = 'none';
		document.getElementById('ValuationDetailsText').style.display = 'none';
    	}
    	
    	running += parseInt(document.getElementById('txtContractAdministration').value);
    	
    	if(parseInt(document.getElementById('txtProjectmanagement').value) > 0)
	{
		document.getElementById('SurveyingDetailsLabel').style.display = '';
		document.getElementById('SurveyingDetailsText').style.display = '';
	}
	else
	{
	    	document.getElementById('SurveyingDetailsLabel').style.display = 'none';
	    	document.getElementById('SurveyingDetailsText').style.display = 'none';
   	}
    }
    

    
    if(document.getElementById('txtSurveyValuation'))
    {
        running += parseInt(document.getElementById('txtSurveyValuation').value);
    }
    
    document.getElementById('txtTotalActivities').value = running;
   
}

function surveyingTypes()
{
    /*var running = 0;
    running += parseInt(document.getElementById('txtBuildingSurveying').value);
    running += parseInt(document.getElementById('txtQuantitySurveying').value);
    running += parseInt(document.getElementById('txtLandSurveying').value);
    running += parseInt(document.getElementById('txtOtherSurveyingType').value);
    
    document.getElementById('txtTotalSurveyingTypes').value = running;
    */
    var jobRole = document.getElementById('ddlJobRole').value;
    if(jobRole == "Other")
    {
        document.getElementById('rowSpecifyOtherSurveyingType').style.display = '';
    }
    else
    {
        document.getElementById('rowSpecifyOtherSurveyingType').style.display = 'none';
    }
}

function cumulativeOffset(element) {
      var valueT = 0, valueL = 0;
      do {
        valueT += element.offsetTop  || 0;
        valueL += element.offsetLeft || 0;
        element = element.offsetParent;
      } while (element);
      return [valueL, valueT];
    };

var helpEvent;
function setFocus(id)
{
    clearTimeout(helpEvent);
    
    var ele = document.getElementById(id);
    ele.style.backgroundColor = 'RGB(243,243,243)';
    
    var ypos = cumulativeOffset(ele)[1];
    var helpPos = document.getElementById('innerHelp').offsetTop;
    

    if(ypos > helpPos)
    {
        moveHelpUp(ypos);
    }
    if(ypos < helpPos)
    {
        moveHelpDown(ypos);
    }
}

function moveHelpUp(pos)
{
    
    var helpPos = parseInt(document.getElementById('innerHelp').offsetTop);

    
    if(pos > helpPos)
    {
        helpPos += 10;
        document.getElementById('innerHelp').style.top = helpPos + 'px';
        helpEvent = setTimeout("moveHelpUp("+pos+")", 10);
    }
    else
    {
        clearTimeout(helpEvent);
    }
}

function moveHelpDown(pos)
{
    var helpPos = parseInt(document.getElementById('innerHelp').offsetTop);

    
    if(pos < helpPos)
    {
        helpPos -= 10;
        document.getElementById('innerHelp').style.top = helpPos + 'px';
        helpEvent = setTimeout("moveHelpDown("+pos+")", 10);
    }
    else
    {
        clearTimeout(helpEvent);
    }
}

function setBlur(id)
{
    document.getElementById(id).style.backgroundColor = '';
    
}

function showHelp(text)
{
    document.getElementById('innerHelp').innerHTML = text;
}



function architectsSubmit()
{

try
{
   var error = document.getElementById('errorDiv');
   errorHTML = '';

    //step 1
    var ok = contactChecker('errorDiv');
        
    if(!ok)
    {
        error.innerHTML += '<p>Please complete <a href="#step1">step 1</a>, all step 1 questions are mandatory.</p>';
        return false;
    }
    
    
    //step 2
    var jobRole = "";
    var businessElement = document.getElementById('ddlJobRole');
    if(businessElement != null)
    {
        jobRole = document.getElementById('ddlJobRole').value;
        if(jobRole == "Please select")
        {
            error.innerHTML = 'Please complete <a href="#step2">step 2</a>';
            return false;
        }
        if(jobRole == "Other")
        {
            if(document.getElementById('txtSpecifySurveyingType').value.length < 2)
            {
               error.innerHTML = 'Please define your job role, this is a question of <a href="#step2">step 2</a>.';
               return false;
            }
        }
    }
    
    if(document.getElementById('txtTotalActivities')!=null)
    {
        var totalActivities = parseInt(document.getElementById('txtTotalActivities').value);
        if(totalActivities != 100)
        {
            error.innerHTML = 'Please account for all your activites, this is a question in <a href="#step2">step 2</a>.';
            return false;
        }
    }
    
    
    if(document.getElementById('txtValuationDetails'))
    {
	    var archValuationValue = document.getElementById('txtValuations').value; 
	    var archValuationDetails = document.getElementById('txtValuationDetails').value; 
	    if(archValuationValue > 0 && archValuationDetails.length < 2)
	    {
		    error.innerHTML = 'Further details regarding your valuation activities required, this is a <a href="#step2">step 2 question</a>.';
		    return false;
	    }
    }
    
    if(document.getElementById('txtSurveyingDetails'))
    {
	    var archLandSurveyingValue = document.getElementById('txtProjectmanagement').value; 
	    var archLandSurveyingDetails = document.getElementById('txtSurveyingDetails').value; 
	    if(archLandSurveyingValue > 0 && archLandSurveyingDetails.length < 2)
	    {
		    error.innerHTML = 'Further details regarding your land surveying activities required, this is a <a href="#step2">step 2 question</a>.';
		    return false;
	    }
    }
    
    
    
    
    var archQualifications = document.getElementById('txtQualifications').value; 
    if(archQualifications.length < 2)
    {
        error.innerHTML = 'Please enter your qualifications, this is a <a href="#step2">step 2 question</a>.';
        return false;
    }
    var archExperience = document.getElementById('txtExperience').value; 
        if(archExperience.length < 2)
        {
            error.innerHTML = 'Please enter your experience, this is a <a href="#step2">step 2 question</a>.';
            return false;
    }
    var archMemberships = document.getElementById('txtMemberships').value; 
    if(archQualifications.length < 2)
    {
        error.innerHTML = 'Please enter the names of any professional bodies you are associated with, this is a <a href="#step2">step 2 question</a>. If you are not a member of any applicable professional bodies, please enter none.';
        return false;
    }
    
    //step 3
    var business = document.getElementById('txtBusinessname').value;
    var years = parseInt(document.getElementById('txtYearsEstablished').value);
    var turnover = parseInt(document.getElementById('txtTurnover').value);
    
    var residential = parseInt(document.getElementById('txtResidential').value);
    var retail = parseInt(document.getElementById('txtRetail').value);
    var office = parseInt(document.getElementById('txtOffice').value);
    var industrial = parseInt(document.getElementById('txtIndustrial').value);
    var other = parseInt(document.getElementById('txtOther').value);
    
    var total = parseInt(document.getElementById('txtTotal').value);
    
    var ukOnly = '';
    var worldwide = document.getElementsByName('radUK');
    if(worldwide[0].checked)
        ukOnly = 'True';
    else if (worldwide[1].checked)
        ukOnly = 'False';
        
    var specifyTurnover = document.getElementById('txtSpecifyTurnover').value;
        
    var countries = document.getElementById('txtOtherCountries').value;
       
    if(business.length == 0 ||
        turnover < 1 ||
        ukOnly.length == 0)
    { 
        error.innerHTML = 'Please complete <a href="#step3">step 3</a>';
        return false;
    }
    
    /*    
    var otherSurveyingType = parseInt(document.getElementById('txtOtherSurveyingType').value);    
    var otherSurveyingTypeSpecified = document.getElementById('txtSpecifySurveyingType').value;
    var total = parseInt(document.getElementById('txtTotal').value);
    if(otherSurveyingType > 0 && otherSurveyingTypeSpecified.length < 1)
    {
        error.innerHTML = 'Please specify your other type of surveying in <a href="#step3">step 3</a>';
        return false;
    }
    */
    
    if(other > 0 && specifyTurnover.length < 1)
    {
        error.innerHTML = 'Please specify your other turnover source in <a href="#step3">step 3</a>';
        return false;
    }
    
    if(ukOnly == 'False' && countries.length < 1)
    {
        error.innerHTML = 'Please list the other counties in which work is undertaken. <a href="#step3">step 3</a>';
        return false;
    }
    
    if(total < 100)
    {
        error.innerHTML = 'Please specify 100% of your turnover source. <a href="#step3">step 3</a>';
        return false;
    }
	
	if(total > 100)
    {
        error.innerHTML = 'You have specified more than 100% for your turnover source. <a href="#step3">step 3</a>';
        return false;
    }
    
    if(document.getElementById('radCIY'))
    {
        var currentlyInsured = '';
        var radsCI = document.getElementsByName('radCI');
        if(radsCI[0].checked)
            currentlyInsured = 'True';
        else if (radsCI[1].checked)
            currentlyInsured = 'False';
            
        if(currentlyInsured == '')
        {
            error.innerHTML = 'Please specify whether you are currently insured. <a href="#step3">step 3</a>';
            return false;
        }
    }
    
    //step 4
    var descLargestProject = document.getElementById('txtDescLargestProject').value;
    var largestValue = parseInt(document.getElementById('txtLargestValue').value);
    var largestFee = parseInt(document.getElementById('txtLargestFee').value);
    
    var descAverageProject = document.getElementById('txtDescAverageProject').value;
    var averageValue = parseInt(document.getElementById('txtAverageValue').value);
    var averageFee = parseInt(document.getElementById('txtAverageFee').value);
    
    if(descLargestProject.length == 0 || largestValue < 1 || largestFee < 1)
    {
        error.innerHTML = 'Please tell us more about the largest project you would undertake in <a href="#step4">step 4</a>';
        return false;
    }
    
    if(descAverageProject.length == 0 || averageValue < 1 || averageFee < 1)
    {
        error.innerHTML = 'Please tell us more about the average project you would undertake in <a href="#step4">step 4</a>';
        return false;
    }
 
    //step 5
    var checkLevels = document.getElementsByName('cbLevels');

    var levelsSelected = 'False';
    
    for(i=0;i<checkLevels.length;i++)
    {
        if(checkLevels[i].checked)
        {
            levelsSelected = 'True';
         }
    }
    
    
    if(levelsSelected == 'False')
    {
        error.innerHTML = 'You have selected no levels in <a href="#step5">step 5</a>';
        return false;
    }
    
    
    
    error.innerHTML = 'success';

    return true;
}
catch(err)
{
    alert(err);
    return false;
}
/*END OF TRY*/
}

function charitiesSubmit()
{
    try
    {
      //step 1
      
      
        
        
        
        
        var turnover = parseInt(document.getElementById('txtTurnover').value);
        var loi = parseInt(document.getElementById('ddlLevel').value);

        var ele = document.getElementById('quote');
        var err = document.getElementById('errorDiv');
        err.innerHTML = '';
        var toErr = document.getElementById('turnoverError');
        
        var ok = contactChecker('errorDiv');
        
         if(!ok)
        {
            err.innerHTML += '<p>Please complete step 1, all step 1 questions are mandatory.</p>';
            return false;
        }

        var value = 0
        
        if(turnover < 1)
        {
            err.innerHTML += '<p>Please enter your turnover.</p>';
            return false;
        }
            
        if(turnover > 2000000)
        {
            toErr.innerHTML += "<p>As your turnover is over &pound;500,000, please <a href='http://www.blyth-valley.co.uk/contactUs.aspx?error=Charity income too high'>contact us</a> for a bespoke quotation</p>";    
            return false;
        }
        
        switch(loi)
        {
            case 0:
                err.innerHTML += '<p>Please select a level of cover</p>';
                break;
            case 100000:
                if(turnover <= 250000)
                    value = 200.00;
                else if(turnover <= 500000)
                    value = 350.00;
                else if(turnover <= 1000000)
                    value = 500.00;
                else if(turnover < 2000000)
                    value = 700.00;
                break;
            case 250000:
                if(turnover <= 250000)
                    value = 350.00;
                else if(turnover <= 500000)
                    value = 500.00;
                else if(turnover <= 1000000)
                    value = 650.00;
                else if(turnover < 2000000)
                    value = 850.00;
                break;
            case 500000:
                if(turnover <= 250000)
                    value = 450.00;
                else if(turnover <= 500000)
                    value = 600.00;
                else if(turnover <= 1000000)
                    value = 750.00;
                else if(turnover < 2000000)
                    value = 1000.00;
                break;
            case 1000000:
                if(turnover <= 250000)
                    value = 600.00;
                else if(turnover <= 500000)
                    value = 800.00;
                else if(turnover <= 1000000)
                    value = 1000.00;
                else if(turnover < 2000000)
                    value = 1250.00;
                break;
            case 2000000:
                if(turnover <= 250000)
                    value = 900.00;
                else if(turnover <= 500000)
                    value = 1100.00;
                else if(turnover <= 1000000)
                    value = 1300.00;
                else if(turnover < 2000000)
                    value = 1650.00;
                break;
            /*DP replaced - 2008,11,13 with new rates supplied by SE
            case 100000:
                if(turnover <= 50000)
                    value = 150.00;
                else if(turnover <=100000)
                    value = 250.00;
                else if(turnover <= 250000)
                    value = 425.00;
                else if(turnover < 500000)
                    value = 625.00;
                break;
            case 250000:
                if(turnover <= 50000)
                    value = 250.00;
                else if(turnover <=100000)
                    value = 350.00;
                else if(turnover <= 250000)
                    value = 525.00;
                else if(turnover < 500000)
                    value = 725.00;
                break;
            case 500000:
                if(turnover <= 50000)
                    value = 400.00;
                else if(turnover <=100000)
                    value = 525.00;
                else if(turnover <= 250000)
                    value = 700.00;
                else if(turnover < 500000)
                    value = 900.00;
                break;    
            case 100000:
                if(turnover <= 1000000)
                    value = 600.00;
                else if(turnover <=100000)
                    value = 700.00;
                else if(turnover <= 250000)
                    value = 900.00;
                else if(turnover < 500000)
                    value = 1100.00;
                break;  */     
            default: alert('error');break;
            
        }
        ele.innerHTML = 'Your premium &pound;' + value; 
        document.getElementById('premium').value = value;
        
        //ASP.charities_aspx.fileInGMS(document.getElementById('txtBusinessname').value, document.getElementById('ddlTitle').value,
        //    document.getElementById('txtFirstname').value, document.getElementById('txtLastname').value, document.getElementById('txtPhone').value,
        //    document.getElementById('txtEmail').value);
    }
    catch(err)
    {
        alert(err);
        return false;
    }
	return ok;
}
function callbackSubmit()
{
    try
    {
      //step 1
	  var err=document.getElementById('error');
	  var message='';
	  var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
	  
	  if(document.getElementById('telephone').value.length < 7)
        {
            message += "<p>Please provide your telephone number.</p>";    
        }
	   if(document.getElementById('email').value.length <3)
        {
            message += "<p>Please provide your email address.</p>";    
        } else 
		{
			if(!document.getElementById('email').value.match(emailPattern))
			{
				message += "<p>Please provide a valid email address.</p>";    
			}
		}
	   if(document.getElementById('firstname').value.length <1)
        {
            message += "<p>Please provide your first name.</p>";    
        }
		if(document.getElementById('surname').value.length <1)
        {
            message += "<p>Please provide your surname.</p>";    
        } 
	    
		if(CallbackTimeValidation() == false)
		{
			message+= "<p>Sorry but we can't call you back at that time</p>";
		}

		if(insideOfficeHours() == false)
		{
			message+= "<p>Sorry but our offices are closed now so we won't be able to call you back</p>";
		}
		
		if(message.length >0)
		{err.innerHTML=message;
		return false;
		}
	  }
    catch(err)
    {
        alert(err);
        return false;
    }
		return true;
}

// Checks if a callback is requested for the same day and after office hours
	function insideOfficeHours()
	{
		var currentDate = new Date();
		var hh = currentDate.getHours();
		var mm = currentDate.getMinutes();
		var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	
		<!-- special xmas rules	-->
		var dayMonth = currentDate.getDate() + '/' + (currentDate.getMonth() + 1);
		if (dayMonth == '25/12' || (dayMonth == '26/12') || (dayMonth == '28/12') || (dayMonth == '1/1'))
			return false;
	
		if(document.getElementById('callat').value == 'Today' || document.getElementById('callat').value == days[currentDate.getDay()])
		{
			if(hh > 17 || (hh == 17 && mm > 30) || currentDate.getDay() == 0 || currentDate.getDay() == 6)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
	}

//Validates the time someone selects to be called back
	function CallbackTimeValidation()
	{
		var currentDate = new Date();
		
		var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
		
		if(document.getElementById('callon').value == 'AM' && currentDate.getHours() > 11)
		{				
			if(document.getElementById('callat').value == 'Today' || document.getElementById('callat').value == days[currentDate.getDay()])
				return false;
			else
				return true;
		}			

		return true;		
	}	

function claimSubmit()
{
    try
    {
      //step 1
	  var err=document.getElementById('error');
	  var message='';
	  var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
	  
	  if(document.getElementById('telephone').value.length < 7)
        {
            message += "<p>Please provide your telephone number.</p>";    
        }
	   if(document.getElementById('email').value.length <3)
        {
            message += "<p>Please provide your email address.</p>";    
        } else
		{
			if(!document.getElementById('email').value.match(emailPattern))
			{
				message += "<p>Please provide a valid email address.</p>";    
			}
		}
	   if(document.getElementById('firstname').value.length <1)
        {
            message += "<p>Please provide your first name.</p>";    
        }
		if(document.getElementById('surname').value.length <1)
        {
            message += "<p>Please provide your surname.</p>";    
        } 
	    
		
		
		if(message.length >0)
		{err.innerHTML=message;
		return false;
		}
	  }
    catch(err)
    {
        alert(err);
        return false;
    }
		return true;
}

function accountantsJobType()
{	
	var jobType = document.getElementById('ddlJobRole').value;
	
	if(jobType == "Other")
    {
        document.getElementById('SpecifyAccountantJob').style.display = '';		
    }
    else
    {
        document.getElementById('SpecifyAccountantJob').style.display = 'none';
	}
}

function accountantsSubmit()
{
	try
	{
		var error = document.getElementById('errorDiv');
		errorHTML = '';		
		
		//step 1
		var ok = contactChecker('errorDiv');
        
		if(!ok)
		{
			error.innerHTML += '<p>Please complete <a href="#step1">step 1</a>, all step 1 questions are mandatory.</p>';
			return false;
		}
       
		//step 2
		var jobRole = "";
		var businessElement = document.getElementById('ddlJobRole');
		
		if(businessElement != null)
		{
			jobRole = document.getElementById('ddlJobRole').value;
			
			if(jobRole == "Please select")
			{
				error.innerHTML = 'Please complete <a href="#step2">step 2</a>';
				return false;
			}
			
			if(jobRole == "Other")
			{
				if(document.getElementById('txtSpecifyAccountantJob').value.length < 2)
				{
					error.innerHTML = 'Please define your job role, this is a question of <a href="#step2">step 2</a>.';
					return false;
				}
				else
					jobRole = document.getElementById('txtSpecifyAccountantJob').value;
			}
		}
    
		if(document.getElementById('txtTotalActivities')!=null)
		{
			var totalActivities = parseInt(document.getElementById('txtTotal').value);
			
			if(totalActivities != 100)
			{
				error.innerHTML = 'Please account for all your activites, this is a question in <a href="#step2">step 2</a>.';
				return false;
			}
		}
        
		if(document.getElementById('txtValuationDetails'))
		{
			var accValuationValue = document.getElementById('txtValuations').value; 
			var accValuationDetails = document.getElementById('txtValuationDetails').value; 
			
			if(accValuationValue > 0 && accValuationDetails.length < 2)
			{
				error.innerHTML = 'Further details regarding your valuation activities required, this is a <a href="#step2">step 2 question</a>.';
				return false;
			}
		}
    
		if(document.getElementById('txtSurveyingDetails'))
		{
			var accLandSurveyingValue = document.getElementById('txtProjectmanagement').value; 
			var accLandSurveyingDetails = document.getElementById('txtSurveyingDetails').value; 
			
			if(accLandSurveyingValue > 0 && accLandSurveyingDetails.length < 2)
			{
				error.innerHTML = 'Further details regarding your land surveying activities required, this is a <a href="#step2">step 2 question</a>.';
				return false;
			}
		}    
    
		var accQualifications = document.getElementById('txtQualifications').value; 
		
		if(accQualifications.length < 2)
		{
			error.innerHTML = 'Please enter your qualifications, this is a <a href="#step2">step 2 question</a>.';
			return false;
		}
		
		var accExperience = document.getElementById('txtExperience').value; 
        
		if(accExperience.length < 2)
        {
            error.innerHTML = 'Please enter your experience, this is a <a href="#step2">step 2 question</a>.';
            return false;
		}
		
		var accMemberships = document.getElementById('txtMemberships').value; 
		
		if(accQualifications.length < 2)
		{
			error.innerHTML = 'Please enter the names of any professional bodies you are associated with, this is a <a href="#step2">step 2 question</a>. If you are not a member of any applicable professional bodies, please enter none.';
			return false;
		}
    
		//step 3
		var business = document.getElementById('txtBusinessname').value;
		var years = parseInt(document.getElementById('txtYearsEstablished').value);
		var turnover = parseInt(document.getElementById('txtTurnover').value);
    
		var audit = parseInt(document.getElementById('txtAudit').value);
		var otherAudit = parseInt(document.getElementById('txtOtherAudit').value);
		var bookkeeping = parseInt(document.getElementById('txtBookKeeping').value);
		var personalTax = parseInt(document.getElementById('txtPersonal').value);
		var pureTax = parseInt(document.getElementById('txtPureTax').value);
		var mancon = parseInt(document.getElementById('txtManCon').value);
		var secretarial = parseInt(document.getElementById('txtShareReg').value);
		var trustees = parseInt(document.getElementById('txtExTrust').value);
		var insolvencies = parseInt(document.getElementById('txtInsLiq').value);
		var genInsurance = parseInt(document.getElementById('txtGenInsurance').value);
		var StockExchange = parseInt(document.getElementById('txtStockEx').value);
		var investment = parseInt(document.getElementById('txtInvestment').value);
		var directorships = parseInt(document.getElementById('txtDirectorship').value);
		var computerConsultancy = parseInt(document.getElementById('txtComCon').value);
		var mergers = parseInt(document.getElementById('txtMerger').value);
		var otherCon = parseInt(document.getElementById('txtConOther').value);
		var other = parseInt(document.getElementById('txtOther').value);
		
		var total = parseInt(document.getElementById('txtTotal').value);
    
		var ukOnly = '';
		var worldwide = document.getElementsByName('radUK');
		
		if(worldwide[0].checked)
			ukOnly = 'True';
		else if (worldwide[1].checked)
			ukOnly = 'False';
        
		var specifyTurnover = document.getElementById('txtSpecifyTurnover').value;
			
		var countries = document.getElementById('txtOtherCountries').value;
       
		if(business.length == 0 || turnover < 1 || ukOnly.length == 0)
		{ 
			error.innerHTML = 'Please complete <a href="#step3">step 3</a>';
			return false;
		}
    
		/*    
		var otherSurveyingType = parseInt(document.getElementById('txtOtherSurveyingType').value);    
		var otherSurveyingTypeSpecified = document.getElementById('txtSpecifySurveyingType').value;
		var total = parseInt(document.getElementById('txtTotal').value);
    
		if(otherSurveyingType > 0 && otherSurveyingTypeSpecified.length < 1)
		{
			error.innerHTML = 'Please specify your other type of surveying in <a href="#step3">step 3</a>';
			return false;
		}
		*/
    
		//====================================================================================== Got here
	
		if(other > 0 && specifyTurnover.length < 1)
		{
			error.innerHTML = 'Please specify your other turnover source in <a href="#step3">step 3</a>';
			return false;
		}
    
		if(ukOnly == 'False' && countries.length < 1)
		{
			error.innerHTML = 'Please list the other counties in which work is undertaken. <a href="#step3">step 3</a>';
			return false;
		}
		
		if(total != 100)
		{
			error.innerHTML = 'Please specify 100% of your turnover source. <a href="#step3">step 3</a>';
			return false;
		}
    
		if(document.getElementById('radCIY'))
		{
			var currentlyInsured = '';
			var radsCI = document.getElementsByName('radCI');
        
			if(radsCI[0].checked)
				currentlyInsured = 'True';
			else if (radsCI[1].checked)
				currentlyInsured = 'False';
            
			if(currentlyInsured == '')
			{
				error.innerHTML = 'Please specify whether you are currently insured. <a href="#step3">step 3</a>';
				return false;
			}
		}
    
		//step 4
		var descLargestProject = document.getElementById('txtDescLargestProject').value;
    
		if(descLargestProject.length == 0)
		{
			error.innerHTML = 'Please tell us more about the largest project you would undertake in <a href="#step4">step 4</a>';
			return false;
		}
 
		//step 5
		var checkLevels = document.getElementsByName('cbLevels');

		var levelsSelected = 'False';
    
		for(i=0;i<checkLevels.length;i++)
		{
			if(checkLevels[i].checked)
			{
				levelsSelected = 'True';
			}
		}
        
		if(levelsSelected == 'False')
		{
			error.innerHTML = 'You have selected no levels in <a href="#step5">step 5</a>';
			return false;
		}
		
		return true;
	}
	catch(err)
	{
		alert(err);
		return false;
	}
/*END OF TRY*/
}

function accTurnover()
{
    var running = 0;
	
	running += parseInt(document.getElementById('txtAudit').value);
	running += parseInt(document.getElementById('txtOtherAudit').value);
	running += parseInt(document.getElementById('txtBookKeeping').value);
	running += parseInt(document.getElementById('txtPersonal').value);
	running += parseInt(document.getElementById('txtPureTax').value);
	running += parseInt(document.getElementById('txtManCon').value);
	running += parseInt(document.getElementById('txtShareReg').value);
	running += parseInt(document.getElementById('txtExTrust').value);
	running += parseInt(document.getElementById('txtInsLiq').value);
	running += parseInt(document.getElementById('txtGenInsurance').value);
	running += parseInt(document.getElementById('txtStockEx').value);
	running += parseInt(document.getElementById('txtInvestment').value);
	running += parseInt(document.getElementById('txtDirectorship').value);
	running += parseInt(document.getElementById('txtComCon').value);
	running += parseInt(document.getElementById('txtMerger').value);
	running += parseInt(document.getElementById('txtConOther').value);
	running += parseInt(document.getElementById('txtOther').value);
	
    if(parseInt(document.getElementById('txtOther').value) > 0)
    {
        document.getElementById('rowTurnoverSpecify').style.display = '';
    }
    else
    {
        document.getElementById('rowTurnoverSpecify').style.display = 'none';
    }
    
    document.getElementById('txtTotal').value = running;
}