// JavaScript Document

/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
		
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype)
{
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
return totaloffset;
}

function iecompattest()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge)
{
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge")
	{
		var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
	if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
	}
else
{
	var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
	if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
	edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
	}
	return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth)
{
	if ((ie||ns6) && document.getElementById("hintbox"))
	{
		dropmenuobj=document.getElementById("hintbox")
		dropmenuobj.innerHTML=menucontents
		dropmenuobj.style.left=dropmenuobj.style.top=-500
		if (tipwidth!="")
		{
			dropmenuobj.widthobj=dropmenuobj.style
			dropmenuobj.widthobj.width=tipwidth
		}
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
		dropmenuobj.style.visibility="visible"
		obj.onmouseout=hidetip
	}
}

function hidetip(e)
{
	dropmenuobj.style.visibility="hidden"
	dropmenuobj.style.left="-500px"
}

function createhintbox()
{
	var divblock=document.createElement("div")
	divblock.setAttribute("id", "hintbox")
	document.body.appendChild(divblock)
}

if (window.addEventListener)
	window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
	window.attachEvent("onload", createhintbox)
else if (document.getElementById)
	window.onload=createhintbox
	
///////////////////////////////
	
	
function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (emaillength==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (emailindexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (emaillastIndexOf(".") <= emailindexOf("@")) {  // last dot must be after the @
        return false;
    } else if (emailindexOf("@") == emaillength) {  // @ must not be the last character
        return false;
    } else if (emailindexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (emailindexOf(".") == emaillength) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < emaillength; i++) {
    var letter = emailcharAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

//ensure all details have been entered into the absence tool
function verify_tools_absence()
{
	var themessage = "Please enter the following details:\n\n";
	
	if (document.tools_absence.no_employees.value=="")
	{
		themessage = themessage + "  - Number of employees\n";
	}
	
	if (document.tools_absence.average_employees.value=="")
	{
		themessage = themessage + "  - Average numbers of days off per employee\n";
	}
	
	if (document.tools_absence.cost_employees.value=="")
	{
		themessage = themessage + "  - Actual cost for each day off per employee\n";
	}					

	//alert if fields are empty and cancel form submit
	if (themessage == "Please enter the following details:\n\n") 
	{
		//submit form here
	}
	else 
	{
		alert(themessage);
		event.returnValue=false;		
	}	
}

//RETENTION TURNOVER CALCULATOR

//perform mid calculation function for rentention/turnover calculator
function mid_calculate_retention(a,b)
{
	intA = parseFloat(a);
	intB = parseFloat(b);
	
	intC = intA / 100;
	
	total = intC * intB;
	
	document.tools_retention.employees_lost.value = total.toFixed(2);
}


//by using the checkbox, automatically add industry average
function cost_employee()
{
	if(document.tools_retention.industry_average.checked == true)
	{
			document.tools_retention.cost_employees.value = "8200";
	}
	else
	{
			document.tools_retention.cost_employees.value = "0";
	}
}

//ensure all details have been entered into the rentention/turnover calculator
function verify_retention_turnover()
{
	var themessage = "Please enter the following details:\n\n";
	
	if (document.tools_retention.no_employees.value=="")
	{
		themessage = themessage + "  - Number of employees\n";
	}
	
	if (document.tools_retention.average_staff_turnover.value=="")
	{
		themessage = themessage + "  - Average staff turnover\n";
	}	
	
	if (document.tools_retention.employees_lost.value=="")
	{
		themessage = themessage + "  - Number of employees lost\n";
	}	
	
	if (document.tools_retention.cost_employees.value=="")
	{
		themessage = themessage + "  - Cost per employee\n";
	}		
				

	//alert if fields are empty and cancel form submit
	if (themessage == "Please enter the following details:\n\n") 
	{
		//submit form here
	}
	else 
	{
		alert(themessage);
		event.returnValue=false;		
	}	
}

//ensure when a user logs into exchange via side include, username 
//and password are present

function check_side_login()
{
	alert("username and password need verifying!");
}


//HEALTH SAFTEY CALCULATOR

function verify_tools_health()
{
	var themessage = "Please enter the following details:\n\n";
	
	if (document.health_safety.no_employees.value=="")
	{
		themessage = themessage + "  - Number of employees\n";
	}
	
	if (document.health_safety.ill_health.value=="")
	{
		themessage = themessage + "  - Number of employees\n";
	}
	
	if (document.health_safety.three_day.value=="")
	{
		themessage = themessage + "  - Number of employees\n";
	}
	
	if (document.health_safety.major.value=="")
	{
		themessage = themessage + "  - Number of employees\n";
	}
	
	if (document.health_safety.fatal.value=="")
	{
		themessage = themessage + "  - Number of employees\n";
	}
	
	if (document.health_safety.incidents.value=="")
	{
		themessage = themessage + "  - Number of employees\n";
	}
				

	//alert if fields are empty and cancel form submit
	if (themessage == "Please enter the following details:\n\n") 
	{
		//submit form here
	}
	else 
	{
		alert(themessage);
		event.returnValue=false;		
	}	
}

//perform calcualtion 1
function health(a,b)
{

	intA = parseFloat(a);
	intB = parseFloat(b/100)*200;
	total = intA * intB;
	total_num = (intA / 100) * parseFloat(b);
	
	document.health_safety.ill_health_cost.value = "£" + total.toFixed(2);		
	document.health_safety.ill_health_no.value = parseFloat(total_num.toFixed(2));

}

//perform calcualtion 1 using check box (industry average)
function cost_ill_health()
{
	if(document.health_safety.ill_health_average.checked == true)
	{
		document.health_safety.ill_health.value = "4.450";
	}
	else
	{
		document.health_safety.ill_health.value = "0";
	}
}

//perform calcualtion 2
function three_day_function(a,c)
{

	intA = parseFloat(a);
	intB = parseFloat(c/100) * 6000;
	total = intA * intB;
	total_num = (intA / 100) * parseFloat(c);
	
	document.health_safety.three_day_cost.value = "£" + total.toFixed(2);	
	document.health_safety.three_day_no.value = parseFloat(total_num.toFixed(2));

}

//perform calcualtion 2 using check box (industry average)
function cost_three_day()
{
	if(document.health_safety.three_day_average.checked == true)
	{
		document.health_safety.three_day.value = "0.420";
	}
	else
	{
		document.health_safety.three_day.value = "0";
	}
}

//perform calcualtion 3
function major_function(a,d)
{

	intA = parseFloat(a);
	intB = parseFloat(d/100) * 65000;
	total = intA * intB;
	total_num = (intA / 100) * parseFloat(d);
	
	document.health_safety.major_cost.value = "£" + total.toFixed(2);	
	document.health_safety.major_no.value = parseFloat(total_num.toFixed(2));

}

//perform calcualtion 3 using check box (industry average)
function cost_major()
{
	if(document.health_safety.major_average.checked == true)
	{
		document.health_safety.major.value = "0.210";
	}
	else
	{
		document.health_safety.major.value = "0";
	}
}

//perform calcualtion 4
function fatal_function(a,e)
{

	intA = parseFloat(a);
	intB = parseFloat(e/100) * 600000;
	total = intA * intB;
	total_num = (intA / 100) * parseFloat(e);
	
	document.health_safety.fatal_cost.value = "£" + total.toFixed(2);	
	document.health_safety.fatal_no.value = parseFloat(total_num.toFixed(2));

}

//perform calcualtion 4 using check box (industry average)
function cost_fatal()
{
	if(document.health_safety.fatal_average.checked == true)
	{
		document.health_safety.fatal.value = "0.004";
	}
	else
	{
		document.health_safety.fatal.value = "0";
	}
}

//perform calcualtion 5
function incidents_function(a,f)
{

	intA = parseFloat(a);
	intB = parseFloat(f) * 200;
	total = intA * intB;
	total_num = (intA) * parseFloat(f);
	
	document.health_safety.incidents_cost.value = "£" + total.toFixed(2);	
	document.health_safety.incidents_no.value = parseFloat(total_num.toFixed(2));	

}

//perform calcualtion 5 using check box (industry average)
function cost_incidents()
{
	if(document.health_safety.incidents_average.checked == true)
	{
		document.health_safety.incidents.value = "1.430";
	}
	else
	{
		document.health_safety.incidents.value = "0";
	}
}

function verify_tools_submission()
{
	
	var themessage = "Please enter the following details:\n\n";
	
	if (document.sendEmailname.value=="")
	{
		themessage = themessage + "  - Your name\n";
	}
	
	if (document.sendEmailcompany.value=="")
	{
		themessage = themessage + "  - Company name\n";
	}
	
	if ((document.sendEmailemailvalue=="")&&(document.sendEmailtelephone.value==""))
	{
		themessage = themessage + "  - An email address or telephone number\n";
	}
	
    if ((! isValidEmail(document.sendEmailemailvalue))&&(document.sendEmailemailvalue!=""))
	{
	    themessage = themessage + "  - Please enter a valid email address";
    }
	
	//alert if fields are empty and cancel form submit
	if (themessage == "Please enter the following details:\n\n") 
	{
		//submit form here
	}
	else 
	{
		alert(themessage);
		event.returnValue=false;		
	}		
}

function verify_multiple_intelligence()
{
    fields = document.multiple_intelligence.getElementsByTagName('input');
    for (i = 0; i < fields.length; i++)
	{
		if(fields[i].value == "")
		{
			alert("Please answer all statements");
			event.returnValue=false;
			return false;
		}
		else if(fields[i].value > 5)
		{
			alert("Answers must be between 0 and 5");
			event.returnValue=false;
			return false;			
		}
	}
}

function verifyPassItOn() 
{
	var answer = '0';
	

		for (var i = 0; i<document.webForm.elements.length; i++) 
		{
			if ((document.webForm.elements[i].value == "") && (document.webForm.elements[i].type == 'text')) 
			{
				answer = '1';
			}
		}

	if(answer == '1')
	{
		alert("Please complete all fields!");
		event.returnValue=false;
	}
}

function verifyTellingTalesToBeLoved() {

	if((document.webForm.Name.value == '') || (document.webForm.Job_Title.value == '') || (document.webForm.Company.value == '') || (document.webForm.Project.value == ''))
	{
		alert("Please enter your details");
		event.returnValue=false;
		return false;
	}
	
	 var el = document.forms[0].elements;
	 for(var i = 0 ; i < el.length ; ++i) {
	  if(el[i].type == "radio") {
	   var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
	   var itemchecked = false;
	   for(var j = 0 ; j < radiogroup.length ; ++j) {
		if(radiogroup[j].checked) {
		 itemchecked = true;
		 break;
		}
	   }
	   if(!itemchecked) { 
		//alert("Please choose an answer for "+el[i].name+".");
		alert("Please answer all questions");
		if(el[i].focus)
		 el[i].focus();
		 event.returnValue=false;
		return false;
	   }
	  }
	 }
	return true;
}