// JavaScript Document

var pathToImages = 'http://localhost/vetau/js/Calendar/images/';
function adults_select(se,div){
	sVal = se.options[se.selectedIndex].value;
	if(sVal !== ''){
			document.getElementById(div).style.visibility='visible';
	}else
	{
		document.getElementById(div).style.visibility='hidden';
	}
}
function way_select(se,div,div2,tysl){
	sVal = se.options[se.selectedIndex].value;
	if(sVal == 1){
			document.getElementById(div).style.display='block';
			document.getElementById(div2).style.display='none';	
			document.getElementById(tysl).value =1;	
	}else{
			document.getElementById(div).style.display='none';
			document.getElementById(div2).style.display='block';
			document.getElementById(tysl).value =2;	
	}
}
//check fornm
function check(){
	if(document.frmbook.bFullName.value == ""){
		alert("Please enter a valid Full Name");
		document.frmbook.bFullName.focus();
		return false;
	}
	if(document.frmbook.bEmail.value == ""){
		alert("Please enter a valid Email");
		document.frmbook.bEmail.focus();
		return false;
	}
	remail=/^\w+\@\w+(\.\w+)+$/	;
	if(!remail.test(document.frmbook.bEmail.value)){
		 alert("error format email address !")
		document.frmbook.bEmail.focus();
	 return false;
	}
	if(document.frmbook.bTelephone.value == ""){
		alert("Please enter a valid Telephone");
		document.frmbook.bTelephone.focus();
		return false;
	}
	if(isNaN(document.frmbook.bTelephone.value)){
		alert(" Telephone is Number");
		document.frmbook.bTelephone.focus();
		return false;
	}
	/*if (document.frmbook.oneway.checked)
	{
			document.frmbook.choneWay.value = "1"
	}
	if (document.frmbook.oneway.checked == false)
	{
			document.frmbook.choneWay.value = "2"
	}*/
	else return true;

}
$(document).ready(function(){
	
	var total = Array(5);
	$("input[@type=radio]").click(function(){

		calulateTotal();							   	
	})
	
	
	$("#paymentapply").click(function() 
	{	
	
		var tong =	$("#totalPrice1").val();
		if(tong == "" || tong == 0){
			alert("Please enter a Choice type ticker");
			return false;
		}else{
			calulateTotal();
			document.frmbook.typeSubmit.value = 1;
		}
		
	});
	/*$("#applyLater").click(function() 
	{	
		caculate();
		document.frmbook.typeSubmit.value = 2;
	});*/
	/*$("#ticketSelect").change(function() 
	{	
		caculate();
	});*/
	//1
	if(document.getElementById('cAdultsMain_Book1')){
		$("#cAdultsMain_Book1").change(function() 
		{	
			caculateticker1();
			calulateTotal();
		});
	}
	if(document.getElementById('cChildren_Book1')){
		$("#cChildren_Book1").change(function() 
		{	
			caculateticker1();
			calulateTotal();
		});
	}
	
	if(document.getElementById('oneway1')){
		$("#oneway1").change(function() 
		{	
			caculateticker1();
			calulateTotal();
		});
	}
	// end 1
	//2
	if(document.getElementById('cAdultsMain_Book2')){
		$("#cAdultsMain_Book2").change(function() 
		{	
			caculateticker2();
			calulateTotal();
		});
	}
	if(document.getElementById('cChildren_Book2')){
		$("#cChildren_Book2").change(function() 
		{	
			caculateticker2();
			calulateTotal();
		});
	}
	
	if(document.getElementById('oneway2')){
		$("#oneway2").change(function() 
		{	
			caculateticker2();
			calulateTotal();
		});
	}
	//end 2
	
	//3
	if(document.getElementById('cAdultsMain_Book3')){
		$("#cAdultsMain_Book3").change(function() 
		{	

			caculateticker3();
			calulateTotal();
		});
	}
	if(document.getElementById('cChildren_Book3')){
		$("#cChildren_Book3").change(function() 
		{	
			caculateticker3();
			calulateTotal();
		});
	}
	
	if(document.getElementById('oneway3')){
		$("#oneway3").change(function() 
		{	
			caculateticker3();
			calulateTotal();
		});
	}
	//end 3
	//4
	if(document.getElementById('cAdultsMain_Book4')){
		$("#cAdultsMain_Book4").change(function() 
		{	
			caculateticker4();
			calulateTotal();
		});
	}
	if(document.getElementById('cChildren_Book4')){
		$("#cChildren_Book4").change(function() 
		{	
			caculateticker4();
			calulateTotal();
		});
	}
	
	if(document.getElementById('oneway4')){
		$("#oneway4").change(function() 
		{	
			caculateticker4();
			calulateTotal();
		});
	}
	//end 4
	//5
	if(document.getElementById('cAdultsMain_Book5')){
		$("#cAdultsMain_Book5").change(function() 
		{	
			caculateticker5();
			calulateTotal();
		});
	}
	if(document.getElementById('cChildren_Book5')){
		$("#cChildren_Book5").change(function() 
		{	
			caculateticker5();
			calulateTotal();
		});
	}
	
	if(document.getElementById('oneway5')){
		$("#oneway5").change(function() 
		{	
			caculateticker5();
			calulateTotal();
		});
	}
	//end 5

	// ticker1 
	function caculateticker1(){
		var ticket1 = $("#ticketSelect1").val();
			if(ticket1 != null){
				var price1 = $("#price1").val();
				var adults1 =  $("#cAdultsMain_Book1").val();
				var Children1 =  $("#cChildren_Book1").val();
			//	var Childrenage1 =  $("#childen_age1").val();
				var oneway1 =  $("#oneway1").val();
				total[0] = caculatePrice(price1,adults1,Children1,oneway1);
				//alert("Giá " + price1 + "\n  Số người lớn " + adults1 + "\n  Số trẻ em " + Children1 + " \n Tuổi : " + Childrenage1 + "\n  Lượt đi "+oneway1 + "\n  Tổng tiền " + total[0] + "\n Các tính ((Gia * số NL) + (gia * Số TrE * tuổi))* lượt đi \n");
				$("#isChoice1").val(1);
				$("#totalPriceticker1").html(total[0]);
				$("#totalPricetickerInput1").val(total[0]);
			}
	}
	//end
	// ticker2 
	function caculateticker2(){
		var ticket2 = $("#ticketSelect2").val();
			if(ticket2 != null){
				var price2 = $("#price2").val();
				var adults2 =  $("#cAdultsMain_Book2").val();
				var Children2 =  $("#cChildren_Book2").val();
				//var Childrenage2 =  $("#childen_age2").val();
				var oneway2 =  $("#oneway2").val();
				total[1] = caculatePrice(price2,adults2,Children2,oneway2);
				//alert("Giá " + price1 + "\n  Số người lớn " + adults1 + "\n  Số trẻ em " + Children1 + " \n Tuổi : " + Childrenage1 + "\n  Lượt đi "+oneway1 + "\n  Tổng tiền " + total[0] + "\n Các tính ((Gia * số NL) + (gia * Số TrE * tuổi))* lượt đi \n");
				$("#isChoice2").val(1);
				$("#totalPriceticker2").html(total[1]);
				$("#totalPricetickerInput2").val(total[1]);
			}
	}
	//end
	// ticker3 
	function caculateticker3(){
		var ticket3 = $("#ticketSelect3").val();
			if(ticket3 != null){
				var price3 = $("#price3").val();
				var adults3 =  $("#cAdultsMain_Book3").val();
				var Children3 =  $("#cChildren_Book3").val();
			//	var Childrenage3 =  $("#childen_age3").val();
				var oneway3 =  $("#oneway3").val();
				total[2] = caculatePrice(price3,adults3,Children3,oneway3);
				//alert("Giá " + price1 + "\n  Số người lớn " + adults1 + "\n  Số trẻ em " + Children1 + " \n Tuổi : " + Childrenage1 + "\n  Lượt đi "+oneway1 + "\n  Tổng tiền " + total[0] + "\n Các tính ((Gia * số NL) + (gia * Số TrE * tuổi))* lượt đi \n");
				$("#isChoice3").val(1);
				$("#totalPriceticker3").html(total[2]);
				$("#totalPricetickerInput3").val(total[2]);
			}
	}
	//end
	// ticker4 
	function caculateticker4(){
		var ticket4 = $("#ticketSelect4").val();
			if(ticket4 != null){
				var price4 = $("#price4").val();
				var adults4 =  $("#cAdultsMain_Book4").val();
				var Children4 =  $("#cChildren_Book4").val();
				//var Childrenage4 =  $("#childen_age4").val();
				var oneway4 =  $("#oneway4").val();
				total[3] = caculatePrice(price4,adults4,Children4,oneway4);
				//alert("Giá " + price1 + "\n  Số người lớn " + adults1 + "\n  Số trẻ em " + Children1 + " \n Tuổi : " + Childrenage1 + "\n  Lượt đi "+oneway1 + "\n  Tổng tiền " + total[0] + "\n Các tính ((Gia * số NL) + (gia * Số TrE * tuổi))* lượt đi \n");
				$("#isChoice4").val(1);
				$("#totalPriceticker4").html(total[3]);
				$("#totalPricetickerInput4").val(total[3]);
			}
	}
	//end
	// ticker5 
	function caculateticker5(){
		var ticket5 = $("#ticketSelect5").val();
			if(ticket5 != null){
				var price5 = $("#price5").val();
				var adults5 =  $("#cAdultsMain_Book5").val();
				var Children5 =  $("#cChildren_Book5").val();
				//var Childrenage5 =  $("#childen_age5").val();
				var oneway5 =  $("#oneway5").val();
				total[4] = caculatePrice(price5,adults5,Children5,oneway5);
				//alert("Giá " + price1 + "\n  Số người lớn " + adults1 + "\n  Số trẻ em " + Children1 + " \n Tuổi : " + Childrenage1 + "\n  Lượt đi "+oneway1 + "\n  Tổng tiền " + total[0] + "\n Các tính ((Gia * số NL) + (gia * Số TrE * tuổi))* lượt đi \n");
				$("#isChoice5").val(1);
				$("#totalPriceticker5").html(total[4]);
				$("#totalPricetickerInput5").val(total[4]);
			}
	}
	//end

	function caculatePrice(ticket,adults,child,oneWay){
		var totalPrice = 0;
		var priceChidren = 0;
		var chidType = 0.7;
		totalPrice = oneWay*(parseFloat(ticket*adults) + parseFloat(ticket*child*chidType));
		return totalPrice.toFixed(2);
	}
	function calulateTotal(){
		var totalPrice = 0;
		var i = 0;
			for(i = 0; i < 5; i++){
				if(total[i] != null){
					totalPrice = parseFloat(totalPrice) + parseFloat(total[i]);
				}
			}
			str = $("input[@name='typeSubmit']:checked").val();
			if(str == 1){
					totalPrice = parseFloat(totalPrice) + parseFloat(totalPrice*4)/100;
							$('#typecheck1').val(1);
			}else{
					totalPrice = parseFloat(totalPrice) + parseFloat(totalPrice*0.05)/100;
						$('#typecheck1').val(0);
				}
			$("#totalPriceShow").html(totalPrice.toFixed(2));
			$("#totalPrice1").val(totalPrice.toFixed(2));
	}
	function isCheck(){
		var oneway = 1;
		if($("#oneway").attr("checked") === true){
			oneway = 1;

		}else{
			oneway = 2;
		}
		return oneway;
	}
	
  });
