// JavaScript Document

/*sIFR code*/
if(typeof sIFR == "function")
{
	sIFR.replaceElement(named({
		sSelector:".hpbanner_inner h2", 
		sFlashSrc:"flash/helvetica.swf", 
		sColor:"#000", 
		sWmode:"transparent"
		}));			
}

function ratings(rating,id,type) 
{
	var ajaxDisplay = document.getElementById('message'+id);
	ajaxDisplay.innerHTML = "";
	
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	//var introtext = document.getElementById('introtext');
	//introtext.innerHTML = '<img src="images/ajax-loader.gif" alt="loading..." />  Your rating is currently been added, Please Wait';
	
	var ratings = document.getElementById('ratings'+id);
	ratings.innerHTML = '';
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				//alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('message'+id);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;

			//document.getElementById('introtext').style.visibility = 'hidden'; 
		}
	}
	
	var queryString = "?rating=" + rating + "&id=" + id + "&type=" + type;
	ajaxRequest.open("GET", "libs/plugins/updateranking.php" + queryString, true);
	ajaxRequest.send(null); 


}

function highlightquote()
{
	
	var control  = document.getElementById('quoterows');
	var inputs    = control.getElementsByTagName('input');
	
	for (var i = 0; i < inputs.length; i++) 
	{
		
		var div = '';
		div = inputs[i].parentNode;
		var id = div.getAttribute('id');
		
		if(id !='')
		{
			
			var rowid = 'quote'+ id;
			
			if(inputs[i].checked == true) 
			{
				div.className = "quoterowselected";
				
			} 
			else 
			{
				div.className = "quoterow";
				
			}
		}
	}
	
}

function clearpopupsconf(id)
{
	if(id != 'popup9')
	{
		Effect.Fade('popup9');
	}
	if(id != 'popup10')
	{
		Effect.Fade('popup10');
	}
	if(id != 'popup11')
	{
		Effect.Fade('popup11');
	}
	if(id != 'popup12')
	{
		Effect.Fade('popup12');
	}
	if(id != 'popup14')
	{
		Effect.Fade('popup14');
	}
}

function clearpopups(id)
{
	if(id != 'popup')
	{
		Effect.Fade('popup');
	}
	if(id != 'popup1')
	{
		Effect.Fade('popup1');
	}
	if(id != 'popup2')
	{
		Effect.Fade('popup2');
	}
	if(id != 'popup3')
	{
		Effect.Fade('popup3');
	}
	if(id != 'popup4')
	{
		Effect.Fade('popup4');
	}
	if(id != 'popup5')
	{
		Effect.Fade('popup5');
	}
	if(id != 'popup6')
	{
		Effect.Fade('popup6');
	}
	if(id != 'popup7')
	{
		Effect.Fade('popup7');
	}
	if(id != 'popup8')
	{
		Effect.Fade('popup8');
	}
}

//validate quote

function checkdetails()
{
	var error = '';
	
	if(document.getElementById('name').value == '')
	{
		error = error + '<li>Please enter your name</li>';
	}
	
	if(document.getElementById('email').value == '')
	{
		error = error + '<li>Please enter your email address</li>';
	}
	
	if(error !='')
	{
		document.getElementById('errormsg').innerHTML = '<div>Sorry the following problems have been found <ul>' + error + '</ul></div>';
		return false;
	}
	else
	{
		return true;
	}
	
}

//get quote

function getquote() 
{
	document.getElementById('quotetotal').value = '0';
	
	for (var i = 0; i < document.getElementById('quoterows').elements.length; i++) 
	{
		if(document.getElementById('quoterows').elements[i].checked == true)
		{
			var prices = document.getElementById('quoterows').elements[i].value;
			var price = prices.split("-");
			
			var currentprice = parseInt(price['0']);
			var currenttotal = document.getElementById('quotetotal').value;
			
			var total = currentprice + parseInt(currenttotal);
			
			document.getElementById('quotetotal').value = total.toFixed(2);  
			
		}
	}
	
	var no_delegates = document.getElementById('delegate').value;
	if(no_delegates !='')
	{
		var delegate_price = document.getElementById('delegatecost').value; 
		
		var delegate_total = parseInt(no_delegates) * parseInt(delegate_price);
		var currenttotal = document.getElementById('quotetotal').value;
		var total = delegate_total + parseInt(currenttotal);
		document.getElementById('quotetotal').value = total.toFixed(2);
	}
	
	
	for (var i = 0; i < document.getElementById('quoterows').elements.length; i++) 
	{
		
			var id = document.getElementById('quoterows').elements[i].id;
			var type = id.split("-");
			if(type[0] == 'catering')
			{
				if(document.getElementById('quoterows').elements[i].value !='')
				{
					var priceid = document.getElementById('quoterows').elements[i].id;
					var prices = document.getElementById('price' + priceid).value;
					var price = prices.split("-");
					var amount = document.getElementById('quoterows').elements[i].value;
					
					var catering_total = amount * price[0];
					var currenttotal = document.getElementById('quotetotal').value;
					var total = catering_total + parseInt(currenttotal);
					document.getElementById('quotetotal').value = total.toFixed(2);
					
				}
			}
	}

}



//check all check boxes
checked = false;

function checkedAll () 
{
	if (checked == false)
	{
		checked = true
	}
	else
	{
		checked = false
	}
	
	for (var i = 0; i < document.getElementById('form').elements.length; i++) 
	{
		document.getElementById('form').elements[i].checked = checked;
	}

}

//print page

function printpage() 
{
	alert('here');
	window.print();  
}

//homepage scrolling images

function start_slideshow(start_frame,end_frame,delay) 
{
	updatenav();
	var start_frame = 1;
	var end_frame = 10; 
	var delay = 8000;

	var frame = document.getElementById('frame').value;
	
	timer = setTimeout(switch_slides(frame,start_frame,end_frame, delay), delay);
		
}
						
function switch_slides(frame, start_frame, end_frame, delay) 
{
	updatenav();
	
	return (function() {
		var frame = document.getElementById('frame').value;
		if(frame > 10)
		{
			frame = 1;
		}
		
		Effect.Fade('box-' + frame);
		
		if (frame > end_frame) { frame = start_frame; } else { frame = parseInt(frame) + 1; }
		
		if(frame > 10)
		{
			frame = 1;
		}
		
		var previousframe = parseInt(frame) - 1;
		
		if(previousframe < 1)
		{
			previousframe = 10;
		}
		setTimeout("Effect.Fade('box-" + previousframe + "');", 80);
		setTimeout("Effect.Appear('box-" + frame + "');", 80);
		updatenav();
		document.getElementById('frame').value = frame;
		timer = setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 80);
	})

}


function next_slides()
{
	var id = document.getElementById('frame').value;
	Effect.Fade('box-' + id);
	id = parseInt(id) + 1;
	if(id > 10)
	{
		id = 1;
	}
	Effect.Appear('box-' + id);
	document.getElementById('frame').value = id;
    clearTimeout(timer);
	start_slideshow();
	updatenav();
}

function previous_slides()
{
	var id = document.getElementById('frame').value;
	
	Effect.Fade('box-' +id);
	//alert('before -' +id);
	id = parseInt(id) - 1;
	
	if(id < 1)
	{
		id = 10;
	}

	Effect.Appear('box-' + id);
	//alert('after -' +id);
	document.getElementById('frame').value = id;
	clearTimeout(timer);
	start_slideshow();
	updatenav();
}

function change_slides(fadeid)
{
	var id = document.getElementById('frame').value;
	
	if(fadeid != id)
	{
		Effect.Fade('box-' + id);
	}
	
	if(fadeid > 10)
	{
		fadeid = 1;
	}
	
	Effect.Appear('box-' + fadeid);
	document.getElementById('frame').value = fadeid;
	//clears the loop timer ie switch_slides and then starts again from when the button is clicked
	clearTimeout(timer);
	start_slideshow();
	updatenav();
}

function updatenav(){

	for(i = 1; i < 11; i++)
	{
		//alert('nav'+i);
		document.getElementById('nav'+i).className = 'noborder';
	}
	
	var id = document.getElementById('frame').value;
	document.getElementById('nav'+id).className = 'border';
	
}

//conference

function showhopper()
{
	document.getElementById('conferencing').className = "showhopper";
}

function hidehopper()
{
	document.getElementById('conferencing').className = "confimagedefault";
}

function showgallery()
{
	document.getElementById('conferencing').className = "showgallery";
}

function hidegallery()
{
	document.getElementById('conferencing').className = "confimagedefault";
}

function showbaker()
{
	document.getElementById('conferencing').className = "showbaker";
}

function hidebaker()
{
	document.getElementById('conferencing').className = "confimagedefault";
}

function showjames()
{
	document.getElementById('conferencing').className = "showjames";
}

function hidejames()
{
	document.getElementById('conferencing').className = "confimagedefault";
}

function showauditorium()
{
	document.getElementById('conferencing').className = "showauditorium";
}

function hideauditorium()
{
	document.getElementById('conferencing').className = "confimagedefault";
}

//ground floor
function showlife()
{
	document.getElementById('groundlevel').className = "showlife";
}

function hidelife()
{
	document.getElementById('groundlevel').className = "groundimagedefault";
}

function showdisease()
{
	document.getElementById('groundlevel').className = "showdisease";
}

function hidedisease()
{
	document.getElementById('groundlevel').className = "groundimagedefault";
}

function showhealth()
{
	document.getElementById('groundlevel').className = "showhealth";
}

function hidehealth()
{
	document.getElementById('groundlevel').className = "groundimagedefault";
}

function showleeds()
{
	document.getElementById('groundlevel').className = "showleeds";
}

function hideleeds()
{
	document.getElementById('groundlevel').className = "groundimagedefault";
}

function showbarker()
{
	document.getElementById('groundlevel').className = "showbarker";
}

function hidebarker()
{
	document.getElementById('groundlevel').className = "groundimagedefault";
}


// first floor
function showwilkinson()
{
	document.getElementById('toplevel').className = "showwilkinson";
}

function hidewilkinson()
{
	document.getElementById('toplevel').className = "imagedefault";
}

function showsurgery()
{
	document.getElementById('toplevel').className = "showsugery";
}

function hidesurgery()
{
	document.getElementById('toplevel').className = "imagedefault";
}

function showbaby()
{
	document.getElementById('toplevel').className = "showbaby";
}

function hidebaby()
{
	document.getElementById('toplevel').className = "imagedefault";
}

function showhannah()
{
	document.getElementById('toplevel').className = "showhannah";
}

function hidehannah()
{
	document.getElementById('toplevel').className = "imagedefault";
}




// EDIT THESE VALUES IF REQUIRED
var alertText = 'Are you sure you wish to perform this action' + "\n"; //DEFAULT TEXT DISPLAYED ON CONFIRM BUTTONS/LINKS WHEN NO ALT/TITLE
var newWindowLink = true; //OPEN EXTERNAL LINKS BY DEFAULT IN A NEW WINDOW (TRUE/FALSE)?


var woms = new Array(); //CREATE ARRAY OF FUNCTIONS TO LAUNCH ONLOAD

//ONLOAD MANAGER
function womOn(){
  window.onload = womGo;
}

function womGo(){
  for(var i = 0;i < woms.length;i++)
    eval(woms[i]);
}

function womAdd(func){
  woms[woms.length] = func;
}

function CreateBookmarkLink() {

	title = document.title;
	url = window.location.href;
	
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,"");
	} else if(window.external) {
		window.external.AddFavorite( url, title); 
	} else if(window.opera && window.print) {
		return true;
	}
	
}

function objToggle(obj) { 

	var obj = document.getElementById(obj);

	if(obj.style.display == "block") { 
		obj.style.display = "none";
	} else { 
		obj.style.display = "block";
	}

}

function printpage() {

	if(!document.getElementById('print')) return false;
	
	var PrintLink = document.getElementById('print');
	
	PrintLink.onclick = function() {
	
		window.print();
		
		return false;
	
	}

}