
// JavaScript Document

var xmlHttp


function init() { 
	ld=document.getElementById('loading');
	ld.style.display="none"; 
}


function validate_login_form(msg)
{
	
	if(isEmpty('username') || isEmpty('password'))
		{
		_$('notification').style.display='block';
		_$('error').innerHTML=msg;
		return false;
		}
		
		else
		return true;
	
	}


function hideNotifications()
{
		_$('notification').style.display='none';
}
	


function convertToAEDAdmin(value,result_div)
{
	
if(value=="")
return false;

$('#'+result_div).text('converting please wait');
	
	$.ajax({
	   type: "POST",
	   url: "../contents/ajax.php",
	   data: "a=convertToAED&value="+value,
	   success: function(msg){
		 $('#'+result_div).text(msg );
	   }
 	});
	
}













function processTotal(feature,unit_price,quantity,result_div)
{
	
	shownoticediv('overlay','extras_notice');
	$('#'+result_div).text('updating please wait');
	
	if(quantity==false)
	quantity=0;
	else if(quantity==true)
	quantity=1;
	
	
	$.ajax({
	   type: "POST",
	   url: "contents/ajax.php",
	   data: "a=updatePrice&item="+feature+"&unit="+unit_price+"&quantity="+quantity,
	   success: function(msg){
		 closenoticediv('overlay','extras_notice');
		 $('#'+result_div).html(msg );
	   }
 	});
	
}


function processEditTotal(feature,unit_price,quantity,result_div)
{
	showeditnoticediv('editoverlay','editextras_notice');
	$('#'+result_div).text('updating please wait');
	
	if(quantity==false)
	quantity=0;
	else if(quantity==true)
	quantity=1;
	
	
	$.ajax({
	   type: "POST",
	   url: "contents/ajax.php",
	   data: "a=editbookingPrice&item="+feature+"&unit="+unit_price+"&quantity="+quantity,
	   success: function(msg){
		 closeeditnoticediv('editoverlay','editextras_notice');
		 $('#'+result_div).html(msg );
	   }
 	});
	
}

function setVisible(obj) 	{
	objSet = document.getElementById(obj);
	objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';
}

function setBookingStatusVisible(id,currstatus) { 
	bookstatus = document.getElementById('order_sts_'+id).value;
	document.getElementById('status_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		if(currstatus=="5" || currstatus=="4")
		{
			return false;	
		}
		else
		{
			objSet = document.getElementById('cancelledstatus_'+id);
			objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';
		}
	} 
	else
	{
		document.getElementById("statusform_"+id).submit();
	}
}
function setPickupBookingStatusVisible(id) { 
	bookstatus = document.getElementById('porder_sts_'+id).value;
	document.getElementById('pstatus_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		objSet = document.getElementById('pcancelledstatus_'+id);
		objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';
	} 
	else
	{
		document.getElementById("pstatusform_"+id).submit();
	}
}
function setOverduePickupBookingStatusVisible(id) { 
	bookstatus = document.getElementById('odporder_sts_'+id).value;
	document.getElementById('odpstatus_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		objSet = document.getElementById('odpcancelledstatus_'+id);
		objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';
	} 
	else
	{
		document.getElementById("odpstatusform_"+id).submit();
	}
}
function setDropBookingStatusVisible(id) { 
	bookstatus = document.getElementById('dorder_sts_'+id).value;
	document.getElementById('dstatus_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		objSet = document.getElementById('dcancelledstatus_'+id);
		objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';
	} 
	else
	{
		document.getElementById("dstatusform_"+id).submit();
	}
}
function setOverdueDropBookingStatusVisible(id) { 
	bookstatus = document.getElementById('oddorder_sts_'+id).value;
	document.getElementById('oddstatus_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		objSet = document.getElementById('oddcancelledstatus_'+id);
		objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';
	} 
	else
	{
		document.getElementById("oddstatusform_"+id).submit();
	}
}
function setNewBookingStatusVisible(id) { 
	bookstatus = document.getElementById('norder_sts_'+id).value;
	document.getElementById('nstatus_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		objSet = document.getElementById('ncancelledstatus_'+id);
		objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';
	} 
	else
	{
		document.getElementById("nstatusform_"+id).submit();
	}
}
function setModifBookingStatusVisible(id) { 
	bookstatus = document.getElementById('morder_sts_'+id).value;
	document.getElementById('mstatus_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		objSet = document.getElementById('mcancelledstatus_'+id);
		objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';
	} 
	else
	{
		document.getElementById("mstatusform_"+id).submit();
	}
}
function setCancelBookingStatusVisible(id) { 
	bookstatus = document.getElementById('corder_sts_'+id).value;
	document.getElementById('cstatus_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		/*objSet = document.getElementById('ccancelledstatus_'+id);
		objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';*/
		return false;
	} 
	else
	{
		document.getElementById("cstatusform_"+id).submit();
	}
}
function setRefundBookingStatusVisible(id) { 
	bookstatus = document.getElementById('rorder_sts_'+id).value;
	document.getElementById('rstatus_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		/*objSet = document.getElementById('rcancelledstatus_'+id);
		objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';*/
		return false;
	} 
	else
	{
		document.getElementById("rstatusform_"+id).submit();
	}
}
function setOverdueBookingStatusVisible(id) { 
	bookstatus = document.getElementById('oorder_sts_'+id).value;
	document.getElementById('ostatus_'+id).value = bookstatus;
	if(bookstatus=="5")
	{
		objSet = document.getElementById('ocancelledstatus_'+id);
		objSet.style.visibility = (objSet.style.visibility == 'visible') ? 'hidden' : 'visible';
	} 
	else
	{
		document.getElementById("ostatusform_"+id).submit();
	}
}


function setrefundreason(reason,divname,pkpdate)
{
	if(reason=='Car Unavailable')	
	{
		document.getElementById(divname).innerHTML = 'Yes, to be refunded&nbsp;';	
	}
	else if(reason=='No Appearance')	
	{
		document.getElementById(divname).innerHTML = 'No&nbsp;';	
	}
	else if(reason=='Cancelled by Customer')
	{
		var currentTime = new Date();
		var currmonth = currentTime.getMonth() + 1;
		if(currmonth<10)
			currmonth = '0'+currmonth;
		var currday = currentTime.getDate();
		if(currday<10)
			currday = '0'+currday;
		var curryear = currentTime.getFullYear();
		var arrPkup = pkpdate.split("/");
		var refundflag = 1;
		if(curryear>arrPkup[2])
		{
			refundflag = 0;
		}
		else
		{
			if(currmonth>arrPkup[0] && curryear==arrPkup[2])
			{
				refundflag = 0;
			}
			else
			{
				if((currday+2)>=arrPkup[1] && currmonth==arrPkup[0] && curryear==arrPkup[2])
				{
					refundflag = 0;
				}
			}
		}
		if(refundflag == 1)
		{
			document.getElementById(divname).innerHTML = 'Yes, to be refunded&nbsp;';
		}
		else if(refundflag == 0)
		{
			document.getElementById(divname).innerHTML = 'No, less than 2 days before pick-up date&nbsp;';
		}
	}
	return true;
}




function saveindexassignedStatus(letr,id) { 
	document.getElementById(letr+"statusform_"+id).submit();	
}

function saveassignedStatus(id) { 
	document.getElementById("statusform_"+id).submit();	
}

function sortOrders() {
	document.frmSort.submit();
}
function show_answer(div_id) {
	objSet = document.getElementById(div_id);
	objSet.style.display = (objSet.style.display == 'none') ? '' : 'none';
}

function searchagain()
{
	if(checkdates()==true)	
	{
		document.booking_form.submit();	
	}
}

function checkdates()
{
	var pkdate = document.getElementById('pick_date').value;
	var pktime = document.getElementById('pick_time').value;
	var rtdate = document.getElementById('return_date').value;
	var rttime = document.getElementById('return_time').value;
	
	var pkdatearr = pkdate.split("/");
	var pkmonth = pkdatearr[1];
	var pkday = pkdatearr[0];
	var pkyear = pkdatearr[2];
	
	var rtdatearr = rtdate.split("/");
	var rtmonth = rtdatearr[1];
	var rtday = rtdatearr[0];
	var rtyear = rtdatearr[2];
	var wrongdate = 0;
	var samedate = 0;
	
	if(pkday==rtday && rtmonth==pkmonth && rtyear==pkyear)
	{
		samedate = 1;	
	}
	else
	{
		if(pkyear>rtyear)
		{
			wrongdate = 1;
		}
		else
		{
			if(pkmonth>rtmonth && rtyear==pkyear)
			{
				wrongdate = 1;
			}
			else
			{			
				if(pkday>rtday && rtmonth==pkmonth && rtyear==pkyear)
				{
					wrongdate = 1;
				}
			}
		}
	}
	
	if(pkdate!=''&&rtdate!='')
	{
		if(pktime=="0"||rttime=="0")
		{
			alert("Please select a valid time!");
			return false;
		}
	
		if(wrongdate==0)
		{
			if(pktime<10)
				pktime = '0'+pktime;
			if(rttime<10)
				rttime = '0'+rttime;
			if((pktime>rttime || pktime==rttime) && samedate==1)
			{
				alert("Pick-up time should be less than Return time!");
				return false;
			}
		}
		else if(wrongdate==1)
		{
			alert("Pick-up date should be less than Return date!");
			return false;	
		}
	}
	return true;
}



function shownoticediv(overlayname,divname) {
	var x=screen.width/3;
	var obj = document.getElementById(divname);
	obj.style.visibility="visible";
	obj.style.left=x+'px';
	var obj1 = document.getElementById(overlayname);
	obj1.style.visibility="visible";
	return false;
}

function closenoticediv(overlayname,divname) {
	var obj = document.getElementById(divname);
	obj.style.visibility="hidden";
	var obj1 = document.getElementById(overlayname);
	obj1.style.visibility="hidden";
}

function showeditnoticediv(overlayname,divname) {
	var x=screen.width/3;
	var obj = document.getElementById(divname);
	obj.style.visibility="visible";
	obj.style.left=x+'px';
	var obj1 = document.getElementById(overlayname);
	obj1.style.visibility="visible";
	return false;
}

function closeeditnoticediv(overlayname,divname) {
	var obj = document.getElementById(divname);
	obj.style.visibility="hidden";
	var obj1 = document.getElementById(overlayname);
	obj1.style.visibility="hidden";
}

function areyousure() {
	 if(confirm("Are you sure you want to delete this item?")) {
		return true;
	}
	else {
		return false;
	}
} 
function backupalert() {
	 if(confirm("Are you sure you want to continue?")) {
		return true;
	}
	else {
		return false;
	}
} 

function restorealert() {
	 if(confirm("Are you sure want to restore? It will overwrite your exisiting Database and User Contents and you will be logged out and you may need to get login again.")) {
		return true;
	}
	else {
		return false;
	}
}

function change_retntime()
{
	var pknum = document.getElementById('pick_time').selectedIndex;
	if(document.getElementById("return_time").selectedIndex==0)
	{
		document.getElementById("return_time").selectedIndex = pknum;
	}	
}

function pikup_chek_locn(locid)
{
	

	
	for(var i=4; i<11; i++)
	{
		document.getElementById("pikup_airportfee_div_"+i).style.display = "none";	
	}
	if(locid>3&&locid<11)
	{
		document.getElementById("pikup_airportfee_div_"+locid).style.display = "";
	}	
	
	
	
	
}

function return_chek_locn(locid)
{
	for(var i=4; i<11; i++)
	{
		document.getElementById("return_airportfee_div_"+i).style.display = "none";	
	}
	if(locid>3&&locid<11)
	{
		document.getElementById("return_airportfee_div_"+locid).style.display = "";
	}	
}



function checkDateAndDisableOptions(sourceDate,selectOther)
{
	
	
	var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
today= day + "/" + month + "/" + year;
if(dateDifference(today,sourceDate) < 2)
{


document.getElementById('t_3').disabled=true;
document.getElementById('t_4').disabled=true;
document.getElementById('t_5').disabled=true;
document.getElementById('t_6').disabled=true;


if(selectOther==1 )
{
document.getElementById('pick_time').value = 7;
}


}
else
{
document.getElementById('t_3').disabled=false;
document.getElementById('t_4').disabled=false;
document.getElementById('t_5').disabled=false;
document.getElementById('t_6').disabled=false;

}

	
	
	}


function dateDifference(t1,t2)
{

   //Total time for one day

        var one_day=1000*60*60*24; 
//Here we need to split the inputed dates to convert them into standard format


        var x=t1.split("/");     
        var y=t2.split("/");
  //date format(Fullyear,month,date) 


        var date1=new Date(x[2],(x[1]-1),x[0]);
  
        var date2=new Date(y[2],(y[1]-1),y[0])
        var month1=x[1]-1;
        var month2=y[1]-1;
        
        //Calculate difference between the two dates, and convert to days

               
        _Diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day)); 
return _Diff;
}


