function change(id){
	document.getElementById('newsletter').style.display = "none";
	document.getElementById('form').style.display = "none";
	document.getElementById(id).style.display = '';
}

function job(id){
	document.getElementById('info').style.display = "none";
	document.getElementById('application').style.display = "none";
	document.getElementById(id).style.display = '';
}

function course(id){
	document.getElementById('info').style.display = "none";
	document.getElementById('application').style.display = "none";
	document.getElementById(id).style.display = '';
}

function show_map(id,ofid){
	i = document.getElementById(id).style.display
	document.getElementById('iframe'+ofid).src = "guide.php?id="+ofid;
	if(i == "none"){
		document.getElementById(id).style.display = "";
	} else {
		document.getElementById(id).style.display = "none";	
	}
}

function change_tab(id,tab){
	document.getElementById('personal_details').style.display = "none";
	document.getElementById('education').style.display = "none";
	document.getElementById('other_training').style.display = "none";
	document.getElementById('employment_history').style.display = "none";
	document.getElementById('achievements').style.display = "none";
	document.getElementById('references').style.display = "none";
	document.getElementById('general_information').style.display = "none";
	document.getElementById('finish').style.display = "none";
		
	document.getElementById('personal_tab').setAttribute("class","");
	document.getElementById('personal_tab').setAttribute("className","");
	document.getElementById('education_tab').setAttribute("class","");
	document.getElementById('education_tab').setAttribute("className","");
	document.getElementById('other_tab').setAttribute("class","");
	document.getElementById('other_tab').setAttribute("className","");
	document.getElementById('employment_tab').setAttribute("class","");
	document.getElementById('employment_tab').setAttribute("className","");
	document.getElementById('achievements_tab').setAttribute("class","");
	document.getElementById('achievements_tab').setAttribute("className","");
	document.getElementById('references_tab').setAttribute("class","");
	document.getElementById('references_tab').setAttribute("className","");
	document.getElementById('general_tab').setAttribute("class","");
	document.getElementById('general_tab').setAttribute("className","");
	document.getElementById('finish_tab').setAttribute("class","");
	document.getElementById('finish_tab').setAttribute("className","");
	
	document.getElementById(tab).setAttribute("class","selected");
	document.getElementById(tab).setAttribute("className","selected");

	document.getElementById(id).style.display = '';
}

function change_tab2(id,tab){
	/*
	document.getElementById('book_form').style.display = "none";
	document.getElementById('book_tab').setAttribute("class","");
	document.getElementById('book_tab').setAttribute("className","");
	*/
	document.getElementById('enquire_form').style.display = "none";	
	document.getElementById('enquire_tab').setAttribute("class","");
	document.getElementById('enquire_tab').setAttribute("className","");
	
	document.getElementById(tab).setAttribute("class","selected");
	document.getElementById(tab).setAttribute("className","selected");

	document.getElementById(id).style.display = '';
}

function change_color(id){
		document.getElementById(id).style.color = '#FF6600';
		document.getElementById(id).style.background = '#DDDDDD';
}
function change_color_back(id){
		document.getElementById(id).style.color = '#606060';
		document.getElementById(id).style.background = '#FFFFFF';
}

function select_date(id){
	window.location = "calender.php?cid="+id;
}

function get_dates(id,cid){
	$("#content").load("_include/queries/events_load.php?cid="+cid+"&month="+id);

}
function change_cost(cdid){
	var places = document.booking_details.places_req.options[document.booking_details.places_req.selectedIndex].value;
	//var total_cost = cost * document.booking_details.price.value;
	//document.getElementById('total_cost').innerHTML = '&pound;'+total_cost.toFixed(2);
	$("#total_cost").load("_include/queries/costing.php?cdid="+cdid+"&places="+places);
}
function change_places(){
	var variables = document.booking.date_time.options[document.booking.date_time.selectedIndex].value;
	//var total_cost = cost * document.booking_details.price.value;
	//document.getElementById('total_cost').innerHTML = '&pound;'+total_cost.toFixed(2);
	//alert(variables);
	$("#places_cost").load("../../_include/queries/place_booking.php?v="+variables);
}
function change_cost2(cdid){
	var places = document.booking.places_req.options[document.booking.places_req.selectedIndex].value;
	//var total_cost = cost * document.booking_details.price.value;
	//document.getElementById('total_cost').innerHTML = '&pound;'+total_cost.toFixed(2);
	$("#total_cost").load("../../_include/queries/costing2.php?cdid="+cdid+"&places="+places);
}

function adjust_price(id,price,v,hr){
	//alert(id +", "+ price +", "+ v +", "+ hr);
	price = price.replace('£','');		
	price = price.replace(/[^\d\.-]/g,'');
	v = v.replace('£','');		
	v = v.replace(/[^\d\.-]/g,'');
	var base_cost = document.booking_details.base_cost.value;
	var base_duration = document.booking_details.base_duration.value;
	var curr_cost = document.booking_details.curr_extra_cost.value;
	var curr_vat = document.booking_details.curr_extra_vat.value;
	var hours = document.booking_details.extra_hours.value;
	var old_hours = hours;
	var x = eval('document.booking_details.'+id+'.checked;');
	if(x==false){
		document.booking_details.curr_extra_cost.value = parseFloat(curr_cost) - parseFloat(price);
		var extra_cost = parseFloat(curr_cost) - parseFloat(price);
		
		if(v!='' || v!=0){
			var extra_vat = parseFloat(curr_vat) - parseFloat(v);	
		}
		
		total_hours = parseFloat(hours) - parseFloat(hr);
	} else {
		document.booking_details.curr_extra_cost.value = parseFloat(price) + parseFloat(curr_cost);
		var extra_cost = parseFloat(curr_cost) + parseFloat(price);
		if(v!='' || v!=0){
			var extra_vat = parseFloat(curr_vat) + parseFloat(v);	
		}
		total_hours = parseFloat(hours) + parseFloat(hr);
	}
	new_days = Math.ceil((total_hours/6));
	old_days = Math.ceil((old_hours/6));
	
	if(base_duration>=new_days){
		new_days = base_duration;
	}
	var check_cost = document.getElementById(new_days+'day').innerHTML;
	var check_vat = (check_cost/100)*17.5;
	var tc = parseFloat(check_cost)+parseFloat(extra_cost);
	tc = tc.toFixed(2);
	var vat = parseFloat(check_vat) + parseFloat(extra_vat);
	vat = vat.toFixed(2);
	var gt = parseFloat(tc) + parseFloat(vat);
	//alert(extra_vat + " " +  check_vat);
	document.getElementById('days').innerHTML = new_days;
	document.booking_details.extra_hours.value = total_hours;
	document.booking_details.curr_extra_vat.value = extra_vat;
	document.getElementById('tc').innerHTML = '&pound;'+tc;
	document.getElementById('vat').innerHTML = '&pound;'+vat;
	document.getElementById('gt').innerHTML = '&pound;'+gt;
	document.booking_details.new_vat.value = vat;
	document.booking_details.new_total.value = tc;
	document.booking_details.new_grand_total.value = gt;
}

/*function adjust_price_old(id,price,v,hr){
	//alert(document.getElementById('tc').innerHTML);
	
	var tc = document.getElementById('tc').innerHTML;
	var vat = document.getElementById('vat').innerHTML;
	var hours = document.booking_details.extra_hours.value;
	var base_cost = document.booking_details.base_cost.value;
	var base_duration = document.booking_details.base_duration.value;
	var old_hours = hours;
	var diff = '';
	//var gt = document.getElementById('gt').innerHTML;
	tc = tc.replace('£','');		
	tc = tc.replace(/[^\d\.-]/g,'');
	vat = vat.replace('£','');		
	vat = vat.replace(/[^\d\.-]/g,'');
	//gt = gt.replace('£','');		
	//gt = gt.replace(/[^\d\.-]/g,'');
	var x = eval('document.booking_details.'+id+'.checked;');
	if(x==false){
	tc = parseFloat(tc) - parseFloat(price);
	tc = tc.toFixed(2);
	vat = parseFloat(vat) - parseFloat(v);
	vat = vat.toFixed(2);
	total_hours = parseFloat(hours) - parseFloat(hr);
	//gt = parseFloat(gt) - parseFloat(price);
	//gt = gt.toFixed(2);
	} else {
	tc = parseFloat(tc) + parseFloat(price);
	tc = tc.toFixed(2);
	vat = parseFloat(vat) + parseFloat(v);
	vat = vat.toFixed(2);
	total_hours = parseFloat(hours) + parseFloat(hr);
	//gt = parseFloat(gt) + parseFloat(price);
	//gt = gt.toFixed(2);
	}
	new_days = Math.ceil((total_hours/6));
	old_days = Math.ceil((old_hours/6));
	if(base_duration>=new_days){
		new_days = base_duration;
	}
	var check_cost = document.getElementById(new_days+'day').innerHTML;
	if(old_days>new_days){
		var check_cost_diff = document.getElementById(old_days+'day').innerHTML;
		diff = parseFloat(check_cost_diff)-parseFloat(check_cost);
		diff_vat = (diff/100)*15;
		diff = diff.toFixed(2);
		diff_vat = diff_vat.toFixed(2);
		//alert(diff);
	}
	
	
	if(check_cost>base_cost){
		if(old_days!=new_days){
		new_cost = parseFloat(check_cost) - parseFloat(base_cost);
		new_cost_vat = parseFloat((new_cost * 1.15))-parseFloat(new_cost);
		tc = parseFloat(tc)+parseFloat(new_cost);
		tc = tc.toFixed(2);
		vat = parseFloat(vat) + parseFloat(new_cost_vat);
		vat = vat.toFixed(2);
		//alert(tc);
		}
	}
	if(diff != ''){
		tc=parseFloat(tc)-parseFloat(diff);
		vat=parseFloat(vat)-parseFloat(diff_vat);
		tc = tc.toFixed(2);
		vat = vat.toFixed(2);
		alert(tc);
	}
	//alert(tc);
	var gt = parseFloat(tc) + parseFloat(vat);
	addCommas(tc);
	addCommas(vat);
	//addCommas(gt);
	document.getElementById('tc').innerHTML = '&pound;'+tc;
	document.getElementById('vat').innerHTML = '&pound;'+vat;
	document.getElementById('gt').innerHTML = '&pound;'+gt;
	document.getElementById('days').innerHTML = new_days;
	document.booking_details.extra_hours.value = total_hours;
	document.booking_details.new_vat.value = vat;
	document.booking_details.new_total.value = tc;
	document.booking_details.new_grand_total.value = gt;
}*/
function adjust_price2(id,price,v,hr){
	//alert(document.getElementById('tc').innerHTML);
	price = price.replace('£','');		
	price = price.replace(/[^\d\.-]/g,'');
	v = v.replace('£','');		
	v = v.replace(/[^\d\.-]/g,'');
	var base_cost = document.booking.base_cost.value;
	var base_duration = document.booking.base_duration.value;
	var curr_cost = document.booking.curr_extra_cost.value;
	var curr_vat = document.booking.curr_extra_vat.value;
	var hours = document.booking.extra_hours.value;
	var old_hours = hours;
	var x = eval('document.booking.'+id+'.checked;');
	if(x==false){
		document.booking.curr_extra_cost.value = parseFloat(curr_cost) - parseFloat(price);
		var extra_cost = parseFloat(curr_cost) - parseFloat(price);
		
		if(v!='' || v!=0){
			var extra_vat = parseFloat(curr_vat) - parseFloat(v);	
		}
		
		total_hours = parseFloat(hours) - parseFloat(hr);
	} else {
		document.booking.curr_extra_cost.value = parseFloat(price) + parseFloat(curr_cost);
		var extra_cost = parseFloat(curr_cost) + parseFloat(price);
		if(v!='' || v!=0){
			var extra_vat = parseFloat(curr_vat) + parseFloat(v);	
		}
		total_hours = parseFloat(hours) + parseFloat(hr);
	}
	new_days = Math.ceil((total_hours/6));
	old_days = Math.ceil((old_hours/6));
	
	if(base_duration>=new_days){
		new_days = base_duration;
	}
	//alert('document.getElementById('+new_days+'day).innerHTML;');
	var check_cost = document.getElementById(base_duration+'day').innerHTML;
	var check_vat = (check_cost/100)*17.5;
	var tc = parseFloat(check_cost)+parseFloat(extra_cost);
	tc = tc.toFixed(2);
	var vat = parseFloat(check_vat) + parseFloat(extra_vat);
	vat = vat.toFixed(2);
	var gt = parseFloat(tc) + parseFloat(vat);
	gt = gt.toFixed(2)
	//alert(extra_vat + " " +  check_vat);
	document.getElementById('days').innerHTML = new_days;
	document.booking.extra_hours.value = total_hours;
	document.booking.curr_extra_vat.value = extra_vat;
	document.getElementById('tc').innerHTML = '&pound;'+tc;
	document.getElementById('vat').innerHTML = '&pound;'+vat;
	document.getElementById('gt').innerHTML = '&pound;'+gt;
	document.booking.new_vat.value = vat;
	document.booking.new_total.value = tc;
	document.booking.new_grand_total.value = gt;
}
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function check_booking_form(form_name){
	var name = eval("document."+form_name+".name.value;");
	var email = eval("document."+form_name+".email.value;");
	var address = eval("document."+form_name+".address.value;");
	var tel = eval("document."+form_name+".tel.value;");
	var num = eval("document."+form_name+".extra_num.value;");
	
	var err = 0;
	var err2 = 1;
	if(name==''){
		err = 1;
	}
	if(email==''){
		err = 1;
	}
	if(address==''){
		err = 1;
	}
	if(tel==''){
		err = 1;
	}
	if(num==''){
		err = 1;
	}
	if(num!=0){
	for(var x=1;x<=num;x++){
		if( eval("document."+form_name+".course_extra"+x+".type")=='hidden'){
			if(eval("document."+form_name+".course_extra"+x+".value")==''){
				var err2 = 1;
			}
		} else {
			if(eval("document."+form_name+".course_extra"+x+".checked")==true){
				//alert('checked');
				var err2 = 0;
			}
		}
	}} else {
		var err2 = 0;
	}
	if(err==1 || err2 == 1){
		alert('The form must be completed fully in order to make a booking.');	
	} else {
		eval("document." + form_name + ".submit();");	
	}
}

function thickbox(title,url)
{
	$(document).ready(function(){ tb_show(title, url, null); });
}

function load_bookings(){
	//alert('http://www.hargreavestraining.com/development/booking.php');
	thickbox('SELECT YOUR COURSE', 'http://www.hargreavestraining.com/booking-pop-up.php?width=820&height=150');	
}
