<!--
/*
calculate each one charge and total charge :

	in paypal amount according to
    $35 for 1st hour and
    $20 per hour after that
    $10 per half hour

recording surcharge: $15 for 2-3.5 hrs, $20 for 4hrs or more

2 hours without rec $55  with rec $70
2.5 hours without rec $65  with rec $80
3 hours without rec $75  with rec $90
3.5 hours without rec $85  with rec $100
4 hours without rec $95  with rec $115
4.5 hours without rec $105  with rec $125
5 hours without rec $115  with rec $135
*/


function paraIsError(n) {
	if (isNaN(n) || n == null || n==0) {
		alert('Parameter error');
		return true;
	}
	return false;
}

//  设置总的 charge
function setChargeTotal() {
	var i, d, tag, total_price = 0;

	for (i = 1; i < 7; i++) {
		d = document.getElementById('mul-dates'+i).style.display;
		if (d == 'block') {
			tag = document.getElementById('price-span'+i).innerHTML;
			total_price += parseInt(tag, 10);
		}
	}

	document.getElementById('total-charge').innerHTML = total_price; // 设置相应时间段的 charge
}


/*
function:  check date, start time and end time
n : time number
m : 1-start time, 2- end time
if start time ,then not alert.
*/
function checkTime(n, m) {
	// parameter error
	if (paraIsError(n) || paraIsError(m)) {
		return false;
	}

	var regempty    = /^\s*$/;

	var dt = document.getElementById('fdt'+n); // Rehearsal Date
	var st = document.getElementById('start_time'+n); // Rehearsal start time
	var ed = document.getElementById('end_time'+n); // Rehearsal end time
	var yes_re = document.getElementById('yesrecording'+n).checked;
	var no_re = document.getElementById('norecording'+n).checked;
	var park_local = document.getElementById('parklocation'+n).checked;
	var greenpoint_local = document.getElementById('greenpointlocation'+n).checked;
	var sunset_local = document.getElementById('sunsetlocation'+n).checked;
	var bushwick_local = document.getElementById('bushwicklocation'+n).checked;
	var williamsburg_local = document.getElementById('williamsburglocation'+n).checked;
	var testwick_local = document.getElementById('testwicklocation'+n).checked;

	
	//if (park_local==false && greenpoint_local==false && sunset_local==false&& bushwick_local==false&& williamsburg_local==false) {
		//document.getElementById('parklocation'+n).checked = true;
	//}
	if (yes_re==false && no_re==false) {
		document.getElementById('norecording'+n).checked = true;
	}
	if ( regempty.test(dt.value) ) {
		alert('Rehearsal Date Sought ' + n + ' field is required!');
		dt.focus();
		return false;
	}
	var d;
	d = dt.value.split("-");
	d[0] = parseInt(d[0], 10);
	d[1] = parseInt(d[1], 10);
	d[2] = parseInt(d[2], 10);
	if (isNaN(d[0]) || isNaN(d[1]) || isNaN(d[2]) || d[0]<1970 || d[0]>9999 || d[1]<1 || d[1]>12 || d[2]<1 || d[2]>31) {
		alert('Rehearsal Date Sought ' + n + ' field is invalid!');
		dt.focus();
		return false;
	}
	if ( st.value == 'PLEASE CHOOSE' ) {
		alert('Start Time ' + n + ' field is required!');
		st.focus();
		return true;
	}
	if ( ed.value == 'PLEASE CHOOSE' ) {
		alert('End Time ' + n + ' field is required!');
		ed.focus();
		return true;
	}
	// following check start time and end time
	var start, end;
	start = st.value.split(":");
	if (start[0] == '09') {
		start[0] = 9;
	}
	start[0] = parseInt(start[0], 10);
	start[1] = parseInt(start[1], 10);
	if (isNaN(start[0]) || isNaN(start[1]) || (start[1]!=0 && start[1]!=30)) {
		//alert('Start Time ' + n + ' field is invalid!');
		st.focus();
		return false;
	}
	end = ed.value.split(":");
	end[0] = parseInt(end[0], 10);
	end[1] = parseInt(end[1], 10);
	if (isNaN(end[0]) || isNaN(end[1]) || (end[1]!=0 && end[1]!=30)) {
		//alert('End Time ' + n + ' field is invalid!');
		ed.focus();
		return false;
	}
	diff = (end[0] - start[0])*60 + end[1] - start[1];
	if (diff <= 0) {
		if (m != 1) {
		alert ('End Time ' + n + ' must be later than ' + 'Start Time ' + n);
		ed.focus();
		}
		return false;
	} else if (diff < 120) { // 60 minuters
		if (m != 1) {
		alert ('Rehearsal Date ' + n + ' : Minimum booking is 2 hours.');
		ed.focus();
		}
		return false;
	}
	return true;
} // end checktime(n, m)



/*
function: count price total
n : date number
m : 1-start time, 2- end time
*/
function getPrice(n, m) {
	// parameter error
	if (paraIsError(n) || paraIsError(m)) {
		return;
	}

	if (!checkTime(n, m)) { // check date, end time
		return false;
	}
	
	if (isNaN(diff)) { // different between start time and end time
		alert('Rehearsal Duration ' + n + ' is invalid.');
		return false;
	}

	var yes_re = document.getElementById('yesrecording'+n).checked;
	var no_re = document.getElementById('norecording'+n).checked;

	var mul, price;
	mul = diff/60; // 1 hour = 60 minutes
	price = 35 + (mul - 1)*20; // USD
	if (yes_re==true && no_re==false) {
		if (mul > 3.5) {
			price += 20;
		} else if (mul >= 2) {
			price += 15;
		}
	} else {
		document.getElementById('norecording'+n).checked = true;
	}
	document.getElementById('price-span' + n).innerHTML = price; // 设置相应时间段的 charge

	setChargeTotal();//  设置总的 charge
}

function checkPost(obj) {
	with(obj) {
		var regempty = /^\s*$/;

	    if ( regempty.test(firstname.value) ) {
	    	alert ('First Name'+' field is required!');
	    	firstname.focus();
	    	return false;
	    }
	    if ( regempty.test(lastname.value) ) {
	    	alert ('Last Name'+' field is required!');
	    	lastname.focus();
	    	return false;
	    }

	    // check date, start time and end time
		var p;
		for (p = 1; p < 7; p++) {
			if (document.getElementById('valid_item'+p).value == 1) {
				if (document.getElementById('yesrecording'+p).checked==false && document.getElementById('norecording'+p).checked==false) {
					document.getElementById('norecording'+p).checked = true;
				}
				if (!checkTime(p, 2)) {
					return false;
				}
			}
		}


	    if ( regempty.test(band.value) ) {
	    	alert ('Band Name'+' field is required!');
	    	band.focus();
	    	return false;
	    }

		// check cell phone
		var temp_pattern = /^[0-9]{10,16}$/;
	    if (!temp_pattern.test(phone.value)) {
	    	alert ('Cell Phone field must be numeric (length: 10 - 16).');
	    	phone.focus();
	    	return false;
	    }
	    // check alt phone
		if (!regempty.test(phone2.value)) {
			if (!temp_pattern.test(phone2.value)) {
		    	alert ('Alt Phone field must be numeric (length: 10 - 16).');
		    	phone2.focus();
		    	return false;
		    }
	    }

	/*-- start: check email address --*/
		if (emailWrong(email)) {
			return false;
		}

	    if (!regempty.test(email2.value) && emailWrong(email2, 'Secondary')) {
			return false;
	    }
	/*-- end: check email address --*/

		if ( regempty.test(address.value) ) {
			alert ('Bandleader(rent-payer) Address'+' field is required!');
			address.focus();
			return false;
		}

		document.getElementById('submitppp').style.display = 'none';
		document.getElementById('progess').style.display = 'block';

		return true;
	}
}

function setAddStatus() {
	// 设置 add another booking entry 显示状态
	var i;
	for (i = 6; i > 0; i--) {
		if (document.getElementById('mul-dates'+i).style.display == 'block') {
			document.getElementById('add-dates'+i).style.display = 'block';
			break;
		}
	}
}

// more booking dates
function createDates(n) {
	var i;
 	/* 第一个日期是必须的 (这里不能用 双斜杠 注释，要么会出错)*/
	for (i = 2; i < 7; i++) {
		if (document.getElementById('mul-dates'+i).style.display == '' || document.getElementById('mul-dates'+i).style.display == 'none') {
			document.getElementById('mul-dates'+i).style.display = 'block';
			document.getElementById('valid_item'+i).value = '1';
			break;
		}
	}

	if (n > 0 && n < 6) { // 针对 1 - 5 dates 自身的 add dates link
		document.getElementById('add-dates' + n).style.display = 'none';
	}

	setAddStatus(); // 设置 add another booking entry 显示状态

	// 判断有多少个日期时间段,若有6个（最大数），则不再显示 添加的链接
	var d, tag;
	tag = 1;
	for (i = 2; i < 7; i++) { // 第一个日期是必须的
		d = document.getElementById('mul-dates'+i).style.display;
		if (d == 'block') {
			tag = tag + 1;
		}
	}
	if (tag == 6) {
		document.getElementById('add-dates6').style.display = 'none';
	}

	setChargeTotal();//  设置总的 charge
}

// cancel one item of booking dates
function cancelDates(n) {
	if (!isNaN(n) && n > 1 && n < 7) {
		document.getElementById('mul-dates'+n).style.display = 'none';
		document.getElementById('valid_item'+n).value = '0';
	}

	setAddStatus(); // 设置 add another booking entry 显示状态
	//setChargeTotal();  设置总的 charge

	var i, d, tag, total_price = 0;
	for (i = 1; i < 7; i++) {
		d = document.getElementById('mul-dates'+i).style.display;
		if (d == 'block') {
			tag = document.getElementById('price-span'+i).innerHTML;
			total_price += parseInt(tag, 10);
		}
	}
	document.getElementById('total-charge').innerHTML = total_price; // 设置相应时间段的 charge
}
-->
