// JavaScript Document
var xmlHttp;
var rootpath;
var divid;
var forlan;

function SearchActivities()
{
	var state = document.getElementById("state");
	var stateValue = state.options[state.selectedIndex].value;
	
	window.open("http://www.dev.au.v3travel.com/CABS2/DiscoveryServices/ProviderSearch.aspx?exl_dn=aaa_mywebsite&exl_spr=0&exl_siz=lge&exl_mod=aet&categoryGrouping=aet&regionAET=s" + stateValue);
}

function RedirectToV3()
{
	var v3propcode = document.getElementById("v3propcode").value;
	
	var adults = document.getElementById("adults").value;
	var children = document.getElementById("children").value;
	var nights = document.getElementById("nights").value;

	var day = document.getElementById("day");
	var dayValue = day.options[day.selectedIndex].value;
	
	var object = document.getElementById("monthYear");
	var objectValue = object.options[object.selectedIndex].value;	
	var monthYear = objectValue.split("/");
	var monthYearValue = monthYear[1] + "-" + monthYear[0] + "-" + dayValue;
	
	window.open("    http://www.au.v3travel.com/CABS2/DiscoveryServices/ProviderAvailability.aspx?exl_psn=v3propcode&exl_dn=FamilyParks_Web&adults="+adults+"&children="+children+"&nights="+nights+"&date="+monthYearValue);
}

function GetSearchResult()
{
	if(document.getElementById("SbyCountry").value == "" && document.getElementById("SbyTown").value == "" && document.getElementById("SbyPark").value == "")
	{
		alert("Please at least fill in one search option");
	}
}

function CheckUsername()
{
	var url= "checkusername.asp?username=" + document.getElementById("tribalusn").value
	divid = "checkresult"
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function ParkMaps(geocode,parkname,address1,address2,address3,addressState,addressPostcode)
{
	geo = geocode.split(",")
	if (GBrowserIsCompatible())
	{
		
		var map = new GMap2(document.getElementById("map"));					
		map.addControl(new GSmallMapControl());
		var point = new GLatLng(geo[0],geo[1]);
		map.setCenter(point, 7);

		/*var popup = document.createElement("div");
		popup.setAttribute("class", "MapPopup");

		var description = document.createElement("div");
		description.setAttribute("class", "MapAddress");

		var heading = document.createElement("strong");
		heading.innerHTML = parkname;
		description.appendChild(heading);

		description.appendChild(document.createElement("br"));

		description.appendChild(document.createTextNode(address1));
		description.appendChild(document.createElement("br"));

		description.appendChild(document.createTextNode(addressState + " " + addressPostcode));
		description.appendChild(document.createElement("br"));*/

		//var a = document.createElement("a");
		//a.setAttribute("href","#");
		//a.setAttribute("onclick","DisplayStreet(-34.913366,138.62878)");
		//a.innerHTML = "STREET VIEW";
		
		//description.appendChild(a);

		//popup.appendChild(description);
		//map.openInfoWindow(point, popup);
		//map.openInfoWindow(point,null);
		
		//SET UP THE ICONS
		var iconPark = new GIcon(); 
		iconPark.image = 'mapImages/markers/marker01.png';
		//iconRestaurant.shadow = 'markers/mm_20_shadow.png';
		iconPark.iconSize = new GSize(39, 52);
	   // iconRestaurant.shadowSize = new GSize(22, 20);
		iconPark.iconAnchor = new GPoint(6, 20);
		iconPark.infoWindowAnchor = new GPoint(5, 1);
		var customIcons = [];
		customIcons["park"] = iconPark;

		var marker = new GMarker(point,customIcons["park"]);
		/*GEvent.addListener (marker, "click", function() {
			marker.openInfoWindow(popup);
			
		});*/
		map.addOverlay(marker);					
	}
	
}

/*function loadMaps()
{
	var fenwayPark = new GLatLng(-34.913366,138.62878);
	panoramaOptions = { latlng:fenwayPark };

	var streetViewClient = new GStreetviewClient();
	streetViewClient.getNearestPanoramaLatLng(fenwayPark, findStreetView);

	if (GBrowserIsCompatible())
	{
		
		var map = new GMap2(document.getElementById("map"));					
		map.addControl(new GSmallMapControl());
		var point = new GLatLng(-34.913366,138.62878);
		map.setCenter(point, 14);

		var popup = document.createElement("div");
		popup.setAttribute("class", "MapPopup");

		var description = document.createElement("div");
		description.setAttribute("class", "MapAddress");

		var heading = document.createElement("strong");
		heading.innerHTML = "Caravan Parks Association of South Australia";
		description.appendChild(heading);

		description.appendChild(document.createElement("br"));

		description.appendChild(document.createTextNode("49 Henry St"));
		description.appendChild(document.createElement("br"));

		description.appendChild(document.createTextNode("Stepney, SA 5069"));
		description.appendChild(document.createElement("br"));

		//var a = document.createElement("a");
		//a.setAttribute("href","#");
		//a.setAttribute("onclick","DisplayStreet(-34.913366,138.62878)");
		//a.innerHTML = "STREET VIEW";
		
		//description.appendChild(a);

		popup.appendChild(description);
		map.openInfoWindow(point, popup);

		var marker = new GMarker(point);
		GEvent.addListener (marker, "click", function() {
			marker.openInfoWindow(popup);
			
		});
		map.addOverlay(marker);					
	}
}*/


//for parkfinder
function updateMap(type){
		var country = document.getElementById("country"); 
		var state = document.getElementById("state"); 
		var location = document.getElementById("location"); 
		
		var stateValue = state.options[state.selectedIndex].value; 
		var locationValue = location.options[location.selectedIndex].value; 
		var countryValue = country.options[country.selectedIndex].value;

		if(type == 'country'){
			locationValue = '';
			stateValue = '';
			
			populateStates(countryValue);	
		}
		
		if(type == 'state'){
			locationValue = '';
		}

		if(stateValue != "" && locationValue == ""){
			document.getElementById("googleFrame").src = "parksGoogleMap.asp?cnt="+countryValue+"&st="+stateValue;
		}
		
		if(locationValue != ""){
			document.getElementById("googleFrame").src = "parksGoogleMap.asp?cnt="+countryValue+"&st="+stateValue+"&loc="+locationValue;
		}
		
		if((stateValue == "" && locationValue == "") || (stateValue == "" && locationValue != "")){
			document.getElementById("googleFrame").src = "parksGoogleMap.asp?cnt="+countryValue;
		}
	
		//alert(document.getElementById("googleFrame").src);
}

function populateStates(country){

	var ausStates = Array(1);
	ausStates[0] = "ACT";
	ausStates[1] = "NSW";
	ausStates[2] = "NT";
	ausStates[3] = "QLD";
	ausStates[4] = "SA";
	ausStates[5] = "TAS";
	ausStates[6] = "VIC";
	ausStates[7] = "WA";
	
	var nzStates = Array(1);
	nzStates[0] = "North Island";
	nzStates[1] = "South Island";
	
	if(country == "aus"){
	
		parent.document.getElementById("state").length=0;

		var opt = document.createElement("option");
		parent.document.getElementById("state").options.add(opt);
		opt.text = '- choose state -';

		for(i=0;  i < ausStates.length; i++){

			var opt = document.createElement("option");
			parent.document.getElementById("state").options.add(opt);
		
			// Assign text and value to Option object
			opt.text = ausStates[i];
			opt.value = ausStates[i].toLowerCase();
					
		}
		
	}else{
	
		parent.document.getElementById("state").length=0;

		var opt = document.createElement("option");
		parent.document.getElementById("state").options.add(opt);
		opt.text = '- choose island -';	
	
		for(i=0;i < nzStates.length;i++){
		
			var opt = document.createElement("option");
			parent.document.getElementById("state").options.add(opt);
			
			// Assign text and value to Option object
			opt.text = nzStates[i];
			
			opt.value = nzStates[i].toLowerCase();
		}
	
	}

}
//end of park finder
	
function test()
{
	document.getElementById("submitform").click();
}

function CheckLogin()
{
	if(document.getElementById("logins").value == "" || document.getElementById("password").value == "")
	{
		document.getElementById("errors").innerHTML = "<img src='images/error1.png' />"
		return false;
	}
	return true;
}

function extend()
{
 	if(document.getElementById("printwhat").selectedIndex == 1)
	{
		
		document.getElementById("extended").style.visibility = "visible";
		document.getElementById("extended").style.position = "relative";
	}
 	else if(document.getElementById("printwhat").selectedIndex == 0)
	{
		document.getElementById("extended").style.visibility = "hidden";
		document.getElementById("extended").style.position = "absolute";
	}
}

function ReturnVIPs()
{
	var tribalno = document.getElementById("tribalno").value
	if(tribalno.length > 6)
	{
		if(tribalno.charAt(0)==";")
		{
			tribalno = tribalno.substring(1,7)
		}
		else
		{
			tribalno = tribalno.substring(4,10)
		}
	}

	var suburb = document.getElementById("suburb").value
	var postcode = document.getElementById("postcode").value
	var name = document.getElementById("name").value

	if(suburb != "" || postcode != "" || name != "" || tribalno != "")
	{
		var url="showvips.asp?suburb="+suburb+"&postcode="+postcode+"&name="+name+"&tribalno="+tribalno
		divid = "viplist"
		document.getElementById(divid).innerHTML = "<div align='center'><img src='images/loader.gif' alt='Loading'/></div>"
		
		xmlHttp=GetXmlHttpObject(stateChanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	}
	else
	{
		alert("Please enter at least on field")
	}
}

function UpdateCountry()
{
	var country = document.getElementById("country")
	var countryValue = country.options[country.selectedIndex].value;
	
	var ausStates = Array(1);
	ausStates[0] = "ACT";
	ausStates[1] = "NSW";
	ausStates[2] = "NT";
	ausStates[3] = "QLD";
	ausStates[4] = "SA";
	ausStates[5] = "TAS";
	ausStates[6] = "VIC";
	ausStates[7] = "WA";
	
	var nzStates = Array(1);
	nzStates[0] = "North Island";
	nzStates[1] = "South Island";
	
	document.getElementById("state").length=0
	
	var opt = document.createElement("option");
	document.getElementById("state").options.add(opt);
	opt.text = "-- Select --";
	opt.value = "";
	
	if(countryValue == "au")
	{
		for(i=0;  i < ausStates.length; i++)
		{
			var opt = document.createElement("option");
			document.getElementById("state").options.add(opt);
			opt.text = ausStates[i];
			opt.value = ausStates[i].toLowerCase();			
		}		
	}
	else
	{
		for(i=0;  i < nzStates.length; i++)
		{
			var opt = document.createElement("option");
			document.getElementById("state").options.add(opt);
			opt.text = nzStates[i];
			opt.value = nzStates[i];			
		}		
	}
}

function UpdateLocation(country)
{
	var state = document.getElementById("state")
	var stateValue = state.options[state.selectedIndex].value;

	var url="UpdateLocation.asp?country="+country+"&state="+stateValue;
	divid = "loc"
	
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)	
}

function GetWeather()
{
	var country = document.getElementById("country")
	var countryValue = country.options[country.selectedIndex].value;
	var state = document.getElementById("state")
	var stateValue = state.options[state.selectedIndex].value;
	var location = document.getElementById("location")
	var locationValue = location.options[location.selectedIndex].value;


	var url="GetWeather.asp?country="+countryValue+"&state="+stateValue+"&location="+locationValue;
	divid = "weather_result"

	document.getElementById("weather_search").style.display = "none";
	document.getElementById("weather_result").innerHTML = "";
	document.getElementById("weather_result").style.display = "inline";
	
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)	
}


function UpdateLocation_weather()
{
	var country = document.getElementById("country")
	var countryValue = country.options[country.selectedIndex].value;

	var state = document.getElementById("state")
	var stateValue = state.options[state.selectedIndex].value;

	var url="UpdateLocation_weather.asp?country="+countryValue+"&state="+stateValue;
	divid = "loc"
	
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)	
}

function SearchFeatures(country)
{
	var state = document.getElementById("state")
	var stateValue = state.options[state.selectedIndex].value;

	var location = document.getElementById("location")
	var locationValue = location.options[location.selectedIndex].value;
	
	var townName = document.getElementById("townName").value;
	var parkName = document.getElementById("parkName").value;
	
	var url="UpdateSearchList.asp?country="+country+"&state="+stateValue+"&location="+locationValue+"&townName="+townName+"&parkName="+parkName;
	divid = "column1inner"
	
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)	
}


function checkFields_whatsnew_edit(theform) 
{
	if(theform.eventdate.value == "") 
	{
		alert("Please enter a Date.");
		theform.eventdate.focus();
		return (false);
	}
	if(theform.Subject.value == "") 
	{
		alert("Please enter a Subject.");
		theform.Subject.focus();
		return (false);
	}
	if(theform.Narrative.value == "") 
	{
		alert("Please enter a Date.");
		theform.Narrative.focus();
		return (false);
	}
}

function checkFields_editspecials(theform) 
{
	
	if(theform.Heading.value == "") 
	{
		alert("Please enter a Heading.");
		theform.Heading.focus();
		return (false);
	}
	if(theform.Narrative.value == "") 
	{
		alert("Please enter a Narrative.");
		return (false);
	}
	if(theform.expire.value == "") 
	{
		alert("Please enter a Expiry date.");
		theform.expire.focus();
		return (false);
	}
}

function checkFields_changedetails(theform) 
{
	if(theform.Name.value == "") 
	{
		alert("Please enter a Name.");
		theform.Name.focus();
		return (false);
	}
	if(theform.Password.value == "") 
	{
		alert("Please enter an Password.");
		theform.Password.focus();
		return (false);
	}	
	if(theform.Password.value != theform.Password1.value) 
	{
		alert("The Verified Password does not match the password.");
		theform.Password1.focus();
		return (false);
	}	
	if(theform.Password.value.length < 3)
	{
		alert("The password must be at least 3 numbers and/or characters");
		theform.Password.focus();
		return (false);
	}
	if(theform.passwordclue.value == "") 
	{
		alert("Please enter a Password Clue.");
		theform.passwordclue.focus();
		return (false);
	}
	if(theform.emailR.value == "") 
	{
		alert("Please enter an Email Address for password recovery.");
		theform.emailR.focus();
		return (false);
	}	
	if(theform.organisation.value == "") 
	{
		alert("Please enter an Organisation.");
		theform.organisation.focus();
		return (false);
	}	
}

function newthread()
{
	var url="newthreadslookup.asp"
	divid="threads"
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function lanchek()
{
	var names = document.getElementById("names");
	//var org = document.getElementById("org");
	var email = document.getElementById("email");
	var subject = document.getElementById("subject");
	var comments = document.getElementById("comments");
	if(names.value=="" || email.value=="" || subject.value=="" || comments.value=="")
	{
		alert("Some of the new topic fields have not been filled out yet.");
		return false;
	}
	else
	{
		var url= "languagelookup.asp?names=" + names.value + "&email=" + email.value + "&subject=" + subject.value + "&comments=" + comments.value
		divid = "warnings"
		xmlHttp=GetXmlHttpObject(stateChanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
		if(forlan != "good")
		{
			forlan = "";
			return false;
		}
	}
	return true;
}

function threads(msgid)
{
	var url= "threadslookup.asp?msgid=" + msgid
	divid = "threads"
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function threads_blog(msgid)
{
	var url= "threadslookup_blog.asp?msgid=" + msgid
	divid = "threads"
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function reply(msgid)
{
	document.getElementById("replyarea").innerHTML="<hr><div id='warnings'></div><table><tr><td align='left' class='normalFont'>Your name:</td><td align='left'><input type='text' id='names' name='names' class='txtBox'></td></tr><tr><td align='left' class='normalFont'>Your email address:</td><td align='left'><input type='text' id='email' name='email' class='txtBox'></td></tr><tr><td align='left' class='normalFont'>Subject:</td><td align='left'><input type='text' id='subject' name='subject' class='txtBox'></td></tr><tr><td valign='top' align='left' class='normalFont'>Your comments:</td><td align='left'><textarea id='comments' name='comments' COLS=60 ROWS=8 class='txtBox'></textarea></td></tr><tr><td>&nbsp;</td><td><INPUT TYPE='submit' VALUE='Submit' name='save' class='txtBox'><INPUT TYPE='reset' VALUE='Reset' class='txtBox'></td></tr></table>"	
}

function hideandshow()
{
	if (document.getElementById("country").selectedIndex == 0)
	{
		document.getElementById("statetr").style.visibility = "visible";
		document.getElementById("statetr").style.position = "relative";
		document.getElementById("citytr").style.visibility = "hidden";
		document.getElementById("citytr").style.position = "absolute";
		//document.getElementById("star").style.visibility = "visible";
		//document.getElementById("star").style.position = "relative";
	}
	else if (document.getElementById("country").selectedIndex == 1)
	{
		document.getElementById("citytr").style.visibility = "visible";
		document.getElementById("citytr").style.position = "relative";
		document.getElementById("statetr").style.visibility = "hidden";
		document.getElementById("statetr").style.position = "absolute";
		//document.getElementById("star").style.visibility = "hidden";
		//document.getElementById("star").style.position = "absolute";
	}
	else if (document.getElementById("country").selectedIndex == 2)
	{
		document.getElementById("statetr").style.visibility = "hidden";
		document.getElementById("statetr").style.position = "absolute";
		document.getElementById("citytr").style.visibility = "hidden";
		document.getElementById("citytr").style.position = "absolute";
		//document.getElementById("star").style.visibility = "visible";
		//document.getElementById("star").style.position = "relative";
	}
}

function checkFields_newvip(theform,ifisrenew) 
{
	if(theform.title.value == "") 
	{
		alert("Please enter a title.");
		theform.title.focus();
		return (false);
	}
	if(theform.initial.value == "") 
	{
		alert("Please enter a Firstname.");
		theform.initial.focus();
		return (false);
	}		
	if(theform.surname.value == "") 
	{
		alert("Please enter a Surname.");
		theform.surname.focus();
		return (false);
	}	
	if(theform.street.value == "") 
	{
		alert("Please enter a Street name.");
		theform.street.focus();
		return (false);
	}
	if(theform.town.value == "" && document.getElementById("country").selectedIndex ==0 ) 
	{
		alert("Please enter a Town/Suburb.");
		theform.town.focus();
		return (false);
	}
	if(theform.city.value == "" && document.getElementById("country").selectedIndex == 1 ) 
	{
		alert("Please enter a City.");
		theform.city.focus();
		return (false);
	}
	if (document.getElementById("country").selectedIndex == 0)
	{
		if(theform.state.value == "") 
		{
			alert("Please enter a State.");
			theform.state.focus();
			return (false);
		}
		theform.city.value = "";
	}
	else if (document.getElementById("country").selectedIndex == 1)
	{
		theform.state.value = "";
	}
	else
	{
		theform.state.value = "";
		theform.city.value = "";
	}
	if(theform.postcode.value == "" && document.getElementById("country").selectedIndex != 1 ) 
	{
		alert("Please enter a postcode.");
		theform.postcode.focus();
		return (false);
	}
	/*if(theform.tribalusn.value == "" && ifisrenew == "yes") 
	{
		alert("Please enter Tribal username");
		theform.tribalusn.focus();
		return (false);
	}
	if(theform.tribalpwd.value == "" && ifisrenew == "yes") 
	{
		alert("Please enter Tribal password");
		theform.tribalpwd.focus();
		return (false);
	}*/	
	/*if(theform.vipno.value == "") 
	{
		alert("Please enter VIP Card No.");
		theform.vipno.focus();
		return (false);
	}*/	
	
	if(ifisrenew == "yes")
	{
		if(theform.date_joined.value == "") 
		{
			alert("Please enter date joined.");
			theform.date_joined.focus();
			return (false);
		}	
	}
	
	
	if(theform.family_park.value == "") 
	{
		alert("Please enter place where added.");
		theform.family_park.focus();
		return (false);
	}	
	
	return (true);
}
function checknum(field)
{
	var flag = true;
	var str = new String(field.value);
	for(var i=0; i<str.length; i++)
	{
		if(str.charAt(i) < '0' || str.charAt(i) > '9')
		{
			flag = false;
		}
	}
	if (flag == false)
	{
		alert("Please Enter Number Only")
		field.value = "";
		field.focus();
	}
	return flag;
}
function plus(myid,numyear)
{	
	var days = document.getElementById(myid).value
	var dayarr = days.split(" ");
	var yearstr = dayarr[2];
	var year = parseInt(yearstr) + numyear;
	document.getElementById("expiry_date").value = dayarr[0] + " " + dayarr[1] + " " + year
}

function changeCase(frmObj) {
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = frmObj.value.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)  {
	for (index = 0; index < strLen; index++)  {
	if (index == 0)  {
	tmpChar = tmpStr.substring(0,1).toUpperCase();
	postString = tmpStr.substring(1,strLen);
	tmpStr = tmpChar + postString;
	}
	else {
	tmpChar = tmpStr.substring(index, index+1);
	if (tmpChar == " " && index < (strLen-1))  {
	tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
	preString = tmpStr.substring(0, index+1);
	postString = tmpStr.substring(index+2,strLen);
	tmpStr = preString + tmpChar + postString;
			 }
		  }
	   }
	}
	frmObj.value = tmpStr;
}

function swap(type)
{
	if(type == "weather_search")
	{
		document.getElementById("weather_search").style.display = "inline";
		document.getElementById("weather_result").style.display = "none";
	}
}

function stateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
		if(xmlHttp.responseText=="good")
			forlan = xmlHttp.responseText
		else
			document.getElementById(divid).innerHTML=xmlHttp.responseText
    }
}

function GetXmlHttpObject(handler)
{
    var objXmlHttp=null
 
    if (navigator.userAgent.indexOf("Opera")>=0)
    {
        alert("Opera not supported...")
        return;
    }
    if (navigator.userAgent.indexOf("MSIE")>=0)
    {
        var strName="Msxml2.XMLHTTP"
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
        {
            strName="Microsoft.XMLHTTP"
        }
        try
        {
            objXmlHttp=new ActiveXObject(strName)
            objXmlHttp.onreadystatechange=handler
            return objXmlHttp
        }
        catch(e)
        {
            alert("Error. Scripting for ActiveX might be disabled")
            return
        }
    }
    if (navigator.userAgent.indexOf("Mozilla")>=0)
    {
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler
        return objXmlHttp
    }
} 
