var localDate = "";
var counter=0
if (document.all)
  var nothing = 0; 
else if (document.layers) 	 
   document.captureEvents(Event.MOUSEDOWN)
var YourCode = '';
var GlobalX=20;
var GlobalY=80;
document.onmousedown = getMouseXY;
var newTable = "";
var SelectedObject="";		// to determain which object is currently active / selected
var SubTableExist = 0; 			// only display suburblist under subject object
var anl = 1;
var subno = -1;
var itemno = -1;
var TotalDestination = 1;
var TelephoneArray = new Array();
var NameArray = new Array();
var ReferenceArray = new Array();
var DepartmentArray = new Array();
var TimeArray = new Array()
var TimeTodayArray = new Array()
var TimeValueTodayArray = new Array()
var AddFrequentAddress = 0
var InvalidSuburb = false;
var serviceoptionArray = new Array();

var server_readyNowOK = "true";

var startBizTime = 0;
var endBizTime = 0;
var todayCurrentTime = 0;
var statusBiz = "";
var nextBizTime = 0;
var nextBizTimeNotSat = 0;
var nextBizStr = 0;
var checkdiff = 0;
var Leg = new Array();
for (w = 1; w < 50; w++)
  Leg[w-1] = new Array();

	
var itemno = -1;							// The currently selected item number
var rw;								// the current row
var tbl;							// the current table
var tbllen;							// number of rows in the table
var selectedText;						// the text in the selected row
var extraText;							// extra text from the table
var inputControl;						// the control we are taking input from
var companyid = 0;
var timerID = 0;				// control timer
var today = new Date();
var currentDay = new Date();
var reloadTime = 0;

var sameCaller = new Array();
var samePhone = new Array();
var sameRef1 = new Array();
var sameRef2 = new Array();
var sameGoods = new Array();
var samePickupSite = new Array();
var samePickupAddress = new Array();
var samePickupSuburb = new Array();
var samePickupSuburbID = new Array();
var sameDestinationSite = new Array();
var sameDestinationAddress = new Array();
var sameDestinationSuburb = new Array();
var sameDestinationSuburbID = new Array();
var sameServiceGroupID = new Array();
var sameServiceTypeID = new Array();
var samePermanentID = new Array();
var samePickupLocalityID = new Array();
var sameDestinationLocalityID = new Array();
var tempInnitialRateType = new Array();
var foundMatchingRow = "";
var tabledivContro= "";
var incomplete = true;

var myCurrentObject = "";

function checkRateType() {
	//
	// check the types of delivery type available for this customer
	// 1. bookedbeforetime 
	// 2. onlyonbusinessday - (monday to friday)
	// 3. advtomorrow cannot be booked on friday
  //
	
	var monday = 1;
	var friday = 5;
	var currentTime = new Date();
  var onetoone_count = 0;
	var disableOnetoone = false;

  var myParent = "";
	var myWindow = "";
	if (parent.document.getElementById("Delivery")) {
 			myWindow = parent
	}  else {		
			myWindow = window
  }

  for (var rate=0; rate<RateTypeData.length; rate++) {
      for (var i=0; i<myWindow.document.getElementById("Delivery").length; i++) {
           if (myWindow.document.getElementById("Delivery").options[i].innerHTML == RateTypeData[rate].description) {					    
			   		   // step 1
						   if (RateTypeData[rate].bookedbeforetime != "") {
  								 if (((currentTime.getHours()*60*60)+(currentTime.getMinutes()*60)) > RateTypeData[rate].bookedbeforetime)	{
	 							       myWindow.document.getElementById("Delivery").options[i] = null
											 break;											 
									 }		 									 
							 }							 
							 // step 2
							 if (RateTypeData[rate].onlyonbusinessday == 't' && 
							     (currentTime.getDay() < monday || currentTime.getDay() > friday)) {
	 							       myWindow.document.getElementById("Delivery").options[i] = null
											 break;											 							 
							 }
							 // step 3
							 if (myWindow.document.getElementById("Delivery").options[i].innerHTML == 'AdvTomorrow' && currentTime.getDay() == friday) {
	 							       myWindow.document.getElementById("Delivery").options[i] = null
											 break;											 							 
							 }		
	         }					 
	    }
  }	
	/*
	if (document.getElementById("Delivery")) {
	   var checkObject = myWindow.document.getElementById("Delivery")
	   var checkServiceObject = myWindow.document.getElementById("Vehicle")

//	   if (checkObject.options[checkObject.selectedIndex].innerHTML.indexOf('General') >= 0 && checkServiceObject.options[checkServiceObject.selectedIndex].innerHTML.indexOf('Service Type') < 0)
	   if (checkServiceObject.options[checkServiceObject.selectedIndex].innerHTML.indexOf('Service Type') < 0)
         SetAdvanceDateTime()
	}
	*/		 
}

function BookSameJob(jobid,totallegs,myCompanyID,permanentjobid) {
   //
	 // user clicked on 'book similar job'
   // 1. show booking page, make sure all options are visible, brand new booking
	 // 2. set all values based on this job
	 //

   var myParent = parent.frames["NewFrame"]
	 if (myParent) {
       var myHigherParent = parent.parent
	 } else {		
	     myParent = parent.frames["mainIframe"].frames["NewFrame"]
       var myHigherParent = parent.parent.parent
	 }		 

	 // step 1
	 var myParentChild = myParent.frames["PickupDestinationFrame"]
   WhoIsVisible("New", myCompanyID)
   disableMyPage(false, myParent.document, myParentChild)

	 // hide other destination
	 for (i=2; i<=10; i++) {
      myParent.frames["PickupDestinationFrame"].document.getElementById("ExtraDestination"+i).innerHTML	= ""
	 }
	 presetBookingDetails(myParent.document.getElementById("Vehicle"), sameServiceGroupID[jobid])
	 DisplayVehicleType(myParent.document.getElementById("Vehicle"));
	 VehicleOption();
	 ShowExtraOption(myParent.document.getElementById(sameServiceTypeID[jobid]))
	 myParent.frames["VehicleFrame"].location.href = "../Booking/VehicleImage.html";

	 // step 2
	 presetBookingDetails(myParent.document.getElementById("MyPermanentID"), sameCaller[jobid])
	 presetBookingDetails(myParent.document.getElementById("CallerNameText"), sameCaller[jobid])
	 presetBookingDetails(myParent.document.getElementById("CallerNumber"), samePhone[jobid])
	 presetBookingDetails(myParent.document.getElementById("Reference1"), sameRef1[jobid])
	 presetBookingDetails(myParent.document.getElementById("Reference2"), sameRef2[jobid])
	 presetBookingDetails(myParent.document.getElementById("Goods"), sameGoods[jobid])
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("PickupSite"), samePickupSite[jobid])
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("PickupAddress"), samePickupAddress[jobid])
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("PickupSuburb"), samePickupSuburb[jobid])
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("PickupLocalityID"), samePickupLocalityID[jobid])
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("PickupSuburbID"), samePickupSuburbID[jobid])

	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("Destination1Site"), sameDestinationSite[jobid+1])
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("Destination1Address"), sameDestinationAddress[jobid+1])
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("Destination1Suburb"), sameDestinationSuburb[jobid+1])
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("Destination1Instruction"), "")
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("Destination1LocalityID"), sameDestinationLocalityID[jobid+1])
	 presetBookingDetails(myParent.frames["PickupDestinationFrame"].document.getElementById("Destination1SuburbID"), sameDestinationSuburbID[jobid+1])
	 	 
   // enable buttons again
	 if (myParent.document.getElementById("SendNowAccount"))									    
  	 myParent.document.getElementById("SendNowAccount").disabled = false;
	if (myParent.document.getElementById("SendNowCredit"))
	   myParent.document.getElementById("SendNowCredit").disabled = false;
	if (myParent.document.getElementById("Price"))
	   myParent.document.getElementById("Price").disabled = false;
	 
	 TotalDestination = totallegs;
	 var tempMyCompany = parent.frames["NewFrame"].document.getElementById("MyCompany").value;
	 if (totallegs > 1) {
	     displayExtraDestination(totallegs, tempMyCompany, jobid,myParent)
	 }		 

}

function displayExtraDestination(totallegs, tempMyCompany,jobid, myParent) {
    //
		// user needs another drop leg 
		//
    for (i=2; i<=totallegs; i++) {
       		 myString = "<input id=Destination"+i+"AddressNumber name=Destination"+i+"AddressNumber value=0 type=hidden>"+
			  		   	  	  "<input id=Destination"+i+"AddressID name=Destination"+i+"AddressID value=0 type=hidden>"+
			  		   	  	  "<input id=Destination"+i+"LocalityID name=Destination"+i+"LocalityID value=0 type=hidden>"+
			  		   	  	  "<input id=Destination"+i+"SuburbID name=Destination"+i+"SuburbID value=0 type=hidden>"+
			  		   				"<fieldset><legend>Destination "+
					   					"<input type=checkbox name=Destination"+i+"Control id=Destination"+i+"Control "+
					   					" onclick=CheckControl('Destination"+i+"',event)"+
					   					" title='Check to add to frequent address. You may then key in your code in relation to this address. Uncheck to delete selected frequent address (optional)'>Frequent Address "+
					   					"&nbsp;&nbsp;"+
				  	   				"<input type='checkbox' name=Destination"+i+"Verify "+
					   					"id=Destination"+i+"Verify "+
					   					"value='0' "+
					   					"title='Tick to form a verified address list'>Verify Address"+												   										 
			             		"</legend>"+
					   					"<table width=100% border=0 id=Destination"+i+"Table name=Destination"+i+"Table"+
					   					" cellpadding=0 cellspacing=3><tr>"+
					   					// Destination Site Name
					 						"<td valign=top width=10%>&nbsp;</td>"+
					   					"<td valign=top width=20%>Name:</td>"+
					   					"<td valign=top width=70%><input style=width:80% type=text name=Destination"+i+"Site id=Destination"+i+"Site "+
											" value='"+sameDestinationSite[jobid+i]+"' \n"+
//	                		" onfocus=ColorBackGround(this,"+tempMyCompany+");ObjectDescription2(18);SetCursorPosition('Destination"+i+"');"+
//					   					" onblur=NormalBackGround(this,"+tempMyCompany+");toUpper(this);CheckAddress('Destination"+i+"',event);SetMyNextFocus('Destination"+i+"Address'); "+
					   					" title='Destination site name (required). \nTo populate it, you can either: \n"+
					   					" 1. click on the frequent address on the left \n"+
					   					" 2. key in the frequent address number and press tab \n"+
					   					" 3. key in a new site name' " +					   
//					   					" onkeyup=CheckAddress('Destination"+i+"',event);>"+
	                		" onfocus=CheckHelp(this);ColorBackGround(this,"+tempMyCompany+");ObjectDescription2(18);SetCursorPosition('Destination"+i+"');"+
					   					" onblur=\"BlurItem(this, document.getElementById('FrequentAddressDiv'));CheckHelp(this);NormalBackGround(this,"+tempMyCompany+");toUpper(this);CheckAddress('Destination"+i+"',event);\" "+
					   					" onkeyup=\"FocusItem(this, document.getElementById('FrequentAddressDiv'),0);MatchItem(event,0);CheckAddress('Destination"+i+"',event);\" "+																
					   					"</td></tr>"+
            	   			// Destination Site Address 
					   					"<tr>"+
						 					"<td valign=top width=10%>&nbsp;</td>"+
						 					"<td valign=top width=20% id='Destination"+i+"AddressColumn'>Address:</td>"+
					   					"<td valign=top width=70%><textarea name=Destination"+i+"Address id=Destination"+i+"Address rows=3 "+  
											" value='"+sameDestinationAddress[jobid+i]+"' \n"+
					   					" style='font:8pt arial;width:80%' "+
            	   			" onfocus=ColorBackGround(this,"+tempMyCompany+");ObjectDescription2(19);useAddressLookupVerify(this,'address','Destination"+i+"Verify','Destination"+i+"Instruction');" +
        		   				" onblur=NormalBackGround(this,"+tempMyCompany+");displayAddressVerify('Destination"+i+"Address','Destination"+i+"Verify','Destination"+i+"Suburb');toUpper(this);" +
					  					" title='Destination site address (required)'"+
					   					" onKeyDown=textCounter(this,60);" +
					   					" onKeyUp=textCounter(this,60);>"+sameDestinationAddress[jobid+i]+"</textarea>"+
							     		"</td></tr>"+
	 						     		// Destination Site Suburb 
							     		"<tr>"+
						 			 		"<td valign=top width=10%>&nbsp;</td>"+
									 		"<td valign=top width=20%>Suburb:</td>"+
	 						    		"<td valign=top width=70% id=Destination"+i+"SuburbColumn "+
											"name=Destination"+i+"SuburbColumn><input type=text name=Destination"+i+"Suburb id=Destination"+i+"Suburb "+
											" value='"+sameDestinationSuburb[jobid+i]+"' \n"+
											" onfocus=useAddressLookupVerify(this,'locality','Destination"+i+"Verify','Destination"+i+"Instruction');CheckHelp(this);ObjectDescription2(24);ColorBackGround(this,"+tempMyCompany+"); " +	
											" onblur=NormalBackGround(this,"+tempMyCompany+");displaySelectedSuburbVerify('Destination"+i+"Suburb','Destination"+i+"Verify');ShowAddDest(); "+  
							     		" title='Destination site suburb (required). Suburb list will be constructed as you type'"+
								 			" style='width:80%;'>"+   
            			 		" <div style=position:absolute; display=none id=SelectSuburb> "+
			  				 			" <label id=SuburbList rows=24 "+ 
							 				" style=background:#ffffff;border:gray thin outset;height:69px;>"+ 
							 				" </label></div>"+
							 				"</td></tr>"+
	 						 				// Destination Site Instruction 
							 				"<tr>"+
						   				"<td valign=top width=10%>&nbsp;</td>"+
											"<td valign=top width=20%>Instructions:</td>"+
	 						 				"<td valign=top width=70%><textarea name=Destination"+i+"Instruction id=Destination"+i+"Instruction rows=2 "+    
         				 			" onfocus=ColorBackGround(this,"+tempMyCompany+");ObjectDescription2(21);" + 
       				 				" onblur=NormalBackGround(this,"+tempMyCompany+");toUpper(this);NextFocus("+i+");" +
							 				" title='Destination site instruction (optional)'"+
											" style='font:8pt arial;width:80%' "+
							 				" onKeyDown=textCounter(this,60);"+
							 				" onKeyUp=textCounter(this,60);></textarea>"+																	    								
							 				"</td></tr>"+
                      "<tr><td colspan=3><input type=text "+ 
  			    		  		"style=border:0;text-decoration:underline;text-align:left; "+ 
	  		    				  "onclick='EraseDest("+i+");' value='Delete Destination' "+
				    				  "onmouseover=ChangeColour(this,'over'); "+ 
				    				  "onmouseout=ChangeColour(this,'out'); "+
			         				"title=Extra Destination readonly=readonly>"+
											"</table>"+
					            "</fieldset>";
		      myParent.frames["PickupDestinationFrame"].document.getElementById("ExtraDestination"+i).innerHTML = myString
	 }
}

function requestTime(samejob) {
  //
	// called by Dtrans-v1.html - onload
	// 1. reload frequent address
	// 2. request for server time based on the cityid
  // 3. clear pickup addresses 
		
	/* step 0 - temporary
	if (parent.parent.document.getElementById("myCityID").value != "(51,0,2)") {
  	 disableMyPage(true, document, window.frames["PickupDestinationFrame"])
		 if (document.getElementById("SendNowAccount")) 									    
  	 		document.getElementById("SendNowAccount").disabled = true;
	   if (document.getElementById("Price")) 
	      document.getElementById("Price").disabled = true;
		 alert("Our internet booking system is unavailable at the moment. Please contact us to book a job")
		 return		
	}		
	*/	
	// step 1
//  parent.parent.window.frames["sideIframe"].location.reload();
	// step 2
	incomplete = true;
  serverRequest("time", parent.parent.document.getElementById("myCityID").value, gotLocalTime,'', '', '');

	var myWindow = parent.parent.window.frames["mainIframe"].frames["NewFrame"].frames["PickupDestinationFrame"]
	if (myWindow) {
			// clear pickup if cityid different to original
			if (parent.parent.window.frames["rightIframe"].document.getElementById("clientcity") == null)
				 return;		
			// step 3
			if (parent.parent.document.getElementById("myCityID").value != 	parent.parent.window.frames["rightIframe"].document.getElementById("clientcity").value) {
					myWindow.document.getElementById("PickupSite").value = ""
					myWindow.document.getElementById("PickupAddress").value = ""
					myWindow.document.getElementById("PickupSuburb").value = ""
					myWindow.document.getElementById("PickupInstruction").value = ""
			}
	}		
}


function gotLocalTime(errorText, response, text) {
  //
	// call when server sends back response through requestTime() function
	// 1. read xml tags
	// 2. set dates and times in  /Booking/DateTime.html
	// 3. reset timer if exists
  // 4. start showing and keeping current time, get business operation hours
	//
	
	// step 1
	var localDateTime = XMLtext(response, "localtime")
	var availabledate = XMLtext(response, "dates")
	var startReturn = XMLtext(response, "starttime")
	var endReturn = XMLtext(response, "endtime")
	var enddaybizReturn = XMLtext(response, "closingtime")
	server_readyNowOK = "true";
	incomplete = false;
	server_readyNowOK = XMLtext(response, "readyNow")
	
	// split it up
	var startTime = startReturn.split("@")
	var endTime = endReturn.split("@")
	var dateOK = availabledate.split("@")
	var enddaybizTime = enddaybizReturn.split("@")
	var opt = "";
	var enddaybizSplit = "";
	var startSplit = ""
	var endSplit = ""
  var counter = 0;
	var checkDay;

	window.frames["ClockFrame"].document.getElementById("FromTime").options.length = 0
	window.frames["ClockFrame"].document.getElementById("ToTime").options.length = 0

	// step 2
	for (i=0; i<dateOK.length; i++) {
   	// clear info
	  window.frames["ClockFrame"].document.getElementById("tempFrom"+i).options.length = 0
	  window.frames["ClockFrame"].document.getElementById("tempTo"+i).options.length = 0
	  checkDay = dateOK[i].split(" ");	
    counter = 0;
		opt = new Option(dateOK[i], dateOK[i]);
    window.frames["ClockFrame"].document.getElementById("showAvailableDates").options[i] = opt
		// set temp dates
    window.frames["ClockFrame"].tempAvailableDates[i] = window.frames["ClockFrame"].document.getElementById("showAvailableDates").options[i].value
		
	  if (checkDay[1] == "Sat") {
			 window.frames["ClockFrame"].document.getElementById("showAvailableDates").options[i].style.color = "red"
		}	 
		startSplit = startTime[i].split(":")
		endSplit = endTime[i].split(":")
		
		var check = 0;
		var startMinute = startSplit[1];
  	for (check=parseFloat(startSplit[0]); check<=parseFloat(endSplit[0]); check++) {
      startMinute = getStartMinute(check, startSplit, startMinute, "first");
			 			 
    	 if (setTimeInDateTimeBox("yes","yes", startSplit, endSplit, counter, i, check, startMinute, "first")) {
			    counter++;
			    startMinute = getStartMinute(check, startSplit, startMinute, "second");
			    if (setTimeInDateTimeBox("yes","yes", startSplit, endSplit, counter, i, check, startMinute, "second")) {
			       counter++;
			    }
			 } else {
			       break;
			 }     
    }

		enddaybizSplit = enddaybizTime[i].split(":")		
		if (check < parseFloat(enddaybizSplit[0])) {
  	 for (secondcheck=check; secondcheck<=parseFloat(enddaybizSplit[0]); secondcheck++) {
         startMinute = getStartMinute(secondcheck, endSplit, startMinute, "first");
			 			 
    	    if (setTimeInDateTimeBox("no","yes", endSplit, enddaybizSplit, counter, i, secondcheck, startMinute, "first")) {
			       counter++;
			       startMinute = getStartMinute(secondcheck, endSplit, startMinute, "second");
			       if (setTimeInDateTimeBox("no","yes", endSplit, enddaybizSplit, counter, i, secondcheck, startMinute, "second")) {
			          counter++;
			       }
			    } 
       }
    }
		
  }
	// step 3
	if(timerID) {
  		clearTimeout(timerID);
   		timerID  = 0;
  }
 

	// step 4
	startLocalTimer();		
  getTime()
	
	// set times in advance box
	if (window.frames["ClockFrame"].document.getElementById("showAvailableDates").length > 0) {
   	 MyAdvanceDateTime()
	}	 

	currentDay = new Date();
	// remember the time difference between my computer and the server
  checkdiff = (currentDay.getTime()/1000) - todayCurrentTime;
}

function getStartMinute(check, startSplit, startMinute, whichOne) {
  if (check == parseFloat(startSplit[0]) && startMinute == startSplit[1] && whichOne == "first") {
			 return startSplit[1]
	} else {
	    if (startMinute == "30")
		     return "00"
		  else   
			    return "30"
	}
}

function getTimeSession(check, startMinute, whichOne, closingTime) {
	 var startAMPM = "";
	 var startZero = "";
	 var timesession = "";
   var startRange = parseFloat(check);
	 
	 if (check == closingTime && startMinute == "30")
	     return timesession;
	 
	 if (whichOne == "second" && startMinute == "00") { 
       startRange = parseFloat(check) + parseFloat(1)
   }				 	 
   // get hour, am/pm
	 if (startRange == 12) {
		   startRange = parseFloat(12)
		   startAMPM = "pm";		
	 } else if (startRange > 12) {
			  startZero = "0";
		   startRange = parseFloat(startRange) - parseFloat(12)
		   startAMPM = "pm";
	 } else {
		   startAMPM = "am";
		   if (startRange < 10)
		       startZero = "0";		
	 }
   timeSession = startZero+startRange+":"+startMinute+startAMPM
	 return timeSession
}

function setTimeInDateTimeBox(setFrom, setTo, startSplit, endSplit, counter, i, check, startMinute, whichOne) {
	    /******** (1ST) ********/
      var timeSession = getTimeSession(check, startMinute, whichOne, parseFloat(endSplit[0]));
			 if (timeSession == "")
			     return false;
			 if (setFrom == "yes") {
  		     var opt = new Option(timeSession, timeSession);
          window.frames["ClockFrame"].document.getElementById("From"+i).options[counter] = opt
		   	var opt = new Option(timeSession, timeSession);
       	window.frames["ClockFrame"].document.getElementById("tempFrom"+i).options[counter] = opt
		   	if (i == 0) {
		          var opt = new Option(timeSession, timeSession);
              window.frames["ClockFrame"].document.getElementById("FromTime").options[counter] = opt
		      }	 
			 }
			 if (setTo == "yes") { 			  
   		     var opt = new Option(timeSession, timeSession);
          window.frames["ClockFrame"].document.getElementById("To"+i).options[counter] = opt
		   	var opt = new Option(timeSession, timeSession);
          window.frames["ClockFrame"].document.getElementById("tempTo"+i).options[counter] = opt
		  	if (i == 0) {
		          var opt = new Option(timeSession, timeSession);
              window.frames["ClockFrame"].document.getElementById("ToTime").options[counter] = opt
		      }
		  }		 		  
//			 if (check == endSplit[0] || startMinute == "30") {
			 if (check == parseFloat(endSplit[0]) && startMinute == endSplit[1]) {
			     return false;
			 }		 
			 
			 return true;		 
//			 counter++;
			 
		   /******** (2ND) ********/
       if (startMinute == "00") 
				startMinute = "30"
		   else 
				startMinute = "00"
				
		   // START TIME 
			  if (startMinute == "30") 
			      startRange = parseFloat(check)			  
			  else 
			      startRange = parseFloat(check) + parseFloat(1)
				 
			  startZero = "";
			  // get hour, am/pm
		   if (startRange == 12) {
		       startRange = parseFloat(12)
		       startAMPM = "pm";		
		   } else if (startRange > 12) {
		     	 startZero = "0";
		     	 startRange = parseFloat(startRange) - parseFloat(12)
		    	 startAMPM = "pm";
		   } else {
		       startRange = parseFloat(startRange)
		       startAMPM = "am";
			      if (startRange < 10)
			         startZero = "0";		
		   }
			 
			 if (setFrom == "yes") {
       		timeSession = startZero+startRange+":"+startMinute+startAMPM
		   		opt = new Option(timeSession, timeSession);
       		window.frames["ClockFrame"].document.getElementById("From"+i).options[counter] = opt
	     		// set temp from times
		   		opt = new Option(timeSession, timeSession);
       		window.frames["ClockFrame"].document.getElementById("tempFrom"+i).options[counter] = opt
		   		if (i == 0) {
		         opt = new Option(timeSession, timeSession);
             window.frames["ClockFrame"].document.getElementById("FromTime").options[counter] = opt
		      }
			 }
			 if (setTo == "yes") {			 
       		timeSession = startZero+startRange+":"+startMinute+startAMPM
		   		opt = new Option(timeSession, timeSession);
       		window.frames["ClockFrame"].document.getElementById("To"+i).options[counter] = opt
		   		opt = new Option(timeSession, timeSession);
       		window.frames["ClockFrame"].document.getElementById("tempTo"+i).options[counter] = opt
		   		if (i == 0) {
		         opt = new Option(timeSession, timeSession);
             window.frames["ClockFrame"].document.getElementById("ToTime").options[counter] = opt
		      }
			 }			 
			 counter++			  			  
			 return true;
}

function getConvertedTime(mytime) {
	var myLocalTime = new Date();
 	myLocalTime.setTime(mytime*1000)
	var localhour = myLocalTime.getHours();
	var localAMPM = "am";
	if (localhour >= 12) 
		 localAMPM = "pm";
   if (localhour > 12) 
     localhour -= 12;			

	return ((localhour < 10) ? "0" : "")+localhour+((myLocalTime.getMinutes() < 10) ? ":0" : ":")+myLocalTime.getMinutes()+localAMPM
} 

function startLocalTimer() {
  //
  // keep track of business operation hours and current time
	// 1. reset timer if exists
	// 2. display current time on status bar
	//    2.1. make sure current time = server current time
	// 3. request for business operation hours and current time every 15 minutes
	
  // step 1
 	if(timerID) {
  		clearTimeout(timerID);
	    clockID  = 0;
  }

	reloadTime++;

	// step 2
  currentDay = new Date();
  // reset opening and closing times
	var mytable = parent.parent.document.getElementsByTagName("table");
//	var mytable = parent.parent.document.getElementsByName("tradinghours");

	// get endtime
	var endtime = getConvertedTime(endBizTime)
	var starttime = getConvertedTime(startBizTime)
//	var endtime = ((localhour < 10) ? "0" : "")+localhour+
//							  ((myLocalTime.getMinutes() < 10) ? ":0" : ":")+myLocalTime.getMinutes()+localAMPM
	/*							
 	myLocalTime.setTime(startBizTime*1000)
	localhour = myLocalTime.getHours();
	localAMPM = "am";
	if (localhour >= 12) 
		 localAMPM = "pm";
  if (localhour > 12) 
     localhour -= 12;			
*/	
	
	
//	var starttime = ((localhour < 10) ? "0" : "")+localhour+
//								  ((myLocalTime.getMinutes() < 10) ? ":0" : ":")+myLocalTime.getMinutes()+localAMPM

	if (document.all) {								
		  if (currentDay.getDay() >= 1 && currentDay.getDay() <= 5 && endBizTime != "" && endBizTime != 0) { 		
			 		mytable[3].childNodes[0].childNodes[0].childNodes[1].innerHTML = starttime+" - "+endtime
	    }	else if (currentDay.getDay() == 6 && mytable[3].childNodes[0].childNodes[1]) {
			    mytable[3].childNodes[0].childNodes[1].childNodes[1].innerHTML = starttime+" - "+endtime	    
	    }
	} else {
		  if (currentDay.getDay() >= 1 && currentDay.getDay() <= 5 && endBizTime != "" && endBizTime != 0) { 																				
	       mytable[3].childNodes[1].childNodes[0].childNodes[1].innerHTML = starttime+" - "+endtime
			} //else if (currentDay.getDay() == 6 && mytable[3].childNodes[1].childNodes[2]) {
			  // mytable[3].childNodes[1].childNodes[2].childNodes[1].innerHTML
			//}	 
	}

	// step 2.1
	// make sure the time showing is always the same as the system
	var actualtime = 0;
	if (checkdiff > 0) {
	    actualtime = currentDay.getTime() - checkdiff
	} else {		
	    actualtime = currentDay.getTime() + checkdiff  
  }

				
	// dont care what their time is
//	today.setTime(actualtime)
//	todayCurrentTime = actualtime/1000

  var mydate = today.getDate();
  var mymonth = today.getMonth()+1;
  var myyear = today.getFullYear();
  var myhour = today.getHours();
	var myminute = today.getMinutes();
	var mysecond = today.getSeconds();	
	var myAMPM = "AM";

	if (myhour >= 12) 
		myAMPM = "PM";
	if (myhour > 12) 
		myhour -= 12;

  window.status = "Your local date and time: "+mydate+"/"+mymonth+"/"+myyear+
	    					 " "+myhour+((myminute < 10) ? ":0" : ":")+myminute+
				 		     ((mysecond < 10) ? ":0" : ":")+mysecond+" "+myAMPM+" EST";

  document.getElementById("mylocaltime").value = myhour+((myminute < 10) ? ":0" : ":")+myminute  						 		
  document.getElementById("mylocaldate").value = mydate+"/"+mymonth+"/"+myyear 						 		
	
	// step 3
  var fifteenMinutes = (60 * 15);
	if (reloadTime == fifteenMinutes) {
		  getTime();
			incomplete = true;
		  serverRequest("time", parent.parent.document.getElementById("myCityID").value, gotLocalTime,'', '', '');
			document.getElementById("PickupTime").selectedIndex = 0;
			document.getElementById("DeliveryTime").selectedIndex = 0;
		  reloadTime = 1;
	}

  if (statusBiz == "HOLIDAY") {
     parent.parent.document.getElementById("trading").style.color = "red";		 
	 	 parent.parent.document.getElementById("trading").innerText = "WE ARE NOW CLOSED"
	 	 parent.parent.document.getElementById("trading").innerHTML = "WE ARE NOW CLOSED"
	} else {
	   if (endBizTime != "" && endBizTime != 0) {
   	   // after hours
     	 if (todayCurrentTime < startBizTime || todayCurrentTime > endBizTime) {
		      parent.parent.document.getElementById("trading").style.color = "red";		 
	 	      parent.parent.document.getElementById("trading").innerText = "WE ARE NOW CLOSED"
  	 	    parent.parent.document.getElementById("trading").innerHTML = "WE ARE NOW CLOSED"
	     }  else {		   
		      parent.parent.document.getElementById("trading").style.color = "black";		 
	 	      parent.parent.document.getElementById("trading").innerText = "WE ARE NOW OPEN"	 
	 	      parent.parent.document.getElementById("trading").innerHTML = "WE ARE NOW OPEN"	 
	     }
		}	  
  }
	timerID = setTimeout("startLocalTimer()",1000); 
}

function useAddressLookupVerify(currentObject, searchType, checkObjectName, nextFocusObject) {
		//
		// lookup address depending on the city
		//
    var myHigherParent = parent.parent.parent
		if (checkObjectName) {
  		if (document.getElementById(checkObjectName).checked || searchType == "locality") 
          useAddressLookup(currentObject,searchType, myHigherParent.document.getElementById("myCityID").value,document.getElementById(nextFocusObject));
		} else if (searchType == "locality") {
         useAddressLookup(currentObject,searchType, myHigherParent.document.getElementById("myCityID").value,document.getElementById(nextFocusObject));
		} 							
}

function displayAddressVerify(currentObjectName, checkObjectName, suburbObjectName) {
    //
		// display verified address
		//
		if (document.getElementById(checkObjectName).checked) {
       displayAddress(document.getElementById(currentObjectName), document.getElementById(suburbObjectName), null, null, null);
		   ShowAddDest();
		   var myObject = document.getElementById(currentObjectName); 
		} else {
		   if (document.getElementById(suburbObjectName+"ID").value == "") 
	    	   document.getElementById(suburbObjectName).value = ""
//			 document.getElementById(suburbObjectName+"ID").value = ""
		}  		
}

function displaySelectedSuburbVerify(currentObjectName,checkObjectName) {
      //
		  // display verified suburb
		  // 1. if suburbid is null, do not proceed, focus on suburb box
			// 2. if suburbid is valid, remove it from the list of invalidsuburb
			//
			if (document.getElementById(currentObjectName).value != "") {
    	 displaySelectedSuburb(document.getElementById(currentObjectName),"onlysuburb")		
	
			 var myObject = document.getElementById(currentObjectName)

//			 if (XMLfield(myObject.item, "locality.suburbid") == null) {
			 if (XMLfield(myObject.item, "locality.suburbid") == null && document.getElementById(currentObjectName+"ID").value == "") {
			     // step 1
	      	 document.getElementById(currentObjectName).select();
	      	 document.getElementById(currentObjectName).focus();		
					 if (document.getElementById("invalidSuburb"))
   					 document.getElementById("invalidSuburb").value += currentObjectName;
		   } else {
			    // step 2
					if (document.getElementById("invalidSuburb")) {
    		 	   var invalidValue = document.getElementById("invalidSuburb").value
	  				 while (invalidValue.indexOf(currentObjectName) > -1) {
		  		   		 invalidValue = invalidValue.replace(currentObjectName,'')
			  		 }			 
   			     document.getElementById("invalidSuburb").value = invalidValue
					}	 			 
			 }
		}

		if (document.getElementById("invalidSuburb"))  {
				regenerateRateList();
				checkRateType()
				// get zone if neccessary
				checkZone()
		}		
}

function regenerateRateList() {
   // set innitial delivery type 
 	 for (var i=0; i<parent.document.getElementById("Delivery").length; i++) { 
  	   tempInnitialRateType[i] = parent.document.getElementById("Delivery").options[i].value+":"+parent.document.getElementById("Delivery").options[i].innerHTML;
   }

	 // remember current selected delivery type
   var tempRateType = parent.document.getElementById("Delivery").options[parent.document.getElementById("Delivery").selectedIndex].innerHTML
	 
	 // reset delivery type values on the page list
   parent.document.getElementById("Delivery").length = 0

/*
    for (var i=0; i<RateTypeData.length; i++) {
      var opt = new Option(RateTypeData[i].description, RateTypeData[i].number);		
		  parent.document.getElementById("Delivery").options[i] = opt;    
    }
*/		

		// regenerate the list from the innitial stored list
    for (var checkme=0; checkme<tempInnitialRateType.length; checkme++)  {
	     var splitcheck = tempInnitialRateType[checkme].split(":")
       var opt = new Option(splitcheck[1], splitcheck[0]);		
		   parent.document.getElementById("Delivery").options[checkme] = opt;    		   
 	  }
    
		// set back to current selected type
		for (var i=0; i<parent.document.getElementById("Delivery").length; i++) {
	    if (parent.document.getElementById("Delivery").options[i].innerHTML == tempRateType)
         parent.document.getElementById("Delivery").selectedIndex = i;
		}		 
}

function SetCompanyID(mycompany) {
    //
    // set user company to global variable
		//
    companyid = mycompany;
}

function highlightThis(tbRow, set)
{
  //
  //	highlight this table row
	//

	if (set) {							 																// Setting highlight?
    tbRow.className = "SecondaryColour"+companyid; 				// Highlight the row 
		if (tbRow.cells[0].innerHTML == "" && inputControl)
		   selectedText	= inputControl.value;							 		// this is a new reference
		else
		   selectedText=tbRow.cells[0].innerHTML;							// save the selected text
			 			 
		if (tbRow.cells.length > 1) {													// is ther more than one column?
			extraText=tbRow.cells[1].innerHTML;									// save the second column as extra text
		}

//		tbRow.cells[0].innerHTML = selectedText
//		FindItem(0)
	} else {
     tbRow.className = ""																	// unhighlighting 
	}
}

function highlightItem(set)
{
  //
  //	highlight or remove highlight from the current row
	//
	if (rw == null)									// If we have no row we are finished
		return;

	highlightThis(rw, set);					// do the highlight
	if (set) {											// Setting highlight?
//		  rw.scrollIntoView(0);				// ensure the row can be seen
		  rw.scrollIntoView(foundMatchingRow);				// ensure the row can be seen
	}
}

function FindItem(isFixed) 
{
  //
  //	find the item matching the input text in the table
	//
	if (inputControl == null)	{					  // how did we get here?
	  selectedText = null;
		return;
  }		
	if (inputControl.value <= ' ') {			// is there any text in the control?
	   // must select from the list
	   if (isFixed == 1) {
		    itemno = 0;					 		 				// no - go back to the start
		    rw = tbl.rows[itemno];
		 }		
		 return;
	}
	if (isFixed == 1) {
    	var matchvalue = "^" + inputControl.value;
			var subcomp = new RegExp(matchvalue, "i");	 			// make a regular expression
			for (itemno=0; itemno<tbllen; itemno++) {		  		// and look for it
	      	rw = tbl.rows[itemno];
					var itm = rw.cells[0];
					if (itm.innerHTML.match(subcomp)) {
					   return;												 						// this is the one - stop processing
		      }
	    }
	    inputControl.value = matchvalue.substr(1, matchvalue.length-2);
	    FindItem(isFixed);																// This string doesn't match - drop the last charav=cter and try again
	} else {
    	var matchvalue = "^" + inputControl.value;
			var subcomp = new RegExp(matchvalue, "i");				// make a regular expression
			for (itemno=0; itemno<tbllen; itemno++) {					// and look for it
	      	rw = tbl.rows[itemno];
					var itm = rw.cells[0];
					if (itm.innerHTML.match(subcomp)) {
					   tabledivControl.style.display="";		
					   foundMatchingRow = itemno;
					   return;												 						// this is the one - stop processing
		      } else {
				      rw = tbl.rows[0];
	    		    inputControl.value = inputControl.value;
							foundMatchingRow = "";
					}
	    }
			if (foundMatchingRow == "") {
			    tabledivControl.style.display="none";		
			}		
	}
}		   
function MatchItem(event, isFixed)
{
  //
  //	match the current value of the inputControl to the table or navigate through the table
	//
	var theKey;
	theKey = event.keyCode;				 		 // extract the current key pressed
	highlightItem(false);

 	if (theKey == 40) {								 // Down arrow
		if (itemno < (tbllen-1)) {
			itemno++;							 				 // move to the next item
			rw = tbl.rows[itemno];
		}
	} else if (theKey == 38) {				// Up arrow
		if (itemno > 0) {
			itemno--;				 		 					// move to the previous item
			rw = tbl.rows[itemno];
		}
//	} else if (theKey == 13) {				// enter key pressed - extract the current value
	} else if (theKey == 13 || theKey == 0 || (!(theKey))) {				// enter key pressed - extract the current value
		if (itemno >= 0 && itemno < tbllen && rw.cells[0]) {
			inputControl.value = rw.cells[0].innerHTML;
			foundMatchingRow = itemno;
			inputControl.blur();
		}
	} else if (theKey == 27) {				// escape key pressed
		selectedText = null;						// nothing has been selected
		inputControl.blur();						// go away
		return;													// right away
	} else {
		FindItem(isFixed);							// a character was typed - match the result to the table
	}
	highlightItem(true);							// highlight the current selection
}

function FocusItem(inputbox, tablediv, isFixed)
{
  //
  //	this control has received the focus to match it's content with the table
	//
  if (document.getElementById("Vehicle"))
		 document.getElementById("Vehicle").style.visibility = "hidden"
  if (!(tablediv))
		 return
	selectedText=null;																		 // nothing has been selected yet
	extraText=null;																				 // and ther is no extra data
	inputControl = inputbox;															 // save the control we are processing
	tabledivControl = tablediv;
	
	tbl = tablediv.getElementsByTagName("TABLE")[0];			 // save the details of the table we are using
	if (!(tbl))
	   return
	tbllen = tbl.rows.length;
	tablediv.style.display="";														 // make our reference table visible

	var parentTop = inputControl.offsetParent;
	var theTopValue = 0;
	var theLeftValue = 0;
  while (parentTop) {
	    theTopValue += parentTop.offsetTop
	    theLeftValue += parentTop.offsetLeft
			parentTop = parentTop.offsetParent;
	}    	
	tablediv.style.top = theTopValue + inputControl.offsetTop + inputControl.offsetHeight;
	tablediv.style.left = theLeftValue + inputControl.offsetLeft + inputControl.offsetLeft;
	
  if (tablediv.id == "FrequentAddressDiv") {
    	tablediv.style.height = Math.min(180, tbl.offsetHeight);	
//	    tablediv.style.width = document.getElementById('PickupSite').offsetWidth
  		tablediv.style.width = inputControl.offsetWidth
	} else {
    	tablediv.style.height = Math.min(90, tbl.offsetHeight);			
	}
	
}


function BlurItem(inputbox, tablediv, extra)
{
  //
  //	the control has lost the focus.  If we have saved a matching value then set the control content to the value.
  //	note - if the user clicked on the table then the matching value was saved on the table row mouseover
	//
	if (foundMatchingRow != "")
	    rw = tablediv.getElementsByTagName("TABLE")[0].rows[foundMatchingRow];

	if (selectedText == null && rw) {						// did the user select anything?
			selectedText = rw.cells[0].innerHTML	
	}

	if (selectedText != null) {						// did the user select anything?
		inputbox.value=selectedText;				// yes - put it in the control
		if (rw) {
   		if (rw.cells[0].id != "") {
		  	   FillMyAddress(parent.parent.parent.frames["sideIframe"].document.getElementById(rw.cells[0].id))
					 foundMatchingRow = inputControl.value
			} else if (inputbox.value != "") {
			     if (parent.parent.parent.frames["sideIframe"].document.getElementById(inputbox.value))
		  	      FillMyAddress(parent.parent.parent.frames["sideIframe"].document.getElementById(inputbox.value))
 		  }		   
    }
		if (extra) {												// do we have an extra (hidden) control for extra data?
			extra.value=extraText;						// save save the extra text
		}
	}
	highlightItem(false);									// remove any highlight
	if (tablediv)
		 tablediv.style.display="none";			// make our reference table visible
	tbl = null;														// clear all out variables
	rw = null;
	inputControl = null;
  tabledivControl = null

	nextObject = document.getElementById(inputbox.id.substring(0,inputbox.id.length-4)+"Instruction")

	//if (nextObject && foundMatchingRow != "") 
	//   nextObject.focus();

	foundMatchingRow = "";
	selectedText = null;
}

function BlurItemExtra(inputbox, extra) 
{
  //
	//	the control has lost the focus.  If we have saved a matching value then set the control content to the value.
	//	note - if the user clicked on the table then the matching value was saved on the table row mouseover
	//
  var tablediv = parent.window.frames["PickupDestinationFrame"].document.getElementById("SuburbDiv")
	if (selectedText != null) {				// did the user select anything?
		inputbox.value=selectedText;		// yes - put it in the control
		if (extra) {										// do we have an extra (hidden) control for extra data?
			extra.value=extraText;				// save save the extra text
		}
	}
	highlightItem(false);							// remove any highlight
	tablediv.style.display="none";		// make our reference table visible
	tbl = null;												// clear all out variables
	rw = null;
	inputControl = null;
}
	
	
function getMouseXY  (e) {
  //
	// get mouse position
	//
  if (document.all) {
     GlobalX = event.clientX + document.body.scrollLeft
     GlobalY = event.clientY + document.body.scrollTop
	}
	else {
     GlobalX = e.pageX;
     GlobalY = e.pageY;
  }
}

function ObjectDescription2(objectNumber) {
   //
	 // display description of box selected
	 //
   if (parent.frames["MultiPurposeFrame"])
      parent.frames["MultiPurposeFrame"].ShowDescription(objectNumber);   
}

function ObjectDescription(objectNumber) {
   //
	 // display description of box selected
	 //
   if (parent.window.frames["NewBookingFrame"])
      parent.window.frames["NewBookingFrame"].frames["MultiPurposeFrame"].ShowDescription(objectNumber);
	 else	
      window.frames["MultiPurposeFrame"].ShowDescription(objectNumber);
}



function CheckDescription(theObject) {
   //
	 // display description of rate type selected
	 //
   if (theObject.options[theObject.selectedIndex].innerHTML == "Standard")
	    ObjectDescription(0) 
   else if (theObject.options[theObject.selectedIndex].innerHTML == "VIP")
	    ObjectDescription(1) 
   else if (theObject.options[theObject.selectedIndex].innerHTML == "Priority")
	    ObjectDescription(2) 
   else if (theObject.options[theObject.selectedIndex].innerHTML == "Premium")
	    ObjectDescription(3) 
   else if (theObject.options[theObject.selectedIndex].innerHTML == "General" || theObject.options[theObject.selectedIndex].innerHTML == "General - Future")
	    ObjectDescription(4) 
   else if (theObject.options[theObject.selectedIndex].innerHTML == "AdvTomorrow")
	    ObjectDescription(5) 
}

function toUpper(thisObject) {
   //
	 // set proper case 
	 //
   var mString = thisObject.value
	 if (thisObject.value) {
   		xString = thisObject.value.toUpperCase()
	    thisObject.value = setProperCase(mString)
	 }	 
   if (document.getElementById("Vehicle"))
		 document.getElementById("Vehicle").style.visibility = "visible"
	 
}

function setProperCase(mString) {
   //
	 // set proper case 
	 //
   var nString = "";
   var x = 0
   for (var i=0; i < mString.length; i++) {
      if ( i < 1 || x > 0 ) {
 	 	  x = 0
 	 	  nString = nString + mString.charAt(i).toUpperCase();
  	  }else{
  		  nString = nString + mString.charAt(i);
  	  }
  	  if (mString.charAt(i) == " " || mString.charAt(i) == "\n")
          x = 1
   }
	 return nString;
}


function SetRowNumber(theObject) {
   //
	 // store row number
	 //
   itemno = theObject.rowIndex;
}
/*
function SetIfCity (isCity) {
   if (isCity == "f") { 	   // if it's not a city area
     if (parent.document.getElementById("Vehicle").value == "(241,0,1)")
         parent.document.getElementById("(240,0,3)").checked = true
		 parent.document.getElementById("VehicleServiceID").value = "(240,0,3)" 
	 }		 	 		 
}


function SetOriginalNormal(objectname) {
	if (itemno > 3)		   // keep the itemno that increases/decreases as with arrow up/down																																									 
	   displayno = 3;    // if redisplay the table, always highlight the last item selected
	else
	   displayno = itemno;	 // highlight according to the itemno
	for (i=0;i<displayno;i++) {
	  if (document.getElementById(objectname+"Table")) {
       document.getElementById(objectname+"Table").rows[displayno].className = ''
		}	 
	}	
}
*/

function SpecDesc(theObject) {
   //
	 // set if vehicle options are selected, and certain options cannot be set together
	 //
   var myParent = parent.frames["NewFrame"]
	 if (myParent) {
       var myHigherParent = parent.parent
	 } else {		
	     myParent = parent.frames["mainIframe"].frames["NewFrame"]
       var myHigherParent = parent.parent.parent
	 }		 
	  var myParentChild = myParent.frames["PickupDestinationFrame"]

    if (theObject.type == "radio") {
       myParent.document.getElementById("VehicleServiceID").value = theObject.id
		}	 
		else {	
			     if (theObject.checked) {
								 for (z=0;z<serviceoptionArray.length; z++)	 {
								    if (serviceoptionArray[z] == theObject.id+"no")
										    serviceoptionArray[z] = theObject.id+"yes"
								 }
								 if (theObject.id == "(242,10,28)") {
								 // 1 tonne tray triple roof rack - century
								 // uncheck roofrack
								     myParent.document.getElementById("(242,10,24)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,10,24)yes")
												    serviceoptionArray[z] = "(242,10,28)no"
										 }
								 
								 } else if (theObject.id == "(242,10,24)") {
								 // 1 tonne tray roof rack - century
								 // uncheck triple roofrack
								     myParent.document.getElementById("(242,10,28)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,10,28)yes")
												    serviceoptionArray[z] = "(242,10,24)no"
										 }								 
								 } else if (theObject.id == "(242,10,29)") {
								 // 1 tonne van triple roof rack - century
								 // uncheck roofrack
								     myParent.document.getElementById("(242,10,25)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,10,25)yes")
												    serviceoptionArray[z] = "(242,10,29)no"
										 }
								 } else if (theObject.id == "(242,10,25)") {
								 // 1 tonne van roof rack - century
								 // uncheck triple roofrack
								     myParent.document.getElementById("(242,10,29)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,10,29)yes")
												    serviceoptionArray[z] = "(242,10,25)no"
										 }
								 } else if (theObject.id == "(242,7,1)") {
								 // 1 tonne tray triple roof rack
								 // uncheck roofrack
								     myParent.document.getElementById("(242,0,1)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,0,1)yes")
												    serviceoptionArray[z] = "(242,0,1)no"
										 }
										 
								 }		 
								 else if (theObject.id == "(242,0,1)") { 		 
								 // 1 tonne tray roof rack
								 // uncheck triple roofrack
								     myParent.document.getElementById("(242,7,1)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,7,1)yes")
												    serviceoptionArray[z] = "(242,7,1)no"
										 }
								 }		 
								 else if (theObject.id == "(242,7,2)") {
								 // 1 tonne van triple roof rack, long wheel base
								 // uncheck roofrack
								     myParent.document.getElementById("(242,0,3)").checked = false
								     myParent.document.getElementById("(242,3,1)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,0,3)yes")
												    serviceoptionArray[z] = "(242,0,3)no"
										    if (serviceoptionArray[z] == "(242,3,1)yes")
												    serviceoptionArray[z] = "(242,3,1)no"
										 }
								 }		 
								 else if (theObject.id == "(242,0,3)") {
								 // 1 tonne van roof rack
								 // uncheck triple roofrack, long wheel base
								     myParent.document.getElementById("(242,7,2)").checked = false
								     myParent.document.getElementById("(242,3,1)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,7,2)yes")
												    serviceoptionArray[z] = "(242,7,2)no"
										    if (serviceoptionArray[z] == "(242,3,1)yes")
												    serviceoptionArray[z] = "(242,3,1)no"
										 }
								 }		 
								 else if (theObject.id == "(242,7,3)")  {
								 // 1 tonne either triple roof rack
								 // uncheck roofrack
								     myParent.document.getElementById("(242,0,25)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,0,25)yes")
												    serviceoptionArray[z] = "(242,0,25)no"
										 }
								 }		 
								 else if (theObject.id == "(242,0,25)")  {
								 // 1 tonne either roof rack
								 // uncheck triple roofrack
								     myParent.document.getElementById("(242,7,3)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,7,3)yes") {
												    serviceoptionArray[z] = "(242,7,3)no"
												}		
										 }
								 }		 
								 else if (theObject.id == "(242,10,1)") {
								 // 1 tonne transit van
								 // uncheck long wheel base
								     myParent.document.getElementById("(242,3,1)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,3,1)yes")
												    serviceoptionArray[z] = "(242,3,1)no"
										 }
								 }		 
								 else if (theObject.id == "(242,3,1)") {
								 // 1 tonne long wheel base
								 // uncheck transit van, roofrack, triple roofrack, towball
								     myParent.document.getElementById("(242,10,1)").checked = false
								     myParent.document.getElementById("(242,7,2)").checked = false
								     myParent.document.getElementById("(242,0,3)").checked = false
								     myParent.document.getElementById("(242,0,4)").checked = false
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,10,1)yes")
												    serviceoptionArray[z] = "(242,10,1)no"
										    if (serviceoptionArray[z] == "(242,7,2)yes")
												    serviceoptionArray[z] = "(242,7,2)no"
										    if (serviceoptionArray[z] == "(242,0,3)yes")
												    serviceoptionArray[z] = "(242,0,3)no"
										    if (serviceoptionArray[z] == "(242,0,4)yes")
												    serviceoptionArray[z] = "(242,0,4)no"
										 }
								  }	else if (theObject.id == "(242,0,4)") {
								 // towball
								 // uncheck long wheel base
								     myParent.document.getElementById("(242,3,1)").checked = false									
										 for (z=0;z<serviceoptionArray.length; z++)	 {
										    if (serviceoptionArray[z] == "(242,3,1)yes")
												    serviceoptionArray[z] = "(242,3,1)no"
										 }
									}	 
				   } else {
							 for (z=0;z<serviceoptionArray.length; z++)	 {
							    if (serviceoptionArray[z].indexOf(theObject.id+"yes") == 0)
									    serviceoptionArray[z] = theObject.id+"no"
							 }
				   }	  			  
		}

   	DisplayImage(theObject.id,"")
}

function CheckToll(isToll) {
  //
	// check if toll option is available
	// 1. depends on rate type
	// 2. depends on carry 108 - Tolls in Booking
	// 3. depends on rate type, check when's next available pickup time
	// 4. depends on rate type, check if the job can have more than 1 drop
	//
	
	var dont_know = 1
	var always_ask = 2
	var no_need_ask = 3
	var never_charge = 4
	 
  var myRateType = document.getElementById("Delivery").options[document.getElementById("Delivery").selectedIndex].innerHTML

  if (document.getElementById("Tolls")) {
	   // step 1
  	if (myRateType == "VIP" || myRateType == "Premium" || myRateType == "Priority") {
	  		document.getElementById("Tolls").checked=false
		    document.getElementById("Tolls").disabled=true
		}  else{
		    // step 2
		    if (isToll == always_ask || isToll == never_charge) {
			       document.getElementById("Tolls").checked = true
		    	  //document.getElementById("Tolls").disabled=true
		    	   document.getElementById("Tolls").disabled=false
			   }  else {	    	 
			       document.getElementById("Tolls").checked = false		
		    	   document.getElementById("Tolls").disabled=false
			   }
	  }
	}	
	
	// step 3
	 var checkObject = document.getElementById("Delivery")
	 var checkServiceObject = document.getElementById("Vehicle")

//	 if (checkObject.options[checkObject.selectedIndex].innerHTML.indexOf('General') >= 0 && checkServiceObject.options[checkServiceObject.selectedIndex].innerHTML.indexOf('Service Type') < 0)
	 if (checkServiceObject.options[checkServiceObject.selectedIndex].innerHTML.indexOf('Service Type') < 0)
       SetAdvanceDateTime()
  
			 
	// step 4
	noExtraDestination();
}

function 	noExtraDestination () {
  //
	// general and advtomorrow rate type - ONLY 1 drop
	//
  var myWindow = "";
  if (document.getElementById("Delivery"))
	   myWindow = window;
  else if (parent.document.getElementById("Delivery")) 		 
     myWindow = parent
	else	 
	   myWindow = parent.frames["mainIframe"].frames["NewFrame"];
		 
  var myRateType = myWindow.document.getElementById("Delivery").options[myWindow.document.getElementById("Delivery").selectedIndex].innerHTML
  // disable extra destination if exists for certain delivery type	
  if (myRateType == "General" || myRateType == "General - Future" || myRateType == "AdvTomorrow") {
			 myWindow.document.getElementById("ExtraDest").style.visibility = "hidden";
			 // if more than 1 destination has been selected, remove it
			 var checkDest = TotalDestination
			 for (var DestNumber=checkDest; DestNumber>1; DestNumber--)
    			 EraseDest(DestNumber);
	 }		 
}


function SetCursorPosition (theValue) {
   //
	 // set temporary value of which box user is clicking, either pickup site or destination site
	 // use to set frequent address
	 //
   parent.document.getElementById("temp").value = theValue	 
}
/*
function CheckSize (theObject) {
   if (document.getElementById(theObject).value.length > 50) {
	   alert("Your address is too long. Please type in address between 40 characters.");
		 document.getElementById(theObject).focus();
	 }
}
*/
/*
function ChangeDisplayFormat (theWindow, theObject) {
    toUpper(theWindow.document.getElementById(theObject+'Site'));
    toUpper(theWindow.document.getElementById(theObject+'Address'));
    toUpper(theWindow.document.getElementById(theObject+'Suburb'));
    toUpper(theWindow.document.getElementById(theObject+'Instruction'));
}
*/

/*function DeleteDestination(evt) {
   var theObject;
   if (document.all)
      theObject = window.event.keyCode;
   else
      theObject = evt.keyCode;

   if (theObject != 13) {
	    if (theObject != 0)
	     return 0;
   }
  			
   var ThisWindow = window.frames["PickupDestinationFrame"];
	 DeleteObject = ThisWindow.document.getElementById("ExtraDestination"+TotalDestination)
	 if (DeleteObject) {			
	   DeleteObject.innerHTML = " ";
	   if (TotalDestination > 1)  // make sure TotalDestination is at least 1 
    	   TotalDestination--;
	 }		   
}
*/
function CheckControl (theObject,evt) {
   //
	 // if box is checked, then add address, if box is not checked, then delete address
	 //
   if (document.getElementById(theObject+"Control").checked)
	    AddDeleteFrequentAddress(theObject,0)					 // add addresss
	 else 		
   	  AddDeleteFrequentAddress(theObject,1)					 // delete address
}

function doEscape(s) {
   //
	 // replace certain reserved words
	 //
   if (navigator.vendor != "undefined" && navigator.vendor != "") {
		 if (document.all) {
         s=s.replace(/\&/g,"&amp;")
         s=s.replace(/\"/g,"&quot;")
         s=s.replace(/\'/g,"&#039;")
         s=s.replace(/>/g,"&gt;")
         s=s.replace(/</g,"&lt;")
//         s=s.replace(/\n/ig,"<br>")
		     return s;
		 } else {
// 		     s=s.replace(/\&#039;/g,"isaquote")
 		     s=s.replace(/\'/g,"isaquote")
 		     s=s.replace(/\&/g,"isampercent")
 		     s=s.replace(/\"/g,"isdoublequote")
 		     s=s.replace(/>/g,"isgreater")
 		     s=s.replace(/</g,"islesser")
				 return s;
		 }
	 } else {
         s=s.replace(/\&/g,"&amp;")
         s=s.replace(/\"/g,"&quot;")
         s=s.replace(/\'/g,"&#039;")
         s=s.replace(/>/g,"&gt;")
         s=s.replace(/</g,"&lt;")
//         s=s.replace(/\n/ig,"<br>")
		     return s;
	 }	 
   return s;
}

/*
function doEscape(s) {
   s=s.replace(/\&/g,"&amp;")
   s=s.replace(/\"/g,"&quot;")
   s=s.replace(/\'/g,"&#039;")
   s=s.replace(/>/g,"&gt;")
   s=s.replace(/</g,"&lt;")
  if (navigator.vendor != "undefined" && navigator.vendor != "") {
		 if (document.all) {
		     return s;
		 } else {
 		     s=s.replace(/\&#039;/g,"isaquote")
				 return s;
		 }
	 }
	 
   return s;
}
*/


function AddDeleteFrequentAddress(ObjectName,option) {
   //
	 // depends on option, this function adds and remove frequent address
	 // step 1 - add address
	 // step 2 - delete address
	 // step 3 - own address cannot be deleted
	 //
	 var tempXMLCommon = parent.window.frames["PickupDestinationFrame"].document.getElementById("XMLCommon").value
	 var cityid = parent.parent.parent.document.getElementById("myCityID").value;
   document.getElementById("AddFrequentAddress").style.display = ""
	 document.getElementById("AddFrame").style.width = "0px";
	 document.getElementById("AddFrame").style.height = "0px";
	 
   if (option == AddFrequentAddress) {	
	   // step 1
	   if (document.getElementById(ObjectName+"Site") != "" && 
			    document.getElementById(ObjectName+"Address")	!= "" &&
			    document.getElementById(ObjectName+"Suburb") != "") {

    		Suburb = document.getElementById(ObjectName+"Suburb").value.toUpperCase();

				var myObject = document.getElementById(ObjectName+"Address")
				var myObjectSuburb = document.getElementById(ObjectName+"Suburb")
			  var addressid = ""
				var suburbid = ""
				if (XMLfield(myObject.item, "address.addressid") && document.getElementById(ObjectName+"Verify").checked)
				   addressid = XMLfield(myObject.item, "address.addressid")
					 
				if (XMLfield(myObjectSuburb.item, "locality.suburbid")) 
			  	 suburbid = XMLfield(myObjectSuburb.item, "locality.suburbid")
				else	 	 
           suburbid = document.getElementById(ObjectName+"SuburbID").value
		    
				if (Suburb == "") {				   
					 alert("Error adding frequent address");
					 return
				}	 

				var myDetails=document.getElementById(ObjectName+"Address").value.replace(/&/ig,"specialcharacter")
				myDetails=document.getElementById(ObjectName+"Address").value.replace(/\n/ig,"<br>")
		    var myInstr=document.getElementById(ObjectName+"Instruction").value.replace(/&/ig,"specialcharacter")
		    myInstr=document.getElementById(ObjectName+"Instruction").value.replace(/\n/ig,"<br>")
			  var mySitename=document.getElementById(ObjectName+"Site").value.replace(/&/ig,"specialcharacter")

				Command = "../../../CustomerPHP/AddFrequentAddress.php?ClientID="+parent.document.getElementById("MyClientID").value+
			    		    "&Instruction="+myInstr+
									"&SiteName="+mySitename+
									"&Address="+myDetails+
					        "&Suburb="+Suburb+
					    		"&SuburbID="+suburbid+
					    		"&CityID="+cityid+
					    		"&Action=INSERT"+
					    		"&AddressID="+addressid
//         window.open(Command, "_blank");
         window.open(Command, "AddFrame");

//	      setTimeout("parent.parent.parent.window.frames['sideIframe'].location.reload()", 12000);
	      setTimeout("parent.parent.parent.window.frames['sideIframe'].location.reload()", 9000);
		 } else {
			  alert("Frequent address cannot be added due to incomplete address information");
        document.getElementById(ObjectName+"Control").checked = false					 
		 } 			
	 } else {
	    // step 2
	    CommonID =  document.getElementById(ObjectName+"AddressNumber").value;
	    if (CommonID != 0) { 
			    Command = "../../../CustomerPHP/AddFrequentAddress.php?ClientID="+parent.document.getElementById("MyClientID").value+
					    		  "&Action=DELETE"+
			              "&CommonID="+CommonID
         window.open(Command, "AddFrame");
	       setTimeout("parent.parent.parent.window.frames['sideIframe'].location.reload()", 9000);
			}
			else {
			    alert("This is your address. It will not be deleted");
          document.getElementById(ObjectName+"Control").checked = true
			}
	 }

//   document.getElementById("AddFrequentAddress").style.display = "none"
   // step 3
	 parent.window.frames["PickupDestinationFrame"].document.getElementById("XMLCommon").value = tempXMLCommon 
}

/*
function ChangeTelephone() {
     document.getElementById("CallerNumber").value = TelephoneArray[document.getElementById("CallerNameText").value]
}

function ChangeName() {
   document.getElementById("CallerNameText").value = document.getElementById("CallerName").options[document.getElementById("CallerName").selectedIndex].text
}
*/

function textCounter(field, maxlimit) {
   //
	 // max characters for individual field
	 //
   if (field.id.indexOf("Site") >= 0) {
	 		maxlimit = 30;
	 }
   if (field.id.indexOf("Address") >= 0 || field.id.indexOf("Good") >= 0) {
	 		maxlimit = 72;
	 }
   if (field.id.indexOf("Instruction") >= 0) {
	 		maxlimit = 48;
	 }

   if (field.value != "") {
      if (field.value.length > maxlimit) { // if too long...trim it!
		   	alert("The information is too long. Please type in between "+maxlimit+" characters")
        field.value = field.value.substring(0, maxlimit);
	    }
	 } 		
}
function EraseDest(DestNumber) {
   //
	 // remove nominated drop
	 //
   var ThisWindow = "";
	 
	 if (parent.window.frames["PickupDestinationFrame"])
    	 ThisWindow = parent.window.frames["PickupDestinationFrame"]
	 else if (window.frames["PickupDestinationFrame"]) 		 
    	 ThisWindow = window.frames["PickupDestinationFrame"]
	 else
	 		 ThisWindow = parent.frames["mainIframe"].frames["NewFrame"].frames["PickupDestinationFrame"]
			 
	 if (!(ThisWindow))
	     ThisWindow = window.frames["PickupDestinationFrame"]

	 DeleteObject = ThisWindow.document.getElementById("ExtraDestination"+DestNumber) 
	 if (DeleteObject) { 			 			
	   DeleteObject.innerHTML = " ";
 	   TotalDestination--;
	 }		   			  
}


function AddDestination() {
    //
	  // add a new destination 
	  //

	  var theObject = parent.frames["NewFrame"].document.getElementById("temp").value
		var ThisWindow = parent.frames["NewFrame"].window.frames["PickupDestinationFrame"];
		var WhichDestination = 0;
		var NotComplete = false; 
		WhichDestination = theObject.substr(theObject.length-1, 1);
		WhichObject = theObject.substr(0, theObject.length-1);
		// if it's new leg, make sure the previous one is filled up
		// also make sure the leg exists before checking them

		if (WhichDestination > 0 && WhichDestination <= TotalDestination) {
		   while (WhichDestination > 0) {
	       if (ThisWindow.document.getElementById(WhichObject+WhichDestination+'Suburb')) {
            if (ThisWindow.document.getElementById(WhichObject+WhichDestination+'Suburb').value == "") {
					 		 NotComplete = true;
					 		 break;
				    }
			   } 
			   WhichDestination--;
 			 }		
		}

   if (NotComplete == false) {
       TotalDestination++;
       theObject = ThisWindow.document.getElementById("DestinationTable");
	     WriteObject = ThisWindow.document.getElementById("ExtraDestination"+TotalDestination) 
       myString = "<input id=Destination"+TotalDestination+"AddressNumber name=Destination"+TotalDestination+"AddressNumber value=0 type=hidden>"+
			  		   	  "<input id=Destination"+TotalDestination+"LocalityID name=Destination"+TotalDestination+"LocalityID value=0 type=hidden>"+
			  		   		"<input id=Destination"+TotalDestination+"AddressID name=Destination"+TotalDestination+"AddressID value=0 type=hidden>"+
			  		   		"<input id=Destination"+TotalDestination+"SuburbID name=Destination"+TotalDestination+"Subur value=0 type=hidden>"+
			  		   		"<fieldset><legend>Destination "+
					   			"<input type=checkbox name=Destination"+TotalDestination+"Control id=Destination"+TotalDestination+"Control "+
					   			" onclick=CheckControl('Destination"+TotalDestination+"',event)"+
					   			" title='Check to add to frequent address. You may then key in your code in relation to this address. Uncheck to delete selected frequent address (optional)'>Frequent Address "+
					   			"&nbsp;&nbsp;"+
				  	   		"<input type='checkbox' name=Destination"+TotalDestination+"Verify "+
					   			"id=Destination"+TotalDestination+"Verify "+
					   			"value='0' "+
					   			"title='Tick to form a verified address list'>Verify Address"+												   										 
			            "</legend>"+
					   			"<table width=100% border=0 id=Destination"+TotalDestination+"Table name=Destination"+TotalDestination+"Table"+
					   			" cellpadding=0 cellspacing=3><tr>"+
					   			// Destination Site Name
					 				"<td valign=top width=10%>&nbsp;</td>"+
					   			"<td valign=top width=20%>Name:</td>"+
					   			"<td valign=top width=70%><input style=width:80% type=text name=Destination"+TotalDestination+"Site id=Destination"+TotalDestination+"Site "+
//	                " onfocus=ColorBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");ObjectDescription2(18);SetCursorPosition('Destination"+TotalDestination+"');"+
//					   			" onblur=NormalBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");toUpper(this);CheckAddress('Destination"+TotalDestination+"',event);SetMyNextFocus('Destination"+TotalDestination+"Address'); "+
	                " onfocus=CheckHelp(this);ColorBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");ObjectDescription2(18);SetCursorPosition('Destination"+TotalDestination+"');"+
					   			" onblur=\"BlurItem(this, document.getElementById('FrequentAddressDiv'));NormalBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");CheckAddress('Destination"+TotalDestination+"',event);toUpper(this);\" "+
					   			" onkeyup=\"FocusItem(this, document.getElementById('FrequentAddressDiv'),0);MatchItem(event,0);\" "+								
					   			" title='Destination site name (required). \nTo populate it, you can either: \n"+
					   			" 1. click on the frequent address on the left \n"+
					   			" 2. key in the frequent address number and press tab \n"+
					   			" 3. key in a new site name' " +					   
//					   			" onkeyup=CheckAddress('Destination"+TotalDestination+"',event);>"+								
					   			"</td></tr>"+
            	   // Destination Site Address 
					   		 "<tr>"+
						 		 "<td valign=top width=10%>&nbsp;</td>"+
						 		 "<td valign=top width=20% id='Destination"+TotalDestination+"AddressColumn'>Address:</td>"+
					   		 "<td valign=top width=70%><textarea name=Destination"+TotalDestination+"Address id=Destination"+TotalDestination+"Address rows=3 "+  
					   		 " style='font:8pt arial;width:80%' "+
            	   " onfocus=ColorBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");ObjectDescription2(19);useAddressLookupVerify(this,'address','Destination"+TotalDestination+"Verify','Destination"+TotalDestination+"Instruction');" +
        		   	 " onblur=NormalBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");displayAddressVerify('Destination"+TotalDestination+"Address','Destination"+TotalDestination+"Verify','Destination"+TotalDestination+"Suburb');toUpper(this);" +
					   		 " title='Destination site address (required)'"+
					   		 " onKeyDown=textCounter(this,60);" ;
	    myString +=" onKeyUp=textCounter(this,60);></textarea>"+
							   "</td></tr>"+
	 						   // Destination Site Suburb 
							   "<tr>"+
						 		 "<td valign=top width=10%>&nbsp;</td>"+
								 "<td valign=top width=20%>Suburb:</td>"+
	 						   "<td valign=top width=70% id=Destination"+TotalDestination+"SuburbColumn "+
								 "name=Destination"+TotalDestination+"SuburbColumn><input type=text name=Destination"+TotalDestination+"Suburb id=Destination"+TotalDestination+"Suburb "+
								 " onfocus=useAddressLookupVerify(this,'locality','Destination"+TotalDestination+"Verify','Destination"+TotalDestination+"Instruction');CheckHelp(this);ObjectDescription2(24);ColorBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+"); " +	
								 " onblur=NormalBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");displaySelectedSuburbVerify('Destination"+TotalDestination+"Suburb','Destination"+TotalDestination+"Verify');ShowAddDest(); "+  
						     " title='Destination site suburb (required). Suburb list will be constructed as you type'"+
								 " style='width:80%;'>"+   
         			 	 " <div style=position:absolute; display=none id=SelectSuburb> "+
			  				 " <label id=SuburbList rows=24 "+ 
							 	 " style=background:#ffffff;border:gray thin outset;height:69px;>"+ 
							 	 " </label></div>"+
							 	 "</td></tr>"+
	 						 	 // Destination Site Instruction 
							 	 "<tr>"+
						   	 "<td valign=top width=10%>&nbsp;</td>"+
								 "<td valign=top width=20%>Instructions:</td>"+
	 						 	 "<td valign=top width=70%><textarea name=Destination"+TotalDestination+"Instruction id=Destination"+TotalDestination+"Instruction rows=2 "+    
         				 " onfocus=ColorBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");ObjectDescription2(21);" + 
//       				 	 " onblur=NormalBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");toUpper(this);NextFocus("+TotalDestination+");" +
       				 	 " onblur=NormalBackGround(this,"+parent.frames["NewFrame"].document.getElementById("MyCompany").value+");toUpper(this);" +
							 	 " title='Destination site instruction (optional)'"+
								 " style='font:8pt arial;width:80%' "+
							 	 " onKeyDown=textCounter(this,60);"

		 	myString +=" onKeyUp=textCounter(this,60);></textarea>"+																	    								
							 	 "</td></tr>";

      myString +="<tr><td colspan=3><input type=text "+ 
  			    		 "style=border:0;text-decoration:underline;text-align:left; "+ 
	  		    		 "onclick='EraseDest("+TotalDestination+");' value='Delete Destination' "+
				    		 "onmouseover=ChangeColour(this,'over'); "+ 
				    		 "onmouseout=ChangeColour(this,'out'); "+
			         	 "title=Extra Destination readonly=readonly>";	 
			myString +="</table>"+
			           "</fieldset>";
			WriteObject.innerHTML = myString		

      ThisWindow.document.getElementById("Destination"+TotalDestination+"Site").focus();
			if (document.all)
   			 ThisWindow.document.body.scrollTop += 210
	 }
	 else {
	    alert("Destination information is not complete");
	 }			
}

function ChangeColour (theObject,overORout) {
    //
		// mouseover and mouseout effect
		//
    if (overORout == "over") {
      theObject.style.color = "blue"
      theObject.style.cursor = "hand"
		} else {
      theObject.style.color = "black"
      theObject.style.cursor = "point"		
		}	 
}

function SetClicked(option) {
    //
		// most of the focus is preset, if a box is click, we track it
		//
    if (document.getElementById("isClick"))
		    document.getElementById("isClick").value = option;
		else		
		    parent.document.getElementById("isClick").value = option;
}

function WhosNext(MyObject,NextObject) {
   //
	 // preset which box to tab to next 
	 //
   if (!(window.frames["PickupDestinationFrame"]) && !(parent.window.frames["PickupDestinationFrame"])) {
	 		return
	 }
	 var checkObject = ""
	 if (document.getElementById("isClick"))
	    checkObject = document.getElementById("isClick")
	 else		
	    checkObject = parent.document.getElementById("isClick")

   if (NextObject == "Destination1Site") 
		   window.frames["PickupDestinationFrame"].document.getElementById(NextObject).focus();
   else if (NextObject == "PickupSite") 
		   window.frames["PickupDestinationFrame"].document.getElementById(NextObject).focus();
   else if (NextObject == "SendNowAccount")  
		   parent.window.document.getElementById(NextObject).focus();
   else   
			 document.getElementById(NextObject).focus();

	 return 		
}
/*
function EmptyObject (theObject) {
    theObject.value = theObject.value.substring(0,0);
}
*/
function ColorBackGround(thisRow,CompanyID) {
   //
	 // color the background of a box
	 //
   thisRow.className = "Background"+CompanyID;
}

function NormalBackGround(thisRow,CompanyID) {
   //
	 // change background of a box back to white
	 //
   thisRow.className = "normal"
}

function DisplayJobInfoMobile(mJob) {
   //
	 // used for eg m.civic.com.au - display job in detail
	 //
   window.open("JobInfoMobile.php?jobid="+mJob,"_self")
}


function DisplayJobInfo(mJob) {
   //
	 // display job in detail - left panel
	 // if in main display screen, a google map is shown, display position of selected job as well as job in detail
	 //	 
   if (parent.parent.parent.window.frames["mainIframe"].frames["NewFrame"].location.href.indexOf("Google") == -1 &&
       parent.parent.parent.window.frames["mainIframe"].frames["NewFrame"].location.href.indexOf("ShowJobWithMap") == -1)
    	 parent.parent.parent.window.frames["sideIframe"].location.href = "JobInfo.php?jobid="+mJob+"&ShowMe=no"
	 else 
	 	   parent.parent.parent.window.frames["sideIframe"].location.href = "JobInfo.php?jobid="+mJob+"&ShowMe=yes"
}

function CheckHelp(theObject) {
   //
	 // display on left panel, as help, description of selected box
	 //
	 var today = new Date();
	 myCurrentObject = theObject; 
   if (theObject.type == "text" || theObject.type == "textarea")
   		 theObject.select();
   if (parent.window.frames["sideIframe"])
	    myWindow = parent.window.frames["sideIframe"];
	 else if (parent.parent.window.frames["sideIframe"])
	    myWindow = parent.parent.window.frames["sideIframe"];
	 else 
	    return
			
   var pos = myWindow.location.href.indexOf("BookingHelp")
   if (pos>=0)  {  // help page is displayed
	     // get companyid
			 pos = myWindow.location.href.indexOf("?")
			 var pos2 = myWindow.location.href.indexOf("#")
			 if (pos2 >= 0)
			     var mycompany = myWindow.location.href.substring(pos+1, pos2)					 			 
			 else
			     var mycompany = myWindow.location.href.substring(pos+1)

		   if (theObject.id == "Vehicle")
            myWindow.location.href = "../../../Global/BookingHelp.php?"+mycompany+"#"+theObject.options[theObject.selectedIndex].innerText		    
			 else
            myWindow.location.href = "../../../Global/BookingHelp.php?"+mycompany+"#"+theObject.id
	 }	 
}

function DisplayIFrame (thecommand,theframe) {
   //
	 // display respective iframe
	 //
   if (theframe == "_self" || theframe == "_blank") {
   	 parent.document.getElementById("BookingDiv").style.visibility="hidden";
	   window.location = thecommand
	 }	 
   else  {
   	 parent.document.getElementById("BookingDiv").style.visibility="visible";
   	 parent.document.getElementById("PickupDestinationDiv").style.visibility="hidden";
		 if (document.all)
		    theframe = theframe
		 else		
		    theframe = "_blank"
     window.open(thecommand,theframe)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
	 }
}

function HideIFrame () {
    //
		// hide this iframe
		//		
    parent.document.getElementById("BookingDiv").style.visibility="hidden";
}
