
/* functions.js*
 * Developed by Technoibiz 
 * www.technoibiz.com
 * Project manager Rejieve Alexander
 * Project technical support Kevin Brown 
 */
function trim(str)
{
    if(!str || typeof str != 'string'){
		var str="";
        return str;
	}
    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function showHide_slide(id){
	$('#'+id).slideToggle('slow');
	$('#'+id).css('float','right');
	
}

function toggleDisabled(el) {
	try {
		el.disabled = el.disabled ? false : true;
	}
	catch(E){}
	
	if (el.childNodes && el.childNodes.length > 0) {
		for (var x = 0; x < el.childNodes.length; x++) {
			toggleDisabled(el.childNodes[x]);
		}
	}
}

function printNow(){
	window.print();
}

function emptyIt(el){
	$("#"+el).empty();
}

function displayByBookingMethod(method){
	if(method=='normalBooking'){
		methodInverse='manualBooking';
	}
	else if(method=='manualBooking'){
		methodInverse='normalBooking';
	}
	$('.'+methodInverse).hide();
	$('.'+method).show();
}


function displayByBookingType(type,mode){	
	if(type=='type1'){
		methodInverse='bookingType2';
		method='bookingType1';		
	}
	else if(type=='type2'){
		methodInverse='bookingType1';
		method='bookingType2';
	}
	$('#'+methodInverse).hide();
	$('#'+method).show();
}


function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function booking_goTo(buttonName,mode,bookingID,rebook){
	if(document.getElementById('mode') && document.getElementById('mode').value=='M'){
		mode='M';
	}
	if(mode=='M' && document.getElementById('dashboard')){
		var bookingIDs=document.getElementsByName('bookingID_manual[]');
			for(var i=0;i<bookingIDs.length;i++){
				if(bookingIDs[i].checked){
					var bookingID=bookingIDs[i].value;
				}
			}
	}
	else{
			var bookingIDs=document.getElementsByName('bookingID[]');
			for(var i=0;i<bookingIDs.length;i++){
				if(bookingIDs[i].checked){
					var bookingID=bookingIDs[i].value;
				}
			}
	}
	
	if(bookingID>0){
		if(mode=='M'){
			switch (buttonName){
				case 'allocateResources':
					if(document.getElementById('pkgId') && document.getElementById('pkgId').value>0){
						document.frmListBooking.action="bookingResourceAllocation.php?bid="+bookingID+'&mode=M';
						
					}
					else{
						document.frmListBooking.action="manualResourceAllocation.php?bid="+bookingID+'&mode=M';
					}
					break;
						
				case 'deallocateResources':
					document.frmListBooking.action="manualbookingResourceDeAllocation.php";
					break;
				
				case 'cancelBooking':
					if(rebook=='Rebook'){
						if(document.getElementById('packageID') && document.getElementById('packageID').value>0){
							document.frmBookingRecDetails.action="cancelManualBooking.php";
							break;
						}
						else{
							document.frmManualBookingRecDetails.action="cancelManualBooking.php";
							break;
						}
					}
					else{				
						document.frmListBooking.action="cancelManualBooking.php?bID="+bookingID;
						break;
					}
				
				case 'editBooking':
					document.frmListBooking.action="editManualBooking.php?bid="+bookingID+'&mode=M';
					break;
				
				case 'allocateVehicle':
					document.frmListBooking.action="manualResourceAllocation.php?bid="+bookingID+'&mode=M';
					break;
			}
		}
		else{
			switch (buttonName){
				case 'allocateResources':
					document.frmListBooking.action="bookingResourceAllocation.php?bid="+bookingID+'&mode=B';
					break;
				
				case 'allocateVehicle':
					document.frmListBooking.action="bookingResourceAllocation.php#top_vehicle?bid="+bookingID+'&mode=B';
					break;
				
				case 'deallocateResources':
					document.frmListBooking.action="bookingResourceDeAllocation.php?bid="+bookingID+'&mode=B';
					break;
				
				case 'cancelBooking':
					if(rebook=='Rebook'){
						document.frmBookingRecDetails.action="cancelBooking.php";
						break;
					}
					else{	
						document.frmListBooking.action="cancelBooking.php?bID="+bookingID;
						break;
					}
				
				case 'editBooking':
					document.frmListBooking.action="editBooking.php?bid="+bookingID+'&mode=B';
					break;
				
				case 'allocateMeals':
					document.frmListBooking.action="allocateLunch.php?bid="+bookingID+'&mode=B';
					break;
			}
		}
	}
	else{
		alert("Please select one");
		return false;		
	}
}

//top menu
function menuHover(id){
	$('.menuItem li ul').hide();
	$('.menuItem li a').css('background','#171515');
	$('#'+id+' li a').css('background','#333333');
	$('#'+id+' li ul').show();
}
function menuHout(){
	$('.menuItem li ul').hide();
	$('.menuItem li a').css('background','#171515');
}

function showHideLoginForm(val){
	if(val==1){
		document.getElementById('loginBox').style.visibility='visible';
	}
	else{
		document.getElementById('loginBox').style.visibility='hidden';
	}
}

function addNewDateField(mode){
	var num=Number(document.getElementById('num_dateFields').value)+1;
	if(mode=='vehicle'){
		$("#vehicleAvailableDatesDiv").append('<tr><td align="left" valign="middle"><input type="text" id="date'+num+'" name="availableDate[]" class="popUpCalendarBox" /><input type="text" id="date'+num+'Alt" name="availableDateAlt[]" class="popUpCalendarBoxAlt" /></td><td align="left" valign="top"><b>Reason : </b><textarea name="txtReason[]" cols="50"  id="txtReason'+num+'"></textarea></td></tr>');
	}
	else{
		$("#packageAvailableDatesDiv").append('<tr><td align="left"><input type="text" id="date'+num+'" name="availableDate[]" class="popUpCalendarBox" /><input type="text" id="date'+num+'Alt" name="availableDateAlt[]" class="popUpCalendarBoxAlt" /></td></tr>');
	}
	document.getElementById('num_dateFields').value=Number(num);
	$("#date"+num).datepicker({mandatory: true, dateFormat:'dd/mm/yy', altField:"#date"+num+"Alt", altFormat:'m/d/yy'});
}

function removeDateField(mode){
	var num=Number(document.getElementById('num_dateFields').value)-1;
	if(Number(num)>=0){
		if(mode=='vehicle'){
			$("#vehicleAvailableDatesDiv tr:last").remove();
		}
		else{
			$("#packageAvailableDatesDiv tr:last").remove();
		}
		document.getElementById('num_dateFields').value=Number(num);
	}
}

function hardCodeAlert(){
	alert("Currently not functional");
	return false;
}

function alertWait(){
	alert('pls wait');
	return false;
}

function cancelAction(){
	history.go(-1);
}

function showTotalMeals(numStaff){
	var totMeals=document.getElementById('hidMealSum').value;
	var tot=eval(numStaff)+eval(totMeals);	
	document.getElementById('displayTotalMeals').innerHTML='<font color="#0066CC">'+tot+'</font>';
}



function displayTotalNumMeals(numStaff,productId,mode){	
	if(mode=='M'){		
		var total=0;
		var staffTotal=0;
		var mealNum=0;
			var tot=document.getElementsByName('hidMMealSum[]');	
			for(var i=0;i<tot.length;i++){
				var totMeals=document.getElementById('hidMMealSum_'+i).value;				
				total=eval(totMeals);			
			}	 
			 var staff=document.getElementsByName('txtMStaffMeal[]');	
			 for(var i=0;i<staff.length;i++){
				var totStaff=document.getElementById('txtMStaffMeal_'+i).value;			
				staffTotal=eval(totStaff)+eval(staffTotal);
			 }	 
		
		var mealNum=eval(staffTotal)+eval(total);	 	
		document.getElementById('displayTotalMealsManual').innerHTML='<font color="#0066CC">'+mealNum+'</font>';		
	}
	else{
		var total=0;
		var staffTotal=0;
		var mealNum=0;		
		var tot=document.getElementsByName('hidMealSum_'+productId+'[]');				
		for(var i=0;i<tot.length;i++){				
			var totMeals=document.getElementById('hidMealSum_'+productId+'_'+i).value;								
			total=eval(totMeals);			
		}	 
		 var staff=document.getElementsByName('txtStaffMeal_'+productId+'[]');	
		 for(var i=0;i<staff.length;i++){
			var totStaff=document.getElementById('txtStaffMeal_'+productId+'_'+i).value;			
			staffTotal=eval(totStaff)+eval(staffTotal);
		 }	 		
		var mealNum=eval(staffTotal)+eval(total);	 					
		document.getElementById('displayTotalMeals_'+productId).innerHTML='<font color="#0066CC">'+mealNum+'</font>';				
	}
	
}




function linkToSite(){
	window.open('http://demo.sightsee.com.au','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');	
}

function showConcession(){
//functon to hide and display concessions
	//To uncheck Price override
	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('chkConcession').checked==true){
		if(document.getElementById('numAdult')){document.getElementById('numAdult').value=0;}
		if(document.getElementById('numChildren')){document.getElementById('numChildren').value=0;}
		if(document.getElementById('familyType')){document.getElementById('familyType').value=0;}
		if(document.getElementById('numFamily')){document.getElementById('numFamily').value=0;}
		/*if(document.getElementById('discount_adult')){document.getElementById('discount_adult').innerHTML='';}
		if(document.getElementById('discount_child')){document.getElementById('discount_child').innerHTML='';}
		if(document.getElementById('discount_family')){document.getElementById('discount_family').innerHTML='';}
		if(document.getElementById('tot_discount')){document.getElementById('tot_discount').innerHTML='';}*/
		document.getElementById('div_concession').style.display="block";
	}
	else{
		if(document.getElementById('numAdult')){document.getElementById('numAdult').value=0;}
		if(document.getElementById('numChildren')){document.getElementById('numChildren').value=0;}
		if(document.getElementById('familyType')){document.getElementById('familyType').value=0;}
		if(document.getElementById('numFamily')){document.getElementById('numFamily').value=0;}
		/*if(document.getElementById('discount_adult')){document.getElementById('discount_adult').innerHTML='';}
		if(document.getElementById('discount_child')){document.getElementById('discount_child').innerHTML='';}
		if(document.getElementById('discount_family')){document.getElementById('discount_family').innerHTML='';}
		if(document.getElementById('tot_discount')){document.getElementById('tot_discount').innerHTML='';}*/
		document.getElementById('div_concession').style.display="none";
		
	}
}

function openNewWindow(path,name){	
	window.open(path,name,"toolbar=yes, directories=no, status=no,scrollbars=yes, resizable=yes, width=500, height=600");
}

function gotoBookingForm(productID,packageID,mode,userType){
	//function to redirect to booking form	
	var numPeople=document.getElementById('txtNumPerson').value;
	if(mode=='B'){
		window.location="../bookingForm.php?packageID="+packageID+"&numPeople="+numPeople+"&productID="+productID;
	}
	else if(userType=='administrator'){
		window.location="manualBookingForm.php?packageID="+packageID+"&numPeople="+numPeople+"&productID="+productID;
	}
	else{
		alert("Please contact back office for group bookings");
		return false;
	}
}


function showAddonType(method){
	//function to display/hide addon package price 	
	if(method=='C'){				
		 $('#ExtraNightDiv').hide();
		 $('#complimentaryDiv').show();
	}
	else {
		 $('#complimentaryDiv').hide();
		 $('#ExtraNightDiv').show();
	}	
	 document.getElementById('txtProduct').value=0;
	 document.getElementById('div_productDisplay').innerHTML="";
}

function DisplayAddons(method){
	//function to display/hide addon package price 	
	if(method=='C'){				
		 $('#addonExtraNight').hide();
		 $('#addonComplimentary').show();
	}
	else {
		$('#addonExtraNight').show();
		$('#addonComplimentary').hide();
	}	
}

function showReportTabs(tabClass){
	$('.'+tabClass).toggle();
}
