function getWindowSize() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
	  return  "width=" + myWidth + ",height=" + myHeight;
	}

function addressPicker(prefix){
	valueCode=eval(prefix+'Code.value');
	valueName=eval(prefix+'Name.value');
	valueAddress1=eval(prefix+'Address1.value');
	valueAddress2=eval(prefix+'Address2.value');
	valueAddress3=eval(prefix+'Address3.value');
	valueCity=eval(prefix+'City.value');
	valuePostcode=eval(prefix+'Postcode.value');
	valueSupplierID=0;
	
	
	valueClientID=eval(document.detailForm.job_jobClientID.value);
	valuePassengerID=eval(document.detailForm.job_jobPassengerID.value);
		
	qs='prefix='+prefix+'&valueSupplierID=0&valueClientID='+valueClientID+'&valuePassengerID='+valuePassengerID+'&valueCode='+valueCode+'&valueName='+valueName+'&valueAddress1='+valueAddress1+'&valueAddress2='+valueAddress2+'&valueAddress3='+valueAddress3+'&valueCity='+valueCity+'&valuePostcode='+valuePostcode
		
	self.newWin = window.open('/private/common/addresspicker/default.aspx?'+qs,'popup','dependent=yes,width=640,height=300,titlebar=yes,status=yes,resizable=no,scrollbars=yes,menubar=no;');
}

function addressPickerNew(prefix, clientID, passengerID, filter, previousFilter) {
	window.open('/partner/common/addressPicker/default.aspx?'
							+ 'prefix=' + prefix + '&clientID=' + clientID + '&passengerID=' + passengerID + '&filter=' + filter + '&previousFilter=' + previousFilter + '&autoSelect=-1',
							'popupAddressPicker',
							'dependent=yes,width=1200,height=635,titlebar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=no;'
							);
}

function flightPicker(prefix1,prefix2,index) {
    var FlightNotesElem;
	if(prefix1 != "")
	  FlightNotesElem = document.getElementById(prefix1 + 'FlightNotes');
	 else
	  FlightNotesElem = document.getElementById(prefix2 + 'FlightNotes');

	if (prefix1 != 'roadshowSegmentPickUp' && prefix1 != "" && prefix1 != 'roadshowSegmentDropOff' && prefix1 != 'jobDropOff' && prefix1 != 'jobPassenger' + index + 'PickUp')
		prefix1 = 'jobPickUp';
	var FlightTypeElem = document.getElementById('Radio1'); // was jobPickUpFlightType but that is the name of the element

	var departureArrival;
	var LocationCodeValue;
	var airport1;
	var airport2;
	var flightnotes2;
	var queryString = '';
	
	var FlightNotesValue = FlightNotesElem.value;
	var FlightDateElem;
    var FlightTimeElem;
	var FlightTimeValue;

	var FlightNumberElem;
	var FlightNumberValue;
	var foundFlight = false;
    if(index>= 0){
	if (FlightTypeElem.checked) {
		departureArrival = 'A';
		    LocationCodeValue = document.getElementById('jobPickUpLocationCode').value;
		airport1 = '&arrivalAirport=';
		airport2 = '&departureAirport=';

		    flightnotes2 = FlightNotesValue.replace(/\/.*/, '');
		    FlightDateElem = document.getElementById('jobPickUpDateTime_select');
		if (FlightDateElem) {
			FlightDateValue = FlightDateElem.value;
			var mDate = new Date(FlightDateValue);
			FlightDateValue = '&flightTime_day=' + mDate.getDate();
			var month = mDate.getMonth()*1; month += 1;
			FlightDateValue += '&flightTime_month=' + month;
			FlightDateValue += '&flightTime_year=' + mDate.getFullYear();
		} else {
			FlightDateValue = '&flightTime_day=' + document.getElementById(prefix1 + 'DateTime_day').value;
			FlightDateValue += '&flightTime_month=' + document.getElementById(prefix1 + 'DateTime_month').value;
			FlightDateValue += '&flightTime_year=' + document.getElementById(prefix1 + 'DateTime_year').value;
		}
	} else {
		departureArrival = 'D';
		//prefix2 = prefix1;
		LocationCodeValue = document.getElementById('jobDropOffLocationCode').value;
		airport1 = '&departureAirport=';
		airport2 = '&arrivalAirport=';
		flightnotes2 = FlightNotesValue.replace(/.*\//,'');
		    FlightDateElem = document.getElementById('jobDropOffDateTime_select');
		if (FlightDateElem) {
			FlightDateValue = FlightDateElem.value;
			var mDate = new Date(FlightDateValue);
			FlightDateValue = '&flightTime_day=' + mDate.getDate();
			var month = mDate.getMonth()*1; month += 1;
			FlightDateValue += '&flightTime_month=' + month;
			FlightDateValue += '&flightTime_year=' + mDate.getFullYear();
		} else {
			FlightDateValue = '&flightTime_day=' + document.getElementById(prefix2 + 'DateTime_day').value;
			FlightDateValue += '&flightTime_month=' + document.getElementById(prefix2 + 'DateTime_month').value;
			FlightDateValue += '&flightTime_year=' + document.getElementById(prefix2 + 'DateTime_year').value;
		}
	}
		if (foundFlight == false) {
		    //prefix1 = 'jobPassenger' + index + 'PickUp';
   		FlightTimeElem = document.getElementById(prefix1 + 'FlightTime_time');
   		FlightTimeValue = FlightTimeElem.value;
   		FlightNumberElem = document.getElementById(prefix1 + 'FlightNumber');
   		FlightNumberValue = FlightNumberElem.value;
		    foundFlight = true;
		}
	}
	if (foundFlight == false) {
	if(prefix1 == 'jobPickUp' || prefix1 == 'roadshowSegmentPickUp'){
	        departureArrival = 'A';
		    LocationCodeValue = document.getElementById(prefix1 + 'LocationCode').value;
		    airport1 = '&arrivalAirport=';
		    airport2 = '&departureAirport=';
		    flightnotes2 = FlightNotesValue.replace(/\/.*/,'');

		    FlightDateElem = document.getElementById(prefix1 + 'DateTime_select');
		    if (FlightDateElem) {
			    FlightDateValue = FlightDateElem.value;
			    var mDate = new Date(FlightDateValue);
			    FlightDateValue = '&flightTime_day=' + mDate.getDate();
			    var month = mDate.getMonth()*1; month += 1;
			    FlightDateValue += '&flightTime_month=' + month;
			    FlightDateValue += '&flightTime_year=' + mDate.getFullYear();
		    } else {
			    FlightDateValue = '&flightTime_day=' + document.getElementById(prefix1 + 'DateTime_day').value;
			    FlightDateValue += '&flightTime_month=' + document.getElementById(prefix1 + 'DateTime_month').value;
			    FlightDateValue += '&flightTime_year=' + document.getElementById(prefix1 + 'DateTime_year').value;
			}
			if (foundFlight == false) {
        FlightTimeElem = document.getElementById(prefix1 + 'FlightTime_time');
   		FlightTimeValue = FlightTimeElem.value;
   		FlightNumberElem = document.getElementById(prefix1 + 'FlightNumber');
   		FlightNumberValue = FlightNumberElem.value;
			    foundFlight = true;
			}

	}else{
	        if (prefix1 == 'roadshowSegmentDropOff' || prefix1 == 'jobDropOff') {
	            prefix2 = prefix1;
	        }
	        departureArrival = 'D';
		    LocationCodeValue = document.getElementById(prefix2 + 'LocationCode').value;
		    airport1 = '&departureAirport=';
		    airport2 = '&arrivalAirport=';
		    flightnotes2 = FlightNotesValue.replace(/.*\//,'');

		    FlightDateElem = document.getElementById(prefix2 + 'DateTime_select');
		    if (FlightDateElem) {
			    FlightDateValue = FlightDateElem.value;
			    var mDate = new Date(FlightDateValue);
			    FlightDateValue = '&flightTime_day=' + mDate.getDate();
			    var month = mDate.getMonth()*1; month += 1;
			    FlightDateValue += '&flightTime_month=' + month;
			    FlightDateValue += '&flightTime_year=' + mDate.getFullYear();
		    } else {
			    FlightDateValue = '&flightTime_day=' + document.getElementById(prefix2 + 'DateTime_day').value;
			    FlightDateValue += '&flightTime_month=' + document.getElementById(prefix2 + 'DateTime_month').value;
			    FlightDateValue += '&flightTime_year=' + document.getElementById(prefix2 + 'DateTime_year').value;
		    }

   		FlightTimeElem = document.getElementById(prefix2 + 'FlightTime_time');
   		FlightTimeValue = FlightTimeElem.value;
   		FlightNumberElem = document.getElementById(prefix2 + 'FlightNumber');
   		FlightNumberValue = FlightNumberElem.value;
   		    foundFlight = true;


   		}
	}
    var jobPickUpPreviousLocationCode = document.getElementById('jobPickUpPreviousLocationCode')

	//queryString += airport1 + LocationCodeValue;
	//queryString += airport2 + flightnotes2;
	queryString += '&flightNo=' + FlightNumberValue;
	queryString += '&flightTime_time=' + FlightTimeValue;
	queryString += FlightDateValue;
	queryString += '&departureArrival=' + departureArrival;
	queryString += '&callback=true';
	if (jobPickUpPreviousLocationCode)
	{
	    queryString += '&oldLocationCode=' + jobPickUpPreviousLocationCode.value;
	}

	window.open('/partner/common/pathFinder/default.aspx?'
							+ 'prefix1=' + prefix1 + '&prefix2=' + prefix2 + queryString,
							'popupFlightPicker',
							'dependent=yes,width=635,height=900,titlebar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=no;'
							);
}

function creditCardPicker(prefix, clientID, roadshowID, groupBookingID, creditCardID, endDatePrefix) {
	var endDay   = document.getElementById(endDatePrefix + '_day' ).value;
	var endMonth = document.getElementById(endDatePrefix + '_month' ).value;
	var endYear  = document.getElementById(endDatePrefix + '_year' ).value;
   
   // Roadshow contacts
    if (document.getElementById("RoadshowContactCount")) {
    var tmp = document.getElementById("RoadshowContactCount").value;
   
    for (var x = 0; x < tmp; x++){
	if (document.getElementById("RoadshowContactID_" + x) && (contactID) && (contactID)){
	        contactID = contactID + "," + (document.getElementById("RoadshowContactID_" + x).value);
	          }
    else if (document.getElementById("RoadshowContactID_" + x)){
	       var contactID = (document.getElementById("RoadshowContactID_" + x).value);
	          }
	          }
	          }
	// GroupBooking Contacts
	    if (document.getElementById("groupBookingContactCount")) {
    var tmp = document.getElementById("groupBookingContactCount").value;
   
       for (var x = 0; x < tmp; x++){
	if (document.getElementById("groupBookingContact" + x + "ClientContactID") && (contactID) && (contactID)){
	        contactID = contactID + "," + (document.getElementById("groupBookingContact" + x + "ClientContactID").value);
	          }
    else if (document.getElementById("groupBookingContact" + x + "ClientContactID")){
	       var contactID = (document.getElementById("groupBookingContact" + x + "ClientContactID").value);
	          }
	          }   
	}
	// Single Job contact
	if	(document.getElementById("jobClientContactID")){
	var contactID = document.getElementById("jobClientContactID").value;    
    	window.open(
		'/partner/common/creditCardPicker/creditCardPicker.aspx?creditCardID=' + creditCardID + '&clientID=' + clientID+ '&contactID=' + contactID + '&roadshowID=' + roadshowID + '&groupBookingID=' + groupBookingID + '&prefix=' + prefix + '&endDay=' + endDay + '&endMonth=' + endMonth + '&endYear=' + endYear,
		'popupPickCreditCard',
		'dependent=yes,width=950,height=400,titlebar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=no;');
    }
    else {
	window.open(
		'/partner/common/creditCardPicker/creditCardPicker.aspx?creditCardID=' + creditCardID + '&clientID=' + clientID+ '&contactID=0&roadshowID=' + roadshowID + '&groupBookingID=' + groupBookingID + '&prefix=' + prefix + '&endDay=' + endDay + '&endMonth=' + endMonth + '&endYear=' + endYear,
		'popupPickCreditCard',
		'dependent=yes,width=950,height=400,titlebar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=no;');
		}
}

function GroupBookingFileUpload(clientID, groupBookingID) {
		window.open(
			'/partner/groupBooking/upload.aspx?ClientID=' + clientID + '&GroupBookingID=' + groupBookingID,
			'popupGroupBookingFileUpload',
			'dependent=yes,width=700,height=350,titlebar=yes,status=yes,resizable=yes,scrollbars=no,menubar=no;');
}

function RoadshowFileUpload(clientID, roadshowID) {
		window.open(
			'/partner/roadshow/upload.aspx?ClientID=' + clientID + '&RoadshowID=' + roadshowID,
			'popupRoadshowFileUpload',
			'dependent=yes,width=700,height=350,titlebar=yes,status=yes,resizable=yes,scrollbars=no,menubar=no;');
}

function datePicker(prefix){
	var pickUpDay   = document.getElementById(prefix + '_day' );
	var pickUpMonth = document.getElementById(prefix + '_month' );
	var pickUpYear  = document.getElementById(prefix + '_year' );
	qs='prefix='+prefix+'&valueDay='+pickUpDay.value+'&valueMonth='+pickUpMonth.value+'&valueYear='+pickUpYear.value
	self.newWin = window.open('/private/common/datepicker/default.aspx?'+qs,'popup','dependent=yes,width=200,height=225,titlebar=yes,status=yes,resizable=no,scrollbars=no,menubar=no;');
}

function applyClientTariff(vehicleCategoryID,validFor,jobID,clientID,city,
													 location1,city1,location2,city2,
													 toCurrencyID,useInTown){
	qs='useClient=-1'+
			'&vehicleCategoryID='+vehicleCategoryID+'&validFor='+validFor+'&jobID='+jobID+'&clientID='+clientID+
			'&city='+city+'&location1='+location1+'&city1='+city1+'&location2='+location2+'&city2='+city2+
			'&toCurrencyID='+toCurrencyID+'&useInTown='+useInTown;
	self.newWin = window.open('/partner/jobPricing/tariffPicker/default.aspx?'+qs,'popup','dependent=yes,width=1000,height=300,titlebar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=no;');
}

function applyPartnerTariff(vehicleCategoryID,validFor,clientPartnerID,
													 location1,city1,location2,city2,
													 toCurrencyID,useInTown){
	qs='useClient=0'+
			'&vehicleCategoryID='+vehicleCategoryID+'&validFor='+validFor+'&clientPartnerID='+clientPartnerID+
			'&location1='+location1+'&city1='+city1+'&location2='+location2+'&city2='+city2+
			'&toCurrencyID='+toCurrencyID+'&useInTown='+useInTown;
	self.newWin = window.open('/partner/jobPricing/tariffPicker/default.aspx?'+qs,'popup','dependent=yes,width=1000,height=300,titlebar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=no;');
}

function applySupplierTariff(vehicleCategoryID,validFor,clientPartnerID,
		location1,city1,location2,city2,
		toCurrencyID,useInTown,supplierID){
	var franchiseTotalMileage = document.getElementById('franchiseTotalMileage').value;
	var franchiseOotMileage   = document.getElementById('franchiseOotMileage').value;
	var franchiseTotalHours   = parseInt(document.getElementById('franchiseTotalHours_h').value) + parseInt(document.getElementById('franchiseTotalHours_m').value) / 60.0;
	var franchiseOotHours     = parseInt(document.getElementById('franchiseOotHours_h').value) + parseInt(document.getElementById('franchiseOotHours_m').value) / 60.0;
	var franchiseIsTransfer   = document.getElementById('franchiseIsTransfer').value;
	

	qs='useClient=0&useSupplier=-1'+
			'&vehicleCategoryID='+vehicleCategoryID+'&validFor='+validFor+'&clientPartnerID='+clientPartnerID+
			'&location1='+location1+'&city1='+city1+'&location2='+location2+'&city2='+city2+
			'&toCurrencyID='+toCurrencyID+'&useInTown='+useInTown+'&supplierID='+supplierID+
			'&franchiseIsTransfer='+franchiseIsTransfer+
			'&franchiseTotalMileage='+franchiseTotalMileage+
			'&franchiseOotMileage='+franchiseOotMileage+
			'&franchiseTotalHours='+franchiseTotalHours+
			'&franchiseOotHours='+franchiseOotHours;

	self.newWin = window.open('/partner/jobPricing/tariffPicker/default.aspx?'+qs,'popup','dependent=yes,width=1000,height=300,titlebar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=no;');
}

function auditlogWindow(recordID, recordType, SecurityOwnerCityID) {
	var qs = 'recordID=' + recordID + '&recordType=' + recordType + '&SecurityOwnerCityID=' + SecurityOwnerCityID
	self.newWin = window.open('/audit/default.aspx?'+qs,'popupAuditlog','dependent=yes,width=700,height=500,titlebar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=no;');
}
function auditlogWindowDetail(filterID) {
	var qs = 'filterID=' + filterID 
	self.newWin = window.open('/audit/detail.aspx?'+qs,'popupAuditlogDetail','dependent=yes,width=400,height=500,titlebar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=no;');
}

function closeIt() {
	if (window.event) {
		if(document.isDirtyForm.isDirty.value!='FALSE') {
			window.event.returnValue = 'Changes you have made on this page will be lost unless they are saved.';
		} else {
			window.event.cancel;
		}
	}
}
	
function phoneNumbersOnly(passedField, passedEvent, dec)
{
var key;
var keychar;
var ctrl;

if (window.event) {
   key = window.event.keyCode;
   ctrl = window.event.ctrlKey;
} else if (passedEvent) {
   key = passedEvent.which;
   ctrl = passedEvent.ctrlKey;
} else {
   return true;
}
keychar = String.fromCharCode(key);

//alert("key=" + key + " keychar=" + keychar + " ctrl=" + ctrl);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) || (key==99 && ctrl) )
   return true;
	   
// numeric values
else if ((("0123456789+,").indexOf(keychar) > -1))
	return true;
else 
	return false;
}
	
function percentageNumbersOnly(passedField, passedEvent, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (passedEvent)
   key = passedEvent.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;
	   
// numeric values
else if ((("0123456789.%").indexOf(keychar) > -1))
	return true;
else 
	return false;
}
function KeyPress() {
	//alert(window.event.keyCode)
	try{
		if (window.event.keyCode == 13)
		window.event.keyCode =0;
	}
	catch(err){
	
	}
} 

function timeNumbersOnly(passedField, passedEvent, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (passedEvent)
   key = passedEvent.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;
	   
// numeric values
else if ((("0123456789.:").indexOf(keychar) > -1))
	return true;
else 
	return false;
}	

function validNumbersOnly(passedField, passedEvent, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (passedEvent)
   key = passedEvent.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;
	   
// numeric values
else if ((("0123456789.").indexOf(keychar) > -1))
	return true;
else 
	return false;
}	
	
function setDirty(){
    var elem = document.getElementById('isDirty')
	if (elem) elem.value='TRUE';
}
	
function validTimeFormat(elem) {
	if ( /^[0-9][0-5][0-9]$/.test(elem.value) == true ) {
		return '0' + elem.value.substring(0,1) + ':' + elem.value.substring(1);
	} else if ( /^([0-1][0-9]|2[0-3])[0-5][0-9]$/.test(elem.value) == true ) {
		return elem.value.substring(0,2) + ':' + elem.value.substring(2);
	} else if ( /^[0-9][:.][0-5][0-9]$/.test(elem.value) == true ) {
		return '0' + elem.value.substring(0,1) + ':' + elem.value.substring(2);
	} else if ( /^([0-1][0-9]|2[0-3])[:.][0-5][0-9]$/.test(elem.value) == true ) {
		return elem.value.substring(0,2) + ':' + elem.value.substring(3);
	} else if ( /^24[:.]?00$/.test(elem.value) == true ) {
		return '00:00';
	} else {
		return '';
	}
}

function checkTimeFormat(elem) {
    // checks if elem value contains a valid time
	// accepts the values of: hmm, h.mm, h:mm, hhmm, hh.mm, hh:mm
	// modifies the value to hh:mm
	// can be used as an event handler (elem == null)
	// or be given an elem to check 
	// tested for IE 6.0
	// LB --------------------------
	if (!elem) elem = event.srcElement;
	var valid = validTimeFormat(elem);
	if (valid == '') {
		alert("Please enter a valid time (hmm, h.mm, h:mm, hhmm, hh.mm or hh:mm).");
		elem.focus();
	} else {
		elem.value = valid
	}
}

function checkTimeFormat_allowBlank(elem) {
    // checks if elem value contains a valid time
	// accepts the values of: hmm, h.mm, h:mm, hhmm, hh.mm, hh:mm
	// modifies the value to hh:mm
	// can be used as an event handler (elem == null)
	// or be given an elem to check 
	// tested for IE 6.0
	// LB --------------------------
	
	if (!elem) elem = event.srcElement;
	if (elem.value != '' ) {
		var valid = validTimeFormat(elem);
		if (valid == '') {
			alert("Please enter a valid time (hmm, h.mm, h:mm, hhmm, hh.mm or hh:mm).");
			elem.focus();
		} else {
			elem.value = valid
		}
	}
}
// by LB

// gets the text of the option with value equal to optionValue from the select identified by selectObj
// returns null if value is not found
function getSelectTextByOptionValue(selectObj,optionValue) {
	selectObj.value = optionValue;
	if (selectObj.selectedIndex >= 0 && selectObj.value == optionValue)
		return selectObj[selectObj.selectedIndex].text;
	return null;
}

// sets the css class name attribute of the object identified by obj to className
function setClass(obj,className) {
	if (obj!=null && className!=null) {
		obj.className = className;
	}
}

function getValue (elemName) {
	var elem = document.getElementById(elemName);
	if (elem) return elem.value;
	return 0;
}
function setValue (elemName, value) {
	var elem = document.getElementById(elemName);
	if (elem) return elem.value = value;
	return 0;
}

// inserts current date and time into given time/date fields
function insertCurrentDateTime(prefix,timeZoneOffset){
	var tDate = new Date();
	var gmtOffset = tDate.getTimezoneOffset()
	tDate.setMinutes(tDate.getMinutes() + gmtOffset);
	tDate.setMinutes(tDate.getMinutes() + 60 * timeZoneOffset);
	tHour = tDate.getHours().toFixed(0);
	tMinute = tDate.getMinutes().toFixed(0);
	tDay = tDate.getDate();
	tMonth = tDate.getMonth();
	tYear = tDate.getFullYear();
	if (tHour<10) tHour = '0' + tHour;
	if (tMinute<10) tMinute = '0' + tMinute;
	tMonth = tMonth + 1;
	setValue(prefix + '_time', '' + tHour + ':' + tMinute);
	setValue(prefix + '_day', tDay);
	setValue(prefix + '_month', tMonth);
	setValue(prefix + '_year', tYear);
	setDirty();
};
													
function editNotes(title, label, notesID) {
	window.open('/partner/common/editNotes/default.aspx?title=' + title + '&label=' + label + '&notesID=' + notesID,'popupEditNotes','dependent=yes,width=600,height=270,titlebar=yes,status=yes,resizable=no,scrollbars=no,menubar=no;');
}

function editItinerary(title, label, itineraryID, clientID) {
	window.open('/partner/common/editItinerary/default.aspx?title=' + title + '&label=' + label + '&itineraryID=' + itineraryID + '&clientID=' + clientID,'popupEditItinerary','dependent=yes,width=920,height=530,titlebar=yes,status=yes,resizable=no,scrollbars=no,menubar=no;');
}

function toggle_jobStatusHelp(element, iframeId, iframeSrc) {
    var ifr = document.getElementById(iframeId);
    if (ifr) {
        ifr.src = toggle_element(element) ? iframeSrc : "";
    }
}

function toggle_element(element) {
	var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
	var itemElem = document.getElementById(element + "_items")
	var iconElem = document.getElementById(element + "_icon")
	if (itemElem && itemElem.style.display=='none') { 
		if (ie4) {
			itemElem.style.display='block';
		} else {
			itemElem.style.display='table-row';
		}
		if (iconElem) iconElem.src='/images/collapse.gif';
		return true;
	} else { 
		if (itemElem) itemElem.style.display='none';
		if (iconElem) iconElem.src='/images/expand.gif';
		return false;
	}
}
function toggle_maintenance() {
	toggle_element("maintenance");
}
function toggle_finance() {
	toggle_element("finance");
}
function toggle_report() {
	toggle_element("report");
}
function toggle_controlScreen() {
	toggle_element("controlScreen");
}

// XXX: hack from http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var agt=navigator.userAgent.toLowerCase();
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));

var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

// From http://webfx.eae.net/dhtml/ieemu/index.html

if (is_nav) {
HTMLElement.prototype.insertAdjacentHTML = function (sWhere, sHTML) {
   var df;   // : DocumentFragment
   var r = this.ownerDocument.createRange();
   
   switch (String(sWhere).toLowerCase()) {  // convert to string and unify case
      case "beforebegin":
         r.setStartBefore(this);
         df = r.createContextualFragment(sHTML);
         this.parentNode.insertBefore(df, this);
         break;
         
      case "afterbegin":
         r.selectNodeContents(this);
         r.collapse(true);
         df = r.createContextualFragment(sHTML);
         this.insertBefore(df, this.firstChild);
         break;
         
      case "beforeend":
         r.selectNodeContents(this);
         r.collapse(false);
         df = r.createContextualFragment(sHTML);
         this.appendChild(df);
         break;
         
      case "afterend":
         r.setStartAfter(this);
         df = r.createContextualFragment(sHTML);
         this.parentNode.insertBefore(df, this.nextSibling);
         break;
   }   
};
HTMLElement.prototype.__defineSetter__("innerText", function (sText) {
   this.innerHTML = sText.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
});
HTMLElement.prototype.__defineGetter__("innerText", function () {
   var r = this.ownerDocument.createRange();
   r.selectNodeContents(this);
   return r.toString();
});

}

function propagatePickUpDate(pickUpPrefix,dateSelectMode) {
	var dropOffPrefix = pickUpPrefix.replace('PickUp', 'DropOff');
	var a;
	var mc = document.getElementById('jobMidpointCount');
	
	if (dateSelectMode) {
		var pickUpSelect = document.getElementById(pickUpPrefix + '_select');
		if (a = document.getElementById(dropOffPrefix + '_select')) a.value = pickUpSelect.value;

		if (mc) {
			var midPointPrefix;
			for(i = 0; i < mc.value; i++) {
				midPointPrefix = 'jobMidpoint' + i + 'DateTime';
				if (a = document.getElementById(midPointPrefix + '_select')) a.value = pickUpSelect.value;
				if (self.updateWeekdayName) self.updateWeekdayName(midPointPrefix,dateSelectMode);
			}
		}
	} else {
		var pickUpDay   = document.getElementById(pickUpPrefix + '_day' );
		var pickUpMonth = document.getElementById(pickUpPrefix + '_month' );
		var pickUpYear  = document.getElementById(pickUpPrefix + '_year' );
		if (a = document.getElementById(dropOffPrefix + '_day')) a.value = pickUpDay.value;
		if (a = document.getElementById(dropOffPrefix + '_month')) a.value = pickUpMonth.value;
		if (a = document.getElementById(dropOffPrefix + '_year')) a.value = pickUpYear.value;
		
		if (mc) {
			var midPointPrefix;
			for(i = 0; i < mc.value; i++) {
				midPointPrefix = 'jobMidpoint' + i + 'DateTime';
				if (a = document.getElementById(midPointPrefix + '_day')) a.value = pickUpDay.value;
				if (a = document.getElementById(midPointPrefix + '_month')) a.value = pickUpMonth.value;
				if (a = document.getElementById(midPointPrefix + '_year')) a.value = pickUpYear.value;
				if (self.updateWeekdayName) self.updateWeekdayName(midPointPrefix,dateSelectMode);
			}
		}
	}

	if (self.updateWeekdayName) self.updateWeekdayName(dropOffPrefix,dateSelectMode);

}

String.prototype.trim = function() {
	return this.replace(/^\s*/,"").replace(/\s*$/,"");
}

function numberToFixed2(Object) {
	if (Object) {
		var t = Object.value * 1;
		Object.value = t.toFixed(2);
	}
}

function substract(value) {
	value = parseInt(value);
	return value-160<0?0:value-160;
}
function addition(value) {
	return value;
}

function doHigh(elem) {
	doSelect(elem, substract);
}
function doNormal(elem) {
	doSelect(elem, addition);
}

var lastColor;

function doSelect(elem, addOrSubstract) {
	var i = 0; //possibly replace this so that it just switches background/foreground for IE8 :)
	var color = elem.style.backgroundColor.toString().toUpperCase();
	if (color == "")
	    color = "#FFFFFF"
	var newStr = "rgb(" ;
	if (addOrSubstract == substract) {
		lastColor = elem.style.backgroundColor;
	    if (lastColor == "")
	        lastColor = "#FFFFFF"
		if (color.charAt(0) == '#') {
			// ie: #FF9900
			var s = color.split("");
			for (i=1; i<s.length; i+=2) {
				newStr += addOrSubstract("0x" + s[i] + s[i+1]) + ",";
			}
		} else {
			// firefox: rgb(255,102,0)
			var s = color.replace(/RGB\((.*)\)/,"$1").split(",");
			for (i=0; i<s.length; i++) {
				newStr += addOrSubstract(s[i]) + ",";
			}

		}
		newStr = newStr.replace(/,$/,")");
		elem.style.backgroundColor = newStr;
		elem.style.color = '#FFFFFF';
	} else {
		elem.style.color = '#000000';
		elem.style.backgroundColor = lastColor;
	}
}


/* 
 * Autoselect stuff 
 *
 * Usage: In body onload() or at the end of the html page generate an
 * object for each select element you would like to add autocomplete features
 * to it. Example
	itemlistvar = new AS_selectItem('itemlistform', 'itemlistvar');
 * Then hook this object to the select onkeypress event like
	<select name="itemlistform" id="itemlistform" onkeypress="return itemlistvar.autoselect(event);">
 * Zats it.
 */

// Simple binary search which tracks back to the first element starting with searchstring
function AS_binarySearch(a, value, left, right) 
{
	var mid;
	var ucase = value.toUpperCase();
	var str;

	//alert(left + ' ' + mid + ' ' + right);

	while (left <= right) {
		mid = parseInt((left+right) / 2);

		// iexplore is so stupid, it takes <\/option> elements as an entity in the dom tree
		while (!(a[mid].value)) {mid--;}

		if (mid<left) return -1;

		str = a[mid].text.substr(0,ucase.length).toUpperCase();
		if (ucase == str) {
			while (1) {
				while (!(a[mid].value)) mid--;
				if (ucase == a[mid].text.substr(0,ucase.length).toUpperCase()) mid--;
				else break;
			}
			return mid+1;
		}
		if (ucase < str) {
			right = mid-1;
		} else if (ucase > str) {
			left = mid+1;
		}
	}
	return -1; // not found

}
function AS_update() {
	var str = this.arr.join('');
	if (str == '') return;
	var obj = this.obj;
	var pos = AS_binarySearch(obj.childNodes, str, 0, obj.childNodes.length-1);
	if (pos>0) { 
		while (!(obj.childNodes[pos].value)) pos++;
		obj.childNodes[pos].selected = true;
	}
}

function AS_autoselect (passedEvent)
{
	var key;

	window.clearTimeout(this.timeoutID);
	if (window.event)
		key = window.event.keyCode;
	else if (passedEvent)
		key = passedEvent.which;
	else
		return true;

	if (key==13 && this.obj.onchange) this.obj.onchange();

	if (!(key==32 || (key>=65 && key<=90) || (key>=97 && key<=122))) {
		return true;
	}

	this.arr.push(String.fromCharCode(key))

	this.update();
	this.timeoutID = window.setTimeout('AS_emptyArray(' + this.varname + ');', 800);
	return false;
}

function AS_emptyArray(variable) {
	while (variable && variable.arr && variable.arr.length > 0) variable.arr.pop();
	if (variable.obj.onchange) variable.obj.onchange()
}

function AS_selectItem(formname, varname) {
	this.varname = varname;
	this.obj = document.getElementById(formname);
	this.arr = new Array();
	this.timeoutID = 0;
	this.autoselect = AS_autoselect;
	this.update = AS_update;
}
	
function clearDate(what) {
		setValue(what + "_day",   0);
		setValue(what + "_month", 0);
		setValue(what + "_year",  0);
}

function addSixMonths(what) {
	var day   = getValue(what + "_day");
	var month = getValue(what + "_month");
	var year  = getValue(what + "_year");
	var date  = new Date(year, month-1, day);
	if ((day == 0) || (month == 0) || (year == 0)) {
		date = new Date();
	}
	date.setMonth(date.getMonth()+6);
	
	setValue(what + "_day",   date.getDate());
	setValue(what + "_month", date.getMonth()+1);
	setValue(what + "_year",  date.getFullYear());
}	
	
function easyInputFromEmail(prefix,roadshowID,groupBookingID)
{
	qs='prefix='+prefix+'&roadshowID='+roadshowID+'&groupBookingID='+groupBookingID
	self.easyInputWin = window.open('/partner/common/easyInput/easyInput.aspx?'+qs,'importPage','dependent=yes,width=1120,height=900,titlebar=yes,status=yes,resizable=yes,menubar=no;');
}

function gotoJobRef(evt, obj) {
    var jobid;
    var keyCode = null;

    if( evt.which ) {
        keyCode = evt.which;
    } else if( evt.keyCode ) {
        keyCode = evt.keyCode;
    }
    if( 13 == keyCode ) {
        jobid = obj.value;
        if (jobid != '') window.location = "/partner/search/default.aspx?redirect=true&searchText=" + jobid;
        return false;
    }
    return true;
}


 function copyNotesFromDivToInput(divName, inputName) {
    var str    = "";
    var src    = document.getElementById(divName);
    var target = document.getElementById(inputName);
    if (src && target) {
        for (var i=0; i<src.childNodes.length; i++) {
            var node = src.childNodes[i];
            switch (node.nodeType) {
                case 3: str += node.nodeValue; 
                        break;
                case 1: if (node.nodeName == "BR") str += "\n";
                        break;
            }
        }
        target.value = str;
        return 0;
    }
    return 1;
 }

function disableEnableForm(formName, disabled) {
    var objElems = formName.elements;
    for (i = 0; i < objElems.length; i++) {
        objElems[i].disabled = disabled;
    }
}

