var AffilliateTypeNone = 0
var AffilliateTypeHotelClubNZ = 1
var AffilliateTypeRatesToGo = 2
var AffilliateTypeViator = 3
var AffilliateTypeHotelClubInt = 4

var ratesToGoLink = "http://b2b.ratestogo.com/enter.asp?id=19003"
var rhsAdWidth = 300

var addEvent = function(elem, type, eventHandle) {
	if (elem == null || elem == undefined) return
	if (elem.addEventListener) {
		elem.addEventListener(type, eventHandle, false)
	} else if (elem.attachEvent) {
		elem.attachEvent("on" + type, eventHandle)
	}
}

function limitMapElement(mapElement, maxSize, copyrightElement)
{
	var width  = parseInt(mapElement.style.width)
	var height = parseInt(mapElement.style.height)

	if (width > maxSize) {
		mapElement.style.height = Math.round(maxSize / width * height) + "px"
		mapElement.style.width = maxSize + "px"
		if (copyrightElement) {
			copyrightElement.style.width = maxSize + "px"
		}
		return true
	}
	return false
}

function resetmap_fixedsize(mapID, copyrightID)
{
	var cWidth = getClientWidth()
	var mapElement
	var copyrightElement

	if (cWidth > 1152) {
    	return
    }

	mapElement = document.getElementById(mapID)
	if (mapElement) {
		if (copyrightID != "") {
			copyrightElement = document.getElementById(copyrightID)
			if (copyrightElement) {
				if (copyrightElement.style.display == "none") {
					afterGoogleMapLoaded(mapID, copyrightID)
				}
			}
		}
		if (cWidth <= 800) { /* limit smaller than 800 wide to 150 */
			return limitMapElement(mapElement, 150, copyrightElement)
		}
		else if (cWidth <= 1024) {
			return limitMapElement(mapElement, 200, copyrightElement)
		}
		else {
			return limitMapElement(mapElement, 250, copyrightElement)
		}
	}
	return false
}

function afterGoogleMapLoaded(mapDiv, copyrightDiv, centreLatitude, centreLongitude, zoomLevel) {
	var mapDivElement = document.getElementById(mapDiv)
	var copyrightDivElement = document.getElementById(copyrightDiv)
	var allHTMLTags = new Array();
	var i
	var htmlContent
	var spanStartImagery
	var startMap

	if (mapDivElement) {
		allHTMLTags = mapDivElement.getElementsByTagName("*");
		for (i=0; i<allHTMLTags.length; i++) {
			htmlContent = allHTMLTags[i].innerHTML
			if (htmlContent) {
				var lCaseHtmlContent = htmlContent.toLowerCase()
				spanStartImagery = lCaseHtmlContent.indexOf("<span>imagery")
				if (spanStartImagery == -1 && lCaseHtmlContent.indexOf("<span>") == 0 && lCaseHtmlContent.indexOf("imagery") != -1) {
					spanStartImagery = 0
				}
				startMap = lCaseHtmlContent.indexOf("map data")
				if (spanStartImagery != -1 || startMap == 0) {
					if (copyrightDivElement) {
						if (copyrightDivElement.style.display != "") {
							var width  = parseInt(mapDivElement.style.width)
							copyrightDivElement.style.width = width
							copyrightDivElement.style.display = ""
							if (spanStartImagery != -1) {
								var innerText = htmlContent.substring(spanStartImagery + 6)
								var spanEnd = innerText.toLowerCase().indexOf("</span>")
								innerText = innerText.substring(0, spanEnd - 2).replace(/imagery/ig, 'Map imagery')
								copyrightDivElement.innerHTML = innerText.replace(/color: white/ig, 'color: black').replace(/\n/g, '')
								htmlContent = htmlContent.substring(0, spanStartImagery) + htmlContent.substring(spanStartImagery + 6 + spanEnd + 7)
							} else {
								copyrightDivElement.innerHTML = htmlContent.substring(0,htmlContent.length - 2)
								htmlContent = ""
							}
							allHTMLTags[i].innerHTML = htmlContent
						}
					}
					if (centreLatitude) {
						map.setCenter(new GLatLng(centreLatitude, centreLongitude), zoomLevel)
					}
					return
				}
			}
		}
	}

	setTimeout(function(){afterGoogleMapLoaded(mapDiv, copyrightDiv, centreLatitude, centreLongitude, zoomLevel)}, 1000)
}

function getDocHeight() {
    var D = document
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    )
}

function getClientWidth() {
    var D = document
    var cWidth1 = D.body ? D.body.clientWidth : 0
    var cWidth2 = D.documentElement ? D.documentElement.clientWidth : 0

    if (cWidth1 == 0) return cWidth2
    else if (cWidth2 == 0) return cWidth1
    else return Math.min(cWidth1, cWidth2)
}

function limitElement(thisID, thisElement, maxSize)
{
	if (thisID.indexOf("map-image") != -1 || thisElement.width > thisElement.height) {
		thisElement.height = Math.round(maxSize / thisElement.width * thisElement.height)
		if (thisElement.width > maxSize) {
			thisElement.width = maxSize
		}
	}
	else {
		if (thisElement.height > maxSize) {
			thisElement.width = Math.round(maxSize / thisElement.height * thisElement.width)
			thisElement.height = maxSize
		}
	}
}

var listingImage = function(ID, maxWidth, maxHeight) {
	this.ID = ID
	this.maxWidth = maxWidth
	this.maxHeight = maxHeight
}
var listingImages = new Array()
var iFormat = 300

function resizeImages() {
	var cWidth = getClientWidth()
	var newFormat = 300

	if (cWidth <= 800) {
		newFormat = 150
	} else if (cWidth <= 1024) {
		newFormat = 200
	} else if (cWidth <= 1152) {
		newFormat = 250
	}
	if (newFormat != iFormat) {
		var thisElement
		var thisImage
		var newWidth

		for (var i=0; i < listingImages.length; i++) {
			thisImage = listingImages[i]
			thisElement = document.getElementById(thisImage.ID)
			if (!thisElement || !thisElement.complete) {
				setTimeout(resizeImages, 200)
				return
			}
			if (thisElement.width != 0) {
				newWidth = Math.min(newFormat, thisImage.maxWidth)
				thisElement.height = Math.round(newWidth / thisImage.maxWidth * thisImage.maxHeight)
				thisElement.width = newWidth
			}
		}
		iFormat = newFormat
	}
}

function addImage(ID, maxWidth, maxHeight) {
	var newImage = new listingImage(ID, maxWidth, maxHeight)

	listingImages.push(newImage)
	if (listingImages.length == 1) {
		addEvent(window, "load", function() { resizeImages() } )
		addEvent(window, "resize", function() { resizeImages() } )
	}
}

function resetimage_fixedsize(thisID, maxImageWidth, maxImageHeight)
{
	var cWidth = getClientWidth()
	var thisElement
	var newSize

	if (cWidth>1152 && !maxImageWidth) {
    	return
    }

	thisElement = document.getElementById(thisID)
	if (thisElement && thisElement.complete && thisElement.width > 0) {

		if (cWidth <= 800) { /* limit smaller than 800 wide to 150 */
			if (maxImageWidth) {
				newSize = maxImageWidth
			} else {
				newSize = 150
			}
		}
		else if (cWidth <= 1024) {
			if (maxImageWidth) {
				newSize = maxImageWidth
			} else {
				newSize = 200
			}
		}
		else {
			if (maxImageWidth) {
				newSize = maxImageWidth
			} else {
				newSize = 250
			}
		}
		if (newSize < thisElement.width) {
			limitElement(thisID,thisElement, newSize)
		}
		if (maxImageHeight && thisElement.height > maxImageHeight) {
			thisElement.width = Math.round(maxImageHeight / thisElement.height * thisElement.width)
			thisElement.height = maxImageHeight
		}
	}
	else {
		setTimeout(function() {resetimage_fixedsize(thisID, maxImageWidth, maxImageHeight)}, 200)
	}
}

function getHotelClubLink(includeCountry)
{
	var hotelClubLink = "http://b2b.hotelclub.net/enter.asp?id=19003"

	if (includeCountry) {
		return (hotelClubLink + "&ru=directcountry.asp?id=15");
	}
	else {
		return (hotelClubLink);
	}
}

function goToAffillate(affilliateType)
{
	var loggingPrefix1 = "http://www" + javaDotBasedDomainName + "/asp/redirect.aspx?listingid="
	var loggingPrefix2 = "&c=0&tryToBill=0&targetlink="
	var newLocation

	if (affilliateType == AffilliateTypeRatesToGo) {
		newLocation = loggingPrefix1 + "Rates-To-Go" + loggingPrefix2 + ratesToGoLink;
	}
	else if (affilliateType == AffilliateTypeHotelClubInt) {
		newLocation = loggingPrefix1 + "Hotel-Club" + loggingPrefix2 + getHotelClubLink(0);
	}
	window.location = newLocation
}

function googlesearch(boxWidth)
{
	if (boxWidth == 0) {
		boxWidth = 20;
	}
	if (rhsAdWidth == 250 && boxWidth == 25) {
		boxWidth = 24
	}
    document.write('<table border="0" bgcolor="#ffffff">')
    document.write('<form method="get" action="http://www.google.com/custom" target="google_window">')
    document.write('<tr><td nowrap="nowrap" valign="top" align="left" height="32">')
    document.write('<a href="http://www.google.com/">')
    document.write('<img width=75 height=32 src="http://www.google.com/logos/Logo_25wht.gif"')
    document.write('border="0" alt="Google"></img></a>')
    document.write('<br/>')
    document.write('<input type="hidden" name="domains" value="NZ.com"></input>')
    document.write('<input type="text" id="q" name="q" size="' + boxWidth + '" maxlength="255" value=""></input>')
    document.write('<input type="submit" name="sa" value="Search"></input>')
    document.write('</td></tr>')
    document.write('<tr>')
    document.write('<td nowrap="nowrap">')
    document.write('<table>')
    document.write('<tr>')
    document.write('<td>')
    document.write('<input type="radio" name="sitesearch" value=""></input>')
    document.write('<font size="-1" color="#000000">Web</font>')
    document.write('</td>')
    document.write('<td>')
    document.write('<input type="radio" name="sitesearch" value="NZ.com" checked="checked"></input>')
    document.write('<font size="-1" color="#000000">www.NZ.com</font>')
    document.write('</td>')
    document.write('</tr>')
    document.write('</table>')
    document.write('<input type="hidden" name="client" value="pub-9408352270785877"></input>')
    document.write('<input type="hidden" name="forid" value="1"></input>')
    document.write('<input type="hidden" name="ie" value="ISO-8859-1"></input>')
    document.write('<input type="hidden" name="oe" value="ISO-8859-1"></input>')
    document.write('<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"></input>')
    document.write('<input type="hidden" name="hl" value="en"></input>')
    document.write('</td></tr></form>')
    document.write('</table>')
}

function addmenuline(bgColor)
{
	if (!bgColor) { bgColor = '#000000' }
    document.write('<TR bgColor=' + bgColor + '> <TD colspan=3><img src="http://www' + javaDotBasedDomainName + '/newimages/spacer.gif" width="1" height="1"></TD><td></td></TR>')
}

function addmenuitem(itemtype, thelink, thetitle, theanchor, addseparator)
{
	var bgcolor = ""

	if (addseparator) { addmenuline("#999999") }
    if (itemtype==0) { bgcolor = "#000000" }
    else if (itemtype==1) { bgcolor = "#003366"	}
    else if (itemtype==2) { bgcolor = "#666666" }
    else if (itemtype==3) {	bgcolor = "#006699"	}

    if ( (itemtype==0) || (itemtype==1) ) // headings so bold and colspan=2
    {
		boldstart = "<b>"
		boldend = "</b>"
		thespacer = '<td><img src="http://www' + javaDotBasedDomainName + '/newimages/spacer.gif" width="6" ></td><TD colspan=2 class="menuframe" width=113> ';
	}
	else
	{
		boldstart = ""
		boldend = ""
		thespacer = '<td></td><td><img src="http://www' + javaDotBasedDomainName + '/newimages/spacer.gif" width="6" ></td><TD class="menuframe" width=107> ';
	}


    document.write('<TR height=22 bgColor=' + bgcolor + '>' + thespacer)
    if (javathispage==thelink)
    {
    	document.write('<font color="#FFCC00">'+ boldstart + theanchor + boldend + '</font>')
	}
    else if (thelink!="") /* if we have a link */
    {
		document.write('<A ')
    	document.write('href="' + thelink + '" Title="' + thetitle + '">' + boldstart + theanchor + boldend + '</A>')
	}
	else /* No link so just output the text */
	{
    	document.write(boldstart + theanchor + boldend)
	}
   	document.write('</TD></TR>')
}

function addNationalMenuItems(itemType)
{
	var theLink

	if (javaPageType == 209) { /* Accomodation Page */
		/* pass a link that matches the title to force it into non link yellow text */
		theLink = javathispage
	}
	else {
		theLink = "http://www.accommodation" + javaDotBasedDomainName + "/"
	}
	addmenuitem(itemType, theLink, 'Search for and book New Zealand accommodation', 'Accommodation')

	if (javaPageType == 208) { /* Activities Page */
		/* pass a link that matches the title to force it into non link yellow text */
		theLink = javathispage
	}
	else {
		theLink = "http://www.activities" + javaDotBasedDomainName + "/"
	}
	addmenuitem(itemType, theLink, 'Search for and book New Zealand activities and tours', 'Activities & Tours')
	addmenuitem(itemType, "http://www.bus" + javaDotBasedDomainName + "/", 'Search for and book bus travel in New Zealand', 'Buses')
	addmenuitem(itemType, "http://www.campervan" + javaDotBasedDomainName + "/", 'Search for and book Campervans in New Zealand', 'Campervans')
	addmenuitem(itemType, "http://www.car-rental" + javaDotBasedDomainName + "/", 'Search for and book Rental Cars in New Zealand', 'Car Rental')
	addmenuitem(itemType, "http://www.events" + javaDotBasedDomainName + "/", 'New Zealand Events', 'Events')
	addmenuitem(itemType, "http://www" + javaDotBasedDomainName + "/news/", "New Zealand News", "News")
}

function javamenu() {
	javathispage = "http://" + javaDomainName + javacurrentpage

    document.write('<TABLE border=0 cellPadding=0 cellSpacing=0>')

    document.write('<TR><TD colspan=3><IMG src="http://www' + javaDotBasedDomainName + '/newimages/layout/sb-top.jpg" WIDTH=119 HEIGHT=47></TD></TR>')

    addmenuitem(0, "http://" + javaDomainName + "/", javaDomainName, javaDisplayName)

	if ((javaPageType == 201) || (javaPageType == 211) || (javaPageType == 214))
	{
		javaLocalMenu()
	}
	else
	{
		addNationalMenuItems(2)
    }

    addmenuline()


	if (javaDomainName==javaParentName)
	{
		addmenuitem(1, "", "", "Tourism & Travel")
	}
	else
	{
		addmenuitem(1, "http://www" + javaDotBasedDomainName + "/", "New Zealand Home", "New Zealand")
	}

    addmenuline()

	if ( (javaPageType == 201) || (javaPageType == 211) || (javaPageType == 214))
	{
   		addNationalMenuItems(3)
	}
    addmenuitem(3, "http://www.study" + javaDotBasedDomainName + "/", "Study in New Zealand", "Study in NZ")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/new-zealand/tourism/", "New Zealand Virtual Tour", "Virtual Tour")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/new-zealand/guide-book/", "New Zealand Guide Book", "NZ Guide Book")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/search/", "Search New Zealand", "Search")

    addmenuline()
    addmenuitem(1, "http://www" + javaDotBasedDomainName + "/new-zealand/tourism/", "nz.com Places", "nz.com Places")

    addmenuline()

    addmenuitem(3, "http://www.auckland" + javaDotBasedDomainName + "/" ,"Auckland - City of Sails", "Auckland")
    addmenuitem(3, "http://www.bay-of-islands" + javaDotBasedDomainName + "/" ,"Bay of Islands - Birthplace of a Nation", "Bay of Islands")
    addmenuitem(3, "http://www.rotorua" + javaDotBasedDomainName + "/" ,"Rotorua - Feel the Spirit", "Rotorua")

    addmenuitem(3, "http://www.wellington" + javaDotBasedDomainName + "/" ,"Wellington - Festival City", "Wellington")
    addmenuitem(3, "http://www.christchurch" + javaDotBasedDomainName + "/" ,"Christchurch - The Garden City", "Christchurch")
    addmenuitem(3, "http://www.queenstown" + javaDotBasedDomainName + "/" ,"Queenstown - Any Season ... Any Reason", "Queenstown")
    addmenuitem(3, "http://www.fiordlandnz.com/" ,"Fiordland - World Heritage Area", "Fiordland")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/new-zealand/tourism/", "Other New Zealand Places", "Other NZ Places")

    addmenuline()

    addmenuitem(1, "http://www" + javaDotBasedDomainName + "/about/", "About New Zealand on the Web", "About nz.com")

    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/about/advertising.aspx", "Advertise with NZ.com", "Advertising")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/client/logon.aspx", "Client Logon", "Client Logon")

    document.write('<TR bgColor=#666666> ')
    document.write('<TD colspan=3 align=center>')
    document.write('<IMG height=10 src="http://www' + javaDotBasedDomainName + '/newimages/spacer.gif" width=1><br>')
    document.write('<A href="http://www' + javaDotBasedDomainName + '/new-zealand/slide-show/" title="New Zealand Images">')
    document.write('<img src="http://www' + javaDotBasedDomainName + '/newimages/menuslideshow.gif" width="98" height="86" border=0></A></TD></TR>')

    document.write('</table>')
}

function javaclientmenu(superUser) {
	javathispage = "http://" + javaDomainName + javacurrentpage

    document.write('<TABLE border=0 cellPadding=0 cellSpacing=0>')

    document.write('<TR><TD colspan=3><IMG src="http://www' + javaDotBasedDomainName + '/newimages/layout/sb-top.jpg" WIDTH=119 HEIGHT=47></TD></TR>')

    addmenuitem(0, "http://" + javaDomainName + "/", javaDomainName, javaDisplayName)

    addmenuline()

    addmenuitem(1, "", "", "Listings")
    addmenuline()
    if (superUser == 'True') {
	    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/viewusers.aspx", "View/Edit Client Records", "Clients")
	}
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/usermenu.aspx", "Edit Listings", "Edit Listings")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/about/formatting.aspx", "Formatting Listings", "- Formatting")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/activityreport.aspx", "Activity Reports", "Activity Reports")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/about/terms.aspx", "Terms & Conditions", "Terms & Conds")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/about/link-to-us.aspx", "Linking to nz.com sites", "Link to nz.com")

    addmenuline()

    addmenuitem(1, "", "", "Account Details")
    addmenuline()

    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/ChangePassword.aspx", "Change Password", "Change Password")
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/logoff.aspx", "End your session", "Log off")
    document.write('</table>')
}

function javalogo() {
    document.write('<TABLE bgColor=#000000 border=0 cellPadding=0 cellSpacing=0 width="100%" class="hideOnPrint">')
    document.write('<TR>')
    document.write('<TD vAlign=bottom width=254><a href="http://www' + javaDotBasedDomainName + '/" title="New Zealand Home">')
    document.write('<IMG height=58 src="http://www' + javaDotBasedDomainName + '/newimages/layout/logo-top.gif" width=251 border=0></a></TD>')
    document.write('<TD align=center width="100%">')
}

function javaworldad() {
	document.write('<table bgcolor=#000000 border=1 cellpadding=0 cellspacing=0 width="450">')
	document.write('<tr><td class = smalltext>')
	document.write('<a href="#" onclick="goToAffillate(' + AffilliateTypeHotelClubInt + '); return false">')
	document.write('<font color=#ffffff>')
	document.write('<font size="+1">Worldwide Accommodation</font><br>')
	document.write('Are you travelling to Australia, the United Kingdom, the US, or anywhere else? Click here to book your accommodation through nz.com.')
	document.write('</font>')
	document.write('</a>')
	document.write('</td></tr>')
	document.write('</table>')
}

function javagoogletopheader() {
	google_ad_client = "pub-9408352270785877";
	google_ad_width = 468;
	google_ad_height = 60;
	google_ad_format = "468x60_as";
	google_ad_type = "text_image";
	google_ad_channel ="9946349517";
	google_color_border = "cccccc";
	google_color_bg = "000000";
	google_color_link = "FFFFFF";
	google_color_url = "FFFFFF";
	google_color_text = "FFFFFF";
}

function calcRHSWidth(must_use_300_wide) {
	var availableWidth  = getClientWidth-120-5-300;

	if (availableWidth <= 400 && !must_use_300_wide) {
		rhsAdWidth = 250
	}
}

function safeLoadjs(URL) {
	try {
		var fileref = document.createElement('script')
		fileref.setAttribute("language","javascript")
		fileref.setAttribute("type","text/javascript")
		fileref.setAttribute("src", URL)
		document.getElementsByTagName("head")[0].appendChild(fileref)
	} catch (e) { alert('An error has occurred: '+e.message) }
}

function googleAd(displayDiv, slot300, slot250, adType, checkHeight) {
	this.displayDiv = displayDiv
	this.slot300 = slot300
	this.slot250 = slot250
	this.adType = adType
	this.checkHeight = checkHeight
}

var googleAds = new Array()

function loadGoogleAds(slotUsed) {
	var newAd = new googleAd('adslot1', '5943318414','4930948428', 'text_image')
	googleAds.push(newAd)
	if (!slotUsed) {
		newAd = new googleAd('adslot2', '2606636823','4930948428', 'text_image')
		googleAds.push(newAd)
	}
	newAd = new googleAd('adslot3', '4834480749','5599422451', 'text', true)
	googleAds.push(newAd)

	addEvent(window, "load", function() { safeLoadGoogleAd() } )
}

var loadingAd = null

function finishedWrite() {
	loadingAd = null
	safeLoadGoogleAd()
}

var tempWrite = function(newHTML) {
	var displayElement = document.getElementById(loadingAd.displayDiv)
	var startScript = newHTML.indexOf('<script>')
	if (startScript == 0) {
		var endScript = newHTML.indexOf('</script>')
		newHTML = newHTML.substr(8, endScript - 8)
		eval(newHTML)
		return
	} else {
		var fileNameStart = newHTML.indexOf('"')
		if (newHTML.indexOf('<script') == 0 && fileNameStart != -1) {
			var fileNameEnd = newHTML.indexOf('"></script>')
			if (fileNameEnd != -1) {
				var newScript = newHTML.substr(fileNameStart + 1, fileNameEnd - fileNameStart - 1)
				safeLoadjs(newScript)
				return
			}
		}
	}
	displayElement.innerHTML += newHTML
	setTimeout(finishedWrite, 500)
}

function safeLoadGoogleAd() {
	if (loadingAd != null) {			// Loading an ad
		setTimeout(safeLoadGoogleAd, 500)
		return
	}
	if (googleAds.length == 0) return	// Finished all ads
	loadingAd = googleAds.shift()
	var displayElement = document.getElementById(loadingAd.displayDiv)
	if (!displayElement) {				// Still loading page
		googleAds.unshift(loadingAd)
		loadingAd = null
		setTimeout(safeLoadGoogleAd, 500)
		return
	}
	if (loadingAd.checkHeight) {
		if (getDocHeight() >= 1140 + 250) {
			var p = displayElement.parentNode
			p.style.height = parseInt(p.style.height) + 250 + 'px'
		}
		else return						// Not enough room for three ads
	}
	google_ad_client = "pub-9408352270785877"
	google_alternate_color = "FFFFFF"
	google_ad_height = 250
	if (rhsAdWidth == 300) {
		google_ad_width = 300
		google_ad_format = "300x250_as"
		google_ad_channel = loadingAd.slot300
	} else {
		google_ad_width = 250
		google_ad_format = "250x250_as"
		google_ad_channel = loadingAd.slot250
	}
	google_ad_type = loadingAd.adType
	google_color_border = "000000"
	google_color_bg = "FFFFFF"
	google_color_link = "0066CC"
	google_color_text = "000000"
	google_color_url = "008000"

	displayElement.style.display = ''
	document.write = tempWrite
	safeLoadjs("http://pagead2.googlesyndication.com/pagead/show_ads.js")
}

function javarestofheader() {
    document.write('</TD></TR></TABLE>')

    document.write('<table bgcolor=#ffffff border=0 cellpadding=0 cellspacing=0 width="100%" class="hideOnPrint">')
    document.write('<tr>')
    document.write('<td><img height=26 width=120 src="http://www' + javaDotBasedDomainName + '/newimages/layout/logo-base.gif" ></td>')
    document.write('<td background="http://www' + javaDotBasedDomainName + '/newimages/layout/tb-leftedge.gif">')

    document.write('<table border=0 cellspacing=0 cellpadding=0>')
    document.write('<tr>')
    document.write('<td><img height=15 src="http://www' + javaDotBasedDomainName + '/newimages/spacer.gif" width=10></td>')
    document.write('<TD class="time">')

	if (javaTimeString != '') {
	    document.write('New Zealand Time is: ' + javaTimeString)
	}

    document.write('</TD></tr><tr> ')
    document.write('<td><img src="http://www' + javaDotBasedDomainName + '/newimages/spacer.gif" width=1 height=1></td>')
    document.write('<td><img height=1 src="http://www' + javaDotBasedDomainName + '/newimages/spacer.gif" width=580></td>')
    document.write('</tr>')
    document.write('</table>')

    document.write('</td>')
    document.write('<td class=menuframe background="http://www' + javaDotBasedDomainName + '/newimages/layout/tb-tile.gif" width="100%">&nbsp;</td>')
    document.write('<td class=menuframe align=right background="http://www' + javaDotBasedDomainName + '/newimages/layout/tb-rightedge.gif" width=290>')
    document.write('&nbsp;</td></tr></table>')
}

// Car Rental Functions


//set select box value
function setCarVal(ctl, newVal) {
    for (var i=0; i<ctl.length; i++) {
        if (ctl[i].text == newVal) {
            ctl.selectedIndex = i
            break
        }
    }
}

//get select box value
function getCarVal(ctl) {
    return ctl.options[ctl.selectedIndex].text
}

//reset out date to (in date + 1)
function resetOutDate() {
    var newOutDate = new Date(getCarVal(document.getElementById('yearin_select')), document.getElementById('monthin_select').selectedIndex, parseInt(getCarVal(document.getElementById('dayin_select'))) + 1)

    var newOutDay = newOutDate.getDate()
    var newOutMonth = newOutDate.getMonth()
    var newOutYear = newOutDate.getFullYear()

    setCarVal(document.getElementById('dayout_select'), newOutDay)
    document.getElementById('monthout_select').selectedIndex = newOutMonth
    setCarVal(document.getElementById('yearout_select'), newOutYear)
}


function submitRentalCar(carCompany) {
var newlocation = ""
var yearnum
var monthnum = ""
var daynum
var dateError = false

	newlocation = 'http://www' + javaDotBasedDomainName + '/asp/redirect.aspx?c=0&tryToBill=0&'
	if (carCompany == 1) {
		newlocation = newlocation + 'listingid=RentalCar'
	}
	else if (carCompany == 2) {
		newlocation = newlocation + 'listingid=United-Campervans'
	}
	else if (carCompany == 3) {
		newlocation = newlocation + 'listingid=Econo-Campers'
	}

	newlocation = newlocation + '&targetlink=http://www.seekom.com/rental/VehicleSearch.php'

	if (carCompany == 1) {
		newlocation = newlocation + '&op=apex&ru=nzotw'
	}
	else if (carCompany == 2) {
		newlocation = newlocation + '&op=unitedc&ru=nzcom'
	}
	else if (carCompany == 3) {
		newlocation = newlocation + '&op=alpha&ru=nzcomal'
	}

	// Start Date
	yearnum = getCarVal(document.getElementById('yearin_select'))
	monthnum = document.getElementById('monthin_select').selectedIndex + 1
	daynum = getCarVal(document.getElementById('dayin_select'))

	newlocation = newlocation + '&datein='
	newlocation = newlocation + yearnum + '-'
	newlocation = newlocation + monthnum + '-'
	newlocation = newlocation + daynum + ' 09:00'

	var pickUpDate = new Date(yearnum, monthnum-1, daynum)
	var christmasPickUp = (monthnum == 12 && daynum >= 20) || (monthnum == 1 && daynum <= 2)
	var rwc2011 = yearnum == 2011 && ((monthnum == 9 && daynum >= 1) || (monthnum == 10 && daynum <= 23))

	// End Date
	yearnum = getCarVal(document.getElementById('yearout_select'))
	monthnum = document.getElementById('monthout_select').selectedIndex + 1
	daynum = getCarVal(document.getElementById('dayout_select'))

	newlocation = newlocation + '&dateout='
	newlocation = newlocation + yearnum + '-'
	newlocation = newlocation + monthnum + '-'
	newlocation = newlocation + daynum + ' 09:00'

	var dropOffDate = new Date(yearnum, monthnum-1, daynum)

	// Location
	newlocation = newlocation + '&puloc='
	newlocation = newlocation + document.getElementById('pu_locn').value
	newlocation = newlocation + '&doloc='
	newlocation = newlocation + document.getElementById('do_locn').value

	var onewayhire = document.getElementById('pu_locn').value != document.getElementById('do_locn').value


	// Check minimum days before opening the new window.
	if (carCompany != 1) {
		var one_day = 1000*60*60*24
		var hireNumDays = Math.round((dropOffDate - pickUpDate)/one_day) + 1

		if (dropOffDate <= pickUpDate) {
			alert('The drop off date ' + dropOffDate + ' must be after the pickup date.')
			dateError = true
		}
		else if (onewayhire && hireNumDays < 14) {
			alert('The minimum hire period is 14 days for one way hires.')
			dateError = true
		}
		else if (christmasPickUp && hireNumDays < 14) {
			alert('The minimum hire period is 14 days for the 20th December to 2nd January pickup periods.')
			dateError = true
		}
		else if (rwc2011 && hireNumDays < 14) {
			alert('The minimum hire period is 14 days for the Rugby World Cup 2011 (1st September to 23rd October) pickup periods.')
			dateError = true
		}
		else if (hireNumDays < 7) {
			alert('The minimum hire period is 7 days.')
			dateError = true
		}
	}
	if (!dateError) {
		ref = window.open(newlocation, '_blank')
	}
}
