
function conditions_check_form(f){
	return true;
}

function summary_check_form(f){
	return true;
}

function seating_check_form(f){
/*	if(
		select_check_not_first(f.elements['seating[1]'],'Please select your first preference') &&
		select_check_not_first(f.elements['seating[2]'],'Please select your second preference') &&
		select_check_not_first(f.elements['seating[3]'],'Please select your third preference') 
	){
		return true;
	}else{
		return false;
	}*/
	return true;
}

function payment_check_form(f){
	if(f.elements['payment[type]'].selectedIndex==0){alert('Please provide the type of credit card');return false;}
	if(!text_check_no_empty(f.elements['payment[number]'],'Please enter your credit card number.')){return false;}
	yyyymm=parseInt(f.elements['payment[expdate_year]'].options[f.elements['payment[expdate_year]'].selectedIndex].value + f.elements['payment[expdate_month]'].options[f.elements['payment[expdate_month]'].selectedIndex].value);
	now=new Date();
	now_yyyymm = parseInt(( now.getYear() < 1000 ? now.getYear()+1900 : now.getYear() ).toString() + ( (now.getMonth()+1 )<10 ? '0':'').toString() +  (now.getMonth()+1).toString());
	if(yyyymm<now_yyyymm){alert('Expiry date appears to be in the past');return false;}	
}


function details_check_form(f){
	if(
		select_check_not_first(f.elements['details[title]'],'Please select your title') &&
		text_check_no_empty(f.elements['details[name_last]'],'Please enter your last name') &&
		text_check_no_empty(f.elements['details[name_first]'],'Please enter your first name') &&
//		text_check_no_empty(f.elements['details[address1]'],'Please enter your address details') &&
//		text_check_no_empty(f.elements['details[postcode]'],'Please enter your post code') &&
//		text_check_no_empty(f.elements['details[email]'],'Please enter your email') &&
		text_check_no_empty(f.elements['details[phone1]'],'Please enter your contact phone') 
	){
		return true;
	}else{
		return false;
	}
}



function tickets_check_form(f){
	var ok=false;
	for(var i=0;i<prices.length;i++){
		if(f.elements['tickets['+prices[i][0]+']'].selectedIndex>0){
			ok=true;
		}
	}
	if(ok){
		return true;
	}else{
		alert('You have not selected any tickets');
		return false;
	}
	
}



function shows_check_form(f){
	var ok=false;
	for(var i=0;i<f.length;i++){
		if(f.elements[i].name=='shows[show]' && f.elements[i].checked ){ok=true;}
	}
	if(!ok){
		alert('Please select a show to attend.');
		return false;
	}else{
		return true;
	}
}




function text_check_no_empty(elem,msg){
	if(elem.value==''){
		alert(msg);
		elem.focus();
		return false;
	}
	return true;
}


function select_check_not_first(elem,msg){
	if(elem.selectedIndex>0){
		return true;
	}else{
		alert(msg);
		elem.focus();
		return false;
	}
}


function total(f){
	var sub=0;
	var e;
	for(var i=0;i<prices.length;i++){
		e=f.elements['tickets['+prices[i][0]+']'];
		sub+=prices[i][1]*e.options[e.selectedIndex].value;
	}
	document.getElementById('total').innerHTML='$ '+dollarfy(sub);
}


function dollarfy(amt)
{
	var s = new String('');
	var a = new Array();
	s=String(amt);
	if(s.indexOf('.')>=0)
	{
		a = s.split('.',2);
		var cents = new String('');
		cents=String((a[1]));
		if(cents.length==1)
		{
			cents=cents+'0';
		}
		else
		{ 
			if(cents.length>2)
			{
				cents=cents[0]+cents[1];
			}
			else
			{
				if(cents.length!=2)
				{
					cents='00';
				}
			}
		}
		return a[0]+'.'+cents[0]+cents[1];
	}
	else
	{
		return amt+'.00';
	}
}

