/* Ajax.js-This is the common Ajax Page  *
 * Developed by Technoibiz 
 * www.technoibiz.com
 * Project manager Rejieve Alexander
 * Project technical support Kevin Brown 
 */
function createRequest(displayDiv){
	$('#layer').show();
	var ajaxRequest;  // magic variable
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){   
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(displayDiv);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			$('#layer').hide();
			
			initialize_date_popups();//call datepicker initializing function
			
			/*$("#txtPreferredDate").datepicker({mandatory: true, minDate:'today', dateFormat:'dd/mm/yy', altField:'#txtPreferredDateAlt', altFormat:'m/d/yy',changeMonth: true,changeYear: true});
			$("#txtCheckinDate").datepicker({mandatory: true, minDate:'today', dateFormat:'dd/mm/yy', altField:'#txtCheckinDateAlt', altFormat:'m/d/yy',changeMonth: true,changeYear: true});
			$("#txtPrefDate").datepicker({mandatory: true, maxDate:'today-1', dateFormat:'dd/mm/yy', altField:'#txtPrefDateAlt', altFormat:'m/d/yy',changeMonth: true,changeYear: true});
			$("#txtChkDate").datepicker({mandatory: true, maxDate:'today-1', dateFormat:'dd/mm/yy', altField:'#txtChkDateAlt', altFormat:'m/d/yy',changeMonth: true,changeYear: true});
			$("#txtbookingDate").datepicker({mandatory: true,dateFormat:'dd/mm/yy',altField:'#txtBookingDateAlt', altFormat:'m/d/yy',changeMonth: true,changeYear: true});		
	
			$("#txtFromDate").datepicker({mandatory: true, dateFormat:'dd/mm/yy', altField:'#txtFromDateAlt', altFormat:'m/d/yy',changeMonth: true,changeYear: true});
			$("#txtToDate").datepicker({mandatory: true, dateFormat:'dd/mm/yy', altField:'#txtToDateAlt', altFormat:'m/d/yy',changeMonth: true,changeYear: true});
	
			$(".popUpCalendarBox").datepicker({mandatory: true, dateFormat:'dd/mm/yy', altField:'.popUpCalendarBoxAlt', altFormat:'m/d/yy',changeMonth: true,changeYear: true});*/
		}
	}
	return ajaxRequest;
}

function createRequestWithEffects(displayDiv){
	$('#layer').show();
	$('#'+displayDiv).slideUp('slow');
	var ajaxRequest;  // magic variable
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){   
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(displayDiv);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			$('#'+displayDiv).slideDown('slow');
			$('#layer').hide();
			$(".popUpCalendarBox").datepicker({mandatory: true, dateFormat:'mm/dd/yy', altField:'.popUpCalendarBoxAlt', altFormat:'m/d/yy'});
		}
	}
	return ajaxRequest;
}

function checkUniqueUser(userName){
	//Function to check Unique UserName
	var ajaxRequest=createRequest('userexist');
	var queryString = "?username="+userName;
	ajaxRequest.open("GET", "../ajax/ajaxCheckUserExist.php" + queryString, true);
	ajaxRequest.send(null);
}

function generatePassword(){
	//Function to generate Password
	var ajaxRequest=createRequest('newpassword');
	var queryString = "?action=generatepass";
	ajaxRequest.open("GET", "../ajax/ajaxGeneratePassword.php" + queryString, true);
	ajaxRequest.send(null);
}

function viewUserList(userTypeId){
	//Function to List Users according to UserType
	var ajaxRequest=createRequest('userlist');
	var queryString = "?usertype="+userTypeId;
	ajaxRequest.open("GET", "ajax/ajaxViewUserList.php" + queryString, true);
	ajaxRequest.send(null);
}

function displayUserNamePasword(userTypeId){
	//Function to Display UserName for Agent Non Credit Registration
	var ajaxRequest=createRequest('displayusernamepaswrd');
	var queryString = "?usertype="+userTypeId;
	ajaxRequest.open("GET", "ajax/ajaxDisplayUserNamePaswrd.php" + queryString, true);
	ajaxRequest.send(null);
}

function displayUserName(userTypeId){
	//Function to Display UserName for Agent Non Credit Registration
	var ajaxRequest=createRequest('displayusersusername');
	var queryString = "?usertype="+userTypeId;
	ajaxRequest.open("GET", "ajax/ajaxDisplayUserName.php" + queryString, true);
	ajaxRequest.send(null);
}

function showAvailableDates(formType){
	//Function for displaying Available Date
		var selectedPackageID=document.getElementById('packageID').value;
		var selectedDate=document.getElementById('txtPreferredDateAlt').value;
		var totalDays=document.getElementById('totalDays').value;
		var bookingMode=document.getElementById('bookingMode').value;
		if((document.getElementById('package_BookingType') && document.getElementById('package_BookingType').value==0) || formType=='M'){
			//var numPeople=document.getElementById('hid_totalNumofPeople').value;
			var numPeople=document.getElementById('txtNumPeople').value;
			if(selectedPackageID>0){
				if(selectedDate==""){
					alert("Please select a date");
					document.getElementById('txtPreferredDate').focus();
					return false;
				}
				else if(numPeople==0){
					alert("Please provide the no:of people travelling");
					document.getElementById('txtNumPeople').focus();
					return false;
				}
			}
			else{
				alert("Please select a package");
				return false;
			}
				var ajaxRequest=createRequestWithEffects('div_availableDates');
				document.getElementById('div_availableDates').style.display='block';
				var queryString = "?selectedDate="+selectedDate+"&selectedPackageID="+selectedPackageID+"&numPeople="+numPeople+"&bookingMode="+bookingMode;	
				//alert(queryString);
			
				if(formType=='M'){					
					checkCourtesyBusAvailability(selectedDate,numPeople,formType,bookingMode,totalDays,selectedPackageID);
					ajaxRequest.open("GET", "../ajax/ajaxShowAvailableDates.php" + queryString, true);
					document.getElementById('CourtesyAvailabilitystatus').value=1;
				}
				else{
					if(document.getElementById('txtTotalCost').value==""){
						showTotal();
					}
					checkCourtesyBusAvailability(selectedDate,numPeople,formType,bookingMode,totalDays,selectedPackageID);
					ajaxRequest.open("GET", "ajax/ajaxShowAvailableDates.php" + queryString, true);
				}
				ajaxRequest.send(null);
		}
		else{
			//var selectedPackageID=document.getElementById('packageID').value;
			var selectedBookingType=document.getElementsByName('bookingType[]');
			var flag=0;
			//var selectedDate=document.getElementById('txtPreferredDateAlt').value;
			//var totalDays=document.getElementById('totalDays').value;
			if(selectedPackageID>0){
				if(selectedDate==""){
					alert("Please select a date");
					return false;
				}
				else{
					for(var i=0;i<selectedBookingType.length;i++){
						if(selectedBookingType[i].checked){
							flag=1;
							var bookingTypeID=selectedBookingType[i].value;
							var numPeople=document.getElementById('numPeople_'+bookingTypeID).value;
						}
					}
					if(flag==0){
						alert("Please select Accomdation Style");
						return false;
					}				
					var ajaxRequest=createRequestWithEffects('div_availableDates');
					document.getElementById('div_availableDates').style.display='block';
					var queryString = "?selectedDate="+selectedDate+"&selectedPackageID="+selectedPackageID+"&numPeople="+numPeople+"&bookingMode="+bookingMode;
					//alert(queryString);
					if(document.getElementById('txtTotalCost').value==""){
						showTotalPrice();
					}
					
					checkCourtesyBusAvailability(selectedDate,numPeople,formType,bookingMode,totalDays,selectedPackageID);
					ajaxRequest.open("GET", "ajax/ajaxShowAvailableDates.php" + queryString, true);
					ajaxRequest.send(null);
				}
			}
			else{
				alert("Please select a package");
				return false;
			}
		}
	/*}*/
}


function showAvailableDates_change(bookingID){
	//Function for displaying Available Date in resource allocation form
	var selectedPackageID=document.getElementById('packageID').value;
	var selectedDate=document.getElementById('txtPreferredDateAlt').value;
	var totalDays=document.getElementById('totalDays').value;
	var numPeople=document.getElementById('txtNumPeople').value;
	var bookingMode=document.getElementById('booking_mode').value;
	if(selectedDate==""){
		alert("Please select a date");
		document.getElementById('txtPreferredDate').focus();
		return false;
	}

	var ajaxRequest=createRequestWithEffects('div_availableDates');
	document.getElementById('div_availableDates').style.display='block';
	var queryString = "?selectedDate="+selectedDate+"&selectedPackageID="+selectedPackageID+"&numPeople="+numPeople+"&bookingMode="+bookingMode+"&bookingID="+bookingID;
	//alert(queryString);
	ajaxRequest.open("GET", "../ajax/ajaxShowAvailableDates.php" + queryString, true);
	ajaxRequest.send(null);
}


function checkCourtesyBusAvailability(selectedDate,numPeople,formType,bookingMode,totalDays,product_id){
	//Function to check courtesy bus availability	
	var userTypeID=document.getElementById('userTypeID').value;	
	if(formType=='Manual'){	
		var selectedDate=document.getElementById('txtPreferredDateAlt').value;
		if(selectedDate==""){
			alert("Please select a date");
			document.getElementById('txtPreferredDate').focus();
			return false;
		}
		
		var numPeople=document.getElementById('txtNumPeople').value;
		if(numPeople==""){
			alert("Please provide the no:of people travelling");
			document.getElementById('txtNumPeople').focus();
			return false;
		}					
		var ajaxRequest=createRequestWithEffects('divCourtesyBusAvailability');
	}
	else{	
		var ajaxRequest=createRequestWithEffects('divCourtesyBus');
	}
	
	//var ajaxRequest=createRequestWithEffects('divCourtesyBus');
	var queryString = "?selectedDate="+selectedDate+"&numPeople="+numPeople+"&userTypeID="+userTypeID+"&formType="+formType+"&bookingMode="+bookingMode+"&totalDays="+totalDays+"&product_id="+product_id;	
	if(formType=='M' || formType=='Manual'){
		ajaxRequest.open("GET", "../ajax/ajaxShowCourtesyBusAvailability.php" + queryString, true);
	}
	else{
		ajaxRequest.open("GET", "ajax/ajaxShowCourtesyBusAvailability.php" + queryString, true);
	}
	ajaxRequest.send(null);
}

function checkCommissionStatus(){
	//Function to check commission status
	if(document.getElementById('userID')){
		var userID=document.getElementById('userID').value;
		var productID=document.getElementById('productID').value;
		if((userID>0) && (productID>0)){
			var ajaxRequest=createRequest('div_userCommissionStatus');
			var queryString = "?userID="+userID+"&productID="+productID;
			ajaxRequest.open("GET", "administrator/ajax/ajaxCheckUserCommissionStatus.php"+queryString, true);
			ajaxRequest.send(null);
		}
	}
}

function showUsers(userTypeId,displayDiv,mode){
	//Function to display users corresponding to selected usertype
	if(mode!='prev'){
		if((userTypeId==1) || (userTypeId==2) || (userTypeId==4)){  //Courtesy bus checkbox
			$('#tab_courtesyBus').show();
		}
		else{
			$('#tab_courtesyBus').hide();
		}
	}
	if(document.getElementById('courtesyBus_status')){
		if(userTypeId==4){
			document.getElementById('courtesyBus_status').checked=false;
		}
		else{
			document.getElementById('courtesyBus_status').checked=false;
		}
	}
	if(userTypeId==4){
		$('#showReferenceNumber').hide();
		/*$('#userNameDisplayDiv').hide();
		document.getElementById('userName').value="";*/
		$('#paymentOptions').show();
		$('#payment_type_row').show();
		document.getElementById('userDisplayDiv').innerHTML="<select></select>";
		if(mode=='M'){
			$('#deposit_row').show();
		}
	}
	else{
		//document.getElementById('userName').value="";
		if(userTypeId==1){
			$('#showReferenceNumber').show();
			$('#paymentOptions').hide();
			$('#payment_type_row').hide();
			if(mode=='M'){
				$('#deposit_row').hide();
			}
		}
		else{
			$('#showReferenceNumber').hide();
			$('#paymentOptions').show();
			$('#payment_type_row').show();
			if(mode=='M'){
				$('#deposit_row').show();
			}
		}
		var ajaxRequest=createRequest(displayDiv);
		var queryString = "?userTypeId="+userTypeId+"&mode="+mode;
		if(mode=='M'||mode=='prev'){
			ajaxRequest.open("GET", "ajax/ajaxDisplayUsersByType.php" + queryString, true);
		}
		else{
			ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayUsersByType.php" + queryString, true);
		}
		ajaxRequest.send(null);
	}
}

function showTourGuide(usertypeId){
	var ambCard=document.getElementById('useAmbassodorCard');
	if(ambCard){
		if(ambCard.checked==true){
			var val=1;
		}
		else{
			var val=0;
		}
	}
	else{
		var val=0;
	}
	var ajaxRequest=createRequest('ambBooking');
	var queryString ="?val="+val+"&usertypeId="+usertypeId;
	ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayAmbOptions.php" + queryString, true);
	ajaxRequest.send(null);
	
}

function showUserDetails(userId,displayDiv,mode){
	//Function to display user details corresponding to selected user	
	if(userId==0){
		alert('Please select a user');
		$('#'+displayDiv).slideUp('slow');
		/*$('#userNameDisplayDiv').hide();
		document.getElementById('userName').value="";*/
	}
	else{
		/*$('#userNameDisplayDiv').show();
		document.getElementById('userName').value="";*/
		var ajaxRequest=createRequestWithEffects(displayDiv);
		var queryString = "?userId="+userId+"&mode="+mode;
		if(mode=='M'){
			ajaxRequest.open("GET", "ajax/ajaxDisplayUserDetails.php"+queryString, true);
		}
		else{
			ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayUserDetails.php"+queryString, true);
		}
		ajaxRequest.send(null);
	}
}


function showPackagesPrev(productID,displayDiv,dir,functionMode){
	//Function to display packages corresponding to product selected
	if(productID==0){
		alert('Please select a Package');
		document.getElementById(displayDiv).innerHTML='<select name="packageID" id="packageID"></select>';
		document.getElementById('packageID').value=0;
		document.getElementById('div_packageOptions').innerHTML='';
	}
	else{
		var ajaxRequest=createRequest(displayDiv);
		var queryString = "?productID="+productID+"&functionMode="+functionMode;
		if(dir=='administrator'){
			ajaxRequest.open("GET", "ajax/ajaxDisplayPackagesByProductsPrev.php" + queryString, true);
		}
		else{
			ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayPackagesByProductsPrev.php" + queryString, true);
		}
		ajaxRequest.send(null);
	}
}
function showPackages(productID,displayDiv,dir,functionMode){
	//Function to display packages corresponding to product selected
	if(productID==0){
		alert('Please select a Package');
		document.getElementById(displayDiv).innerHTML='<select name="packageID" id="packageID"></select>';
		document.getElementById('packageID').value=0;
		document.getElementById('div_packageOptions').innerHTML='';
	}
	else{
		var ajaxRequest=createRequest(displayDiv);
		var queryString = "?productID="+productID+"&functionMode="+functionMode;
		if(dir=='administrator'){
			ajaxRequest.open("GET", "ajax/ajaxDisplayPackagesByProducts.php" + queryString, true);
		}
		else{
			ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayPackagesByProducts.php" + queryString, true);
		}
		ajaxRequest.send(null);
	}
}

function showPackageOptions(packageID){
	//Function to display details of add-on on selecting a package	
	if(packageID==0){
		alert('Please select a package');
		document.getElementById('div_packageOptions').innerHTML='';
	}
	else{
		if(document.getElementById('userTypeID')){
			userTypeID=document.getElementById('userTypeID').value;
		}
		else{
			userTypeID=0;
		}
		var productID=document.getElementById('productID').value;
		var ajaxRequest=createRequest('div_packageOptions');
		var queryString = "?packageID="+packageID+"&productID="+productID+"&userTypeID="+userTypeID;
		ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayPackageOptions.php" + queryString, true);
		ajaxRequest.send(null);
	}
}


function showPackageOptionsPrev(packageID){
	//Function to display details of add-on on slecting a package	
	if(packageID==0){
		alert('Please select a product');
		document.getElementById('div_packageOptions').innerHTML='';
	}
	else{
		if(document.getElementById('userTypeID')){
			userTypeID=document.getElementById('userTypeID').value;
		}
		else{
			userTypeID=0;
		}
		var productID=document.getElementById('productID').value;
		var ajaxRequest=createRequest('div_packageOptions');
		var queryString = "?packageID="+packageID+"&productID="+productID+"&userTypeID="+userTypeID;		
		ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayPackageOptionsPrev.php" + queryString, true);		
		ajaxRequest.send(null);
	}
}



function showFamilyType(){
	//Function to reset all values upon changing the family type
	//document.getElementById('hid_total_Concession').value="";
	//document.getElementById('hid_totalNumofPeople').value="";
	document.getElementById('numFamily').value=0;
	<!--document.getElementById('discount_family').innerHTML='';-->
			
	var PackagePricePerPerson=document.getElementById('package_BookingTypePrice').value;
	var noofPeople=document.getElementById('txtNumPeople').value;
	var concession_Adult=document.getElementById('concession_Adult').value;
	var concession_Child=document.getElementById('concession_Child').value;
	var totalPrice=eval(PackagePricePerPerson)*eval(noofPeople);
	totalPrice=roundNumber(totalPrice,2);
	if(document.getElementById('numChildren')){
		var numChildren=document.getElementById('numChildren').value;
	}
	else{
		var numChildren=0;
	}
	
	if(document.getElementById('numAdult')){
		var numAdult=document.getElementById('numAdult').value;
	}
	else{
		var numAdult=0;
		
	}

	if(document.getElementById('useAmbassodorCard')){
		if(document.getElementById('familyType').value>0){
			document.getElementById('ambDisplay').style.display="none";
			document.getElementById('useAmbassodorCard').checked=false;
		}
		else{
			if(eval(numChildren)>0 ||  eval(numAdult)>0){
				document.getElementById('useAmbassodorCard').checked=false;
				document.getElementById('ambDisplay').style.display="none";
			}
			else{
				document.getElementById('useAmbassodorCard').checked=false;
				document.getElementById('ambDisplay').style.display="block";
			}
		}
	}

}

function showTotal(){
	//Function to dispaly the total cost when no of people is given
	if(document.getElementById('dateAvailabilitystatus')){
		document.getElementById('dateAvailabilitystatus').value='0';
	}
	
	var sessionUserType=document.getElementById('sessionUserType').value;
	if(sessionUserType=='administrator'){					//if priceoverride
		document.getElementById('priceoverride').checked=false;
		$('#divReason').hide();
		document.getElementById('txtReason').value="";	
		document.getElementById('priceField').innerHTML='<b>AUD</b> <input type="text" name="txtTotalCost" id="txtTotalCost" style="margin-left:-2px;" readonly=""/>';
	}
		
	if(document.getElementById('useAmbassodorCard')){
		//document.getElementById('ambDisplay').style.display="block";
		document.getElementById('useAmbassodorCard').checked=false;
	}
		var PackagePricePerPerson=document.getElementById('package_BookingTypePrice').value;//Package Price
		var noofPeople=document.getElementById('txtNumPeople').value;		//No of people
		var totalPrice=eval(PackagePricePerPerson)*eval(noofPeople);		//Total price without any concession
		totalPrice=roundNumber(totalPrice,2);
		document.getElementById('txtTotalCost').value=totalPrice;			//displaying Total Price
		document.getElementById('txtHidCost').value=totalPrice;				 //Hidden field
			
			//if(document.getElementById('hid_totalNumofPeople').value>0){
		if(noofPeople>0){
			if(document.getElementById('numFamily')){
				var familyType=document.getElementById('familyType').value;		//Family type
				var numFamily=document.getElementById('numFamily').value;		//No of Families
				
			}
			else{
				var numFamily=0;
			}
			
			if(document.getElementById('numAdult')){
				var numAdult=document.getElementById('numAdult').value;			//No of Adults
			}
			else{
				var numAdult=0;
			}
			
			if(document.getElementById('numChildren')){
				var numChildren=document.getElementById('numChildren').value;		//No of children
			}
			else{
				var numChildren=0;
			}
			//Fetching Concessions from hidden fields
			var concession_1chldFamily=document.getElementById('concession_1chldFamily').value;
			var concession_2chldFamily=document.getElementById('concession_2chldFamily').value;
			var concession_3chldFamily=document.getElementById('concession_3chldFamily').value;
			var concession_4chldFamily=document.getElementById('concession_4chldFamily').value;
			var concession_Adult=document.getElementById('concession_Adult').value;
			var concession_Child=document.getElementById('concession_Child').value;
			
			if(familyType>0){                       				//if type of family present
				if(familyType==1){									//if familytype 1 is selected
					var numFamilymember=eval(document.getElementById('numFamily').value)*3;
					var concession=eval(concession_1chldFamily)*eval(numFamily) +eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					
					var totnum=eval(numFamilymember)+eval(numAdult)+eval(numChildren);
					var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
					
					/*if(concession_1chldFamily>0){
						document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_1chldFamily+'  =$'+eval(concession_1chldFamily)*eval(numFamily)+'</font>';
					}*/
				}
				else if(familyType==2){							//if familytype 2 is selected
					var numFamilymember=eval(document.getElementById('numFamily').value)*4;
					var concession=eval(concession_2chldFamily)*eval(numFamily) +eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					
					var totnum=eval(numFamilymember)+eval(numAdult)+eval(numChildren);
					var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
					
					/*if(concession_2chldFamily>0){
						document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_2chldFamily+'  =$'+eval(concession_2chldFamily)*eval(numFamily)+'</font>';
					}*/
				}
				else if(familyType==3){							//if familytype3 is selected
					var numFamilymember=eval(document.getElementById('numFamily').value)*5;
					var concession=eval(concession_3chldFamily)*eval(numFamily) +eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					
					 var totnum=eval(numFamilymember)+eval(numAdult)+eval(numChildren);
					 var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
					 
					
					/*if(concession_3chldFamily>0){
						document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_3chldFamily+'  =$'+eval(concession_3chldFamily)*eval(numFamily)+'</font>';
					}*/
				}
				else if(familyType==4){						//if familytype4 is selected
					var numFamilymember=eval(document.getElementById('numFamily').value)*6;
					var concession=eval(concession_4chldFamily)*eval(numFamily) +eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					
					var totnum=eval(numFamilymember)+eval(numAdult)+eval(numChildren);
					var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
				
					/*if(concession_4chldFamily>0){
						document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_4chldFamily+'  =$'+eval(concession_4chldFamily)*eval(numFamily)+'</font>';

					}*/
				}
			}
			else{                		//if no family type present
					var concession=eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					var totnum=eval(numAdult)+eval(numChildren);
					var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
				
					/*if(document.getElementById('numFamily')){
						document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_1chldFamily+'  =$'+eval(concession_1chldFamily)*eval(numFamily)+'</font>';
					}*/
			}
			//var totalprice=eval(concession);
			if(eval(concession)>0){
				var totalprice=eval(concession);
			}
			else{
				var totalprice=eval(packagePrice);
			}
		
			/*if(document.getElementById('numAdult') && numAdult>0){
			document.getElementById('discount_adult').innerHTML='<font color="#000000">Discount='+numAdult+' x '+concession_Adult+'  =$'+eval(concession_Adult)*eval(numAdult)+'</font>';
			}*/
			/*if(document.getElementById('numChildren') && numChildren>0){
			document.getElementById('discount_child').innerHTML='<font color="#000000">Discount='+numChildren+' x '+concession_Child+'  =$'+eval(concession_Child)*eval(numChildren)+'</font>';
			}*/
			/*if(concession>0){
			document.getElementById('tot_discount').innerHTML='<font color="#000000"><b>Total Discount= $'+concession+'</b></font>';
			}*/
			
			document.getElementById('hid_totalNumofPeople').value=totnum;
			var totalEntered=document.getElementById('txtNumPeople').value;
			if(totalEntered>totnum){ 				//if Extra people present
				var	ExtraNumber=eval(totalEntered)-eval(totnum);
				var ExtraPrice=eval(ExtraNumber)*eval(PackagePricePerPerson);
			}
			if(ExtraPrice>0){
				totalprice=eval(totalprice)+eval(ExtraPrice);
			}			
			
			if(document.getElementById('extraNumPeople')){
				document.getElementById('extraNumPeople').value=ExtraNumber;
			}
		//amb display ends here

			totalprice=roundNumber(totalprice,2);
			document.getElementById('txtTotalCost').value=totalprice; //displaying total price
			document.getElementById('txtHidCost').value=totalprice;
			document.getElementById('hid_total_Concession').value=concession;

			}
}


function showTotalPrice(){
	//Function to display total price of the package
if(document.getElementById('package_BookingType').value==0){           //booking type 2	
	
	if(document.getElementById('txtNumPeople').value==0){
		alert("Please enter the Total no of person travelling First");
		if(document.getElementById('numFamily')){
			document.getElementById('numFamily').value=0;
		}
		if(document.getElementById('numAdult')){
			document.getElementById('numAdult').value=0;
		}
			
		if(document.getElementById('numChildren')){
			document.getElementById('numChildren').value=0;
		}
		document.getElementById('txtNumPeople').focus;
		return false;
	}
	
	if(document.getElementById('dateAvailabilitystatus')){	
		document.getElementById('dateAvailabilitystatus').value='0';
	}
		var PackagePricePerPerson=document.getElementById('package_BookingTypePrice').value; //Pacakeg Price
		
		if(document.getElementById('numFamily')){                   //type of family not selected
			if(document.getElementById('numFamily').value>0 && document.getElementById('familyType').value==0){
				alert("Please select the Family Type First");
				document.getElementById('numFamily').value=0;
				return false;
			}
		}
		
		var sessionUserType=document.getElementById('sessionUserType').value;
		
		if(sessionUserType=='administrator'){					//if priceoverride
			document.getElementById('priceoverride').checked=false;
			$('#divReason').hide();
			document.getElementById('txtReason').value="";	
			document.getElementById('priceField').innerHTML='<b>AUD</b> <input type="text" name="txtTotalCost" id="txtTotalCost" style="margin-left:-2px;" readonly=""/>';
		}

			if(document.getElementById('numFamily')){
				var numFamily=document.getElementById('numFamily').value;
				var familyType=document.getElementById('familyType').value;
			}
			else{
				var numFamily=0;
			}
			
			if(document.getElementById('numChildren')){
				var numChildren=document.getElementById('numChildren').value;
			}
			else{
				var numChildren=0;
			}
			
			if(document.getElementById('numAdult')){
				var numAdult=document.getElementById('numAdult').value;
			}
			else{
				var numAdult=0;
				
			}
			if(numFamily>0 || numChildren>0 || (document.getElementById('familyType') && document.getElementById('familyType').value>0) || numAdult>0){//display ambassasor booking
					if(document.getElementById('useAmbassodorCard')){
						document.getElementById('useAmbassodorCard').checked=false;
						document.getElementById('ambDisplay').style.display="none";
					}
				}
			else{
				if(document.getElementById('useAmbassodorCard')){
					document.getElementById('ambDisplay').style.display="block";
					document.getElementById('useAmbassodorCard').checked=false;
				}
			}
			//Fetching Concessions from hidden fields
			var concession_1chldFamily=document.getElementById('concession_1chldFamily').value;
			var concession_2chldFamily=document.getElementById('concession_2chldFamily').value;
			var concession_3chldFamily=document.getElementById('concession_3chldFamily').value;
			var concession_4chldFamily=document.getElementById('concession_4chldFamily').value;
			var concession_Adult=document.getElementById('concession_Adult').value;
			var concession_Child=document.getElementById('concession_Child').value;
			
			if(familyType>0){                       //if type of family present
				if(familyType==1){					//if familytype 1 is selected
					var numFamilymember=eval(document.getElementById('numFamily').value)*3;
					var concession=eval(concession_1chldFamily)*eval(numFamily) +eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					
					var totnum=eval(numFamilymember)+eval(numAdult)+eval(numChildren);
					var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
					
					/*if(concession_1chldFamily>0){
						if(numFamily>0){
							document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_1chldFamily+'  =$'+eval(concession_1chldFamily)*eval(numFamily)+'</font>';
						}
						else{
							document.getElementById('discount_family').innerHTML='';
						}
					}*/
				}
				else if(familyType==2){				//if familytype 2 is selected
					var numFamilymember=eval(document.getElementById('numFamily').value)*4;
					var concession=eval(concession_2chldFamily)*eval(numFamily) +eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					
					var totnum=eval(numFamilymember)+eval(numAdult)+eval(numChildren);
					var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
					
					/*if(concession_2chldFamily>0){
						if(numFamily>0){
							document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_2chldFamily+'  =$'+eval(concession_2chldFamily)*eval(numFamily)+'</font>';
						}
						else{
							document.getElementById('discount_family').innerHTML='';
						}
					}*/
				}
				else if(familyType==3){				//if familytype3 is selected
					var numFamilymember=eval(document.getElementById('numFamily').value)*5;
					var concession=eval(concession_3chldFamily)*eval(numFamily) +eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					
					 var totnum=eval(numFamilymember)+eval(numAdult)+eval(numChildren);
					 var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
					 
					
					/*if(concession_3chldFamily>0){
						if(numFamily>0){
							document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_3chldFamily+'  =$'+eval(concession_3chldFamily)*eval(numFamily)+'</font>';
						}
						else{
							document.getElementById('discount_family').innerHTML='';
						}
					}*/
				}
				else if(familyType==4){			//if familytype4 is selected
					var numFamilymember=eval(document.getElementById('numFamily').value)*6;
					var concession=eval(concession_4chldFamily)*eval(numFamily) +eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					
					var totnum=eval(numFamilymember)+eval(numAdult)+eval(numChildren);
					var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
				
					/*if(concession_4chldFamily>0){
						if(numFamily>0){
							document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_4chldFamily+'  =$'+eval(concession_4chldFamily)*eval(numFamily)+'</font>';
						}
						else{
							document.getElementById('discount_family').innerHTML='';
						}

					}*/
				}
			}
			else{                //if no family type present
					var concession=eval(concession_Adult)*eval(numAdult)+eval(concession_Child)*eval(numChildren);
					var totnum=eval(numAdult)+eval(numChildren);
					var packagePrice=eval(PackagePricePerPerson)*eval(totnum);
				
					/*if(document.getElementById('numFamily')){
						document.getElementById('discount_family').innerHTML='<font color="#000000">Discount='+numFamily+' x '+concession_1chldFamily+'  =$'+eval(concession_1chldFamily)*eval(numFamily)+'</font>';
					}*/
			}
			if(eval(concession)>0){
				var totalprice=eval(concession);
			}
			else{
				var totalprice=eval(packagePrice);
			}
		
		
			/*if(document.getElementById('numAdult')){
				if(numAdult>0){
					document.getElementById('discount_adult').innerHTML='<font color="#000000">Discount='+numAdult+' x '+concession_Adult+'  =$'+eval(concession_Adult)*eval(numAdult)+'</font>';
				}
				else{
					document.getElementById('discount_adult').innerHTML='';
				}
			}*/
			/*if(document.getElementById('numChildren')){
				 if(numChildren>0){
					document.getElementById('discount_child').innerHTML='<font color="#000000">Discount='+numChildren+' x '+concession_Child+'  =$'+eval(concession_Child)*eval(numChildren)+'</font>';
				 }
				 else{
					document.getElementById('discount_child').innerHTML=''; 
				 }
			}*/
			/*if(concession>0){
			document.getElementById('tot_discount').innerHTML='<font color="#000000"><b>Total Discount= $'+concession+'</b></font>';
			}
			else{
			document.getElementById('tot_discount').innerHTML='<font color="#000000"><b>Total Discount= $0</b></font>';
			}*/
			
			document.getElementById('hid_totalNumofPeople').value=totnum;
			var totalEntered=document.getElementById('txtNumPeople').value;
			if(totalEntered>totnum){ 				//if Extra people present
				var	ExtraNumber=eval(totalEntered)-eval(totnum);
				var ExtraPrice=eval(ExtraNumber)*eval(PackagePricePerPerson);
			}
			if(ExtraPrice>0){
				totalprice=eval(totalprice)+eval(ExtraPrice);
			}
			
			if(document.getElementById('extraNumPeople')){
				document.getElementById('extraNumPeople').value=ExtraNumber;
			}
		//amb display ends here
		
			totalprice=roundNumber(totalprice,2);
			document.getElementById('txtTotalCost').value=totalprice;
			document.getElementById('txtHidCost').value=totalprice;
			document.getElementById('hid_total_Concession').value=concession;
		
		
}
else //Booking type 1
{
		if(document.getElementById('useAmbassodorCard')){
			document.getElementById('useAmbassodorCard').checked=false;
		}
		document.getElementById('dateAvailabilitystatus').value='0';
		var selectedBookingType=document.getElementsByName('bookingType[]');
		var sessionUserType=document.getElementById('sessionUserType').value;
		if(sessionUserType=='administrator'){
			document.getElementById('priceoverride').checked=false;
			$('#divReason').hide();
			document.getElementById('txtReason').value="";	
			document.getElementById('priceField').innerHTML='<b>AUD</b> <input type="text" name="txtTotalCost" id="txtTotalCost" style="margin-left:-2px;" readonly=""/>';
		}
		for(var i=0;i<selectedBookingType.length;i++){
			if(selectedBookingType[i].checked){
				var bookingTypeID=selectedBookingType[i].value;
				var numOfPeople=document.getElementById('numPeople_'+bookingTypeID).value;
				var mainPackagePricePerPerson=document.getElementById('packagePrice_'+bookingTypeID).value;
				var mainPackagePrice=eval(mainPackagePricePerPerson)*eval(numOfPeople);
			}
		}	
		
		if(bookingTypeID>0){
			var extraNight=document.getElementsByName('extraNight[]');
			totalAddonPrice=0;
			for(var i=0;i<extraNight.length;i++){
				if(document.getElementById('addonPackagePrice_'+i+'_'+bookingTypeID)){
					var extraNights=document.getElementById('extraNight_'+i).value;
					var addonPricePerOne=document.getElementById('addonPackagePrice_'+i+'_'+bookingTypeID).value;
					var addonPrice=extraNights*eval(addonPricePerOne)*numOfPeople;
					totalAddonPrice=eval(addonPrice)+eval(totalAddonPrice);
				}
			}
			
			var totalPrice=eval(totalAddonPrice)+eval(mainPackagePrice);
			totalPrice=roundNumber(totalPrice,2);
			document.getElementById('txtTotalCost').value=totalPrice;
			document.getElementById('txtHidCost').value=totalPrice;
		}
		else{
			alert("Please select an 'Accommodation Style'");
		}
}
}


function showBookingDetails(bookingID,num,mode,pkgid){
	//Function to display booking detals  for selected bookings
	if(mode=='M'){
		if(document.getElementById('dashboard')){
			document.getElementById('bookingID_manual_'+num).checked=true;
			document.getElementById('mode').value='M';
			//var ajaxRequest=createRequest('bookingDetails');
		}
		else{
			
			document.getElementById('bookingID_manual_'+num).checked=true;
			document.getElementById('mode').value='M';
			if(pkgid){
				document.getElementById('pkgId').value=pkgid;
			}
			else{
				if(document.getElementById('pkgId')){
					document.getElementById('pkgId').value="";
				}
			}
			//var ajaxRequest=createRequest('bookingDetails');
		}
	}
	else{
		document.getElementById('bookingID_'+num).checked=true;
		document.getElementById('mode').value='B';
		if(document.getElementById('pkgId')){
		   document.getElementById('pkgId').value="";
		}
		//var ajaxRequest=createRequest('bookingDetails');
	}
	var ajaxRequest=createRequest('bookingDetails');
	var queryString = "?bookingID="+bookingID+"&mode="+mode;
	ajaxRequest.open("GET", "ajax/ajaxDisplayBookingDetails.php" + queryString, true);
	ajaxRequest.send(null);
}

function showBookingDetails_admin(bookingID,num,mode,pkgid){
	//Function to display booking detals  for selected bookings
	if(mode=='M'){
		if(document.getElementById('dashboard')){
			document.getElementById('bookingID_manual_'+num).checked=true;
			document.getElementById('mode').value='M';
			//var ajaxRequest=createRequest('bookingDetails');
		}
		else{
			
			document.getElementById('bookingID_manual_'+num).checked=true;
			document.getElementById('mode').value='M';
			if(pkgid){
				document.getElementById('pkgId').value=pkgid;
			}
			else{
				if(document.getElementById('pkgId')){
					document.getElementById('pkgId').value="";
				}
			}
			//var ajaxRequest=createRequest('bookingDetails');
		}
	}
	else{
		document.getElementById('bookingID_'+num).checked=true;
		document.getElementById('mode').value='B';
		if(document.getElementById('pkgId')){
		   document.getElementById('pkgId').value="";
		}
		//var ajaxRequest=createRequest('bookingDetails');
	}
	var ajaxRequest=createRequest('bookingDetails');
	var queryString = "?bookingID="+bookingID+"&mode="+mode;
	ajaxRequest.open("GET", "ajax/ajaxDisplayBookingDetails_admin.php" + queryString, true);
	ajaxRequest.send(null);
}


function showWholesalerPayments(){
	//Function to display payments of a wholesaler
	var userID=document.getElementById('userID').value;
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var status=document.getElementById('status').value;
	if(status=='2'){
	   document.getElementById('dateFilter').style.visibility='hidden';
	}
	else{
		document.getElementById('dateFilter').style.visibility='visible';
	}
	/*if(document.getElementById('normalBooking').checked==true){
	 	var mode='B';
	 }
	 else{
		var mode='M';
	 }*/
	var ajaxRequest=createRequest('wholesalerPaymentsDisplayDiv');
	var queryString = "?userID="+userID+"&startDate="+startDate+"&endDate="+endDate+"&status="+status;
	ajaxRequest.open("GET", "ajax/ajaxDisplayWholesalerPayments.php" + queryString, true);
	ajaxRequest.send(null);
}

function filterVoucher(){
	//Function to display vouchers of a credit agent
	
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var status=document.getElementById('paymentStatus').value;	
	var ajaxRequest=createRequest('wholesalerPaymentsDisplayDiv');
	var queryString = "?startDate="+startDate+"&endDate="+endDate+"&status="+status;
	ajaxRequest.open("GET", "ajax/ajaxDisplayVoucher.php" + queryString, true);
	ajaxRequest.send(null);
}


function showCreditAgentSales(){
	//Function to display sales/Credit Agent
	var status=document.getElementById('status').value;
	var userID=document.getElementById('userID').value;
	
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var ajaxRequest=createRequest('creditAgentSalesDisplayDiv');
	var queryString = "?status="+status+"&userID="+userID+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayCreditAgentSales.php" + queryString, true);
	ajaxRequest.send(null);	
}

function changeMonth(){
document.getElementById('month_num').value=0;	
}

function showNotificationDetails(){	
	//Function to display Notification details of a wholesaler
	var userID=document.getElementById('userID').value;		
	var startDate=document.getElementById('txtFromDateAlt').value;	
	var endDate=document.getElementById('txtToDateAlt').value;
	var month=document.getElementById('month_num').value;		
	var year=document.getElementById('year_num').value;
	if(month>0){
		//document.getElementById('div_dateOfTravel').innerHTML="";
		//document.getElementById('div_dateOfTravel').style.display="none";
		document.getElementById('div_dateOfTravel').style.visibility="hidden";
	}
	else{
		document.getElementById('div_dateOfTravel').style.visibility="visible";
	}
	var ajaxRequest=createRequest('NotificationDetailsDisplayDiv');		
	var queryString = "?userID="+userID+"&startDate="+startDate+"&endDate="+endDate+"&month="+month+"&year="+year;
	ajaxRequest.open("GET", "ajax/ajaxDisplayNotificationDetails.php" + queryString, true);	
	ajaxRequest.send(null);	
}

function showUnpayedInvoice(){
	//Function to display Unpaid invoices of a wholesaler
	var userID=document.getElementById('userID').value;	
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var ajaxRequest=createRequest('wholesalerInvoiceDisplayDiv');	
	var queryString = "?userID="+userID+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayUnpaidInvoice.php" + queryString, true);
	ajaxRequest.send(null);
}


function showManualInvoice(){	
	//Function to display Unpaid invoices of manual payment
	var userType=document.getElementById('userType').value;		
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var ajaxRequest=createRequest('fullpaymentDisplayDiv');	
	var queryString = "?userType="+userType+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayManualPayment.php" + queryString, true);
	ajaxRequest.send(null);
}


function showCommissionPayments(){
	//Function to display Commission of an Agent
	var status=document.getElementById('status').value;
	var userID=document.getElementById('userID').value;
	if(document.getElementById('normalBooking').checked==true){
	 	var mode='B';
	 }
	 else{
		var mode='M';
	 }
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var ajaxRequest=createRequest('commissionPaymentsDisplayDiv');
	var queryString = "?status="+status+"&userID="+userID+"&mode="+mode+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayCommissionPayments.php" + queryString, true);
	ajaxRequest.send(null);
}


function showAgentCommissionPayments(){
	//Function to display Commission payment details of an Agent
	var paymentStatus=document.getElementById('paymentStatus').value;
	var userID=document.getElementById('userID').value;
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var ajaxRequest=createRequest('AgentPaymentList_div');
	var queryString = "?paymentStatus="+paymentStatus+"&userID="+userID+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayAgentCommissionPayments.php" + queryString, true);
	ajaxRequest.send(null);
}


function showAgentInvoices(){
	//Function to Invoice Details of an Agent
	if(document.getElementById('normalBooking').checked==true){
	 	var mode='B';
	 }
	 else{
		var mode='M';
	 }
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var ajaxRequest=createRequest('agentInvoicesDisplayDiv');
	var queryString = "?mode="+mode+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayAgentInvoices.php" + queryString, true);
	ajaxRequest.send(null);
}

function filterInvoices(){
	//Function to filter invoice
	var bookingStatus=document.getElementById('bookingStatus').value;	
	var paymentStatus=document.getElementById('paymentStatus').value;	
	var userType=document.getElementById('userType').value;
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;	
	/*if(userType=='ret' || userType=='nca'){
		document.getElementById('divdate').innerHTML='Date Of Travel';	
	}
	else{
		document.getElementById('divdate').innerHTML='Invoice Date';
	}*/
	var ajaxRequest=createRequest('invoicesDisplayDiv');	
	var queryString = "?bookingStatus="+bookingStatus+"&userType="+userType+"&paymentStatus="+paymentStatus+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayInvoices.php" + queryString, true);
	ajaxRequest.send(null);
}


function filterStatements(mode){
	//Function to filter Statements
	
	var paymentStatus=document.getElementById('paymentStatus').value;		
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;		
	var ajaxRequest=createRequest('statementsDisplayDiv');	
	var queryString = "?paymentStatus="+paymentStatus+"&startDate="+startDate+"&endDate="+endDate;	
	ajaxRequest.open("GET", "ajax/ajaxDisplayStatements.php" + queryString, true);	
	ajaxRequest.send(null);
}


function changeProductStatus(productID,productStatus){
	
	var productStatus=productStatus;
	if(productStatus==1){
		var ans=confirm("Are you sure you want to disable this Package?");
	}
	if(productStatus==0){
		var ans=confirm("Are you sure you want to enable this Package?");
	}
	if(ans==false){
		return false;
	}
	var associationNumber=document.getElementById('num_association_'+productID).value;
	if(associationNumber>0){
		alert('This Package is associated with some products/addons. Please deassociate before disable.');
		return false;
	}
	else{
		var ajaxRequest=createRequest('productStatusDiv_'+productID);
		var queryString = "?productID="+productID+"&productStatus="+productStatus;
		ajaxRequest.open("GET", "ajax/ajaxChangeProductStatus.php" + queryString, true);
		ajaxRequest.send(null);
	}
}

function changePackageStatus(packageID,packageStatus){
	//Function to change Pacakage status
	var packageStatus=packageStatus;
	if(packageStatus==1){
		var ans=confirm("Are you sure you want to disable this Product?");
	}
	if(packageStatus==0){
		var ans=confirm("Are you sure you want to enable this Product?");
	}
	if(ans==false){
		return false;
	}	
	var ajaxRequest=createRequest('packageStatusDiv_'+packageID);
	var queryString = "?packageID="+packageID+"&packageStatus="+packageStatus;
	ajaxRequest.open("GET", "ajax/ajaxChangePackageStatus.php"+queryString, true);
	ajaxRequest.send(null);
}

function changeAddonPackageStatus(addonpackageID,addonpackageStatus,mode){
	//Function to change AddOn Pacakage status
	
	if(addonpackageStatus==1){
		var ans= confirm("Are you sure, you want to disable this Addon package");
	}
	if(addonpackageStatus==0){
		var ans=confirm("Are you sure, you want to enable this Addon package");
	}
	if(ans==false){
		return false;
	}
	if(mode=='E'){
		var ajaxRequest=createRequest('addonPackageStatusDiv_'+addonpackageID);
	}
	else{
		var ajaxRequest=createRequest('addoncomplimentaryStatusDiv_'+addonpackageID);
	}
		
	var queryString = "?addonpackageID="+addonpackageID+"&addonpackageStatus="+addonpackageStatus+"&mode="+mode;
	ajaxRequest.open("GET", "ajax/ajaxChangeAddonPackageStatus.php"+queryString, true);
	ajaxRequest.send(null);
}

function changeVehicleStatus(vehicleID,vehicleStatus){
	//Function to change vehicle status
	var associationNumber=document.getElementById('num_association_'+vehicleID).value;
	if(associationNumber>0){
		alert('This Vehicle is associated with some upcoming Bookings. Please deassociate before disable.');
		return false;
	}
	else{
		var ajaxRequest=createRequest('vehicleStatusDiv_'+vehicleID);
		var queryString = "?vehicleID="+vehicleID+"&vehicleStatus="+vehicleStatus;
		ajaxRequest.open("GET", "ajax/ajaxChangeVehicleStatus.php" + queryString, true);
		ajaxRequest.send(null);
	}
}

function sendAddonCompanyMail(companyID,bookingID,addonID){
	//Function to send mail for Addon
	var ajaxRequest=createRequest('addonSendMailActionDiv_'+addonID);
	var startDate=document.getElementById('addon_'+addonID+'_start_date').value;
	var endDate=document.getElementById('addon_'+addonID+'_end_date').value;
	var customMailText=document.getElementById('customAddonAccomMailText_'+addonID).value;
	var queryString = "?companyID="+companyID+"&bookingID="+bookingID+"&addonID="+addonID+"&startDate="+startDate+"&endDate="+endDate+"&customMailText="+customMailText;
	ajaxRequest.open("GET","ajax/ajaxSendAddonCompanyMail.php"+queryString, true);
	ajaxRequest.send(null);
}

function sendComplAddonMail(bookingID,complAddonID){
	//Function to send mail for Complimentory Addon
	var ajaxRequest=createRequest('addonSendComplMailActionDiv_'+complAddonID);
	var customMailText=document.getElementById('customComplAddonAccomMailText_'+complAddonID).value;
	var queryString = "?bookingID="+bookingID+"&addonID="+complAddonID+"&customMailText="+customMailText;
	ajaxRequest.open("GET","ajax/ajaxSendComplAddonCompanyMail.php"+queryString, true);
	ajaxRequest.send(null);
}

function confirmAddonAccommodation(bookingID,bookingMode){
	//Function to confirm Addon accomdation
	var answer=confirm("Confirm?");
	if(answer){
		var ajaxRequest=createRequest('bookingAddonAccommodationConfirmationStatus_'+bookingID);
		var queryString = "?bookingID="+bookingID+"&bookingMode="+bookingMode;
		ajaxRequest.open("GET","ajax/ajaxAddonAccommodationConfirmation.php"+queryString, true);
		ajaxRequest.send(null);
	}
}


function showAddonAccommodation(bookingMode){
	//Function to display additional package accommodation status
	var companyID=document.getElementById('companyID').value;
	var bookingAddonAccomStatus=document.getElementById('bookingAddonAccomStatus').value;
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var ajaxRequest=createRequest('addonAccommodationDisplayDiv');
	var queryString = "?companyID="+companyID+"&bookingAddonAccomStatus="+bookingAddonAccomStatus+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayAddonAccommodation.php" + queryString, true);
	ajaxRequest.send(null);
}

function sendPackageCompanyMail(companyID,bookingID,mode){
	//Function to Send accomdation mail
	var ajaxRequest=createRequest('packageSendMailActionDiv_'+companyID);
	var fromDate=document.getElementById('txtFromDate_p_accom_'+companyID).value;
	var toDate=document.getElementById('txtToDate_p_accom_'+companyID).value;
	var mailText=document.getElementById('customAccomMailText_'+companyID).value;
	var queryString = "?companyID="+companyID+"&bookingID="+bookingID+"&mode="+mode+"&fromDate="+fromDate+"&toDate="+toDate+"&mailText="+mailText;
	ajaxRequest.open("GET","ajax/ajaxSendPackageCompanyMail.php"+queryString, true);
	ajaxRequest.send(null);
}

function confirmPackageAccommodation(bookingID,bookingMode){
	//Function to confirm Accommodation
	var answer=confirm("Confirm?");
	if(answer){
		var ajaxRequest=createRequest('bookingPackageAccommodationConfirmationStatus_'+bookingID);
		var queryString = "?bookingID="+bookingID+"&bookingMode="+bookingMode;
		ajaxRequest.open("GET","ajax/ajaxPackageAccommodationConfirmation.php"+queryString, true);
		ajaxRequest.send(null);
	}
}

function showPackageAccommodation(bookingMode){
	//Function to display additional package accommodation status
	var companyID=document.getElementById('companyID').value;
	var bookingPackageAccomStatus=document.getElementById('bookingPackageAccomStatus').value;
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var ajaxRequest=createRequest('packageAccommodationDisplayDiv');
	var queryString = "?companyID="+companyID+"&bookingPackageAccomStatus="+bookingPackageAccomStatus+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayPackageAccommodation.php" + queryString, true);
	ajaxRequest.send(null);
}

/*function showVehicles(pl_ID,mode){
	//Function to display vehicles
	if(pl_ID==0){
		alert('No pick-up locations selected');
	}
	else{
			/////--------------------------8-12-10---------------------------------------------
			/*if(packageType='C'){
				var from_date=trim(document.frmBookingChildVehicleAllocation.vehicle_start_date.value);
				var to_date=trim(document.frmBookingChildVehicleAllocation.vehicle_end_date.value);
				var num_people=document.getElementById('bookingNumberOfPeople').value;
				var ajaxRequest=createRequest('vehicleDisplayDiv_child');	
			}*/
			/////--------------------------------------------------------------------------------
			/*else{*\/
				var from_date=trim(document.frmBookingVehicleAllocation.vehicle_start_date.value);
				var to_date=trim(document.frmBookingVehicleAllocation.vehicle_end_date.value);
				var num_people=document.getElementById('bookingNumberOfPeople').value;
				var ajaxRequest=createRequest('vehicleDisplayDiv');
			/*}*\/
		
		if(document.getElementById('packageID') && document.getElementById('packageID').value>0){
			var packageID=document.getElementById('packageID').value;
			var queryString = "?pl_ID="+pl_ID+"&num_people="+num_people+"&mode="+mode+"&from_date="+from_date+"&to_date="+to_date+"&packageID="+packageID;
		}
		else{
			var queryString = "?pl_ID="+pl_ID+"&num_people="+num_people+"&mode="+mode+"&from_date="+from_date+"&to_date="+to_date+"&packageID=0";
		}
		/*if(mode=='B'){
			var packageID=document.getElementById('packageID').value;
			queryString +="&packageID="+packageID;
		}*\/
		ajaxRequest.open("GET","ajax/ajaxDisplayVehiclesBYPickUpLocation.php"+queryString, true);
		ajaxRequest.send(null);
	}
}*/



function showVehiclesByPickup(bookingID,mode,packageID,selectedPackageID,num_people,pl_ID){
	//Function to display vehicles
	if(pl_ID==0){
		alert('No pick-up locations selected');
	}
	else{
		var from_date=trim(document.getElementById('dateoftravel_valloc').value);
		var to_date=trim(document.getElementById('to_dateoftravel_valloc').value);
		if(trim(packageID)==''){
			packageID=0;
		}
		
		//var queryString = "pl_ID="+pl_ID+"&num_people="+num_people+"&bookingID="+bookingID+"&mode="+mode+"&from_date="+dateoftravel_valloc+"&to_date="+to_dateoftravel_valloc+"&packageID="+packageID+"&selectedPackageID="+selectedPackageID;
		var queryString = "pl_ID="+pl_ID+"&num_people="+num_people+"&bookingID="+bookingID+"&mode="+mode+"&from_date="+from_date+"&to_date="+to_date+"&packageID="+packageID+"&selectedPackageID="+selectedPackageID;

		$('#layer').show();
		$.ajax({
		   type:"POST",
		   url:baseUrl+"administrator/ajax/ajaxDisplayVehiclesBYPickUpLocation.php",
		   data:queryString,
		   /*dataType:'json',
		   success:function(resultData){
				if(trim(resultData['flag'])=='true'){
					document.getElementById('bookingVehicleAllocationDiv').innerHTML=resultData['html'];
					//document.getElementById('div_customAllocationOptions').innerHTML='';
				}
				else{
					alert(resultData['html']);
				}
				$('#layer').hide();
		   }*/
		   
		   dataType:'html',
		   success:function(html){
				document.getElementById('vehicleDisplayDiv_'+packageID).innerHTML=html;
				$('#layer').hide();
		   }
		});
	}
}





function allocateVehicle(selectedPackageID,dateOfTravel,numPeople,bookingID,bookingMode){
	//function for allocating vehicles
	var packages=document.getElementsByName('alloc_pkg[]');
	var numPackages=packages.length;
	var p_vs_string='';
	//alert(numPeople);
	for(var pi=0;pi<numPackages;pi++){
		packageID=packages[pi].value;
		var pickup=document.getElementById('txtPickupLocation_'+packageID).value;
		
		var vehicles=document.getElementsByName('vehicle_id_'+packageID+'[]');
		var numVehicles=vehicles.length;
		var totalSelectedSeats=0;
		var vs_string='';
		if(Number(numVehicles)>0){
			for(var i=0;i<numVehicles;i++){
				var vehicleID=vehicles[i].value;
				if(bookingMode=='B'){
					if(document.getElementById('vehicle_seats_'+packageID+'_'+vehicleID).checked){
						var seats=document.getElementById('vehicle_seats_'+packageID+'_'+vehicleID).value;
					}
					else{
						var seats=0;
					}
				}
				else{
					var seats=document.getElementById('vehicle_seats_'+packageID+'_'+vehicleID).value;
				}
				
				if((document.getElementById('privateVehicle')) && (document.getElementById('privateVehicle').checked==true)){
					if(seats>0){
						var privateVehicle=trim(document.getElementById('privateVehicle').value);
						var vehicleTotalSeats=document.getElementById('vehicleTotalSeats_'+packageID+'_'+vehicleID).value;
						var vehicleAvailableSeats=document.getElementById('vehicleAvailableSeats_'+packageID+'_'+vehicleID).value; 
						if(vehicleTotalSeats!=vehicleAvailableSeats){
							alert("Private Booking is not possible for one of the selected vehicle as some of its seats are already allocated for another booking..");
							return false;
						}
					}
				}
				else{
					var privateVehicle=0;
				}
				
				if(Number(seats)>0){
					totalSelectedSeats=Number(totalSelectedSeats)+Number(seats);
					if(trim(vs_string)==''){
						vs_string=vehicleID+":"+seats;
					}
					else{
						vs_string=vs_string+"|"+vehicleID+":"+seats;
					}
				}
			}
		}
		//alert(packageID+"---"+totalSelectedSeats);
		if(Number(totalSelectedSeats)!=Number(numPeople)){
			if(bookingMode=='B'){
				var msg="Please select a vehicle.";
			}else{
				var msg="Selected number of seats must be equal to number of people travelling.";
			}
			alert(msg);
			return false;
		}
		
		if(trim(p_vs_string)==''){
			p_vs_string=packageID+"^"+vs_string+"^"+pickup;
		}
		else{
			p_vs_string=p_vs_string+"<>"+packageID+"^"+vs_string+"^"+pickup;
		}
	}
	
	if(document.getElementById('exclusiveAllocation').value=="true"){
		var ans=confirm("Please make sure that you have selected the correct pickup locations for each product. If not, kindly click 'Cancel' and select pick ups. Else, click 'Ok' to continue...");
	}
	else{
		var ans=true;
	}
	
	if(ans){
		$('#layer').show();
		$.ajax({
		   type:"POST",
		   url:baseUrl+"administrator/ajax/ajaxAllocateVehicle.php",
		   data:"selectedPackageID="+selectedPackageID+"&dateOfTravel="+dateOfTravel+"&numPeople="+numPeople+"&bookingMode="+bookingMode+"&bookingID="+bookingID+"&privateVehicle="+privateVehicle+"&p_vs_string="+p_vs_string,
		   /*dataType:'json',
		   success:function(resultData){
				if(trim(resultData['flag'])=='true'){
					document.getElementById('bookingVehicleAllocationDiv').innerHTML=resultData['html'];
					//document.getElementById('div_customAllocationOptions').innerHTML='';
				}
				else{
					alert(resultData['html']);
				}
				$('#layer').hide();
		   }*/
		   
		   dataType:'html',
		   success:function(html){
				document.getElementById('bookingVehicleAllocationDiv').innerHTML=html;
				$('#layer').hide();
		   }
		});
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/*var num_people=document.getElementById('bookingNumberOfPeople').value;
	var vehicles=document.getElementsByName('vehicleID[]');
	array_size=vehicles.length;
	vehicleArray= new Array();
	vehicleFilter= new Array();
	var vehicleNum=0;
	var totalSeats=0;
	for(var i=0;i<array_size;i++){
		if(document.getElementById('vehicleID_'+i)){
			if(document.getElementById('vehicleID_'+i).checked){
				vid=document.getElementById('vehicleID_'+i).value;
				if(bookingMode=='M'){
					seats=document.getElementById('seatstobeallocated_'+vid).value;
				}
				else{
					seats=num_people;
				}
				if(trim(vid)=='' || trim(seats)==''){
					vid=0;
					seats=0;
				}
				totalSeats = Number(Number(totalSeats) + Number(seats));
				vehicleArray[vehicleNum]=vid+"|"+seats;
				vehicleNum++;
			}
		}
	}

	if(vehicleNum==0){
		alert('Please select vehicles to be allocated');
		return false;
	}
	
	if(totalSeats!=num_people){
		alert("Total seats to be allocated must be equal to number of people travelling!");
		return false;
	}
	
	if(vehicleNum>0){
		var from_date=trim(document.frmBookingVehicleAllocation.vehicle_start_date.value);
		var to_date=trim(document.frmBookingVehicleAllocation.vehicle_end_date.value);
		if((document.getElementById('privateVehicle')) && (document.getElementById('privateVehicle').checked==true)){
			vehicleArraySize=vehicleArray.length;
			for(var i=0;i<vehicleArraySize;i++){
				vehicle_seats=vehicleArray[i].split('|');
				vehicleID=vehicle_seats[0];
				//alert(vehicleID);
				var privateVehicle=trim(document.getElementById('privateVehicle').value);
				var vehicleTotalSeats=document.getElementById('vehicleTotalSeats_'+vehicleID).value;
				var vehicleAvailableSeats=document.getElementById('vehicleAvailableSeats_'+vehicleID).value;
				if(vehicleTotalSeats!=vehicleAvailableSeats){
					alert("Private Booking is not possible for the selected vehicle as it is already allocated for another booking..");
					return false;
				}
			}
		}

		var bookingID=document.getElementById('bookingID').value;
		var pl_ID=document.getElementById('pickUpLocID').value;
		var queryString = "bookingMode="+bookingMode+"&from_date="+from_date+"&to_date="+to_date+"&bookingID="+bookingID+"&vehicle_string="+vehicleArray.toString()+"&num_people="+num_people+"&pl_ID="+pl_ID+"&privateVehicle="+privateVehicle;

		$('#layer').show();
		$.ajax({
			type: "POST",
			url: "ajax/ajaxAllocateVehicle.php",
			data: queryString,
			dataType:"html",
			success: function(html){
				document.getElementById('bookingVehicleAllocationDiv').innerHTML=html;
				$('#layer').hide();
			}
		});
	}
	else{
		alert('Please select vehicles to be allocated');
	}*/
}

function deallocateVehicle(bookingMode,bookingID,packageID,packageType){
	//Function for deallocating vehicles
	var ans=confirm("Do you really want to remove this allocation?");
	if(ans){
		var queryString = "bookingMode="+bookingMode+"&bookingID="+bookingID;
		$('#layer').show();
		$.ajax({
			type: "POST",
			url: baseUrl+"administrator/ajax/ajaxDeallocateVehicle.php",
			data: queryString,
			dataType:"html",
			success: function(html){
				document.getElementById('bookingVehicleAllocationDiv').innerHTML=html;
				$('#layer').hide();
			}
		});
	}
}

function showAllocatedVehicles(){
	//Function to filter vehicles alocated for booking
	var vehicleID=document.getElementById('vehicleID').value;
	var vehicleArea=document.getElementById('vehicleArea').value;
	var ajaxRequest=createRequest('vehiclesDisplayDiv');		
	var queryString = "?vehicleID="+vehicleID+"&vehicleArea="+vehicleArea;	
	ajaxRequest.open("GET", "ajax/ajaxDisplayAllocatedVehicles.php" + queryString, true);
	ajaxRequest.send(null);
}

function sendCompanyMail(bookingID,companyID,fromdate,todate,button,mode){
	//Function to send accomdation mail for manual booking	
	if(button!='T'){		
		if(document.getElementById('companyId').value==0){
			alert("Please Choose a Hotel");
			return false;
		}		
		var mode=companyID;			
		var companyID=document.getElementById('companyId').value;
		var fromdate=document.getElementById('txtFromDateAlt').value;
		var todate=document.getElementById('txtToDateAlt').value;
		var mailText=document.getElementById('customAccomMailText').value;		
		
		var ajaxRequest=createRequest('companySendMailActionDiv');
		var queryString = "?companyID="+companyID+"&bookingID="+bookingID+"&from="+fromdate+"&to="+todate+"&button="+button+"&mode="+mode+"&mailText="+mailText;
		ajaxRequest.open("GET","ajax/ajaxSendCompanyMail.php"+queryString, true);
		ajaxRequest.send(null);		
	}
	else{	
		if(mode=='mail'){
			var mailText=document.getElementById('customAccomMailText').value;			
		}
		
		var ajaxRequest=createRequest('companySendMailActionDiv');
		var queryString = "?companyID="+companyID+"&bookingID="+bookingID+"&from="+fromdate+"&to="+todate+"&button="+button+"&mode="+mode+"&mailText="+mailText;
		ajaxRequest.open("GET","ajax/ajaxSendCompanyMail.php"+queryString, true);
		ajaxRequest.send(null);
	}
}


function showCreditReport(){
	//Function to display sales/Credit Agent	
	var status=document.getElementById('status').value;
	var userID=document.getElementById('userID').value;
	
	if(document.getElementById('userID').value==0){
		alert("Please Choose a Credit Agent-Name");
		return false;
	}
	
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;	
	var ajaxRequest=createRequest('creditReportDisplayDiv');
	var queryString = "?status="+status+"&userID="+userID+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayCreditReport.php" + queryString, true);
	ajaxRequest.send(null);	
}


function showBookings_country(){
	//Function to display bookings from country			
	var txtCountry=document.getElementById('txtCountry').value;
	
	if(document.getElementById('txtCountry').value==0){
		alert("Please Choose a Country name");
		return false;
	}		
	
	if(document.getElementById('normalBooking').checked==true){
	 	var mode='B';
	 }
	 else{
		var mode='M';
	 }	 
	
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;	
	var ajaxRequest=createRequest('bookings_countryDisplayDiv');
	var queryString = "?txtCountry="+txtCountry+"&startDate="+startDate+"&endDate="+endDate+"&mode="+mode;
	ajaxRequest.open("GET", "ajax/ajaxDisplayBookings_country.php" + queryString, true);
	ajaxRequest.send(null);	
}


function showLunchDetail(bookingID,mode){
//Function to display lunch details for Manual Booking
	var meals=document.getElementsByName('mealId[]');
	var numPerson=document.getElementsByName('txtNumPerson[]');
	var flag=0;
	var mealsID=new Array();
	for(var i=0;i<meals.length;i++){
		if(numPerson[i].value==""){
			flag=1;
		}
		if(isNaN(numPerson[i].value)){
			flag=2;
		}
		mealID=document.getElementById('mealId_'+i).value;
		mealsID[mealID]=document.getElementById('txtNumPerson_'+i).value;
	}
	
	if(flag==1){
		alert("Please Enter Values for Number of Person");
		return false;
	}
	
	if(flag==2){
		alert("Please Enter Only Numeric Values for No of Person");
		return false;
	}
	var ajaxRequest=createRequest('lunchDetails');
	var queryString ="?mealsID="+mealsID+"&bookingID="+bookingID+"&mode="+mode;
	ajaxRequest.open("GET", "ajax/ajaxDisplayLunchDetails.php" + queryString, true);
	ajaxRequest.send(null);
}

function editLunchDetails(){
	//Function for editing lunch details 
	var bookingID=document.getElementById('bookingID').value;	
	var ajaxRequest=createRequest('lunchDetails');
	var queryString ="?bookingID="+bookingID;
	ajaxRequest.open("GET", "ajax/ajaxEditLunchDetails.php" + queryString, true);
	ajaxRequest.send(null);	
}

function cancelManualBooking(){
	//Function To cancal Manual Booking
	var bookingID=document.getElementById('bookingID').value;	
	var ajaxRequest=createRequest('deleteManualBooking');
	var queryString = "?bookingID="+bookingID;
	ajaxRequest.open("GET", "ajax/ajaxDeleteManualBooking.php" + queryString, true);
	ajaxRequest.send(null);
}


function showDirectSales(){
	//Function to display details of direct sales 		
	
	var bookingStatus=document.getElementById('bookingStatus').value;
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;	
	var ajaxRequest=createRequest('directSalesDisplayDiv');	
	var queryString = "?startDate="+startDate+"&endDate="+endDate+"&bookingStatus="+bookingStatus;
	ajaxRequest.open("GET", "ajax/ajaxDirectSales.php" + queryString, true);
	ajaxRequest.send(null);	
}


function showAgentSales(){
	//Function to display details of Agent sales 		
	
	var userID=document.getElementById('userID').value;
	var bookingStatus=document.getElementById('bookingStatus').value;
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;	
	var ajaxRequest=createRequest('agentSalesDisplayDiv');	
	var queryString = "?startDate="+startDate+"&endDate="+endDate+"&bookingStatus="+bookingStatus+"&userID="+userID;
	ajaxRequest.open("GET", "ajax/ajaxDisplayAgentSales.php" + queryString, true);
	ajaxRequest.send(null);	
}

function showAvailablePackage(user){
	//Function To show available package
	var selDate=document.getElementById('txtFromDateAlt').value;
	var packageId=document.getElementById('packageId').value;
	var numPeople=trim(document.getElementById('txtNumPerson').value);
	if(selDate==""){
		alert("Please select a date");
		document.getElementById('txtFromDate').focus();
	}
	else{
		if(numPeople==""){
			alert("Please enter the number of people");
			document.getElementById('txtNumPerson').focus();
		}
		else{
			if(isNaN(numPeople)){
				alert("Please enter numeric values only");
				document.getElementById('txtNumPerson').value="";
				document.getElementById('txtNumPerson').focus();
			}
			else{
				var ajaxRequest=createRequest('displayAvailablePackage');	
				var queryString = "?selDate="+selDate+"&numPeople="+numPeople+"&packageId="+packageId;
				//if(user=='agent'){
				ajaxRequest.open("GET","../ajax/ajaxShowAvailablePackage.php"+queryString, true);
				/*}
				else{
				ajaxRequest.open("GET","ajax/ajaxShowAvailablePackage.php"+queryString, true);
				}*/
				ajaxRequest.send(null);
			}
		}
	}
}


function showAvailableVehicles(){
//Function to filter vehicles available
	var vehicleCategID=document.getElementById('vehicleCategID').value;
	var assoProduct=document.getElementById('assoProduct').value;
	var startDate=document.getElementById('txtFromDateAlt').value;
	if(startDate=="" ){
		alert("Please select a date");
		document.getElementById('txtFromDate').focus();
		return false;
	}	
	
	var ajaxRequest=createRequest('availableVehiclesDisplayDiv');		
	var queryString = "?vehicleCategID="+vehicleCategID+"&assoProduct="+assoProduct+"&startDate="+startDate;	
	ajaxRequest.open("GET", "ajax/ajaxDisplayAvailableVehicles.php" + queryString, true);
	ajaxRequest.send(null);	
}

function showAvailableCourtesyBus(){
//Function to filter available Courtesy vehicles	
	var startDate=document.getElementById('txtFromDateAlt').value;
	if(startDate=="" ){
		alert("Please select a date");
		document.getElementById('txtFromDate').focus();
		return false;
	}		
	var ajaxRequest=createRequest('availableCourtesyBusDisplayDiv');		
	var queryString = "?startDate="+startDate;	
	ajaxRequest.open("GET", "ajax/ajaxDisplayAvailableCourtesyBus.php" + queryString, true);
	ajaxRequest.send(null);	
}


function deletePackageDate(delDate,packageID){
	//Function to delete package date
	var ans=confirm("Do you really want to delete this date");
	if(ans){
		var ajaxRequest=createRequest('packageCurrentAvailableDatesDiv');	
		var queryString = "?delDate="+delDate+"&packageID="+packageID;	
		ajaxRequest.open("GET","ajax/ajaxRemovePackageDate.php"+queryString, true);
		ajaxRequest.send(null);
	}
}

function showPackageDetails(productID,displayDiv){
	//Function to show the details of a package
	if(productID==0){
		alert("No products selected");
	}
	else{
		var ajaxRequest=createRequest(displayDiv);	
		var queryString = "?productID="+productID;
		ajaxRequest.open("GET","ajax/ajaxDisplayPackageDetails.php"+queryString, true);
		ajaxRequest.send(null);
	}
}


function changeVCategoryStatus(vCategoryId,status){
	//Function to change the status of a vehicle
	var id=vCategoryId;
	var status=status;	
	
	if(status==1){
		var ans=confirm("Are you sure you want to disable this Vehicle Category?");
	}
	if(status==0){
		var ans=confirm("Are you sure you want to enable this Vehicle Category?");
	}
	if(ans==false){
		return false;
	}
	
	else
	{
		if(status==1){
	var categID=document.getElementsByName('vehicleAssociation[]');	
	
	var flag=0;
		for(var i=0;i<categID.length;i++){
			if(categID[i].value==id){
				 flag=1;
			}
		}			
		
		if(flag==1){			
			alert("This Vehicle Category can't be disable as this Vehicle Category have an association with Vehicle. Please deassociate the corresponding Vehicle  before disable.");
			return false;
		}	
		}
		
		var ajaxRequest=createRequest('vCategoryStatusDiv_'+id);
		var queryString = "?id="+id+"&status="+status;		
		ajaxRequest.open("GET", "ajax/ajaxChangeVCategoryStatus.php" + queryString, true);		
		ajaxRequest.send(null);
			
	}
}


function deleteVCategory(vCategoryId){
	//Function to dlete Vehicle Category
	var id=vCategoryId;
	var a=confirm("Are you sure you want to delete?");
	
	if(a==false){				
		return false;
	}
	else{
		var categID=document.getElementsByName('vehicleAssociation[]');	
		var flag=0;
			for(var i=0;i<categID.length;i++){
				if(categID[i].value==id){
					 flag=1;
				}
			}				
			if(flag==1){
				alert("This Vehicle Category can't be delete as this Vehicle Category have an association with Vehicle.  Please deassociate the corresponding Vehicle  before delete");
				return false;
			}		
			else{
				var ajaxRequest=createRequest('vCategoryDeleteDiv_'+id);
				var queryString = "?id="+id;		
				ajaxRequest.open("GET", "ajax/ajaxDeleteVehicleCategory.php" + queryString, true);		
				ajaxRequest.send(null);
			}	
	}
}


function displayUser(userTypeId,form){
	//Function to display users corresponding to selected usertype
	if(userTypeId==4){
		alert('Please select a user-type');
	}
		var ajaxRequest=createRequest('userDisplayDiv');
		var queryString = "?userTypeId="+userTypeId+"&form="+form;
		ajaxRequest.open("GET", "ajax/ajaxDisplayUsersByType.php" + queryString, true);
		ajaxRequest.send(null);
}

function checkSetCommission(userId){
	//Function to Check whthe the user commission is set or not
		var ajaxRequest=createRequest('displayCheckSetCommission');
		var queryString = "?userId="+userId;
		ajaxRequest.open("GET", "ajax/ajaxCheckSetCommission.php" + queryString, true);
		ajaxRequest.send(null);
}


function showPickupLocation(){
	//Function to display PickupLocation according to selected 	product
	var productID=document.getElementById('productID').value;	
	var ajaxRequest=createRequest('product_pickuplocationDisplayDiv');	
	var queryString = "?productID="+productID;
	ajaxRequest.open("GET", "ajax/ajaxDisplayPickupLocation.php" + queryString, true);
	ajaxRequest.send(null);	
}

function showBookingLunchDetail(bookingID,mode){
//Function to display lunch details for Manual Booking
alert(bookingID);
	var meals=document.getElementsByName('mealId[]');
	alert(meals.length);
	
	var mealsID=new Array();
	for(var i=0;i<meals.length;i++){
		mealID=document.getElementById('mealId_'+i).value;
			mealsID[mealID]=document.getElementById('txtNumPerson_'+i).value;
	}
	var ajaxRequest=createRequest('lunchDetails');
	var queryString ="?mealsID="+mealsID+"&bookingID="+bookingID+"&mode="+mode;
	alert(queryString);
	ajaxRequest.open("GET", "ajax/ajaxDisplayBookingLunchDetails.php" + queryString, true);
	ajaxRequest.send(null);
}


function showPickupLocationProductEdit(vehicle_productId,vehicleID){
	//Function to display PickupLocation according to selected 	product
	var vehicle_productId=vehicle_productId;		
	var vehicleID=vehicleID;		
	var productID=document.getElementById('productID').value;		
	if(productID==0){
		var productID=document.getElementById('productID').value;	
		var ajaxRequest=createRequest('productEdit_pickuplocationDisplayDiv');	
		var queryString = "?productID="+productID+"&vehicleID="+vehicleID;
		ajaxRequest.open("GET", "ajax/ajaxDisplayEditProductPickupLocation.php" + queryString, true);
		ajaxRequest.send(null);		
	}
	else{					
		//alert("Allocated Pickup Locations will be deallocated !");
		var productID=document.getElementById('productID').value;				
		var ajaxRequest=createRequest('productEdit_pickuplocationDisplayDiv');	
		var queryString = "?productID="+productID+"&vehicleID="+vehicleID;
		ajaxRequest.open("GET", "ajax/ajaxDisplayEditProductPickupLocation.php" + queryString, true);
		ajaxRequest.send(null);				
	}
}

function showVehciles(productID){
	//Function to dispaly vehicles by products
	if(productID==0){
		alert("Please Select a Product");
		return false;
	}
	sdate=document.getElementById('curDateAlt').value;
	var ajaxRequest=createRequest('vehicleDisplayDiv');	
	var queryString = "?productID="+productID+"&sdate="+sdate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayVehicleByProduct.php" + queryString, true);
	ajaxRequest.send(null);		
}

function changeUserStatus(userID,type,userStatus,num){
	//Function to change status of a user
	if(userStatus==1){
		var ans=confirm("Are you sure you want to disable this user?");
	}
	if(userStatus==0){
		if(type==3){
			var ans=confirm("Are you sure you want to enable this user?");
		}
		else if(num<=0){
			alert("User Cant be Enabled Please Set the Commission first");
			return false;
		}
		else{
			var ans=confirm("Are you sure you want to enable this user?");
		}
	}
	if(ans==false){
		return false;
	}
		var ajaxRequest=createRequest('userStatusDiv_'+userID);
		var queryString = "?userID="+userID+"&userStatus="+userStatus+"&num="+num+"&type="+type;
		ajaxRequest.open("GET", "ajax/ajaxChangeUserStatus.php" + queryString, true);
		ajaxRequest.send(null);
}

function updateBookingLunch(mode){
	//Function to allocate meals
	var bookingID=document.getElementById('bookingID').value;
	var meals=document.getElementsByName('lunch_Id[]');
	var mealsIDs=new Array();
	var mealsNOs=new Array();
	for(var i=0;i<meals.length;i++){
		mealID=document.getElementById('lunch_Id_'+i).value;
		mealNumber=document.getElementById('txtNumPerson_'+i).value;
		mealsIDs[i]=mealID;
		mealsNOs[i]=Number(mealNumber);
	}
	var ajaxRequest=createRequest('bookingMealsAllocation_div');
	var queryString = "?mealsIDs="+mealsIDs+"&mealsNOs="+mealsNOs+"&bookingID="+bookingID+"&mode="+mode;
	ajaxRequest.open("GET", "ajax/ajaxAllocateBookingMeals.php" + queryString, true);
	ajaxRequest.send(null);
}

function showPickUpLocationsByProduct(productID){
	//function to show pick up locations by product
	var ajaxRequest=createRequest('pickuplocations_outerDiv');
	var queryString = "?productID="+productID;
	ajaxRequest.open("GET", "ajax/ajaxDisplayPickupLocationsByProduct.php" + queryString, true);
	ajaxRequest.send(null);
}

function calculateTotalBookings(div){
	//Function to calcaluate total Bookings
	if(div=='pl_Total'){
		var status=1;
		var plTotal=0;
		var num_places1=document.getElementById('numberOfPlaces1').value;
		if(document.getElementById('pick_up_loc_check').checked==true){
			for(var i=1;i<=num_places1;i++){
				if(trim(document.getElementById('numberOfBookings1__'+i).value)==''){
					status=0;
					alert("Please enter number in all boxes");
					document.getElementById('numberOfBookings1__'+i).focus();
					return false;
				}
				if(isNaN(trim(document.getElementById('numberOfBookings1__'+i).value))){
					status=0;
					alert("Please enter numeric values");
					document.getElementById('numberOfBookings1__'+i).value='';
					document.getElementById('numberOfBookings1__'+i).focus();
					return false;
				}
				plTotal=Number(plTotal)+Number(trim(document.getElementById('numberOfBookings1__'+i).value));
			}
			if(status==1){
				document.getElementById('pl_Total').value=Number(plTotal);
			}
		}
	}
	else{
		var status=1;
		var poTotal=0;
		var num_places=document.getElementById('numberOfPlaces').value;
		for(var i=1;i<=Number(num_places);i++){
			if(trim(document.getElementById('numberOfBookings__'+i).value)==''){
				status=0;
				alert("Please enter number in all boxes");
				document.getElementById('numberOfBookings__'+i).focus();
				return false;
			}
			if(isNaN(trim(document.getElementById('numberOfBookings__'+i).value))){
				status=0;
				alert("Please enter numeric values");
				document.getElementById('numberOfBookings__'+i).value='';
				document.getElementById('numberOfBookings__'+i).focus();
				return false;
			}
			else{
				poTotal=Number(poTotal)+Number(trim(document.getElementById('numberOfBookings__'+i).value));
			}
		}
		if(status==1){
			document.getElementById('po_Total').value=Number(poTotal);
		}
	}
}

function showMealsReport(){
	//Function to show Meals Report
	var startDate=document.getElementById('txtFromDateAlt').value;	
	var productID=document.getElementById('productID').value;
	var packageID=document.getElementById('packageID').value;
	var vehicleID=document.getElementById('vehicleID').value;
	
	if(startDate==""){
		alert("Please Select Date of Travel.");
		return false;
	}
	if(productID==0){
		alert("Please Select a Package.");
		return false;
	}
	
	if(packageID==0){
		alert("Please Select a Product.");
		return false;
	}
	
	if(vehicleID==0){
		alert("Please Select a Vehicle.");
		return false;
	}

	var ajaxRequest=createRequest('displayMealDetails');
	var queryString = "?startDate="+startDate+"&productID="+productID+"&packageID="+packageID+"&vehicleID="+vehicleID;	
	ajaxRequest.open("GET", "ajax/ajaxDisplayMealDetails.php" + queryString, true);
	ajaxRequest.send(null);
}


function showMeals(){
	//Function to show Meals Report
	var startDate=document.getElementById('txtFromDateAlt').value;

	if(startDate==""){
		alert("Please Select Date of Travel.");
		return false;
	}
	var ajaxRequest=createRequest('displayMealDetails');	
	var queryString = "?startDate="+startDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayMealDetails1.php" + queryString, true);
	ajaxRequest.send(null);
}





function generateRunSheet(mode,pid,newposition,currentPositionArray){
	//Function to generate Runsheet
	sdate=document.getElementById('curDateAlt').value;
	if(trim(sdate)==''){
		alert("Please Select a date");
		return false;
	}
	vehicleID=document.getElementById('vehicleID').value;
	if(vehicleID==0){
		alert("Please Select a vehicle");
		return false;
	}
	var ajaxRequest=createRequest('runSheetDisplayDiv');
	var queryString = "?vehicleID="+vehicleID+"&sdate="+sdate;
	if(mode=='sort'){
		queryString += "&pid="+pid+"&newposition="+newposition+"&currentPositionArray="+currentPositionArray;
	}
	ajaxRequest.open("GET", "ajax/ajaxGenerateRunSheet.php" + queryString, true);
	ajaxRequest.send(null);		
}

function updateRunsheetOrder(pid,newposition){
	//Functon to update Run sheet
	var currentPositionArray=document.getElementById('positionArray').value;
	generateRunSheet('sort',pid,newposition,currentPositionArray);
}

function generateCBusRunSheet(mode,pid,newposition,currentPositionArray){
	//Function to generate courtesy bus Runsheet
	sdate=document.getElementById('curDate').value;
	if(trim(sdate)==''){
		alert("Please Select a date");
		return false;
	}
	busID=document.getElementById('busID').value;
	if(busID==0){
		alert("Please Select a vehicle");
		return false;
	}
	var ajaxRequest=createRequest('courtesyBusRunSheetDisplayDiv');
	var queryString = "?busID="+busID+"&sdate="+sdate;
	if(mode=='sort'){
		queryString += "&pid="+pid+"&newposition="+newposition+"&currentPositionArray="+currentPositionArray;
	}
	ajaxRequest.open("GET", "ajax/ajaxGenerateBusSheet.php" + queryString, true);
	ajaxRequest.send(null);		
}

function updateCBusRunsheetOrder(pid,newposition){
	//Functon to update Run sheet
	var currentPositionArray=document.getElementById('positionArray').value;
	generateCBusRunSheet('sort',pid,newposition,currentPositionArray);
}

function showPaymentOptions(option){
	//Function to Show and hide payment details
	if((option=='cc_n') || (option=='ca_l')){
		$('#paymentOptions').show();
	}
	else{
		$('#paymentOptions').hide();
	}
}

function showPackageDescription(packageId){
	//Function to show package description on booking Form
	var ajaxRequest=createRequest('displayPackageDescription');
	var queryString = "?packageId="+packageId;
	ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayPackageDescription.php" + queryString, true);
	ajaxRequest.send(null);
}

function calculateTotalCommission(){
	//Function to Calculate Total Commission
	var values=document.getElementsByName('commissionValue[]');
	var total_commission=0;
	for(var i=0;i<values.length;i++){
		if(document.getElementById('commissionValue_'+i).checked==true){
			commission_=document.getElementById('commissionValue_'+i).value;
			commission__=commission_.split('|');
			commission=eval(commission__[0]);
			total_commission=eval(total_commission+commission);
		}
	}
	document.getElementById('div_totalCommission').innerHTML=total_commission;
}



function displayBookingByBkgType(bookingTypeId,formType){
	//function to display Bookings by Booking Type
	if(bookingTypeId==0){
		document.getElementById('viewProduct').style.display='none';
		if(formType!='D'){
			document.getElementById('viewStatus').style.display='none';
		}
	}
	else if(bookingTypeId==1){
		document.getElementById('viewProduct').style.display='block';
		if(formType!='D'){
			document.getElementById('viewStatus').style.display='none';
		}
	}
	else if(bookingTypeId==2){
		if(formType!='D'){
			document.getElementById('viewStatus').style.display='block';
		}
		document.getElementById('viewProduct').style.display='none';
	}
		if(document.getElementById('txtStatus')){
			var status=document.getElementById('txtStatus').value;
		}
		var ajaxRequest=createRequest('displayBooking');
		var queryString = "?bkgTypeId="+bookingTypeId+"&status="+status;
		if(formType=='D'){
			ajaxRequest.open("GET", "ajax/ajaxFilterDashBoard.php" + queryString, true);
		}
		else{
			ajaxRequest.open("GET", "ajax/ajaxDisplayListBookingByProduct.php" + queryString, true);
		}
		ajaxRequest.send(null);
}

function displayBookingByProduct(formType){
	//function to display Bookings by Products selected
	for(var i=0;i<3;i++){
		if(document.getElementById('txtBookingType_'+i)){
			if(document.getElementById('txtBookingType_'+i).checked==true){
						var bookingTypeId=i;
			}
		}
	}
	if(document.getElementById('normalBooking')|| document.getElementById('manualBooking')){
		if(document.getElementById('normalBooking').checked=true){
			var bookingTypeId=document.getElementById('normalBooking').value;
		}
		else if(document.getElementById('manualBooking').checked=true){
			var bookingTypeId=document.getElementById('manualBooking').value;
		}
	 }
	if(document.getElementById('txtPreferredDateAlt')){
		var preferredDate=document.getElementById('txtPreferredDateAlt').value;
	}
	if(document.getElementById('txtStatus')){
		var status=document.getElementById('txtStatus').value;
	}
	var productId=document.getElementById('txtProduct').value;
	
	/*if(status!=-1){
		productId=0;
	}*/
	var ajaxRequest=createRequest('displayBooking');
	var queryString = "?productId="+productId+"&bkgTypeId="+bookingTypeId+"&preferredDate="+preferredDate+"&status="+status;
	if(formType=='D'){
		ajaxRequest.open("GET", "ajax/ajaxFilterDashBoard.php" + queryString, true);
	}
	else{
		ajaxRequest.open("GET", "ajax/ajaxDisplayListBookingByProduct.php" + queryString, true);
	}
	ajaxRequest.send(null);
}


function displayPrevBookingByProduct(){
	//function to display  Previous Bookings by Products selected	
	for(var i=0;i<3;i++){
		if(document.getElementById('txtBookingType_'+i).checked==true){
			var bookingTypeId=i;
		}
	}
	var productId=document.getElementById('txtProduct').value;
	var status=document.getElementById('txtStatus').value;
	
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;

	var ajaxRequest=createRequest('displayBooking');
	var queryString = "?productId="+productId+"&bkgTypeId="+bookingTypeId+"&status="+status+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayPrevBookingByProduct.php" + queryString, true);
	ajaxRequest.send(null);
	
}

/*function displayPrevBookingByStatus(status){
	//function to display Previous Bookings by Staus 
	var bookingTypeId=2;
	var ajaxRequest=createRequest('displayBooking');
	var queryString = "?status="+status+"&bkgTypeId="+bookingTypeId;
	ajaxRequest.open("GET", "ajax/ajaxDisplayPrevBookingByProduct.php" + queryString, true);
	ajaxRequest.send(null);
}
*/
function displayPrevBookingByBkgType(bookingTypeId){
	//function to display Previous Bookings by Booking Type
	if(bookingTypeId==0){
		document.getElementById('viewProduct').style.display='none';
		document.getElementById('viewStatus').style.display='none';
	}
	else if(bookingTypeId==1){
		document.getElementById('viewProduct').style.display='block';
		document.getElementById('viewStatus').style.display='none';
	}
	else if(bookingTypeId==2){
		document.getElementById('viewStatus').style.display='block';
		document.getElementById('viewProduct').style.display='none';
	}
		var status=document.getElementById('txtStatus').value;
		var ajaxRequest=createRequest('displayBooking');
		var queryString = "?bkgTypeId="+bookingTypeId+"&status="+status;
		ajaxRequest.open("GET", "ajax/ajaxDisplayPrevBookingByProduct.php" + queryString, true);
		ajaxRequest.send(null);
}



function displayDashBordBookingByProduct(productId){
	//function to display Bookings by Products selected
	var bookingTypeId=1;
	var ajaxRequest=createRequest('displayBooking');
	var queryString = "?productId="+productId+"&bkgTypeId="+bookingTypeId;
	ajaxRequest.open("GET", "ajax/ajaxDisplayListDashBookingByProduct.php" + queryString, true);
	ajaxRequest.send(null);
}

function displayDashBordBookingByBkgType(bookingTypeId){
	//function to display Bookings by Booking Type
	if(bookingTypeId==0){
		document.getElementById('viewProduct').style.display='none';
	}
	else if(bookingTypeId==1){
		document.getElementById('viewProduct').style.display='block';
		var ajaxRequest=createRequest('dashBoardDisplayDiv_B');
	}
	else if(bookingTypeId==2){
		document.getElementById('viewProduct').style.display='none';
		var ajaxRequest=createRequest('dashBoardDisplayDiv_M');
	}
		var queryString = "?bkgTypeId="+bookingTypeId+"&status="+status;
		ajaxRequest.open("GET", "ajax/ajaxDisplayListDashBookingByProduct.php" + queryString, true);
		ajaxRequest.send(null);
}


function showAmbOptions(mode,call){
	//Function for ambassador booking
	if(document.getElementById('useAmbassodorCard')){
		var ambCard=document.getElementById('useAmbassodorCard');
		var ambdiscount=document.getElementById('ambdiscount').value;
	}
	/*var totalCalculated=document.getElementById('hid_totalNumofPeople').value;
	var totalEntered=document.getElementById('txtNumPeople').value;		
	if(eval(totalCalculated)>0){
		if(eval(totalCalculated)>eval(totalEntered)){
			alert("Total No.of people entered is less than the selected Number");
			document.getElementById('txtNumPeople').focus;
			document.getElementById('useAmbassodorCard').checked="false";
			return false;
		}
	}*/
	var totalCost=document.getElementById('txtTotalCost').value;
	var usertypeId=document.getElementById('userTypeID').value;	
	/*if(document.getElementById('extraNumPeople')){
		var extraNumPeople=document.getElementById('extraNumPeople').value;
	}*/
	if(call!='function'){
			if(document.getElementById('package_BookingType').value==0){
				/*if(document.getElementById('numFamily').value==0 && document.getElementById('numAdult').value==0 
				&& document.getElementById('numChildren').value==0){*/
				if(document.getElementById('txtNumPeople').value==0){
					alert("Please provide the no:of people travelling");
					document.getElementById('useAmbassodorCard').checked=false;
					document.getElementById('ambBooking').innerHTML='';
					return false;
				}	
			}
			else{
				var bookingtype=document.getElementsByName('bookingType[]');
				var flag=0;
				for(var i=0;i<bookingtype.length;i++){
					if(bookingtype[i].checked){
						 flag=1;
					}
				}
			}
		}
		if(flag==0 && document.getElementById('package_BookingType').value==1){
			alert("Please select Accomdation Style First");
			document.getElementById('useAmbassodorCard').checked=false;
			document.getElementById('ambBooking').innerHTML='';
			return false;
		}
	
	
	if(document.getElementById('txtNumPeople')){
		var NumPeople=document.getElementById('txtNumPeople').value;
	}
	//#Addedon 2/6/10
	else if(document.getElementById('package_BookingType').value==1){
		var bookingtype=document.getElementsByName('bookingType[]');
		for(var i=0;i<bookingtype.length;i++){
			if(bookingtype[i].checked){
				var bTypeId=bookingtype[i].value;
				//break;
			}
		}
		//alert(bTypeId);
		var NumPeople=document.getElementById('numPeople_'+bTypeId).value;
		//alert(NumPeople);
	}
	
	// ##
		
		//else{
			var ambdiscount=document.getElementById('ambdiscount').value;
			var usertypeId=document.getElementById('userTypeID').value;
			var totalCost=document.getElementById('txtTotalCost').value;
			var hidCost=document.getElementById('txtHidCost').value;
			var ambCard=document.getElementById('useAmbassodorCard');
			
			if(document.getElementById('priceoverride').checked==true){
				if(ambCard.checked==true){
					var val=1;
					document.getElementById('txtTotalCost').value=eval(totalCost) - (eval(ambdiscount)*eval(NumPeople));
				}
				else{
					var val=0;
					document.getElementById('txtTotalCost').value=eval(totalCost) + (eval(ambdiscount)*eval(NumPeople));
				}
			}
			else{
				if(ambCard.checked==true){
					  var val=1;
					  document.getElementById('txtTotalCost').value=eval(totalCost) - (eval(ambdiscount)*eval(NumPeople));
				}
				else{
					 var val=0;
					 document.getElementById('txtTotalCost').value=eval(hidCost);
				}
			}
		//}
		var ajaxRequest=createRequest('ambBooking');
		var queryString ="?val="+val+"&usertypeId="+usertypeId;
		ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayAmbOptions.php" + queryString, true);
		ajaxRequest.send(null);
}






function showAssignedVehicles(packageId,mode){
	//Function to display assigned vehicles
	var ajaxRequest=createRequest('vehicleDisplayDiv');
	var queryString = "?packageId="+packageId+"&mode="+mode;
	ajaxRequest.open("GET", "ajax/ajaxDisplayAssignedVehicles.php" + queryString, true);
	ajaxRequest.send(null);
}

function displayCancelledBookings(){
	//Function to display cancelled bookings
	var txtFromDate=document.getElementById('txtFromDateAlt').value;	
	if(txtFromDate==""){
		alert("Please select date of travel");
		return false;
	}
	var ajaxRequest=createRequest('displayCancelledBookingDiv');
	var queryString = "?preferredDate="+txtFromDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayCancelledBookings.php" + queryString, true);
	ajaxRequest.send(null);
}

function changeCourtesyBusStatus(id,status){
	//Function to change courtesy bus status
	var ans=confirm("Do you really want to "+status+" this bus");
	if(ans){
		var ajaxRequest=createRequest('courtesy_bus_actions_'+id);
		var queryString = "?status="+status+"&id="+id;
		ajaxRequest.open("GET", "ajax/ajaxChangeCourtesyBusStatus.php" + queryString, true);
		ajaxRequest.send(null);
	}
}

function confirmdeleteCourtesyBus(id){
	//Function to delete courtesy bus
	if(document.getElementById('allocationFlag_'+id).value==1){
		alert("This courtesy bus cannot be deleted as it is allocated to a booking");
		return false;
	}
	var ans=confirm("Do you really want to delete this courtesy bus?");
	if(ans){
		var ajaxRequest=createRequest('div_courtesyBusDisplay');
		var queryString = "?id="+id;
		ajaxRequest.open("GET", "ajax/ajaxDeleteCourtesyBus.php" + queryString, true);
		ajaxRequest.send(null);
	}
}

function listAvailableCourtesyBuses(bookingID){
	//Function to allocate courtesy bus for a booking
	var allocDate=document.getElementById('courtesyBusAllocDate').value;
	if(trim(allocDate)!=""){
		var ajaxRequest=createRequest('tab_courtesyBusAllocListing');
		var queryString = "?allocDate="+allocDate+"&bookingID="+bookingID;
		ajaxRequest.open("GET", "ajax/ajaxListAvailableCourtesyBuses.php" + queryString, true);
		ajaxRequest.send(null);
	}
	else{
		alert("Please select the date to be allocated.");
	}
}

function allocateCourtesyBus(busID,bookingID,bookingMode,num_people,packageID){
	//Function to allocate courtesy bus for a booking
	var allocDate=document.getElementById('courtesyBusAllocDate').value;
	if(trim(allocDate)!=""){
		var ajaxRequest=createRequest('tab_courtesyBusAllocation');
		var queryString = "?id="+busID+"&bookingID="+bookingID+"&allocDate="+allocDate+"&bookingMode="+bookingMode+"&num_people="+num_people+"&packageID="+packageID;
		ajaxRequest.open("GET", "ajax/ajaxAllocateCourtesyBus.php" + queryString, true);
		ajaxRequest.send(null);
	}
	else{
		alert("Please select the date to be allocated.");
	}
}

function deAllocateCourtesyBus(bookingID,bookingMode){
	//Function to de-allocate courtesy bus for a booking
	var ans=confirm("Do you really want to remove this allocation");
	if(ans){
		var ajaxRequest=createRequest('tab_courtesyBusAllocation');
		var queryString = "?bookingID="+bookingID+"&bookingMode="+bookingMode;
		ajaxRequest.open("GET", "ajax/ajaxDeAllocateCourtesyBus.php" + queryString, true);
		ajaxRequest.send(null);
	}
}

function assignToBus(){
	var ids=document.getElementsByName('caID[]');
	for(var i=0;i<ids.length;i++){ 
		if(ids[i]){
			if(ids[i].checked==true){
				var bookingID_stat=ids[i].value;
				var bookingID_st=bookingID_stat.split('#');
				var bookingID=bookingID_st[0];
				var stat=bookingID_st[1];
				var booking_mode=bookingID_st[2];
				var ajaxRequest=createRequest('cbus_'+bookingID);
				var queryString = "?bookingID="+bookingID+"&stat="+stat+"&booking_mode="+booking_mode;
				ajaxRequest.open("GET", "ajax/ajaxConfirmBusAllocation.php" + queryString, true);
				ajaxRequest.send(null);
			}
		}
	}
}

function showManualPackageOptions(packageID){
	if(packageID!=0){
	<!--	document.getElementById('tab_courtesyBus').style.display="none";-->
		document.getElementById('CheckDateAvailabilityButton').style.display="block";		
		<!--document.getElementById('NewPackageName').innerHTML='<input type="text" name="txtPackageName" id="txtPackageName" readonly=""/>';-->
		document.getElementById('divCourtesyBusButton').style.display="none";	
		document.getElementById('div_availableDates').style.display="block";
		if(document.getElementById('courtesyBus_status')){			
			document.getElementById('courtesyBus_status').value=0;	
			document.getElementById('courtesyBus_status').checked=false;			
		}
	}
	else{
		document.getElementById('CheckDateAvailabilityButton').style.display="none";
		document.getElementById('div_availableDates').style.display="none";
		<!--document.getElementById('tab_courtesyBus').style.display="block";-->
		<!--document.getElementById('NewPackageName').innerHTML='<input type="text" name="txtPackageName" id="txtPackageName"  			 />';	-->
		document.getElementById('divCourtesyBus').style.display="none";
		document.getElementById('divCourtesyBusButton').style.display="block";		
		document.getElementById('divCourtesyBusAvailability').style.display="none";		
		if(document.getElementById('courtesyBus_status')){			
			document.getElementById('courtesyBus_status').value=0;	
			document.getElementById('courtesyBus_status').checked=false;			
		}
	}
		var ajaxRequest=createRequest('displayNumDays');
		var queryString = "?packageID="+packageID;
		ajaxRequest.open("GET", "ajax/ajaxDisplayPackageNumDays.php" + queryString, true);
		ajaxRequest.send(null);
}

function createSalesReport(){
	//Function generate sales report
	var packageID=document.getElementById('packageID').value;
	if(packageID==0){
		var packageName = document.getElementById('packageID').options[document.getElementById('packageID').selectedIndex].text
	}
	else{
		var packageName = '';
	}
	var reportMode=document.getElementById('reportMode').value;
	var fromDate=document.getElementById('txtFromDateAlt').value;
	var toDate=document.getElementById('txtToDateAlt').value;
	var queryString = "packageID="+packageID+"&reportMode="+reportMode+"&fromDate="+fromDate+"&toDate="+toDate+"&packageName="+packageName;
	$('#layer').show();
	$.ajax({
		url: "ajax/ajaxGenerateSalesReport.php",
		global: true,
		type: "POST",
		data: queryString,
		dataType: "html",
		success: function(html){
			//alert(html);
			document.getElementById('display_salesReport').innerHTML=html;
			$('#layer').hide();
		}
	});
}

function showBankInfoForm(user_type){
	if(user_type==2){
		$('#div_bankAccountInfo').show();
	}
	else{
		$('#div_bankAccountInfo').hide();
	}
}

function confirmAccommodation(companyId,bookingId,mode){	
	// Function to confirm Accommodation
	var answer=confirm("Confirm?");
	if(answer){				
		var fromDate=document.getElementById('txtFromDate_p_accom_'+companyId).value;		
		var toDate=document.getElementById('txtToDate_p_accom_'+companyId).value;
		if(fromDate==""){
			alert("Invalid date selection");		
			return false;
		}
		if(toDate==""){
			alert("Invalid date selection");
			return false;
		}			
		var ajaxRequest=createRequest('displayConfirmAccomdation');
		var queryString = "?companyId="+companyId+"&bookingId="+bookingId+"&mode="+mode+"&fromDate="+fromDate+"&toDate="+toDate;
		ajaxRequest.open("GET", "ajax/ajaxConfirmAccomdation.php" + queryString, true);	
		ajaxRequest.send(null);				
	}
}

function confirmAddon(companyID,bookingID,addonID){
	// Function to confirm Addon Accommodation
	var answer=confirm("Confirm?");
	if(answer){	
		var startDate=document.getElementById('addon_'+addonID+'_start_date').value;
		var endDate=document.getElementById('addon_'+addonID+'_end_date').value;			
		if(startDate=="" || endDate==""){
			alert("Invalid date selection");		
			return false;
		}
		var queryString = "?companyID="+companyID+"&bookingID="+bookingID+"&addonID="+addonID+"&startDate="+startDate+"&endDate="+endDate;		
		var ajaxRequest=createRequest('displayConfirmAddon');		
		ajaxRequest.open("GET", "ajax/ajaxConfirmAddonAccomdation.php" + queryString, true);	
		ajaxRequest.send(null);
	}
}


function confirmCompAddon(bookingID,compAddonID){
	// Function to confirm Complimentory Addon Accommodation
	var answer=confirm("Confirm?");
	if(answer){	
/*		var startDate=document.getElementById('addon_'+addonID+'_start_date').value;
		var endDate=document.getElementById('addon_'+addonID+'_end_date').value;			
		if(startDate=="" || endDate==""){
			alert("Invalid date selection");		
			return false;
		}
*/		var queryString = "?bookingID="+bookingID+"&addonID="+compAddonID;		
		var ajaxRequest=createRequest('displayConfirmComplAddon');		
		ajaxRequest.open("GET", "ajax/ajaxConfirmComplAddon.php" + queryString, true);	
		ajaxRequest.send(null);
	}
}

function showCreditAgentMonthlySales(mode){
//Function to generate sales report/month for credit agents	
	
	var month_num=document.getElementById('month_num').value;
	var year_num=document.getElementById('year_num').value;	
	
		var ajaxRequest=createRequest('creditAgentMSalesDiv');
		var queryString ="?month="+month_num+"&year="+year_num;	
		if(mode=='credit'){
			ajaxRequest.open("GET", "ajax/ajaxDisplayMonthlySales_creditAgent.php" + queryString, true);
		}
		else{
			ajaxRequest.open("GET", "ajax/ajaxDisplayMonthlySales_nonCreditAgent.php" + queryString, true);
		}			
		ajaxRequest.send(null);
	
}

function createMonthlySalesReport(){
	//Function generate Monthly sales report
	var month_num=document.getElementById('month_num').value;
	var year_num=document.getElementById('year_num').value;
	var user_type=document.getElementById('user_type').value;
	var queryString = "?month_num="+month_num+"&year_num="+year_num+"&user_type="+user_type;
	var ajaxRequest=createRequest('display_salesReport');
	ajaxRequest.open("GET", "ajax/ajaxGenerateMonthlySalesReport.php" + queryString, true);
	ajaxRequest.send(null);
}

function showAssociatedVehicles(){
	//var availableId=document.getElementById('txtAvailablity').value
	var productId=document.getElementById('txtProduct').value;
	for(i=0; i<document.getElementsByName('txtVehicleAlloc').length;i++){
		if(document.getElementsByName('txtVehicleAlloc')[i].checked){
			var exclusiveType=document.getElementsByName('txtVehicleAlloc')[i].value;
		}
	}
	if(exclusiveType==0){
		var availableId	=0;
	}
	else{
		var availableId	=1;
	}
	if(productId==0){
		alert("Kindly select a Package");
		document.getElementById('txtAvailablity').value=0;
		return false;
	}
	if(document.getElementById('txtProductAssocation_1')){
		if(document.getElementById('txtProductAssocation_1').checked==true && document.getElementById('txtAssocPackage').value==0){
			alert("Kindly select the associated product");
			document.getElementById('txtAvailablity').value=0;
			document.getElementById('txtAssocPackage').focus();
			return false;
		}
	}
	if(availableId==1 && exclusiveType==1){
		document.getElementById('txtAvailablity').value='1';
		var queryString = "?productId="+productId;
		var ajaxRequest=createRequest('div_displayVehicle');
		ajaxRequest.open("GET", "ajax/ajaxShowAssocaitedVehicles.php" + queryString, true);
		ajaxRequest.send(null);
	}
	else if(availableId==1 && exclusiveType==2){
		document.getElementById('txtAvailablity').value='1';
		var ajaxRequest=createRequest('div_displayVehicle');
		ajaxRequest.open("GET", "ajax/ajaxShowExclusiveDays.php" , true);
		ajaxRequest.send(null);
	}
	else{
		document.getElementById('txtAvailablity').value='0';
		document.getElementById('div_displayVehicle').innerHTML="ALL";
	}
}

function changeAvailableDays(){
	//document.getElementById('txtAvailablity').value=0;
}

function deallocateRunsheetVehicle(){
	var ans=confirm("Do You Really Want To DeAllocate The Selected Vehicle From The Listed Bookings?");
	if(ans){
		var vehicleID=document.getElementById('vehicleID').value;
		if(vehicleID>0){
			var bids=document.getElementsByName('booking_ids[]');
			var num=bids.length;
			var str_bid="";
			if(num>0){
				for(var i=0;i<num;i++){
					var bval=bids[i].value;
					var bvals=bval.split('|');
					if(bvals[0]>0){
						str_bid=bval+','+str_bid;
					}
				}
				var queryString = "?str_bid="+str_bid+"&vehicleID="+vehicleID;
				var ajaxRequest=createRequest('runSheetDisplayDiv');
				ajaxRequest.open("GET", "ajax/ajaxDeallocateRunsheetVehicle.php" + queryString, true);
				ajaxRequest.send(null);
			}
			else{
				alert('Bookings Not Found');
			}
		}
		else{
			alert("Vehicle Not Selected");
		}
	}
}

/*function showSuburb(pId,mode){
	//Function to show the suburb name in booking forms
	var queryString = "?pId="+pId+"&mode="+mode;
	var ajaxRequest=createRequest('div_displaySuburb');
	if(mode=='M'){
		ajaxRequest.open("GET", "ajax/ajaxDisplaySuburb.php" + queryString, true);
	}
	else{
		ajaxRequest.open("GET", "administrator/ajax/ajaxDisplaySuburb.php" + queryString, true);
	}
	ajaxRequest.send(null);	
}

function showPickupTime(pickuplocationId,mode){
	//function to show the pick up time
	var queryString = "?pickuplocationId="+pickuplocationId;
	var ajaxRequest=createRequest('div_displayPickupTime');
	if(mode=='M'){
		ajaxRequest.open("GET", "ajax/ajaxDisplayPickupTime.php" + queryString, true);
	}
	else{
		ajaxRequest.open("GET", "administrator/ajax/ajaxDisplayPickupTime.php" + queryString, true);
	}
	ajaxRequest.send(null);	
}*/


function displayPickup(packageId){
	//function to display packages for a product selcted
	if(document.getElementById('txtPackage_'+packageId).checked==true){
		document.getElementById('div_displayPickup_'+packageId).style.display="block";
	}
	else{
		document.getElementById('div_displayPickup_'+packageId).style.display="none";
		var pickup=document.getElementsByName('txtPickup_'+packageId+'[]');
		var size=pickup.length;
		for(var i=0;i<size;i++){
			pickup[i].checked=false;
		}
	}
}

function displayPackages(productId){
	//function to display packages for a product selcted
	if(document.getElementById('txtProduct_'+productId).checked==true){
		document.getElementById('div_displayPackage_'+productId).style.display="block";
	}
	else{
		document.getElementById('div_displayPackage_'+productId).style.display="none";
		var package=document.getElementsByName('txtPackage_'+productId+'[]');
		var size=package.length;
		for(var i=0;i<size;i++){
			if(package[i].checked==true){
				packageId=package[i].value;
				document.getElementById('div_displayPickup_'+packageId).style.display="none";
				var pickup=document.getElementsByName('txtPickup_'+packageId+'[]');
				var size=pickup.length;
				for(var j=0;j<size;j++){
					pickup[j].checked=false;
				}
			}
			package[i].checked=false;
		}
	}
}

function showAvailableDays(vehicleId){
	//function to show avaialble days for a given vehcileId
	var txtAssocPackage=document.getElementById('txtAssocPackage').value;
	var numDays=document.getElementById('txtNumOfDays').value;
	var queryString = "?vehicleId="+vehicleId+"&txtAssocPackage="+txtAssocPackage+"&numDays="+numDays;
	var ajaxRequest=createRequest('div_availableDays');
	ajaxRequest.open("GET", "ajax/ajaxDisplayAvailableDays.php" + queryString, true);
	ajaxRequest.send(null);
	
}

function deleteVehicleDate(delDate,vehicleID,type){
	//Function to delete vehicle unavailable date
	var ans=confirm("Do you really want to delete this date");
	if(ans){
		var ajaxRequest=createRequest('vehicleCurrentAvailableDatesDiv');	
		var queryString = "?delDate="+delDate+"&vehicleID="+vehicleID+"&type="+type;	
		ajaxRequest.open("GET","ajax/ajaxRemoveVehicleDate.php"+queryString, true);
		ajaxRequest.send(null);
	}
}

function showAssociatedPackage(val){
	//Function  to show and hide associated package wj\hile package creation
	if(val==1){
		if(document.getElementById('txtNumOfDays').value==''){
			alert("Please enter the no of days in the product first");
			document.getElementById('txtNumOfDays').focus();
			return false;
		}
		document.getElementById('div_associatedPackage').style.display="block";	
		document.getElementById('txtAvailablity').value=0;
		document.getElementById('txtVehicleAlloc3').checked=true;
		document.getElementById('div_displayVehicle').innerHTML='ALL';
	}
	else{
		document.getElementById('div_associatedPackage').style.display="none";	
		document.getElementById('txtAvailablity').value=0;
		document.getElementById('txtVehicleAlloc3').checked=true;
		document.getElementById('div_displayVehicle').innerHTML='ALL';
	}
}

function showShareMeals(packageId,val){
	//function to show share meals while creating package
	if(packageId>0){
		$.ajax({
				   type:"POST",
				   url:"ajax/ajaxDayCheck.php",
				   data:"pkgId="+packageId,
				   dataType:"json",
				   success:function(val){
					   if(eval(document.getElementById('txtNumOfDays').value)<eval(val.package_numberOfDays)){
							alert("No of days entered for the product is less than the associated product's days.Please change the days.");
							document.getElementById('txtNumOfDays').focus();
							document.getElementById('txtAssocPackage').value='0';							
							return false;
						}
						else{
								document.getElementById('div_displayShareMeals').style.display="block";
								document.getElementById('txtAvailablity').value='0';
								document.getElementById('txtVehicleAlloc3').checked=true;
								document.getElementById('div_displayVehicle').innerHTML="ALL";
		
						}
				   }
			   })
			  
			   
			
			
			
		//document.getElementById('txtShareMeal_2').checked=true;
		/*if(val=='changepdt'){
			 var meals=document.getElementsByName('txtMeals[]');
			 for(var i=0;i<meals.length;i++){
				meals[i].checked=false;
				//alert("Already associated meals may get unchecked kindly select the associated meals ");
				//return false;
			 }
		}*/
	}
	else{
		document.getElementById('txtShareMeal_2').checked=true;
		document.getElementById('div_displayShareMeals').style.display="none";
	}
	
/*	if(document.getElementById('txtAssocPackage_'+packageId).checked==true){
		document.getElementById('div_displayShareMeals_'+packageId).style.display="block";
	}
	else{
		document.getElementById('div_displayShareMeals_'+packageId).style.display="none";
	}*/
}

function changeChildPackageVehiclePickup(i){
	var bookingID=document.getElementById('plChange_bookingID_'+i).value;
	var bookingMode=document.getElementById('plChange_bookingMode_'+i).value;
	var vehicleID=document.getElementById('plChange_vehicleID_'+i).value;
	var packageID=document.getElementById('plChange_packageID_'+i).value;
	var changedPickUpId=document.getElementById('changePickUpLoc_'+bookingMode+'_'+bookingID+'_'+vehicleID+'_'+packageID).value;
	if(changedPickUpId>0){
		var newlocation='bookingResourceAllocation.php?action=changeChildPickup&bookingID='+bookingID+'&bookingMode='+bookingMode+'&vehicleID='+vehicleID+'&packageID='+packageID+'&changedPickUpId='+changedPickUpId;
		document.location.href=newlocation;
	}
	else{
		alert('None Selected.');
	}
}

function changePackageVehiclePickup(bookingID,bookingMode,packageID,parentType){
	//alert('changePickUpLoc_'+bookingMode+'_'+bookingID+'_'+packageID+'_'+parentType);
	var changedPickUpId=document.getElementById('changePickUpLoc_'+bookingMode+'_'+bookingID+'_'+packageID+'_'+parentType).value;
	if(changedPickUpId>0){
		var newlocation='bookingResourceAllocation.php?action=changePickup&bookingID='+bookingID+'&bookingMode='+bookingMode+'&packageID='+packageID+'&parentType='+parentType+'&changedPickUpId='+changedPickUpId;
		document.location.href=newlocation;
	}
	else{
		alert('None Selected.');
	}
}

function getVehicle(pl_ID,mode,from_date,numDays,packageID,num_people,loc){
	//Function to display vehicles
	if(pl_ID==0){
		alert('No pick-up locations selected');
	}
	else{
		var queryString = "?pl_ID="+pl_ID+"&num_people="+num_people+"&mode="+mode+"&from_date="+from_date+"&numDays="+numDays+"&packageID="+packageID;
		var ajaxRequest=createRequest('bookingFormSelectedVehicleID');
		if((mode=='M') || (loc=='admin')){
			ajaxRequest.open("GET","../ajax/ajaxVehicleBYPickUp.php"+queryString, true);
		}
		else{
			ajaxRequest.open("GET","ajax/ajaxVehicleBYPickUp.php"+queryString, true);
		}
		ajaxRequest.send(null);
	}
}

function showTourGuideCommissionPayments(){
	//Function to display Commission payment details of an Agent
	var paymentStatus=document.getElementById('paymentStatus').value;
	var userID=document.getElementById('userID').value;
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;
	var ajaxRequest=createRequest('TourGuidePaymentList_div');
	var queryString = "?paymentStatus="+paymentStatus+"&userID="+userID+"&startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxDisplayTourGuideCommissionPayments.php" + queryString, true);
	ajaxRequest.send(null);
}
function showDepositAmount(val,amt,id){
	var ajaxRequest=createRequest('div_depositAmount'+id);
	var queryString = "?val="+val+"&amt="+amt+"&id="+id;
	ajaxRequest.open("GET", "ajax/ajaxDisplayDeposit.php" + queryString, true);
	ajaxRequest.send(null);
}

function filterReconcileCash(){
	var startDate=document.getElementById('txtFromDateAlt').value;
	var endDate=document.getElementById('txtToDateAlt').value;	
	if(startDate==""){
		alert("Please enter From Date");
		document.getElementById('txtFromDate').focus();
		return false;
	}
	if(endDate==""){
		alert("Please enter To Date");
		document.getElementById('txtToDate').focus();
		return false;
	}
	var ajaxRequest=createRequest('reconcileDisplayDiv');	
	var queryString = "?startDate="+startDate+"&endDate="+endDate;
	ajaxRequest.open("GET", "ajax/ajaxfilterReconcileCash.php" + queryString, true);
	ajaxRequest.send(null);
}

function displayAgentType(usertypeID){
	//if(usertypeID==1){
		var ajaxRequest=createRequest('div_agentType');	
		var queryString = "?usertypeID="+usertypeID;
		ajaxRequest.open("GET", "ajax/ajaxDisplayAgentType.php" + queryString, true);
		ajaxRequest.send(null);
	//}
}

function savetourguide(){
	var	guide=document.getElementById('guide').value;
	var curDateAlt=document.getElementById('curDateAlt').value;
	var vehicleID=document.getElementById('vehicleID').value;	
	var txtTotalPeople=document.getElementById('txtTotalPeople').value;
	
	if(txtTotalPeople>0){
		$.ajax({
			type: "POST",
			url: "ajax/ajaxSaveTourGuide.php",
			data: "guide="+guide+"&curDateAlt="+curDateAlt+"&vehicleID="+vehicleID,
			dataType:"html",
			success: function(msg){
				printNow();
			}
		});
	}
	else{
		alert("No Information to print !!");	
	}
}

/*function checkAvailableDaysStatus(status){
		/*document.getElementById('txtAvailablity').value=0;
		document.getElementById('div_displayVehicle').innerHTML='';
	if(status==1 ||status==2){
		document.getElementById('div_availableDays_display').innerHTML='<select name="txtAvailablity" id="txtAvailablity" onchange="showAssociatedVehicles(this.value);"><option value="1" selected>Choose Days</option></select>';
	}
	else{
		document.getElementById('div_availableDays_display').innerHTML='<select name="txtAvailablity" id="txtAvailablity" onchange="showAssociatedVehicles(this.value);"><option value="0">All</select>';
	}
		
}*/





function showPloEntries(){
	$('#layer').show();
	var curDateAlt=document.getElementById('curDateAlt').value;
	var productID=document.getElementById('productID').value;	
	var packageID=document.getElementById('packageID').value;
	
	if(curDateAlt==""){
		alert("Please select a date");
	}
	else if(packageID>0 && productID>0){
		$.ajax({
			type: "POST",
			url: "ajax/ajaxShowPloEntries.php",
			data: "curDateAlt="+curDateAlt+"&productID="+productID+"&packageID="+packageID,
			dataType:"html",
			success: function(html){
				document.getElementById('div_placeoforigin').innerHTML=html;
				$('#layer').hide();
			}
		});
	}
	else{
		alert("Please select a product and package");
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function sendChildPackageCompanyMail(companyID,bookingID,mode){
	//Function to Send accomdation mail
	var fromDate=document.getElementById('txtFromDate_c_accom_'+companyID).value;
	var toDate=document.getElementById('txtToDate_c_accom_'+companyID).value;
	var mailText=document.getElementById('customChildAccomMailText_'+companyID).value;
	$.ajax({
		   type:"POST",
		   url:"ajax/ajaxSendChildPackageCompanyMail.php",
		   data:"companyID="+companyID+"&bookingID="+bookingID+"&mode="+mode+"&fromDate="+fromDate+"&toDate="+toDate+"&mailText="+mailText,
		   dataType:"html",
		   success:function(html){
			 document.getElementById('packageSendMailActionDiv_'+companyID).innerHTML=html;
		   }
    });
}

function confirmChildAccommodation(companyId,bookingId,mode){	
	// Function to confirm Accommodation
	var answer=confirm("Confirm?");
	if(answer){				
		var fromDate=document.getElementById('txtFromDate_c_accom_'+companyId).value;		
		var toDate=document.getElementById('txtToDate_c_accom_'+companyId).value;
		if(fromDate==""){
			alert("Invalid date selection");		
			return false;
		}
		if(toDate==""){
			alert("Invalid date selection");
			return false;
		}	
		$.ajax({
				type:"POST",
				url:'ajax/ajaxConfirmChildAccomdation.php',
				data:"companyId="+companyId+"&bookingId="+bookingId+"&mode="+mode+"&fromDate="+fromDate+"&toDate="+toDate,
				dataType:'html',
				success:function(html){
					document.getElementById('displayConfirmAccomdation').innerHTML=html	;				
				}
		});
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function displayProduct(packageId,formType){	
	var addonType=document.getElementById('txtAddonType').value;		
	$.ajax({
		   type:"POST",
		   url:"ajax/ajaxDisplayProduct.php",
		   data:"packageId="+packageId+"&addonType="+addonType,
		   dataType:'html',
		   success:function(html){
			   document.getElementById('div_productDisplay').innerHTML=html;
		   }
		   });
}


function reserveVehicle(selectedPackageID,dateOfTravel,numPeople,bookingMode){
	var packages=document.getElementsByName('alloc_pkg[]');
	var numPackages=packages.length;
	var p_vs_string='';
	//alert(numPeople);
	for(var pi=0;pi<numPackages;pi++){
		packageID=packages[pi].value;
		var pickup=document.getElementById('txtPickupLocation_'+packageID).value;
		
		var vehicles=document.getElementsByName('vehicle_id_'+packageID+'[]');
		var numVehicles=vehicles.length;
		var totalSelectedSeats=0;
		var vs_string='';
		if(Number(numVehicles)>0){
			for(var i=0;i<numVehicles;i++){
				vehicleID=vehicles[i].value;
				seats=document.getElementById('vehicle_seats_'+packageID+'_'+vehicleID).value;
				if(Number(seats)>0){
					totalSelectedSeats=Number(totalSelectedSeats)+Number(seats);
					if(trim(vs_string)==''){
						vs_string=vehicleID+":"+seats;
					}
					else{
						vs_string=vs_string+"|"+vehicleID+":"+seats;
					}
				}
			}
		}
		//alert(packageID+"---"+totalSelectedSeats);
		if(Number(totalSelectedSeats)!=Number(numPeople)){
			alert("Selected number of seats must be equal to number of people travelling");
			return false;
		}
		
		if(trim(p_vs_string)==''){
			p_vs_string=packageID+"^"+vs_string+"^"+pickup;
		}
		else{
			p_vs_string=p_vs_string+"<>"+packageID+"^"+vs_string+"^"+pickup;
		}
	}
	
	var ans=confirm("Please make sure that you have selected the correct pickup locations for each product. If not, kindly click 'Cancel' and select pick ups. Else, click 'Ok' to continue...");
	if(ans){
		$('#layer').show();
		$.ajax({
		   type:"POST",
		   url:baseUrl+"administrator/ajax/ajaxReserveVehicle.php",
		   data:"selectedPackageID="+selectedPackageID+"&dateOfTravel="+dateOfTravel+"&numPeople="+numPeople+"&bookingMode="+bookingMode+"&p_vs_string="+p_vs_string,
		   dataType:'json',
		   success:function(resultData){
				if(trim(resultData['flag'])=='true'){
					document.getElementById('div_availableDates').innerHTML=resultData['html'];
					document.getElementById('div_customAllocationOptions').innerHTML='';
				}
				else{
					document.getElementById('div_customAllocationOptions').innerHTML=resultData['html'];
				}
				$('#layer').hide();
		   }
		   
		   /*dataType:'html',
		   success:function(html){
				alert(html);
				document.getElementById('div_customAllocationOptions').innerHTML=html;
				$('#layer').hide();
		   }*/
		});
	}
}

function disableSameVehicles(vehicleID,packageID){
	var packages=document.getElementsByName('alloc_pkg[]');
	var numPackages=packages.length;
	if(trim(document.getElementById('sameDayCheck').value)=='true'){
		for(var pi=0;pi<numPackages;pi++){
			pid=packages[pi].value;			
			if((document.getElementById('vehicle_seats_'+pid+'_'+vehicleID)) && (Number(pid)!=Number(packageID))){
				if(Number(document.getElementById('vehicle_seats_'+packageID+'_'+vehicleID).value)>0){
					document.getElementById('vehicle_seats_'+pid+'_'+vehicleID).disabled=true;
				}
				else{
					document.getElementById('vehicle_seats_'+pid+'_'+vehicleID).disabled=false;
				}
			}
		}
	}
}

function remove_courtesy_bus_allocation(booking_id,mode){
	$.ajax({
		   type:"POST",
		   url:baseUrl+"administrator/ajax/ajaxDeAllocateCourtesyBus.php",
		   data:'booking_id='+booking_id+'&mode='+mode,
		   dataType:"html",
		   success:function(html){
				$('#courtesy_bus_deallocation_div').html(html);		
		   }
	});
		   
			
}

