var changeCity = false
var Hoffset=70 //Enter buttons' offset from right edge of window (adjust depending on images width)
var Voffset=80 //Enter buttons' offset from bottom edge of window (adjust depending on images height)
var leftspeed=3 //Enter scroll speed in integer (Advised: 1-3)
var mainspeed=3 //Enter scroll speed in integer (Advised: 1-3)
var rightspeed=3 //Enter scroll speed in integer (Advised: 1-3)

var ieNOTopera=document.all&&navigator.userAgent.indexOf("Opera")==-1
var myleftspeed=0
var mymainspeed=0
var myrightspeed=0
var myleftdowncount=0
var myrightdowncount=0
var mymaindowncount=0
var myleftupcount=0
var myrightupcount=0
var mymainupcount=0
var ieHoffset_extra=document.all? 15 : 0

function showAddress() {
   //
   // reload frequent address after user changes city selection
	 //
	 alert("Reloading Frequent Address")
   window.frames["sideIframe"].location.reload()
}

function changeMyCityID (theObject, action, samejob) {
   //
   // user decides to change city selection
	 // 1. recreate frequent address and reload it on the screen
	 // 2. change vehicle list
	 // 3. clear booking address and delete current pickup address
	 // 
	 if (parent.parent.document.getElementById("myCityID"))
	    parent.parent.document.getElementById("myCityID").value = theObject.value

   var myWindow = ""
	 if (parent.parent.frames["contentsframe"]) {
	    myWindow = parent.parent.frames["contentsframe"] 
	    myWindow.document.getElementById("myCityID").value = theObject.value
	    parent.parent.document.getElementById("myCityID").value = theObject.value
	 } else {
	    if (window.frames["mainIframe"])
	        myWindow = window.frames["mainIframe"].frames["NewFrame"]
			if (document.getElementById("myCityID"))		
	        document.getElementById("myCityID").value = theObject.value
	 }
	 
	 var mySplit = window.location.href.split("/")
/*
	 // step 1
   Command = "../../../CustomerPHP/CreateFrequentAddress.php?"+
	 				   "InternetID="+myWindow.document.getElementById("MyInternetID").value+
						 "&CityID="+theObject.value+
	 				   "&Directory="+mySplit[3];
*/
	 if (myWindow) {
	    if (myWindow.document.getElementById("Vehicle")) {
	 		     // step 2
	          myWindow.document.getElementById("Vehicle").options.length = 0
	          myWindow.getServiceType(document.getElementById("myCompanyUnique").value)
	          myWindow.document.getElementById("Vehicle").options.selectedIndex = 0
	          myWindow.document.getElementById("Options").innerHTML = ""
		        if (myWindow.frames["PickupDestinationFrame"] == null)
			          return
						if (window.frames["rightIframe"].frames["CurrentStatus"].document.getElementById("clientcity") == null)
							 return;		
						if (document.all)		
							 myWindow.document.getElementById("PickupDestinationDiv").style.visibility = "hidden"		
	 					// step 3
						myWindow.frames["PickupDestinationFrame"].location.reload();
						setTimeout("deleteAddress()", 1000);	 
			}			
   }	 
}

function deleteAddress() {
    // 
		// delete pre-set pickup address when user changes city selection
		//
    var myWindow = ""
		var myDocument = ""
		var myParent = ""
	  if (parent.parent.frames["contentsframe"]) {
	     myWindow = parent.parent.frames["contentsframe"] 
	     myDocument = parent.parent.frames["contentsframe"].document 
	     myParent = parent.parent 
	  } else {
	     myWindow = window.frames["mainIframe"].frames["NewFrame"]
			 myDocument = document
	     myParent = window
 	  }
//		if (myDocument.document.getElementById("myCityID").value != window.frames["rightIframe"].frames["CurrentStatus"].document.getElementById("clientcity").value) {
		if (myDocument.getElementById("myCityID").value != myParent.frames["rightIframe"].frames["CurrentStatus"].document.getElementById("clientcity").value) {
				myWindow.frames["PickupDestinationFrame"].document.getElementById("PickupSite").value = ""
				myWindow.frames["PickupDestinationFrame"].document.getElementById("PickupAddress").value = ""
				myWindow.frames["PickupDestinationFrame"].document.getElementById("PickupSuburb").value = ""
				myWindow.frames["PickupDestinationFrame"].document.getElementById("PickupSuburbID").value = ""
				myWindow.frames["PickupDestinationFrame"].document.getElementById("PickupLocalityID").value = ""
				myWindow.frames["PickupDestinationFrame"].document.getElementById("PickupAddressID").value = ""
				myWindow.frames["PickupDestinationFrame"].document.getElementById("PickupInstruction").value = ""
		}
 	  if (document.all)
		   myWindow.document.getElementById("PickupDestinationDiv").style.visibility = "visible"		
}

function ScrollUp(theObject, whichFrame) {
   //
	 //  scrolling up function by clicking and mouseover arrow up icon at the bottom of the page
	 //
   if (whichFrame == "Left") {
      myleftupcount+=1
	    // increase speed
	    if (myleftupcount == 1) {
	       myleftspeed = myleftspeed - 8
				 theObject.title = "Click again to go to the top of the screen"
			}	 
			// go to the top of the screen
	    if (myleftupcount == 2)	{	
	        myleftspeed = myleftspeed - 3
				 myleftupcount = 0  
				 theObject.title = "Scroll Up. Click once to increase the speed. Click twice to get to the top"
				 if (window.frames["sideIframe"])
    				 window.frames["sideIframe"].scrollTo(0,0)
			}	 
	 }
   if (whichFrame == "Main") {
      mymainupcount+=1
	    // increase speed
	    if (mymainupcount == 1) {
	       mymainspeed = mymainspeed - 8
				 theObject.title = "Click again to go to the top of the screen"
			}	 
			// go to the end of the screen
	    if (mymainupcount == 2)	{	
	       mymainspeed = mymainspeed - 3
				 mymainupcount = 0  
				 theObject.title = "Scroll Up. Click once to increase the speed. Click twice to get to the top"
         if (window.frames["mainIframe"].frames["PickupDestinationFrame"])
				    window.frames["mainIframe"].frames["PickupDestinationFrame"].scrollTo(0,0)
      	 else
            window.frames["mainIframe"].scrollTo(0,0)
			}	 	 
	 }
   if (whichFrame == "Right") {
   	  myrightupcount += 1
	    // increase speed
	    if (myrightupcount == 1) {
	       myrightspeed = myrightspeed - 8
				 theObject.title = "Click again to go to the top of the screen"
			}	 
			// go to the end of the screen
	    if (myrightupcount == 2)	{	
	       myrightspeed = myrightspeed - 3
				 myrightupcount = 0  
				 window.frames["rightIframe"].scrollTo(0,0)
			}	 
   }	 
}

function ScrollDown(theObject, whichFrame) {
   //
	 //  scrolling down function by clicking and mouseover arrow down icon at the bottom of the page
	 //
   if (whichFrame == "Left") {
      myleftdowncount+=1
	    // increase speed
	    if (myleftdowncount == 1) {
	       myleftspeed += 8
				 theObject.title = "Click again to go to the end of the screen"
			}	 
			// go to the end of the screen
	    if (myleftdowncount == 2)	{	
	       myleftspeed = 3
				 myleftdowncount = 0  
				 theObject.title = "Scroll Down. Click once to increase the speed. Click twice to get to the bottom"
				 if (window.frames["sideIframe"])
   				 window.frames["sideIframe"].scrollTo(0,window.frames["sideIframe"].document.body.scrollHeight)
			}	 
	 }
   if (whichFrame == "Main") {
      mymaindowncount+=1
	    // increase speed
	    if (mymaindowncount == 1) {
	       mymainspeed += 8
				 theObject.title = "Click again to go to the end of the screen"
			}	 
			// go to the end of the screen
	    if (mymaindowncount == 2)	{	
	       mymainspeed = 3
				 mymaindowncount = 0  
				 theObject.title = "Scroll Down. Click once to increase the speed. Click twice to get to the bottom"
         if (window.frames["mainIframe"].frames["PickupDestinationFrame"])
				    window.frames["mainIframe"].frames["PickupDestinationFrame"].scrollTo(0,window.frames["mainIframe"].frames["PickupDestinationFrame"].document.body.scrollHeight)
      	 else
            window.frames["mainIframe"].scrollTo(0,window.frames["mainIframe"].document.body.scrollHeight)
			}	 
	 }	 
   if (whichFrame == "Right") {
   	  myrightdowncount += 1
	    // increase speed
	    if (myrightdowncount == 1) {
	       myrightspeed += 8
				 theObject.title = "Click again to go to the end of the screen"
			}	 
			// go to the end of the screen
	    if (myrightdowncount == 2)	{	
	       myrightspeed = 3
				 myrightdowncount = 0  
				 window.frames["rightIframe"].scrollTo(0,window.frames["rightIframe"].document.body.scrollHeight)
			}	 
	 }
}

function scrollLeftFrame(){
   //
	 //  scrolling left frame
	 //
   if (window.frames["sideIframe"])
      window.frames["sideIframe"].scrollBy(0,myleftspeed)
}

function scrollMainFrame(){
   //
	 //  scrolling middle/main frame
	 //
   if (window.frames["mainIframe"].frames["PickupDestinationFrame"])
      window.frames["mainIframe"].frames["PickupDestinationFrame"].scrollBy(0,mymainspeed)
	 else
      window.frames["mainIframe"].scrollBy(0,mymainspeed)
}

function scrollRightFrame(){
   //
	 //  scrolling right frame
	 //
   window.frames["rightIframe"].scrollBy(0,myrightspeed)
}

function initializeIT(){
   //
	 //  start scrolling
	 //
   if (myleftspeed!=0)
      scrollLeftFrame()
   if (mymainspeed!=0)
      scrollMainFrame()
   if (myrightspeed!=0)
      scrollRightFrame()
}

if (document.all||document.getElementById||document.layers)
   setInterval("initializeIT()",20)


function toPrint(selectedFrame) {
   //
	 //  printing frames
	 //
   if (selectedFrame == "sideIframe") {
	   if (window.frames[selectedFrame].document.getElementById("temp")) {
       window.frames[selectedFrame].document.getElementById("temp").value="Print"
       window.frames[selectedFrame].document.getElementById("View").onclick()
		 }	 
	   window.frames[selectedFrame].focus();
     window.frames[selectedFrame].print();
			
	 } else if (selectedFrame == "mainIframe") {
	    var myDiv = "";
			var myFrame = "";
			if (window.frames[selectedFrame].document.getElementById("NewDiv").style.visibility == "" || window.frames[selectedFrame].document.getElementById("NewDiv").style.visibility == "visible") {
			   myDiv = "NewDiv";
			   myFrame = "NewFrame";
			} else if (window.frames[selectedFrame].document.getElementById("PaymentDiv").style.visibility == "" || window.frames[selectedFrame].document.getElementById("PaymentDiv").style.visibility == "visible") {
			   myDiv = "PaymentDiv";
			   myFrame = "PaymentFrame";
			} else if (window.frames[selectedFrame].document.getElementById("ReportDiv").style.visibility == "" || window.frames[selectedFrame].document.getElementById("ReportDiv").style.visibility == "visible") {
			   myDiv = "ReportDiv";
			   myFrame = "ReportFrame";
			} else if (window.frames[selectedFrame].document.getElementById("SearchDiv").style.visibility == "" || window.frames[selectedFrame].document.getElementById("SearchDiv").style.visibility == "visible") {
			   myDiv = "SearchDiv";
			   myFrame = "SearchFrame";
			} else if (window.frames[selectedFrame].document.getElementById("SetupDiv").style.visibility == "" || window.frames[selectedFrame].document.getElementById("SetupDiv").style.visibility == "visible") {
			   myDiv = "SetupDiv";
			   myFrame = "SetupFrame";
			} else if (window.frames[selectedFrame].document.getElementById("ContactDiv").style.visibility == "" || window.frames[selectedFrame].document.getElementById("ContactDiv").style.visibility == "visible") {
			   myDiv = "ContactDiv";
			   myFrame = "ContactFrame";
			} 
			
      if (window.frames[selectedFrame].frames[myFrame].location.href.indexOf("CreateLabel") > -1) {
		 		   window.frames[selectedFrame].frames[myFrame].frames[0].focus();
 				   window.frames[selectedFrame].frames[myFrame].frames[0].print();	 				 
 		  } else {
	         window.frames[selectedFrame].focus();
     	     window.frames[selectedFrame].print();				 
			}	
	 } else {
	       window.frames[selectedFrame].focus();
     		 window.frames[selectedFrame].print();	 
	 }
}

	 
/*
function toPrint(selectedFrame) {
   //
	 //  printing frames
	 //
   if (selectedFrame == "sideIframe") {
	   if (window.frames[selectedFrame].document.getElementById("temp")) {
       window.frames[selectedFrame].document.getElementById("temp").value="Print"
       window.frames[selectedFrame].document.getElementById("View").onclick()
		 }	 
	   window.frames[selectedFrame].focus();
     window.frames[selectedFrame].print();
			
	 }		
   else {	 
	    if (window.frames[selectedFrame].frames["clientFrame"]) {
			   window.frames[selectedFrame].frames["clientFrame"].focus();
			   window.frames[selectedFrame].frames["clientFrame"].print();
			 }  
	    else {
			  window.frames[selectedFrame].focus();
				// enable options for printing
				if (window.frames[selectedFrame].document.getElementById("CallerNameText")) {
				   var AddressObject = window.frames[selectedFrame].window.frames["PickupDestinationFrame"];
					 window.frames[selectedFrame].document.getElementById("CallerNameText").disabled = false
					 window.frames[selectedFrame].document.getElementById("CallerNumber").disabled = false
					 if (window.frames[selectedFrame].document.getElementById("Reference1"))
     			    window.frames[selectedFrame].document.getElementById("Reference1").disabled = false
					 if (window.frames[selectedFrame].document.getElementById("Reference2"))
   	 			 		window.frames[selectedFrame].document.getElementById("Reference2").disabled = false
					 if (window.frames[selectedFrame].document.getElementById("Tolls"))
  	 			    window.frames[selectedFrame].document.getElementById("Tolls").disabled = false  
  				 window.frames[selectedFrame].document.getElementById("Goods").disabled = false  
  				 window.frames[selectedFrame].document.getElementById("Vehicle").disabled = false
           window.frames[selectedFrame].document.getElementById("DeliveryTime").disabled = false  
  				 window.frames[selectedFrame].document.getElementById("PickupTime").disabled = false  
  				 window.frames[selectedFrame].document.getElementById("Delivery").disabled = false
  				 window.frames[selectedFrame].document.getElementById("GoodsClass").disabled = false
  				 AddressObject.document.getElementById("PickupSite").disabled = false  
					 AddressObject.document.getElementById("PickupAddress").disabled = false   
  				 AddressObject.document.getElementById("PickupSuburb").disabled = false  
  				 AddressObject.document.getElementById("PickupInstruction").disabled = false

  				 for(i=1; i<=window.frames[selectedFrame].document.getElementById("TotalDestination").value; i++) {
	     		    if (AddressObject.document.getElementById("Destination"+i+"Site")) {
  		 		 			 AddressObject.document.getElementById("Destination"+i+"Site").disabled = false
  		 		 			 AddressObject.document.getElementById("Destination"+i+"Address").disabled = false
  		 		 			 AddressObject.document.getElementById("Destination"+i+"Suburb").disabled = false
  		 		 			 AddressObject.document.getElementById("Destination"+i+"Instruction").disabled = false
	            }
           }		
				}	 
		    window.frames[selectedFrame].print();


				// after printing, disable options again
				if (window.frames[selectedFrame].document.getElementById("CallerNameText")) {
				   var AddressObject = window.frames[selectedFrame].window.frames["PickupDestinationFrame"];
					 window.frames[selectedFrame].document.getElementById("CallerNameText").disabled = true
					 window.frames[selectedFrame].document.getElementById("CallerNumber").disabled = true
					 if (window.frames[selectedFrame].document.getElementById("Reference1"))
     			    window.frames[selectedFrame].document.getElementById("Reference1").disabled = true
					 if (window.frames[selectedFrame].document.getElementById("Reference2"))
   	 			 		window.frames[selectedFrame].document.getElementById("Reference2").disabled = true
					 if (window.frames[selectedFrame].document.getElementById("Tolls"))
  	 			    window.frames[selectedFrame].document.getElementById("Tolls").disabled = true  
  				 window.frames[selectedFrame].document.getElementById("Goods").disabled = true  
  				 window.frames[selectedFrame].document.getElementById("Vehicle").disabled = true
           window.frames[selectedFrame].document.getElementById("DeliveryTime").disabled = true  
  				 window.frames[selectedFrame].document.getElementById("PickupTime").disabled = true  
  				 window.frames[selectedFrame].document.getElementById("Delivery").disabled = true
  				 window.frames[selectedFrame].document.getElementById("GoodsClass").disabled = true
  				 AddressObject.document.getElementById("PickupSite").disabled = true  
					 AddressObject.document.getElementById("PickupAddress").disabled = true   
  				 AddressObject.document.getElementById("PickupSuburb").disabled = true  
  				 AddressObject.document.getElementById("PickupInstruction").disabled = true

  				 for(i=1; i<=window.frames[selectedFrame].document.getElementById("TotalDestination").value; i++) {
	     		    if (AddressObject.document.getElementById("Destination"+i+"Site")) {
  		 		 			 AddressObject.document.getElementById("Destination"+i+"Site").disabled = true
  		 		 			 AddressObject.document.getElementById("Destination"+i+"Address").disabled = true
  		 		 			 AddressObject.document.getElementById("Destination"+i+"Suburb").disabled = true
  		 		 			 AddressObject.document.getElementById("Destination"+i+"Instruction").disabled = true
	            }
           }		
				}	 
			 }    
	 } 
}
*/

function toCopy(selectedFrame) {
   //
	 //  copy data from selected frame
	 //
   if (selectedFrame == "sideIframe") {
	   window.frames[selectedFrame].focus();
	  	var range = window.frames[selectedFrame].document.body.createTextRange();
   		range.execCommand('Copy');		
	 } else {
	   if (window.frames[selectedFrame].frames["clientFrame"]) {
			   window.frames[selectedFrame].frames["clientFrame"].focus();
			   var range = window.frames[selectedFrame].frames["clientFrame"].document.body.createTextRange(); 
			} else {   
	      window.frames[selectedFrame].focus();
			   var range = window.frames[selectedFrame].document.body.createTextRange(); 
			}   
	  	range.execCommand('Copy');
	 }		
}


function SignOut() {
   //
	 //  deletes cookie and bring user to main webpage
	 //
//   window.open("../Booking/KillCookie.php?Company="+'<?echo $_SESSION["DCompanyID"];?>','_self')
   window.open("../Booking/KillCookie.php?Company="+'<?echo $_SESSION["DCompanyID"];?>','_top')
}  

function changeicon(theObject) {
   //
	 //  change icon cursor
	 //
    theObject.style.cursor ='pointer'		
}

function ChangeClient() {
   //
	 //  user changing from 1 account code to another, or choose to signout
	 //
   var theObject = document.getElementById("AnotherCode");
	 // signout
   if (theObject.value == "signout")
	 		window.open("/deletecookie/index.php","_top")
	 // back to same/innitial account code
   else if (theObject.options[theObject.selectedIndex].id != "")
	    window.open("Booking.html", "_top");	    
	 // another account code
	 else {		
	    var myName = "";
	    var myCode = "";
	    var UniqueCompany = "";
			var WebSite = "";
	    if (window.frames["mainIframe"]) {
      	 myName = window.frames["mainIframe"].frames["NewFrame"].document.getElementById("CallerNameText").value
      	 myCode = document.getElementById("AnotherCode").options[document.getElementById("AnotherCode").selectedIndex].innerHTML
      	 UniqueCompany = window.frames["mainIframe"].frames["NewFrame"].document.getElementById("MyCompany").value
	       window.open("/Validation.php?WebSite="+WebSite+"&Name="+myName+"&AccountCode="+myCode+"&UniqueCompany="+UniqueCompany+"&SameGroup=yes", "_top");
			} else {
      	 myName = parent.window.frames["contentsframe"].document.getElementById("CallerNameText").value
      	 myCode = document.getElementById("AnotherCode").options[document.getElementById("AnotherCode").selectedIndex].innerHTML
//      	 UniqueCompany =  parent.window.frames["contentsframe"].document.getElementById("myCompanyUnique").value			
      	 UniqueCompany =  window.frames["contentsframe"].document.getElementById("myCompanyUnique").value			
				 WebSite = "CivicNew";
	 	     window.open("/Validation.php?ToggleCode=yes&WebSite="+WebSite+"&Name="+myName+"&AccountCode="+myCode+"&UniqueCompany="+UniqueCompany+"&SameGroup=yes", "_self");
			}	 
	 }
}
function changeCityValue() {
   //
	 //  flagged city has been changed
	 //
   changeCity=true;
}


