var _datelinks = ["strtlink","ldglink","actlink","pkglink"];
var _now = new Date().valueOf();

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
				oldonload();
				func();
			};
	}
}

addLoadEvent(function() {					  
		var tmp;
	
		var isession = "";
		var sessregex = /sessionid=[0-9a-zA-Z\-]{30,40}/ig;
		tmp = sessregex.exec(document.body.innerHTML);
		if(tmp !== null) {
			isession = tmp[0];
		}
		
		var iarrival = "";
		var arrregex = /arrivaldate=([^&"A]{8,20})/ig;
		tmp = arrregex.exec(document.body.innerHTML);
		if(tmp !== null) {
			if(tmp.length > 1) {
				iarrival = tmp[1];
			} else {
				iarrival = tmp[0];
			}
		} else {
			var _arrival = new Date(_now+(60*60*24*1000*3));
			iarrival = ""+(_arrival.getMonth()+1)+'/'+_arrival.getDate()+'/'+_arrival.getFullYear();
		}
		
		var ideparture = "";
		var depregex = /departuredate=([^&"D]{8,20})/ig;
		tmp = depregex.exec(document.body.innerHTML);
		if(tmp !== null) {
			if(tmp.length > 1) {
				ideparture = tmp[1];
			} else {
				ideparture = tmp[0];
			}
		} else {
			var _departure = new Date(_now+(60*60*24*1000*9));
			ideparture = ""+(_departure.getMonth()+1)+'/'+_departure.getDate()+'/'+_departure.getFullYear();
		}
		
		var _tmp;
		for(var _datelink=0; _datelink<_datelinks.length; _datelink++) {
			_tmp = document.getElementById(_datelinks[_datelink]);
			_tmp.href = _tmp.href.replace("ARRIVAL",iarrival);
			_tmp.href = _tmp.href.replace("DEPARTURE",ideparture);
			if(isession.length > 0) {
				_tmp.href += "&"+isession;
			}
		}
	});
