var quotenum=0;
var anim=0;
var TimeToFade = 650.0;
var filearray = new Array("aboutus","wandringminstrels","shop","joinus","news","links","fundraising");
var file=0;
var memdivid=new Array();
var soundspans = new Array();
var soundspanshtml = new Array();
var tickarray=new Array(); //production-info title-0=key, 1=value
var ticksalesarray=new Array();
var tcaparray=new Array(); //ticket capacities
function onloadset()
{
	updatead("first");
	quotes(1);
	getPages();
	gettickets();
}
function updatead(x)
{	
	switch(x)
	{
		case "first":
			x = document.getElementById("adlist").getElementsByTagName("img")[0].src;
			updatead2(x);
			break;
		default:
			updatead2(x);
			_gaq.push(['_trackEvent', 'Adlist', x]);
			break;
	}
}

function updatead2(x)
{
	var y = x.replace(".jpg","info.jpg");
	y = y.replace("jpg","php");	
	getinfo(y);
	//document.getElementById("maininfo").src=y;
}
function getPages()
{
	xmlHttp4=GetXmlHttpObject();
	if (xmlHttp4==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url=filearray[file]+".php";
	url=url+"?sid="+Math.random();
	xmlHttp4.onreadystatechange=receivePages;
	xmlHttp4.open("GET",url,true);
	xmlHttp4.send(null);
}

function receivePages() 
{ 
	if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete")
	{ 			
		// populate
		var str = xmlHttp4.responseText;
		document.getElementById(filearray[file]).innerHTML=str;
		if(file<6)
		{
			file=file+1;
			getPages();
		}
		else
		{	
			aboutpress("about0");
			calendar("reset");
			filltickets();
		}
	}
}
function gettickets()
{
	xmlHttp5=GetXmlHttpObject();
	if (xmlHttp5==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="tickets/tickets.php";
	url=url+"?sid="+Math.random();
	xmlHttp5.onreadystatechange=receiveTickets;
	xmlHttp5.open("GET",url,true);
	xmlHttp5.send(null);
}

function receiveTickets() 
{ 
	if (xmlHttp5.readyState==4 || xmlHttp5.readyState=="complete")
	{ 			
		// populate
		var str = xmlHttp5.responseText;
		var myarray = str.split("^");
		var y=0;
		var i=0;
		var j=0;
		var k=0;
		var l=0;
		var prodlength = new Number(myarray[y]); //number of productions
		y++;
		var infolength; //number of info titles in each production
		var valuelength; //number of values in each info
		for(i=0;i<prodlength;i++)  //i=ticket type
		{
			tickarray[i] = new Array();
			tickarray[i][0] = new Array();
			tickarray[i][0][0] = myarray[y];
			y++;
			infolength = new Number(myarray[y]); //number of info titles
			//alert("length="+infolength);
			y++;
			for(j=1;j<infolength+1;j++)
			{
				tickarray[i][0][j] = myarray[y];
				y++;
				tickarray[i][j] = new Array();
				tickarray[i][j][0] = new Array();
				tickarray[i][j][1] = new Array();
				valuelength = myarray[y]; //number of value titles
				y++;
				for(k=0;k<valuelength;k++)
				{
					tickarray[i][j][0][k] = myarray[y];
					y++;
					tickarray[i][j][1][k] = myarray[y];
					y++;
				}
			}
		}
		for(i=0;i<prodlength;i++)  //i=ticket type
		{
			infolength = new Number(myarray[y]);
			y++;
			tcaparray[i]=new Array();
			for(j=0;j<infolength;j++)
			{
				tcaparray[i][j]=new Number(myarray[y]);
				y++;
			}
		}
	}
}
function getinfo(file)
{
	xmlHttp3=GetXmlHttpObject();
	if (xmlHttp3==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url=file;
	url=url+"?sid="+Math.random();
	xmlHttp3.onreadystatechange=receiveInfo;
	xmlHttp3.open("GET",url,true);
	xmlHttp3.send(null);
}

function receiveInfo() 
{ 
	if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete")
	{ 			
		// populate
		var str = xmlHttp3.responseText;
		document.getElementById("maininfo").innerHTML=str;
		var x = new Array();
		//getaudioclips(0);
	}
}

function menupress(x)
{
	window.scroll(0,0);
	document.getElementById("menu0").className="boldgray";
	document.getElementById("menu1").className="boldgray";
	document.getElementById("menu2").className="boldgray";
	document.getElementById("menu3").className="boldgray";
	document.getElementById("menu4").className="boldgray";
	document.getElementById("menu5").className="boldgray";
	document.getElementById("menu6").className="boldgray";
	document.getElementById("menu7").className="boldgray";	
	document.getElementById("menu8").className="boldgray";
	document.getElementById("menu9").className="boldgray";
	document.getElementById(x).className="bold";
	
	document.getElementById("home").className="hidden";
	document.getElementById("aboutus").className="hidden";
	document.getElementById("whatson").className="hidden";
	document.getElementById("wandringminstrels").className="hidden";
	document.getElementById("shop").className="hidden";
	document.getElementById("joinus").className="hidden";
	document.getElementById("news").className="hidden";
	document.getElementById("links").className="hidden";
	document.getElementById("fundraising").className="hidden";
	document.getElementById("members").className="hidden";
	var y;
	switch(x)
	{
		case "menu0":
			y="home";
			updatead("first");
			_gaq.push(['_trackEvent', 'Menu', 'Home']);
			break;
		case "menu1":
			y="aboutus";
			_gaq.push(['_trackEvent', 'Menu', 'About Us']);
			break;
		case "menu2":
			y="whatson";
			listinfo();
			_gaq.push(['_trackEvent', 'Menu', 'Whats On']);
			break;
		case "menu3":
			y="wandringminstrels";
			listinfo();
			_gaq.push(['_trackEvent', 'Menu', 'Wandring Minstrels']);
			break;
		case "menu4":
			y="shop";
			_gaq.push(['_trackEvent', 'Menu', 'Shop']);
			break;
		case "menu5":
			y="joinus";
			_gaq.push(['_trackEvent', 'Menu', 'Join Us']);
			break;
		case "menu6":
			y="news";
			_gaq.push(['_trackEvent', 'Menu', 'News']);
			break;
		case "menu7":
			y="links";
			_gaq.push(['_trackEvent', 'Menu', 'Links']);
			break;
		case "menu8":
			y="fundraising";
			_gaq.push(['_trackEvent', 'Menu', 'Fundraising']);
			break;
		case "menu9":
			y="members";
			_gaq.push(['_trackEvent', 'Menu', 'Members']);
			break;
		default:
			break;		
	}
	document.getElementById(y).className="";
}

function aboutpress(x)
{	
	//document.getElementById("about0").className="";
	//document.getElementById("about1").className="";
	//document.getElementById("about2").className="";
	//document.getElementById("about3").className="";
	//document.getElementById("about4").className="";	
	//document.getElementById(x).className="bold";//

	document.getElementById("about0sp").style.backgroundImage="url(img/ppmgfade.jpg)";
	document.getElementById("about1sp").style.backgroundImage="url(img/mwfade.jpg)";
	document.getElementById("about2sp").style.backgroundImage="url(img/rudfade.jpg)";
	document.getElementById("about3sp").style.backgroundImage="url(img/pinfade.jpg)";
	document.getElementById("about4sp").style.backgroundImage="url(img/gilfade.jpg)";

	document.getElementById("about0tab").className="abtabs";
	document.getElementById("about1tab").className="abtabs";
	document.getElementById("about2tab").className="abtabs";
	document.getElementById("about3tab").className="abtabs";
	document.getElementById("about4tab").className="abtabs";
	
	document.getElementById("about").className="hidden";
	document.getElementById("history").className="hidden";
	document.getElementById("gallery").className="hidden";
	document.getElementById("past").className="hidden";
	document.getElementById("gilbert").className="hidden";
	var y;
	x = x.substr(0,6);
	switch(x)
	{
		case "about0":
			y="about";
			//updatead("first");
			document.getElementById("about0sp").style.backgroundImage="url(img/ppmg.jpg)";
			document.getElementById("about0tab").className="abtabssel";
			_gaq.push(['_trackEvent', 'About', 'The Fellowship']);
			break;
		case "about1":
			y="history";
			document.getElementById("about1sp").style.backgroundImage="url(img/mw.jpg)";
			document.getElementById("about1tab").className="abtabssel";
			_gaq.push(['_trackEvent', 'About', 'History']);
			break;
		case "about2":
			y="gallery";
			document.getElementById("about2sp").style.backgroundImage="url(img/rud.jpg)";
			document.getElementById("about2tab").className="abtabssel";
			_gaq.push(['_trackEvent', 'About', 'Gallery']);
			break;
		case "about3":
			y="past";
			document.getElementById("about3sp").style.backgroundImage="url(img/pin.jpg)";
			document.getElementById("about3tab").className="abtabssel";
			_gaq.push(['_trackEvent', 'About', 'Past Productions']);
			break;
		case "about4":
			y="gilbert";
			document.getElementById("about4sp").style.backgroundImage="url(img/gil.jpg)";
			document.getElementById("about4tab").className="abtabssel";
			_gaq.push(['_trackEvent', 'About', 'Gilbert&Sullivan']);
			break;
		default:
			break;		
	}
	document.getElementById(y).className="";
}
function quotes(x)
{
	var str;
	var num;
	if(x!=999)
	{
	if(x==0)
	{
		num=x;
		quotenum=x;
	}
	else
	{
		if(quotenum>14)
			quotenum=1;
		num=quotenum;
	}
	}
	else
	{
		num=quotenum;
		quotenum++;
	}
	str=getquotes(num);
}

function getquotes(num)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="quotes.php";
	url=url+"?num="+num;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
 	{
		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}
	catch (e)
 	{
 		// Internet Explorer
 		try
 		{
 			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
 		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 			
		// populate
		var str = xmlHttp.responseText;
		if(quotenum==0)
			str=document.getElementById("quotes").innerHTML;
		document.getElementById("quotes").innerHTML=str;
		if(anim==1)
		{
			fade("quotes");
			setTimeout("quotes(999)",5000);
			anim=0;
		}
		else
		{
			if(quotenum==0)
				setTimeout("quotes(999)",5000);
			else
			{
				anim++;
				fade("quotes");
				setTimeout("quotes(666)",1000);
			}
		}
	}
}
function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null 
        || element.style.opacity == '' 
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
    
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}
function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = ' 
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
  
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

function calendar(id)
{
	var d = new Date();
	var month=new Array(12);
	month[0]="January";
	month[1]="February";	
	month[2]="March";	
	month[3]="April";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="August";
	month[8]="September";
	month[9]="October";
	month[10]="November";
	month[11]="December";
	var txt = document.getElementById("calmon").innerHTML;
	var mtxt = txt.substr(0,txt.length-5); // gets the month txt
	var ytxt = txt.substr(txt.length-4); // gets the month txt
	var i = d.getMonth(); //current month index;
	var y = d.getFullYear(); //current year;
	var currenttxt = month[i]+" "+y;
	var x; 
	for(x=0;x<12;x++) //find the month currently displayed
	{
		if(month[x]==mtxt)
			i=x; //reset the month index to suit if required			
	}
	switch(id)
	{
		case "reset":
			i=i;
			break;
		case "calbck":
			i=i-1;
			y=ytxt;
			break;
		case "calfwd":
			i=i+1;
			y=ytxt;
			break;
		default:
			break;
	}
	if(i==12)
	{
		i=0;
		y++;
	}
	if(i==-1)
	{
		i=11;
		y=y-1;
	}
	if((y==d.getFullYear()) || (y==d.getFullYear()-1 && i>d.getMonth()) || (y==d.getFullYear()+1 && i<d.getMonth()))
	{
		var m = month[i]; //current month txt for initial setting
		var usetxt = m+" "+y;
		document.getElementById("calmon").innerHTML=usetxt;
		document.getElementById("calcontent").innerHTML="...Loading...";
		fillcalendar(currenttxt,usetxt,d.getDate());
	}
}

function fillcalendar(currentdate,selectdate,currentday)  //sends inputdata to the server for calculation
{
	xmlHttp2=GetXmlHttpObject();
	if(xmlHttp2==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="calendar.php";
	url=url+"?selectdate="+selectdate;
	url=url+"&currentdate="+currentdate;
	url=url+"&currentday="+currentday;
	url=url+"&sid="+Math.random();
	xmlHttp2.onreadystatechange=receiveCalendar;
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
}

var datetxt=new Array();
var basictxt=new Array();
var expanddatetxt=new Array();
var expandbasictxt=new Array();
var expandwmbasictxt=new Array();
var expandexpandtxt=new Array();
var expandtxt=new Array();

function receiveCalendar() 
{ 
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
	{ 			
		var calarray = xmlHttp2.responseText;
		var myarray = calarray.split("^");
		var y=0;
		var callength = myarray[y];
		y++;
		var expandlength = myarray[y];
		y++;
		var x=0;
		var caltxt="";
		while(x<callength)
		{
			datetxt[x] = '<span class="caldate">'+myarray[y]+'</span>';
			x++;
			y++;
		}
		x=0;
		while(x<callength)
		{
			basictxt[x] = '<span class="calinfo">'+myarray[y]+'</span>';
			caltxt=caltxt+datetxt[x]+basictxt[x];
			x++;
			y++;
		}
		x=0;
		var whatsontxt="";
		while(x<expandlength)
		{
			expanddatetxt[x] = '<span class="whatsondate">'+myarray[y]+'</span>';
			x++;
			y++;
		}
		x=0;
		while(x<expandlength)
		{
			expandbasictxt[x] = '<div class="whatsoninfo"><span class="whatsoninfotxt">'+myarray[y]+'</span><span id='+x+' class="moreinfo" onclick="moreinfo(id,\'scroll\')">More info</span></div>';
			expandwmbasictxt[x] = '<div class="whatsoninfo"><span class="whatsoninfotxt">'+myarray[y]+'</span><span id='+x+' class="moreinfo" onclick="moreinfo(id)">More info</span></div>';
			x++;
			y++;
		}
		x=0;
		while(x<expandlength)
		{
			expandexpandtxt[x] = '<span class="whatsonexpand">'+myarray[y]+'</span>';
			whatsontxt=whatsontxt+expanddatetxt[x]+expandbasictxt[x];
			expandtxt[x]=expanddatetxt[x]+expandexpandtxt[x];
			x++;
			y++;
		}
		x=0;
		var wmconcertstxt="";
		while(x<expanddatetxt.length)
		{
			var str=expandbasictxt[x];
			if(str.indexOf("Wand'ring")!=-1 || str.indexOf("wand'ring")!=-1)
			{
				wmconcertstxt=wmconcertstxt+expanddatetxt[x]+expandwmbasictxt[x];
			}
			x++;
		}
		document.getElementById("calcontent").innerHTML=caltxt;
		document.getElementById("whatsonbasic").innerHTML=whatsontxt;
		document.getElementById("wmconcerts").innerHTML=wmconcertstxt;				
	}
}
function moreinfo(id,scroll)
{
	if(scroll=="scroll")
		window.scroll(0,0);
	document.getElementById("whatsonbasic").className="hidden";
	document.getElementById("whatsonexpand").className="";	
	document.getElementById("whatsonexpand").innerHTML='<span class="listinfo" onclick="listinfo(\'scroll\')">Back to What\'s On list</span>'+expandtxt[id];
	document.getElementById("wmconcerts").className="hidden";
	document.getElementById("wmexpand").className="";
	document.getElementById("wmexpand").innerHTML='<span class="listinfo" onclick="listinfo()">Back to concerts list</span>'+expandtxt[id];	
}
function listinfo(scroll)
{
	if(scroll=="scroll")
		window.scroll(0,0);
	document.getElementById("whatsonbasic").className="";
	document.getElementById("whatsonexpand").className="hidden";
	document.getElementById("wmconcerts").className="";
	document.getElementById("wmexpand").className="hidden";	
}
function vpbiogon(id)
{
	document.getElementById("vpbiog").className="";
	document.getElementById("vpbiog").style.zIndex=2;
	getbiog(id);
}
function vpbiogoff()
{
	document.getElementById("vpbiog").className="hidden";
	document.getElementById("vpbiog").style.zIndex=-1;
	var txt="...Loading...";
	document.getElementById("vpbiog").innerHTML=txt;
}
function getbiog(id)  //sends inputdata to the server for calculation
{
	xmlHttp3=GetXmlHttpObject();
	if(xmlHttp3==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="vpbiogs.php";
	url=url+"?name="+id;
	url=url+"&sid="+Math.random();
	xmlHttp3.onreadystatechange=receiveBiog;
	xmlHttp3.open("GET",url,true);
	xmlHttp3.send(null);
}
function receiveBiog() 
{ 
	if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete")
	{ 			
		var txt = xmlHttp3.responseText;
		document.getElementById("vpbiog").innerHTML=txt;				
	}
}
function caston(id)
{
	document.getElementById("cast").className="";
	document.getElementById("cast").style.zIndex=2;
	getcast(id);
}
function castoff()
{
	document.getElementById("cast").className="hidden";
	document.getElementById("cast").style.zIndex=-1;
	var txt="...Loading...";
	document.getElementById("cast").innerHTML=txt;
}
function getcast(id)  //sends inputdata to the server for calculation
{
	xmlHttp3=GetXmlHttpObject();
	if(xmlHttp3==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="cast.php";
	url=url+"?name="+encodeURIComponent(id);
	url=url+"&sid="+Math.random();
	xmlHttp3.onreadystatechange=receiveCast;
	xmlHttp3.open("GET",url,true);
	xmlHttp3.send(null);
}
function receiveCast() 
{ 
	if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete")
	{ 			
		var txt = xmlHttp3.responseText;
		document.getElementById("cast").innerHTML=txt;				
	}
}

function pwordenter()
{
	if(event.keyCode==13)
		pword();
}


function pword()
{
	var pword = document.getElementById("pword").value;
	pword = pword.toLowerCase();
	getpword(pword);
}

function getpword(pword)
{
	xmlHttp4=GetXmlHttpObject();
	if(xmlHttp4==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="pword.php";
	url=url+"?pword="+pword;
	url=url+"&sid="+Math.random();
	xmlHttp4.onreadystatechange=receivePword;
	xmlHttp4.open("GET",url,true);
	xmlHttp4.send(null);
}

function receivePword() 
{ 
	if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete")
	{ 			
		var txt = xmlHttp4.responseText;
		if(txt=="yes")
		{
			getmemberspage();
			document.getElementById("pfail").className="";
			document.getElementById("pfail").innerHTML="Password correct, please wait while the page loads...<br /><br />This page contains many large files, these are now being prepared for playback...<br /><br />If your computer and/or internet connection is slow, particularly if you are using a dial-up or non-fibre optic broadband (BT copper wire etc) this can take a while...<br /><br />We are working towards enhancing this page for the minority with a slower connection...<br /><br />Please be patient for a little longer...";
		}
		else
		{
			document.getElementById("pfail").className="";	
			document.getElementById("pfail").innerHTML="Incorrect password please try again or contact us for assistance.";
			_gaq.push(['_trackEvent', 'Members', 'Incorrect Password']);	
		}		
	}
}

function getmemberspage()
{
	xmlHttp4=GetXmlHttpObject();
	if(xmlHttp4==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="members.php";
	url=url+"?sid="+Math.random();
	xmlHttp4.onreadystatechange=receiveMemberspage;
	xmlHttp4.open("GET",url,true);
	xmlHttp4.send(null);
}

function receiveMemberspage() 
{ 
	if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete")
	{ 			
		var txt = xmlHttp4.responseText;
		document.getElementById("mpage").innerHTML=txt;
		_gaq.push(['_trackEvent', 'Members', 'Correct Password']);				
	}
}

function getmembersdiv(id)
{
	memshowhide(id);
	memdivid['current']=id;
	if(!memdivid[id])
	{
		memdivid[id]="temp";
		xmlHttp5=GetXmlHttpObject();
		if(xmlHttp5==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url="members/"+id+".php";
		url=url+"?sid="+Math.random();
		xmlHttp5.onreadystatechange=receiveMembersdiv;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
	}
	else
		document.getElementById(id).innerHTML=memdivid[id];
}

function receiveMembersdiv() 
{ 
	if (xmlHttp5.readyState==4 || xmlHttp5.readyState=="complete")
	{ 			
		var txt = xmlHttp5.responseText;
		memdivid[memdivid['current']]=txt;
		document.getElementById(memdivid['current']).innerHTML=txt;
		//_gaq.push(['_trackEvent', 'Members', 'Correct Password']);				
	}
	//document.getElementById(memdivid).className="";
}

function getaudioclips(index)
{
	if(document.getElementById("soundtrack"))
	{
		alert("index="+index);
		if(index==0)
		{
			soundspans = document.getElementById("soundtrack").getElementsByTagName("span");
			soundspanshtml = new Array();
		}
		if(index<soundspans.length)
		{
			id=soundspans[index].id;
			txt2=soundspans[index].innerHTML;
			alert("-----"+txt2+id+"------");
			txt=txt2.split("^");
			title=txt[0];
			subtit=txt[1];
			file=txt[2];
			getaudio(file,title,subtit,id,index);
		}
		else
			fillsoundspans();
	}
}

function fillsoundspans()
{
	var x = soundspanshtml.length;
	alert(x);
	document.getElementById("soundtrack").innerHTML="";
	for(i=0;i<x;i++)
	{
		var d = document.getElementById("soundtrack").innerHTML;
		document.getElementById("soundtrack").innerHTML=d+soundspanshtml[i]+'<br /><br />';
		alert(soundspanshtml[i]);
		//soundspans[i].innerHTML=soundspanshtml[i];
	}
}

function getaudio(file,title,subtit,id,index)
{
	alert("---"+file+title+subtit+id+"===");
	xmlHttp4=GetXmlHttpObject();
	if(xmlHttp4==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="audioclip.php";
	url=url+"?file="+file;
	url=url+"&title="+title;
	url=url+"&subtit="+subtit;
	url=url+"&id="+id;
	url=url+"&index="+index;
	url=url+"&sid="+Math.random();
	alert("url = "+url);
	xmlHttp4.onreadystatechange=receiveAudio;
	xmlHttp4.open("GET",url,true);
	xmlHttp4.send(null);
}

function receiveAudio() 
{ 
	if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete")
	{ 			
		var txt = xmlHttp4.responseText;
		alert(txt);
		var txtarray = txt.split("^");
		if(txtarray[2]=="no")
			document.getElementById(txtarray[0]).innerHTML=txtarray[1];
		else
		{
			var num = new Number(txtarray[2]);
			num = num-1;
			soundspanshtml[num]=txtarray[1];
			getaudioclips(txtarray[2]);
		}				
	}
}

function tracking(event,label)
{
	_gaq.push(['_trackEvent', event, label]);
}

var show="";
var clipid="";
function showvoice(id,value)
{
	id = id.substr(4);
	clipid=id;
	x = document.getElementById(id).getElementsByTagName("div");
	if(x.length>0)
	{
		for(y=0;y<x.length;y++)
		{
			x[y].className="hidden";
		}
	}
	id = "voice"+id;
	document.getElementById(id).className=""; //show voice type selection
	document.getElementById(id).selectedIndex=0; //show voice type selection
	show=value;
}

function showclips(id,value)
{
	id = id.substr(5);
	x = document.getElementById(id).getElementsByTagName("div");
	if(x.length>0)
	{
		for(y=0;y<x.length;y++)
		{
			x[y].className="hidden";
		}
	}
	if(id==clipid)
	{
		if(value!="none")
		{	
			document.getElementById(id).className="";
			id = show+value+id;
			document.getElementById(id).className="";
			x = document.getElementById(id).getElementsByTagName("div");
			if(x.length>0)
			{
				for(y=0;y<x.length;y++)
				{
					x[y].className="";
				}
			}
		}
	}
	else
	{
		sid = "show"+id;
		document.getElementById(sid).selectedIndex=0;
		vid = "voice"+id;
		document.getElementById(vid).selectedIndex=0;
		document.getElementById(vid).className="hidden";
	}
}

function memshowhide(id)
{
	if(document.getElementById(id).className=="hidden")
	{
		document.getElementById(id).className="";
		document.getElementById(id).innerHTML="Loading content, please wait...";
	}
	else
		document.getElementById(id).className="hidden";
		
}

function checkcap(prod,perf,quan)
{
	var quan = new Number(quan);
	var answer = false;
	if(tcaparray[prod][perf]>=quan)
		answer = true;
	else
		if(document.getElementById(tickarray[prod][1][1][1]+"quantxt"))
			document.getElementById(tickarray[prod][1][1][1]+"quantxt").className="";
	return answer;
}

function filltickets()
{
	var prodlength = tickarray.length;
	var infolength;
	var preflength;
	var reqlength;
	var x;
	var y;
	var z;
	var codetitle;
	var divhtml = document.getElementById("ticketdiv").innerHTML;
	divhtml="";
	for(x=0;x<prodlength;x++)
	{
		codetitle="";
		infolength=0;
		if(tickarray[x][1][0][1]=="codetitle")
		{
			codetitle=tickarray[x][1][1][1];
			divhtml=divhtml+'<div class="shopitem"><div class="shoptopbot">&nbsp;<div class="shoptitle">PRODUCTION TICKETS - <b>';
			divhtml=divhtml+tickarray[x][0][0];
			divhtml=divhtml+'</b></div><div class="shopcost">';
			divhtml=divhtml+tickarray[x][1][1][0];
			divhtml=divhtml+'</div></div><span class="cddesc">The Plymouth <b>Gilbert</b>&amp;<b>Sullivan</b> Fellowship presents ';
			divhtml=divhtml+tickarray[x][0][0];
			divhtml=divhtml+'.</span><span class="imgsmallright">Telephone Bookings 01752 40 49 71</span><div class="shopbox"><img alt="" class="cd" src="img/';
			divhtml=divhtml+tickarray[x][1][1][2];
			divhtml=divhtml+'"/><div class="shopq"><br /><div class="shoplist"><div class="shopq">Performance<br /><br /><span id="';
			divhtml=divhtml+codetitle+"ttype";
			divhtml=divhtml+'" class="ttype">Ticket Type<br /><br />Quantity<br /><br />Seating<br /><span class="comtit"><br />Requests:<br />';
			reqlength=tickarray[x][4][1].length;
			for(y=0;y<reqlength;y++)
			{
				divhtml=divhtml+tickarray[x][4][1][y]+' <input type="checkbox" disabled="disabled" id="'+codetitle+'request'+y+'" value="'+tickarray[x][4][1][y]+'" /><br />';
			}
			divhtml=divhtml+'</span></span></div><div class="shopq"><select id="';
			divhtml=divhtml+codetitle+"ticketdate";
			divhtml=divhtml+'" class="ticketdate" onchange="tickdate(id)"><option value="first">Please select a performance...</option>';
			infolength=tickarray[x][0].length;
			//alert("..."+infolength);
			for(y=6;y<infolength;y++)
			{
				if(checkcap(x,y-6,1))
					divhtml=divhtml+'<option value="'+tickarray[x][0][y]+'">'+tickarray[x][0][y]+'</option>';
			}
			divhtml=divhtml+'</select><br /><br /><select id="';
			divhtml=divhtml+codetitle+"ticketprice";
			divhtml=divhtml+'" class="ticketprice" disabled="disabled" onchange="tickprice(id)"><option value="ticket">Please select a performance...</option>';
			divhtml=divhtml+'</select><br /><br /><input id="';
			divhtml=divhtml+codetitle+"quantity";
			divhtml=divhtml+'" class="quantity" disabled="disabled" type="num" value="1" size="4" onkeyup="tickquan(id,value)" /><span id="';
			divhtml=divhtml+codetitle+"quantxt";
			divhtml=divhtml+'" class="hidden">..Insufficient seating</span><br /><br /><select id="';
			divhtml=divhtml+codetitle+"preference";
			divhtml=divhtml+'" class="preference" disabled="disabled" onchange="tickpref(id)"><option value="pref">Please select a seating preference...</option>';
			preflength=tickarray[x][3][1].length;
			for(y=0;y<preflength;y++)
			{
				divhtml=divhtml+'<option value="'+tickarray[x][3][1][y]+'">'+tickarray[x][3][1][y]+'</option>';
			}
			divhtml=divhtml+'</select><br /><br /></div><div>';
			divhtml=divhtml+'<span id="';
			divhtml=divhtml+codetitle+"addbut";
			divhtml=divhtml+'" class="buttonhid" onclick="tickadd(id)">Add to ticket list</span></div></div>';
			divhtml=divhtml+'<div class="clearboth"><span class="comtit">';
			feeslength = tickarray[x][5][1].length;
			if(feeslength>0)
			{
				divhtml=divhtml+'<br />Additional fees:';
				for(z=0;z<feeslength;z++)
				{
					divhtml=divhtml+'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
					if(tickarray[x][5][1][z]<1)
					{
						divhtml=divhtml+100*tickarray[x][5][1][z]+'p/ticket';
					}	
					else
					{
						divhtml=divhtml+'£'+tickarray[x][5][1][z]+'/ticket';
					}
					divhtml=divhtml+" "+tickarray[x][5][0][z];
				}
			}
			disclength = tickarray[x][2][1].length;
			var amount;
			if(disclength>0)
			{
				divhtml=divhtml+'<br />Group discounts available:';
				for(z=0;z<disclength;z++)
				{
					divhtml=divhtml+'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
					if(tickarray[x][2][1][z]<1)
					{
						divhtml=divhtml+100*tickarray[x][2][1][z]+'p/ticket';
					}	
					else
					{
						divhtml=divhtml+'£'+tickarray[x][2][1][z]+'/ticket';
					}
					divhtml=divhtml+"   ("+tickarray[x][2][0][z]+"+ per performance)";
				}
			}
			divhtml=divhtml+'</span></div>';
			divhtml=divhtml+'</div><div class="mytickets"><div class="ticktit">Ticket List</div><div class="tickcont" id="';
			divhtml=divhtml+codetitle+"ticketlist";
			divhtml=divhtml+'"><br /><br /><br />...create your ticket list...</div><div class="tickfee"><span class="comtit" id="';
			divhtml=divhtml+codetitle+"ticketfees";
			divhtml=divhtml+'"><hr />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;</span></div><span class="comtit"><hr />We will endeavour to accommodate all seating preferences and other requests where possible, otherwise you will be contacted and provided with an alternative.  Refunds are not available once payment has been accepted, please <a href="mailto:secretary@plymouthgilbertandsullivan.com?Subject=Query regarding My Fair Lady tickets:">contact us</a> prior to booking if in doubt.</span></div></div><div class="shopbox">&nbsp;</div></div>';
		}
	}
	document.getElementById("ticketdiv").innerHTML = divhtml;
}
function getprodindex(id)
{
	var prodlength = tickarray.length;
	var x;
	var prodindex;
	for(x=0;x<prodlength;x++)
	{
		if(tickarray[x][1][1][1]==id)
			prodindex=x;
	}
	return prodindex;
}
function getperfindex(prodindex,value)
{
	var infolength=tickarray[prodindex][0].length;
	var y;
	var perfindex;
	for(y=6;y<infolength;y++)
	{
		if(tickarray[prodindex][0][y]==value)
			perfindex=y;
	}
	return perfindex;
}
function tickdate(id) //,value)
{
	var select = document.getElementById(id);
	var value= select.options[select.selectedIndex].value;
	var length=id.length;
	var id=id.substr(0,length-10);
	if(value!="first")
	{
		document.getElementById(id+"ttype").style.color="black";
		document.getElementById(id+"ticketprice").disabled="";
		document.getElementById(id+"quantity").disabled="";
		document.getElementById(id+"ticketprice").options.length=0;
		var prodindex=getprodindex(id);
		var perfindex=getperfindex(prodindex,value);
		var valuelength=tickarray[prodindex][perfindex][1].length;
		var z;
		document.getElementById(id+"ticketprice").options[0]=new Option("Please select a ticket type...", "ticket", true, true);
		for(z=1;z<valuelength;z++)
		{
			document.getElementById(id+"ticketprice").options[z]=new Option("£"+tickarray[prodindex][perfindex][1][z]+" - "+tickarray[prodindex][perfindex][0][z], tickarray[prodindex][perfindex][0][z], false, false);
		}
		document.getElementById(id+"ticketprice").selectedIndex = 0;	
		document.getElementById(id+"preference").selectedIndex = 0;	
	}
	else
	{
		document.getElementById(id+"ttype").style.color="gray";
		document.getElementById(id+"ticketprice").disabled="disabled";
		document.getElementById(id+"quantity").disabled="disabled";
		document.getElementById(id+"preference").disabled="disabled";
		document.getElementById(id+"ticketprice").selectedIndex = 0;	
		document.getElementById(id+"preference").selectedIndex = 0;
		document.getElementById(id+"addbut").className="buttonhid";
		var prodindex=getprodindex(id);
		var reqlength=tickarray[prodindex][4][1].length;
		for(y=0;y<reqlength;y++)
		{
			document.getElementById(id+"request"+y).disabled="disabled";
			document.getElementById(id+"request"+y).checked="";
		}		
	}
	document.getElementById(id+"quantxt").className="hidden";
}
function tickprice(id)
{
	var select = document.getElementById(id);
	var value= select.options[select.selectedIndex].value;
	var length=id.length;
	var id=id.substr(0,length-11);
	var prodindex=getprodindex(id);
	var reqlength=tickarray[prodindex][4][1].length;
	if(value!="ticket")
	{
		var quan = document.getElementById(id+"quantity").value;
		if(isint(quan)&&quan>0)
		{
			document.getElementById(id+"preference").disabled="";	
			document.getElementById(id+"preference").selectedIndex = 0;
			for(y=0;y<reqlength;y++)
			{
				document.getElementById(id+"request"+y).disabled="";
			}
		}		
	}
	else
	{
		document.getElementById(id+"addbut").className="buttonhid";
		document.getElementById(id+"preference").disabled="disabled";
		document.getElementById(id+"preference").selectedIndex = 0;	
		for(y=0;y<reqlength;y++)
		{
			document.getElementById(id+"request"+y).disabled="disabled";
			document.getElementById(id+"request"+y).checked="";
		}	
	}	
}
function isint(value)
{
	if((parseFloat(value)==parseInt(value))&&!isNaN(value))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function tickquan(id,value)
{
	var length=id.length;
	var id=id.substr(0,length-8);
	if(isint(value)&&value>0)
	{
		if(document.getElementById(id+"ticketprice").options[document.getElementById(id+"ticketprice").selectedIndex].text!="Please select a ticket type...")
		{
			document.getElementById(id+"preference").disabled="";		
		}
	}
	else
	{
		document.getElementById(id+"preference").disabled="disabled";				
	}
	
	document.getElementById(id+"quantxt").className="hidden";
	var prodindex=getprodindex(id);
	var perfindex=getperfindex(prodindex,document.getElementById(id+"ticketdate").options[document.getElementById(id+"ticketdate").selectedIndex].text);
	perfindex=perfindex-6;
	if(!checkcap(prodindex,perfindex,value))
	{
		document.getElementById(id+"addbut").className="buttonhid";
		document.getElementById(id+"preference").disabled="disabled";
		if(isint(value)&&value>0)
			document.getElementById(id+"quantxt").className="";						
	}
	else
	{
		if(document.getElementById(id+"preference").options[document.getElementById(id+"preference").selectedIndex].text!="Please select a seating preference...")
		{
			document.getElementById(id+"addbut").className="button";
		}
	}					
}
function tickpref(id)
{
	var select = document.getElementById(id);
	var value= select.options[select.selectedIndex].value;
	var length=id.length;
	var id=id.substr(0,length-10);
	if(value!="pref")
	{
		if(document.getElementById(id+"preference").options[document.getElementById(id+"preference").selectedIndex].text!="Please select a seating preference...")
		{
			document.getElementById(id+"addbut").className="button";
		}		
	}
	else
	{
		document.getElementById(id+"addbut").className="buttonhid";		
	}	
}
var ticketlist="";
var tickcopy=false;
var typecopy=false;
var perfcopy=false;
var salesindex;
var salesperfindex;
var salestickindex;
var saleslength;
var salesperflength;
function tickadd(id)
{	
	ticketlist="";
	var length=id.length;
	var id=id.substr(0,length-6);
	if(document.getElementById(id+"addbut").className=="button")
	{
	var prodindex=getprodindex(id);
	var perfindex=getperfindex(prodindex,document.getElementById(id+"ticketdate").options[document.getElementById(id+"ticketdate").selectedIndex].text);
	perfindex=perfindex-6;
	var reqlength=tickarray[prodindex][4][1].length;
	if(document.getElementById(id+"ticketprice").options[document.getElementById(id+"ticketprice").selectedIndex].text!="Please select a ticket type...")
	{
		perfcopy=false;	
		saleslength = ticksalesarray.length;
		if(saleslength>0)
		{
			for(x=0;x<saleslength;x++)
			{
				if(ticksalesarray[x][0]==id)
				{
					perfcopy=true;
					typecopy=false;
					salesindex=x;
					salesperflength = ticksalesarray[salesindex].length;
					for(y=1;y<salesperflength;y++)
					{
						if(ticksalesarray[salesindex][y][0][0]==document.getElementById(id+"ticketdate").options[document.getElementById(id+"ticketdate").selectedIndex].text)
						{	
							typecopy=true;
							tickcopy=false;
							salesperfindex=y;
							if(checkcap(prodindex,perfindex,ticksalesarray[salesindex][salesperfindex][0][1]+new Number(document.getElementById(id+"quantity").value)))
							{
							salesticklength = ticksalesarray[salesindex][salesperfindex].length;
							for(z=1;z<salesticklength;z++)
							{
								if(ticksalesarray[salesindex][salesperfindex][z][1]==document.getElementById(id+"ticketprice").options[document.getElementById(id+"ticketprice").selectedIndex].text)
								{
									if(ticksalesarray[salesindex][salesperfindex][z][2]==document.getElementById(id+"preference").options[document.getElementById(id+"preference").selectedIndex].text)
									{
										salestickindex=z;
										ticksalesarray[salesindex][salesperfindex][salestickindex][0]=ticksalesarray[salesindex][salesperfindex][salestickindex][0]+new Number(document.getElementById(id+"quantity").value);
										ticksalesarray[salesindex][salesperfindex][0][1]=ticksalesarray[salesindex][salesperfindex][0][1]+new Number(document.getElementById(id+"quantity").value);
										ticksalesarray[salesindex][salesperfindex][salestickindex][2]=document.getElementById(id+"preference").options[document.getElementById(id+"preference").selectedIndex].text;
										ticksalesarray[salesindex][salesperfindex][salestickindex][3]=new Array();
										var x=0;
										for(y=0;y<reqlength;y++)
										{
											if(document.getElementById(id+"request"+y).checked)
											{
												ticksalesarray[salesindex][salesperfindex][salestickindex][3][x]=tickarray[prodindex][4][1][y];
												x++;
											}
										}	
										if(ticksalesarray[salesindex][salesperfindex][salestickindex][3].length==0)
											ticksalesarray[salesindex][salesperfindex][salestickindex][3][0]="none";
										tickcopy=true;
									}
								}	
							}
							if(tickcopy==false)
							{
								salestickindex=salesticklength;
								ticksalesarray[salesindex][salesperfindex][salestickindex]=new Array();
								ticksalesarray[salesindex][salesperfindex][salestickindex][0]=new Number(document.getElementById(id+"quantity").value);
								ticksalesarray[salesindex][salesperfindex][salestickindex][1]=document.getElementById(id+"ticketprice").options[document.getElementById(id+"ticketprice").selectedIndex].text;
								ticksalesarray[salesindex][salesperfindex][salestickindex][2]=document.getElementById(id+"preference").options[document.getElementById(id+"preference").selectedIndex].text;
								ticksalesarray[salesindex][salesperfindex][salestickindex][3]=new Array();
								var x=0;
								for(y=0;y<reqlength;y++)
								{
									if(document.getElementById(id+"request"+y).checked)
									{
										ticksalesarray[salesindex][salesperfindex][salestickindex][3][x]=tickarray[prodindex][4][1][y];
										x++;
									}
								}
								if(ticksalesarray[salesindex][salesperfindex][salestickindex][3].length==0)
									ticksalesarray[salesindex][salesperfindex][salestickindex][3][0]="none";
								ticksalesarray[salesindex][salesperfindex][0][1]=ticksalesarray[salesindex][salesperfindex][0][1]+new Number(document.getElementById(id+"quantity").value);
							}
							}
							break;
							break;	
						}	
					}
					if(typecopy==false)
					{
						salesperfindex=salesperflength;
						if(checkcap(prodindex,perfindex,new Number(document.getElementById(id+"quantity").value)))
						{
						salestickindex = 1;
						ticksalesarray[salesindex][salesperfindex]=new Array();
						ticksalesarray[salesindex][salesperfindex][0]=new Array();
						ticksalesarray[salesindex][salesperfindex][0][0]=document.getElementById(id+"ticketdate").options[document.getElementById(id+"ticketdate").selectedIndex].text;
						ticksalesarray[salesindex][salesperfindex][0][1]=new Number(document.getElementById(id+"quantity").value);
						ticksalesarray[salesindex][salesperfindex][salestickindex]=new Array();
						ticksalesarray[salesindex][salesperfindex][salestickindex][0]=new Number(document.getElementById(id+"quantity").value);
						ticksalesarray[salesindex][salesperfindex][salestickindex][1]=document.getElementById(id+"ticketprice").options[document.getElementById(id+"ticketprice").selectedIndex].text;
						ticksalesarray[salesindex][salesperfindex][salestickindex][2]=document.getElementById(id+"preference").options[document.getElementById(id+"preference").selectedIndex].text;
						ticksalesarray[salesindex][salesperfindex][salestickindex][3]=new Array();
						var x=0;
						for(y=0;y<reqlength;y++)
						{
							if(document.getElementById(id+"request"+y).checked)
							{
								ticksalesarray[salesindex][salesperfindex][salestickindex][3][x]=tickarray[prodindex][4][1][y];
								x++;
							}
						}
						if(ticksalesarray[salesindex][salesperfindex][salestickindex][3].length==0)
							ticksalesarray[salesindex][salesperfindex][salestickindex][3][0]="none";
						}
					}
					break;
				}
			}
			if(perfcopy==false)
			{
				salesindex=saleslength;
				ticksalesarray[salesindex]=new Array();
				ticksalesarray[salesindex][0]=id;
				salesperfindex = 1;
				if(checkcap(prodindex,perfindex,new Number(document.getElementById(id+"quantity").value)))
				{
				salestickindex = 1;
				ticksalesarray[salesindex][salesperfindex]=new Array();
				ticksalesarray[salesindex][salesperfindex][0]=new Array();
				ticksalesarray[salesindex][salesperfindex][0][0]=document.getElementById(id+"ticketdate").options[document.getElementById(id+"ticketdate").selectedIndex].text;
				ticksalesarray[salesindex][salesperfindex][0][1]=new Number(document.getElementById(id+"quantity").value);
				ticksalesarray[salesindex][salesperfindex][salestickindex]=new Array();
				ticksalesarray[salesindex][salesperfindex][salestickindex][0]=new Number(document.getElementById(id+"quantity").value);
				ticksalesarray[salesindex][salesperfindex][salestickindex][1]=document.getElementById(id+"ticketprice").options[document.getElementById(id+"ticketprice").selectedIndex].text;
				ticksalesarray[salesindex][salesperfindex][salestickindex][2]=document.getElementById(id+"preference").options[document.getElementById(id+"preference").selectedIndex].text;
				ticksalesarray[salesindex][salesperfindex][salestickindex][3]=new Array();
				var x=0;
				for(y=0;y<reqlength;y++)
				{
					if(document.getElementById(id+"request"+y).checked)
					{
						ticksalesarray[salesindex][salesperfindex][salestickindex][3][x]=tickarray[prodindex][4][1][y];
						x++;
					}
				}
				if(ticksalesarray[salesindex][salesperfindex][salestickindex][3].length==0)
					ticksalesarray[salesindex][salesperfindex][salestickindex][3][0]="none";
				}
			}
		}
		if(perfcopy==false)
		{
			salesindex=saleslength;
			ticksalesarray[salesindex]=new Array();
			ticksalesarray[salesindex][0]=id;
			salesperfindex = 1;
			if(checkcap(prodindex,perfindex,new Number(document.getElementById(id+"quantity").value)))
			{
			salestickindex = 1;
			ticksalesarray[salesindex][salesperfindex]=new Array();
			ticksalesarray[salesindex][salesperfindex][0]=new Array();
			ticksalesarray[salesindex][salesperfindex][0][0]=document.getElementById(id+"ticketdate").options[document.getElementById(id+"ticketdate").selectedIndex].text;
			ticksalesarray[salesindex][salesperfindex][0][1]=new Number(document.getElementById(id+"quantity").value);
			ticksalesarray[salesindex][salesperfindex][salestickindex]=new Array();
			ticksalesarray[salesindex][salesperfindex][salestickindex][0]=new Number(document.getElementById(id+"quantity").value);
			ticksalesarray[salesindex][salesperfindex][salestickindex][1]=document.getElementById(id+"ticketprice").options[document.getElementById(id+"ticketprice").selectedIndex].text;
			ticksalesarray[salesindex][salesperfindex][salestickindex][2]=document.getElementById(id+"preference").options[document.getElementById(id+"preference").selectedIndex].text;
			ticksalesarray[salesindex][salesperfindex][salestickindex][3]=new Array();
			var x=0;
			for(y=0;y<reqlength;y++)
			{
				if(document.getElementById(id+"request"+y).checked)
				{
					ticksalesarray[salesindex][salesperfindex][salestickindex][3][x]=tickarray[prodindex][4][1][y];
					x++;
				}
			}
			if(ticksalesarray[salesindex][salesperfindex][salestickindex][3].length==0)
				ticksalesarray[salesindex][salesperfindex][salestickindex][3][0]="none";
			}
		}
		tickdisplist(id);
		document.getElementById(id+"ttype").style.color="gray";
		document.getElementById(id+"ticketprice").disabled="disabled";
		document.getElementById(id+"quantity").disabled="disabled";
		document.getElementById(id+"ticketdate").selectedIndex=0;
		document.getElementById(id+"ticketprice").selectedIndex=0;
		document.getElementById(id+"quantity").value="1";
		document.getElementById(id+"addbut").className="buttonhid";
		document.getElementById(id+"preference").disabled="disabled";
		document.getElementById(id+"preference").selectedIndex=0;
		for(y=0;y<reqlength;y++)
		{
			document.getElementById(id+"request"+y).disabled="disabled";
			document.getElementById(id+"request"+y).checked="";
		}
	}
	}
}	
function tickdel(id,x,y,z)
{
	var quantity = ticksalesarray[x][y][z][0];
	if(ticksalesarray[x][y].length>2)
	{
		ticksalesarray[x][y].splice([z],1);
		ticksalesarray[x][y][0][1]=ticksalesarray[x][y][0][1]-quantity;
	}
	else
		ticksalesarray[x].splice([y],1);
	tickdisplist(id);
	
}
function tickdisplist(id)
{
	saleslength = ticksalesarray.length;
	var ticketlist="";	
	var prodindex=getprodindex(id);
	disclength=tickarray[prodindex][0][2].length;
	feelength=tickarray[prodindex][5][1].length;
	var discounttxt="";
	var feetxt="";
	var fee = 0;
	var disctotal=0;
	var ticktotal=0;
	for(x=0;x<saleslength;x++)
	{
		salesperflength = ticksalesarray[x].length;
		for(y=1;y<salesperflength;y++)
		{
			var perfindex = getperfindex(prodindex,ticksalesarray[x][y][0][0]);
			discounttxt="";
			ticketlist=ticketlist+"<br /><u>"+ticksalesarray[x][y][0][0]+"</u><br />";		
			salesticklength = ticksalesarray[x][y].length;
			for(z=1;z<salesticklength;z++)
			{					
				ticketlist=ticketlist+ticksalesarray[x][y][z][0]+" x "+ticksalesarray[x][y][z][1]+", "+ticksalesarray[x][y][z][2];
				if(ticksalesarray[x][y][z][3][0]!="none")
					ticketlist=ticketlist+"<br />"+ticksalesarray[x][y][z][3];
				ticketlist=ticketlist+"<span class='tickedit' onclick=\"tickdel('"+id+"','"+x+"','"+y+"','"+z+"')\"><img class='tickimgcss' src='img/del.gif' alt='Delete this entry.' title='Delete this entry.' /></span><br />";
									
				for(w=0;w<feelength;w++)
				{
					fee = fee+(ticksalesarray[x][y][z][0]*tickarray[prodindex][5][1][w]);
				}
				var valuelength=tickarray[prodindex][perfindex][1].length;
				var valueindex;
				var q;
				for(q=0;q<valuelength;q++)
				{
					if(ticksalesarray[x][y][z][1].match(tickarray[prodindex][perfindex][0][q]))
						valueindex=q;
				}
				ticksalesarray[x][y][z][4]=tickarray[prodindex][perfindex][1][valueindex];
				ticktotal=ticktotal+new Number(ticksalesarray[x][y][z][0]*tickarray[prodindex][perfindex][1][valueindex]);
			}
			ticksalesarray[x][y][0][3]=0;
			for(w=0;w<disclength;w++)
			{
				if(ticksalesarray[x][y][0][1]>=tickarray[prodindex][2][0][w])
				{
					ticksalesarray[x][y][0][2]=w;
					discounttxt="Group discount = £"+(ticksalesarray[x][y][0][1]*tickarray[prodindex][2][1][w]).toFixed(2)+"<br />";
					ticksalesarray[x][y][0][3]=ticksalesarray[x][y][0][1]*tickarray[prodindex][2][1][w];
				}
			}
			disctotal=disctotal+new Number(ticksalesarray[x][y][0][3]);
			ticketlist=ticketlist+discounttxt;
		}
	}
	ticknet=ticktotal-new Number(disctotal)+new Number(fee);
	var ppform=getppform(id);
	if(fee>0)
		feetxt="<hr />"+ppform+"tickets = £"+ticktotal.toFixed(2)+"<br />discounts = £"+disctotal.toFixed(2)+"<br />fees = £"+fee.toFixed(2)+"<br />total = £"+ticknet.toFixed(2);
	else
		feetxt="<hr />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;";
	ticketlist=ticketlist;
	document.getElementById(id+"ticketlist").innerHTML='<span class="comtit">'+ticketlist+'</span>';
	document.getElementById(id+"ticketfees").innerHTML=feetxt;
}
function getppform(id)
{
	var ppform="";
	ppform='<form class="tickimg" target="paypal" alt="Make payments with PayPal - it’s fast, free and secure!" title="Make payments with PayPal - it’s fast, free and secure!" action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_cart"><input type="hidden" name="upload" value="1"><input type="hidden" name="currency_code" value="GBP"><input type="hidden" name="business" value="sales@plymouthgilbertandsullivan.com">';
	var prodindex = getprodindex(id);
	disclength=tickarray[prodindex][0][2].length;
	feelength=tickarray[prodindex][5][1].length;
	var saleslength = ticksalesarray.length;
	var y;
	var salesperflength;
	var salesticklength;
	var p;
	var z;
	var w;
	var itemnum=1;
	for(x=0;x<saleslength;x++)
	{
		salesperflength = ticksalesarray[x].length;
		for(y=1;y<salesperflength;y++) // for each performance
		{
			var perfindex = getperfindex(prodindex,ticksalesarray[x][y][0][0]);
			discounttxt="";
			ticketlist=ticketlist+"<br />"+ticksalesarray[x][y][0][0]+"<br />";		
			salesticklength = ticksalesarray[x][y].length;
			for(z=1;z<salesticklength;z++) // for each ticket type
			{					
				var valuelength=tickarray[prodindex][perfindex][1].length;
				var valueindex;
				var q;
				for(q=0;q<valuelength;q++)
				{
					if(ticksalesarray[x][y][z][1].match(tickarray[prodindex][perfindex][0][q]))
						valueindex=q;
				}
				ppform=ppform+'<input type="hidden" name="item_name_'+itemnum+'" value="';
				ppform=ppform+ticksalesarray[x][y][0][0];
				ppform=ppform+', ';
				ppform=ppform+ticksalesarray[x][y][z][1];
				ppform=ppform+', discount=£';
				var tickdisc=0;
				if(tickarray[prodindex][2][1][ticksalesarray[x][y][0][2]])
					tickdisc=tickarray[prodindex][2][1][ticksalesarray[x][y][0][2]];
				ppform=ppform+tickdisc;
				ppform=ppform+', fees=£';
				var tickcost=new Number(tickarray[prodindex][perfindex][1][valueindex]);
				var tickfee=0;
				for(w=0;w<feelength;w++)
				{
					tickfee = tickfee+new Number(tickarray[prodindex][5][1][w]);
				}
				ppform=ppform+tickfee;
				ppform=ppform+', preference=';
				ppform=ppform+ticksalesarray[x][y][z][2];
				ppform=ppform+', request=';
				ppform=ppform+ticksalesarray[x][y][z][3];
				ppform=ppform+'"><input type="hidden" name="quantity_'+itemnum+'" value="';
				ppform=ppform+ticksalesarray[x][y][z][0];
				ppform=ppform+'"><input type="hidden" name="amount_'+itemnum+'" value="';
				var tickamount = new Number(tickcost)+new Number(tickfee)-new Number(tickdisc);
				ppform=ppform+tickamount;
				ppform=ppform+'">';
				itemnum++;
			}
		}
	}
	ppform=ppform+'<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it’s fast, free and secure!"></form>';
	return ppform;
}
