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"

function limitElement(thisElement, maxSize)
{
	if (thisElement.width > thisElement.height) {
		if (thisElement.width > maxSize) {
			thisElement.width = maxSize
		}
	}
	else {
		if (thisElement.height > maxSize) {
			thisElement.height = maxSize
		}
	}
}

function resetimage_fixedsize(thisID)
{
	var thisElement

	if (document.body.offsetWidth>1152) {
    	return
    }

	thisElement = document.getElementById(thisID)
	if (thisElement && thisElement.complete && thisElement.width > 0) {

		if (document.body.offsetWidth <= 800) { /* limit smaller than 800 wide to 150 */
			limitElement(thisElement, 150)
		}
		else if (document.body.offsetWidth <= 1024) {
			limitElement(thisElement, 200)
		}
		else {
			limitElement(thisElement, 250)
		}
	}
	else {
		setTimeout("resetimage_fixedsize('" + thisID + "')", 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;
	}
    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" 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()
{
    document.write('<TR bgColor=#000000> <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, affiliateType)
{
	bgcolor = ""

    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 ')
		if (affiliateType != AffilliateTypeNone)
		{
			document.write('onMouseOver=\'window.status="' + thetitle + '"; return true\'; onMouseOut=\'window.status=""; return true\' ');
		}
    	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', AffilliateTypeNone)

	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', AffilliateTypeNone)
	addmenuitem(itemType, "http://www.bus" + javaDotBasedDomainName + "/", 'Search for and book bus travel in New Zealand', 'Buses', AffilliateTypeNone)
	addmenuitem(itemType, "http://www.campervan" + javaDotBasedDomainName + "/", 'Search for and book Campervans in New Zealand', 'Campervans', AffilliateTypeNone)
	addmenuitem(itemType, "http://www.car-rental" + javaDotBasedDomainName + "/", 'Search for and book Rental Cars in New Zealand', 'Car Rental', AffilliateTypeNone)
	addmenuitem(itemType, "http://www" + javaDotBasedDomainName + "/news/", "New Zealand News", "News", AffilliateTypeNone)
}

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" ></TD></TR>')

    addmenuitem(0, "http://" + javaDomainName + "/", javaDomainName, javaDisplayName, AffilliateTypeNone)

    addmenuline()

	if ((javaPageType == 201) || (javaPageType == 204) || (javaPageType == 211) || (javaPageType == 214))
	{
		javaLocalMenu()
	}
	else
	{
		addNationalMenuItems(2)
    }

    addmenuline()


	if (javaDomainName==javaParentName)
	{
		addmenuitem(1, "", "", "Tourism & Travel", AffilliateTypeNone)
	}
	else
	{
		addmenuitem(1, "http://www" + javaDotBasedDomainName + "/", "New Zealand Home", "New Zealand", AffilliateTypeNone)
	}

    addmenuline()

	if ( (javaPageType == 201) || (javaPageType == 204) || (javaPageType == 211) || (javaPageType == 214))
	{
   		addNationalMenuItems(3)
	}
    addmenuitem(3, "http://www.study" + javaDotBasedDomainName + "/", "Study in New Zealand", "Study in NZ", AffilliateTypeNone)
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/new-zealand/tourism/", "New Zealand Virtual Tour", "Virtual Tour", AffilliateTypeNone)
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/new-zealand/guide-book/", "New Zealand Guide Book", "NZ Guide Book", AffilliateTypeNone)
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/search/", "Search New Zealand", "Search", AffilliateTypeNone)

    addmenuline()
    addmenuitem(1, "http://www" + javaDotBasedDomainName + "/new-zealand/tourism/", "nz.com Places", "nz.com Places", AffilliateTypeNone)

    addmenuline()

    addmenuitem(3, "http://www.auckland" + javaDotBasedDomainName + "/" ,"Auckland - City of Sails", "Auckland", AffilliateTypeNone)
    addmenuitem(3, "http://www.rotorua" + javaDotBasedDomainName + "/" ,"Rotorua - Feel the Spirit", "Rotorua", AffilliateTypeNone)

    addmenuitem(3, "http://www.wellington" + javaDotBasedDomainName + "/" ,"Wellington - Festival City", "Wellington", AffilliateTypeNone)
    addmenuitem(3, "http://www.christchurch" + javaDotBasedDomainName + "/" ,"Christchurch - The Garden City", "Christchurch", AffilliateTypeNone)
    addmenuitem(3, "http://www.queenstown" + javaDotBasedDomainName + "/" ,"Queenstown - Any Season ... Any Reason", "Queenstown", AffilliateTypeNone)
    addmenuitem(3, "http://www.fiordlandnz.com/" ,"Fiordland - World Heritage Area", "Fiordland", AffilliateTypeNone)
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/new-zealand/tourism/", "Other New Zealand Places", "Other NZ Places", AffilliateTypeNone)

    addmenuline()

    addmenuitem(1, "http://www" + javaDotBasedDomainName + "/about/", "About New Zealand on the Web", "About nz.com", AffilliateTypeNone)

    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/about/advertising.aspx", "Advertise with NZ.com", "Advertising", AffilliateTypeNone)
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/client/logon.aspx", "Client Logon", "Client Logon", AffilliateTypeNone)

    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" 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" ></TD></TR>')

    addmenuitem(0, "http://" + javaDomainName + "/", javaDomainName, javaDisplayName, AffilliateTypeNone)

    addmenuline()

    addmenuitem(1, "", "", "Listings", AffilliateTypeNone)
    addmenuline()
    if (superUser == 'True') {
	    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/viewusers.aspx", "View/Edit Client Records", "Clients", AffilliateTypeNone)
	}
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/usermenu.aspx", "Edit Listings", "Edit Listings", AffilliateTypeNone)
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/activityreport.aspx", "Activity Reports", "Activity Reports", AffilliateTypeNone)
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/about/terms.aspx", "Terms & Conditions", "Terms & Conds", AffilliateTypeNone)
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/about/link-to-us.aspx", "Linking to nz.com sites", "Link to nz.com", AffilliateTypeNone)

    addmenuline()

    addmenuitem(1, "", "", "Account Details", AffilliateTypeNone)
    addmenuline()

    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/ChangePassword.aspx", "Change Password", "Change Password", AffilliateTypeNone)
    addmenuitem(3, "http://www" + javaDotBasedDomainName + "/asp/logoff.aspx", "End your session", "Log off", AffilliateTypeNone)
    document.write('</table>')
}

function javalogo() {
    document.write('<TABLE bgColor=#000000 border=0 cellPadding=0 cellSpacing=0 width="100%">')
    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 javagoogle300x250adheader() {
	google_ad_client = "pub-9408352270785877";
	google_alternate_color = "FFFFFF";
	google_ad_width = 300;
	google_ad_height = 250;
	google_ad_format = "300x250_as";
	google_ad_type = "text_image";
	//2007-02-12: 300x250 Medium Rectangles
	google_color_border = "000000";
	google_color_bg = "FFFFFF";
	google_color_link = "0066CC";
	google_color_text = "000000";
	google_color_url = "008000";
}

function javaGoogleFlights(extraHint) {
//2007-02-13: Flights
	google_ad_channel = "5943318414";
	google_hints = "new zealand flights, flights to new zealand, flights from new zealand";
}

function javaGoogleJobsAndImmigration() {
//2007-02-13: Employment or Immigration
	google_ad_channel = "2606636823";
	google_hints = "new zealand jobs, new zealand employment, new zealand immigration";
}

function javarestofheader() {
    document.write('</TD></TR></TABLE>')

    document.write('<table bgcolor=#ffffff border=0 cellpadding=0 cellspacing=0 width="100%">')
    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)

	// 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

		if (dropOffDate <= pickUpDate) {
			alert('The drop off date ' + dropOffDate + ' must be after the pickup date.')
			dateError = true
		}
		else if (onewayhire && (Math.round((dropOffDate - pickUpDate)/one_day) + 1 < 14)) {
			alert('The minimum hire period is 14 days for one way hires.')
			dateError = true
		}
		else if (christmasPickUp && (Math.round((dropOffDate - pickUpDate)/one_day) + 1 < 14)) {
			alert('The minimum hire period is 14 days for the 20th December to 2nd January pickup periods.')
			dateError = true
		}
		else if (Math.round((dropOffDate - pickUpDate)/one_day) + 1 < 7) {
			alert('The minimum hire period is 7 days.')
			dateError = true
		}
	}
	if (!dateError) {
		ref = window.open(newlocation, '_blank')
	}
}