
var pickup_day;
var pickup_month;
var pickup_year;
var pickup_monthyear;
var return_day;
var return_month;
var return_year;
var return_monthyear;
var cal_pickup;
var cal_return;
var IntUrl_hiddenPickupTime = '12:00';
var IntUrl_hiddenReturnTime = '12:00';

function RecordTime(theTime,type)
{
           if(type=='pickup')
           {
           IntUrl_hiddenPickupTime = theTime;
           }
           else
           {
           IntUrl_hiddenReturnTime = theTime;
           }
 }

function initialise_cal(pickup_day,pickup_month,pickup_year,return_day,return_month,return_year)
{
    this.pickup_day = pickup_day;
    this.pickup_month = pickup_month;
    this.pickup_year = pickup_year;
    this.return_day = return_day;
    this.return_month = return_month;
    this.return_year = return_year;
    cal_pickup = new CalendarPopup();
    cal_pickup.setReturnFunction("setMultipleValues4");
    cal_return = new CalendarPopup();
    cal_return.setReturnFunction("setMultipleValues5");
}
function initialise_cal_MY(pickup_day,pickup_monthyear,return_day,return_monthyear)
{
    this.pickup_day = pickup_day;
    this.pickup_monthyear = pickup_monthyear;
    this.return_day = return_day;
    this.return_monthyear = return_monthyear;
    cal_pickup = new CalendarPopup();
    cal_pickup.setReturnFunction("setMultipleValues6");
    cal_return = new CalendarPopup();
    cal_return.setReturnFunction("setMultipleValues7");
}

function initialise_pickup(pickup_day,pickup_month,pickup_year)
{
    this.pickup_day = pickup_day;
    this.pickup_month = pickup_month;
    this.pickup_year = pickup_year;
}

function initialise_return(return_day,return_month,return_year)
{
    this.return_day = return_day;
    this.return_month = return_month;
    this.return_year = return_year;
}

function setMultipleValues4(y,m,d) 
{
	this.pickup_year.value = y;
	this.pickup_month.value = m;
	for (var i=0; i<this.pickup_day.options.length; i++) {
		if (this.pickup_day.options[i].value==d) {
			this.pickup_day.selectedIndex=i;
		}
	}
	pushReturnForward("pickup_day");
}

function setMultipleValues5(y,m,d) 
{
	this.return_year.value = y
	this.return_month.value = m;
	for (var i=0; i<this.return_day.options.length; i++) {
		if (this.return_day.options[i].value==d) {
			this.return_day.selectedIndex=i;
		}
	}
	set_return_day = true;
	set_return_month = true;
	set_return_year = true;
	pushReturnForward("return_day");
}

function setMultipleValues6(y,m,d) 
{
	this.pickup_monthyear.value = y + "-" + m;
	for (var i=0; i<this.pickup_day.options.length; i++) {
		if (this.pickup_day.options[i].value==d) {
			this.pickup_day.selectedIndex=i;
		}
	}
	pushReturnForward("pickup_day");
}

function setMultipleValues7(y,m,d) 
{
	this.return_monthyear.value = y + "-" + m;
	for (var i=0; i<this.return_day.options.length; i++) {
		if (this.return_day.options[i].value==d) {
			this.return_day.selectedIndex=i;
		}
	}
	set_return_day = true;
	set_return_month = true;
	set_return_year = true;
	pushReturnForward("return_day");
}
function getDateString(y_obj,m_obj,d_obj) 
{
	var y = getSelectedValue(y_obj);
	var m = getSelectedValue(m_obj);
	var d = getSelectedValue(d_obj);
	if (y=="") { return null; }
	if (m=="") { return null; }
	if (d=="") { d=1; }
	return str= y+'-'+m+'-'+d;
}
function getDateStringMY(ym_obj,d_obj) 
{
	var ym = getSelectedValue(ym_obj);
	var d = getSelectedValue(d_obj);
	if (ym=="") { return null; }
	if (d=="") { d=1; }
	return str= ym+'-'+d;
}
function getSelectedValue(ddl_obj){
	return ddl_obj.options[ddl_obj.selectedIndex].value;
}
function getMonthNum(abbMonth){
	var arrMon = new Array("Jan","Feb","Mar","Apr","May","Jun",
      "Jul","Aug","Sep","Oct","Nov","Dec");
	for(i=0; i<arrMon.length; i++) {
  		if(abbMonth == arrMon[i]) {
    		return i+1;
		}
	}
}
var set_return_day = false;
var set_return_month = false;
var set_return_year = false;
function pushReturnForward(fn){
	if (fn == "return_year") {
		set_return_year = true;
    } else if (fn == "return_month") {
    	set_return_month = true;
	} else if (fn == "return_day") {
		set_return_day = true;
	}
	var pd = this.pickup_day.value;
	var rd = this.return_day.value;
	
	if (this.pickup_monthyear)
	{
	    var pym = this.pickup_monthyear.value;
	    var rym = this.return_monthyear.value;
	    if (parseDate(pym+'-'+pd) > parseDate(rym+'-'+rd))
	    {
		    this.return_monthyear.value = pym;
		    this.return_day.value = pd;
	    }
	}
	else
	{
	    var pm = this.pickup_month.value;
	    var py = this.pickup_year.value;
	    var rm = this.return_month.value;
	    var ry = this.return_year.value;
	    
	    if (parseInt(py) > parseInt(ry) && set_return_year == false) {
		    this.return_year.value = py;
		    this.return_month.value = pm;
	    } 
	    if (parseInt(pm) > parseInt(rm) && set_return_month == false) {
		    this.return_month.value = pm;
	    }
	    if (parseInt(pd) > parseInt(rd) && set_return_day == false) {
		    this.return_day.value = pd;
	    }	
	}
	
	/*	//var PD = new Date(py, pm-1, pd, 12, 0, 0); //pickup date
	//var RD = new Date(ry, rm-1, rd, 12, 0, 0); //return date
	if ((fn == "pickup_year" || fn == "return_year")  
	 && (PD.getFullYear() > ry || (set_return_year == false && set_return_month == false && set_return_year == false))
	) {
		alert("y");
		this.return_year.value = PD.getFullYear();
		this.return_month.value = PD.getMonth()+1;
		this.return_day.value = PD.getDate();
	} 
	if ((fn == "pickup_month" || fn == "return_month")
	 && ((PD.getMonth()+1 > rm && PD.getFullYear() >= ry) || (set_return_month == false && set_return_day == false))
	) {
		alert("m");
		this.return_month.value = PD.getMonth()+1;
		this.return_day.value = PD.getDate();
	}
	if ((fn == "pickup_day" || fn == "return_day") 
	 && ((PD.getDate() > rd && PD.getMonth()+1 >= rm && PD.getFullYear() >= ry) || set_return_day == false)
	) {
		alert("d");
		if (PD.getDate() > rd){
			this.return_day.value = PD.getDate();
		}
	}*/
	
}
var IntUrl_hiddenPDt = new Date();
var IntUrl_hiddenRDt = new Date();
IntUrl_hiddenPDt.setDate(IntUrl_hiddenPDt.getDate()+1);
IntUrl_hiddenRDt.setDate(IntUrl_hiddenRDt.getDate()+2);
function PickupDropdownsChange(uxPickupDay, uxPickupMonth, uxPickupYear, uxReturnDay, uxReturnMonth, uxReturnYear)
{
    
    
    var pdt = parseDate(uxPickupYear.value+'-'+uxPickupMonth.value+'-'+uxPickupDay.value)
    var rdt = parseDate(uxReturnYear.value+'-'+uxReturnMonth.value+'-'+uxReturnDay.value)
    
   
    
   
    if (pdt > rdt)
    {
        //add a day to the pickup date
        pdt.setDate(pdt.getDate() + 1);

        //set selections
        uxReturnYear.value = pdt.getFullYear();
        uxReturnMonth.value = pdt.getMonth()+1;
        uxReturnDay.value = pdt.getDate();
    }
    IntUrl_hiddenPDt = pdt;
    IntUrl_hiddenRDt = rdt;
    
}

function PickupDropdownsChange_MY(uxPickupDay, uxPickupMonthYear, uxReturnDay, uxReturnMonthYear)
{

    var pdt = parseDate(uxPickupMonthYear.value+'-'+uxPickupDay.value)
    var rdt = parseDate(uxReturnMonthYear.value+'-'+uxReturnDay.value)
    
    IntUrl_hiddenPDt = pdt;
    IntUrl_hiddenPDt = rdt;
    
    if (pdt > rdt)
    {
        //add a day to the pickup date
        pdt.setDate(pdt.getDate() + 1);

        var mnth = pdt.getMonth()+1
        //set selections
        uxReturnMonthYear.value = pdt.getFullYear() +'-'+ mnth;
        uxReturnDay.value = pdt.getDate();
    }
    
}