// JavaScript Document
// Add trim functionality to String prototype
String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g,''); };

// validate that the form controls have the correct value
function Validate()
{
	var isValid = true;
	var errorText = "Please amend the following erorrs:\r\n";
	
	var s = String( document.frmSearch.txtLocation.value );
	
	if ( s.trim().length == 0 )
	{				
		errorText = AddBreakToTextBlock(errorText, "\r\n" ) + "Enter a city town or postcode";
		isValid = false;
	}
	else
	{
		var loc = document.getElementById("txtLocation").value;
		var mapstyle = "mtGoogle";
		var searchAddr = "http://www.blood.co.uk/SessionSearcher/ShowResults.aspx?Location=" + loc + "&MapStyle=" + mapstyle;
		document.frmSearch.action = searchAddr;
		//document.frmSearch.submit();
	}
	
  }

function SetStatus( checkControl )
{
	if ( checkControl != null )
	{
		if ( checkControl.id == "chkDateOn" )
		{
			document.frmSearch.chkDateAfter.checked = false;
			document.frmSearch.chkDateBefore.checked = false;
		}
		else
		{
			document.frmSearch.chkDateOn.checked = false;
		}
	}
}

function AddBreakToTextBlock( s, breaker )
{
	var s1 = String(s);
	
	if ( s1.length > 0 ) { s1 = s1+breaker; }
	
	return s1;
}

function popup(url,winname,w,h,feat)
{
	if (!(isNaN(w) || isNaN(h)))
	{
		var x=parseInt((screen.width-w)/2);
		var y=parseInt((screen.height-h)/2);
		if (x<0)	x=0;
		if (y<0)	y=0;
		
		if (feat!=null && feat!="")
		{
			feat=","+feat;
		}
		else
		{
			feat="";
		}
		feat="left="+x+",top="+y+",width="+w+",height="+h+feat;
	}
	window.open(url,winname,feat);
}

function tabSelect(whichTab, productname)

{
		switch(productname)
		{
		case 'faq':
		  var tabCount = 23;
		  break    
		}

	tabNum = whichTab.substr(3,2);

	for (i=1;i<=tabCount;i++)
	{
		var div = document.getElementById('tab'+i);
		var liactive = document.getElementById('li'+i);
		var menu = document.getElementById('m'+i);
		document.getElementById("tab"+i).className='hide';
		if (i==tabNum)
		{
			if(div.style.display == 'block'){
				div.style.display = 'none';
				document.getElementById("m"+i).className='';
				document.getElementById("li"+i).className='';
			}else{
			div.style.display = 'block';
			document.getElementById("m"+i).className='active';
			document.getElementById("li"+i).className='active';
			
			}
			
		} else {
			div.style.display = 'none';	
			document.getElementById("m"+i).className='';
			document.getElementById("li"+i).className='';
		}
	}
}

function showlocation(city) {
	setclear();	
	document.getElementById("all_locations").style.display = "block";
	document.getElementById(city).style.display = "block";
}

function showlocationtwo(city,city2) {
	setclear();	
	document.getElementById("all_locations").style.display = "block";
	document.getElementById(city).style.display = "block";
	document.getElementById(city2).style.display = "block";
}

function showlocationthree(city,city2,city3) {
	setclear();	
	document.getElementById("all_locations").style.display = "block";
	document.getElementById(city).style.display = "block";
	document.getElementById(city2).style.display = "block";
	document.getElementById(city3).style.display = "block";
}

function showlocationall (){

	document.getElementById("birminghamvincent").style.display = "inline";
	document.getElementById("birminghamnew").style.display = "inline";
	document.getElementById("brentwood").style.display = "inline";
	document.getElementById("bristol").style.display = "inline";
	document.getElementById("cambridge").style.display = "inline";
	document.getElementById("elstree").style.display = "inline";
	document.getElementById("leeds").style.display = "inline";	
	document.getElementById("liverpool").style.display = "inline";
	document.getElementById("londoncolindale").style.display = "inline";	
	document.getElementById("londontooting").style.display = "inline";	
	document.getElementById("london").style.display = "inline";	
	document.getElementById("manchester").style.display = "inline";
	document.getElementById("newcastle").style.display = "inline";
	document.getElementById("oxfordheadington").style.display = "inline";	
	document.getElementById("oxfordsciencepark").style.display = "inline";	
	document.getElementById("plymouth").style.display = "inline";	
	document.getElementById("sheffield").style.display = "inline";
	document.getElementById("southampton").style.display = "inline";	
	document.getElementById("wakefield").style.display = "inline";
	document.getElementById("watford").style.display = "inline";
	
}

function setclear (){
	document.getElementById("birminghamvincent").style.display = "none";
	document.getElementById("birminghamnew").style.display = "none";
	document.getElementById("brentwood").style.display = "none";
	document.getElementById("bristol").style.display = "none";
	document.getElementById("cambridge").style.display = "none";
	document.getElementById("elstree").style.display = "none";
	document.getElementById("leeds").style.display = "none";	
	document.getElementById("liverpool").style.display = "none";
	document.getElementById("londoncolindale").style.display = "none";	
	document.getElementById("londontooting").style.display = "none";	
	document.getElementById("london").style.display = "none";	
	document.getElementById("manchester").style.display = "none";
	document.getElementById("newcastle").style.display = "none";
	document.getElementById("oxfordheadington").style.display = "none";
	document.getElementById("oxfordsciencepark").style.display = "none";
	document.getElementById("plymouth").style.display = "none";	
	document.getElementById("sheffield").style.display = "none";
	document.getElementById("southampton").style.display = "none";	
	document.getElementById("wakefield").style.display = "none";
	document.getElementById("watford").style.display = "none";

}

function open_virtual_session()
{
	// code to place the pop up window in the centre of the screen.
	var width = 719;
	var height = 529;
	var screenX = screen.width
	var screenY = screen.height
	
	var adjust = 20;
	
	var x = (screenX - width)/2;
	var y = (screenY - height)/2 - adjust;

	var open_it = window.open(dotdotpath + "virtualsession/index.asp","newwin","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=719,height=529,top=" + y + ",left=" + x);
			
}

var questionhistory = new Array();

function nextstep(id,fromid)
{	
	if (questionhistory[questionhistory.length-1] != id)
	{
		questionhistory.push(id)
	}
	
	$.post(dotdotpath + "can-i-give-blood/donor-health-check/post.asp", {page: id, pagefrom: fromid }, function(data){
		var div = document.getElementById("questionbox");	
		var div2 = document.getElementById("progresscube");	
		
		div.innerHTML = data;
		if (id != 1)
		{
			div2.style.width = id * 10 + "px";
		} else {
			div2.style.width = "0px";
		}
		if (id == 30 || id == 31 || id == 32)
		{
			div2.style.width = "320px";			
		}
	});
	
}

function backstep()
{
	whichoneto = questionhistory.length - 2;
	whichone = questionhistory.length - 3;
	whichonefrom = questionhistory[whichone];
	
	questionhistory.pop();
	
	if (questionhistory[whichoneto] == null)
	{
		questionhistory[whichoneto] = 1	
	}
	
	if (whichonefrom == null)
	{
		whichonefrom = 1	
	}
	
	nextstep(questionhistory[whichoneto],whichonefrom);
}