var xeroImgs = new Array();
xeroImgs[0] = 1;
xeroImgs[1] = "rtm";
xeroImgs[2] = "egr";
xeroImgs[3] = "cyi";
xeroImgs[4] = "ibs";

var xeroText = new Array();
xeroText[0] = 1;
xeroText[1] = "Real-time dashboard";
xeroText[2] = "Easily generate reports";
xeroText[3] = "Control your invoices";
xeroText[4] = "Import bank statements";

var allowCloseAllDivs = true;

function MouseOverImg(obj)
{
	obj.src = obj.src.replace(".png", "_mouseover.png");
}

function MouseOutImg(obj)
{
	obj.src = obj.src.replace("_mouseover.png", ".png");
}

function LoadMap()
{	
	if (GBrowserIsCompatible()) 
	{
		var map = new GMap2(document.getElementById("ContentAboutUsMapGoogleMap"), { size:new GSize(222, 222) });
		var mapControl = new GSmallZoomControl3D();

		var mapMarker = new GMarker(new GLatLng(-41.34860893950099, 173.1901502609253));
		
		map.setUIToDefault();
		map.setMapType(G_NORMAL_MAP);
		
		map.addControl(new GSmallZoomControl3D());
		map.addOverlay(mapMarker);
		
		map.setCenter(new GLatLng(-41.34860893950099, 173.1901502609253), 15);
		
		GEvent.addListener(mapMarker, 'click', function() { mapMarker.openInfoWindowHtml("test", { maxWidth: 150 }); });
	}
}

function OpenLargeGoogleMap()
{	
	if (GBrowserIsCompatible()) 
	{
		var pageGrayoutObj = document.getElementById("PageGrayout");
		var contentAboutUsMapLargeObj = document.getElementById("ContentAboutUsMapLarge");
		var map = new GMap2(document.getElementById("ContentAboutUsMapLargeGoogleMap"), { size:new GSize(540, 450) });
		//var mapControl = new GSmallZoomControl3D();

		pageGrayoutObj.style.display = "block";
		contentAboutUsMapLargeObj.style.display = "block";
		
		var mapMarker = new GMarker(new GLatLng(-41.34860893950099, 173.1901502609253));
		
		map.setUIToDefault();
		map.setMapType(G_NORMAL_MAP);
		
		//map.addControl(new GSmallZoomControl3D());
		map.addOverlay(mapMarker);
		
		map.setCenter(new GLatLng(-41.34860893950099, 173.1901502609253), 15);
		
		GEvent.addListener(mapMarker, 'click', function() { mapMarker.openInfoWindowHtml(String.fromCharCode(60) + "span style='font-size:16px; font-weight:600;'" + String.fromCharCode(62) + "Your Accountant Ltd" + String.fromCharCode(60) + "/span" + String.fromCharCode(62) + String.fromCharCode(60) + "br /" + String.fromCharCode(62) + "27 Hunter Avenue, Richmond, Nelson 7020", { maxWidth: 150 }); });
	}
}

function CloseLargeGoogleMap()
{	
	if (GBrowserIsCompatible()) 
	{
		var pageGrayoutObj = document.getElementById("PageGrayout");
		var contentAboutUsMapLargeObj = document.getElementById("ContentAboutUsMapLarge");
		
		pageGrayoutObj.style.display = "none";
		contentAboutUsMapLargeObj.style.display = "none";
		GUnload();
	}
}

function ShowXeroFixed(xeroImgsId)
{
	var contentXeroFixedMainImgObj = document.getElementById("ContentXeroFixedMainImg");
	var contentXeroFixedNavigationTextObj = document.getElementById("ContentXeroFixedNavigationText");
	var pageGrayoutObj = document.getElementById("PageGrayout");
	var contentXeroFixedObj = document.getElementById("ContentXeroFixed");
	
	xeroImgs[0] = xeroImgsId;
	contentXeroFixedMainImgObj.src = "images/content_xero_screenshots_" + xeroImgs[xeroImgsId] + "_big.png";
	contentXeroFixedNavigationTextObj.innerHTML = xeroText[xeroImgsId];
	pageGrayoutObj.style.display = "block";
	contentXeroFixedObj.style.display = "block";
}

function ScrollXeroFixedMain(direction)
{
	var contentXeroFixedMainImgObj = document.getElementById("ContentXeroFixedMainImg");
	var contentXeroFixedNavigationTextObj = document.getElementById("ContentXeroFixedNavigationText");
	
	if(direction == "l")
	{
		if(xeroImgs[0] == 0)
		{
			contentXeroFixedMainImgObj.src = "images/content_xero_screenshots_" + xeroImgs[4] + "_big.png";
			contentXeroFixedNavigationTextObj.innerHTML = xeroText[4];
			xeroImgs[0] = 4;
		}
		else
		{
			contentXeroFixedMainImgObj.src = "images/content_xero_screenshots_" + xeroImgs[xeroImgs[0] - 1] + "_big.png";
			contentXeroFixedNavigationTextObj.innerHTML = xeroText[xeroImgs[0] - 1];
			xeroImgs[0] = xeroImgs[0] - 1;
		}
	}
	else
	{
		if(xeroImgs[0] == 4)
		{
			contentXeroFixedMainImgObj.src = "images/content_xero_screenshots_" + xeroImgs[1] + "_big.png";
			contentXeroFixedNavigationTextObj.innerHTML = xeroText[1];
			xeroImgs[0] = 1;
		}
		else
		{
			contentXeroFixedMainImgObj.src = "images/content_xero_screenshots_" + xeroImgs[xeroImgs[0] + 1] + "_big.png";
			contentXeroFixedNavigationTextObj.innerHTML = xeroText[xeroImgs[0] + 1];
			xeroImgs[0] = xeroImgs[0] + 1;
		}
	}
}

function CloseXeroFixed()
{	
	var pageGrayoutObj = document.getElementById("PageGrayout");
	var contentXeroFixedObj = document.getElementById("ContentXeroFixed");
	
	pageGrayoutObj.style.display = "none";
	contentXeroFixedObj.style.display = "none";
}

function OpenEmailFixed()
{
	var pageGrayoutObj = document.getElementById("PageGrayout");
	var emailFixedObj = document.getElementById("EmailFixed");
	
	pageGrayoutObj.style.display = "block";
	emailFixedObj.style.display = "block";
}

function CloseEmailFixed()
{
	var pageGrayoutObj = document.getElementById("PageGrayout");
	var emailFixedObj = document.getElementById("EmailFixed");
	
	pageGrayoutObj.style.display = "none";
	emailFixedObj.style.display = "none";
}

function CloseAllFixedDivs()
{
	if(allowCloseAllDivs == true)
	{
		CloseEmailFixed();
		CloseXeroFixed();
		CloseLargeGoogleMap();
	}
}

function SubmitForm()
{
	var submitInt = 0;
	var emailFixedMainFormNameInputObj = document.getElementById("EmailFixedMainFormNameInput");
	var emailFixedMainFormEmailInputObj = document.getElementById("EmailFixedMainFormEmailInput");
	var emailFixedMainFormMessageInputObj = document.getElementById("EmailFixedMainFormMessageInput");
	var emailFixedMainFormValidationInputObj = document.getElementById("EmailFixedMainFormValidationInput");
	var emailFixedMainFormErrorBoxObj = document.getElementById("EmailFixedMainFormErrorBox");
	
	if(emailFixedMainFormNameInputObj.value == "")
	{
		emailFixedMainFormNameInputObj.style.backgroundColor = "#e55916";
		emailFixedMainFormNameInputObj.style.color = "#ffffff";	
		emailFixedMainFormErrorBoxObj.innerHTML = "Please fill out your name.";
		
		return false;
	}
	else
	{
		emailFixedMainFormNameInputObj.style.backgroundColor = "#ffffff";
		emailFixedMainFormNameInputObj.style.color = "#000000";	
		submitInt++;
	}
	
	if(emailFixedMainFormEmailInputObj.value == "")
	{
		emailFixedMainFormEmailInputObj.style.backgroundColor = "#e55916";
		emailFixedMainFormEmailInputObj.style.color = "#ffffff";	
		emailFixedMainFormErrorBoxObj.innerHTML = "Please fill out your email address.";
		
		return false;
	}
	else
	{
		emailFixedMainFormEmailInputObj.style.backgroundColor = "#ffffff";
		emailFixedMainFormEmailInputObj.style.color = "#000000";	
		submitInt++;
	}
	
	if(emailFixedMainFormEmailInputObj.value.length <= emailFixedMainFormEmailInputObj.value.lastIndexOf('.') + 1)
	{
		emailFixedMainFormEmailInputObj.style.backgroundColor = "#e55916";
		emailFixedMainFormEmailInputObj.style.color = "#ffffff";
		emailFixedMainFormErrorBoxObj.style.backgroundColor = "#e55916";
		emailFixedMainFormErrorBoxObj.innerHTML = "The email address you entered is not valid.";
		
		return false;
	}
	else
	{
		emailFixedMainFormEmailInputObj.style.backgroundColor = "#ffffff";
		emailFixedMainFormEmailInputObj.style.color = "#000000";	
		submitInt++;
	}
	
	if(emailFixedMainFormEmailInputObj.value.indexOf('@') <= 0)
	{
		emailFixedMainFormEmailInputObj.style.backgroundColor = "#e55916";
		emailFixedMainFormEmailInputObj.style.color = "#ffffff";	
		emailFixedMainFormErrorBoxObj.innerHTML = "The email address you entered is not valid.";
		
		return false;
	}
	else
	{
		emailFixedMainFormEmailInputObj.style.backgroundColor = "#ffffff";
		emailFixedMainFormEmailInputObj.style.color = "#000000";	
		submitInt++;
	}
	
	if(emailFixedMainFormEmailInputObj.value.lastIndexOf('.') <= emailFixedMainFormEmailInputObj.value.indexOf('@') + 1)
	{
		emailFixedMainFormEmailInputObj.style.backgroundColor = "#e55916";
		emailFixedMainFormEmailInputObj.style.color = "#ffffff";	
		emailFixedMainFormErrorBoxObj.innerHTML = "The email address you entered is not valid.";
		
		return false;
	}
	else
	{
		emailFixedMainFormEmailInputObj.style.backgroundColor = "#ffffff";
		emailFixedMainFormEmailInputObj.style.color = "#000000";	
		submitInt++;
	}
	
	if(emailFixedMainFormMessageInputObj.value == "")
	{
		emailFixedMainFormMessageInputObj.style.backgroundColor = "#e55916";
		emailFixedMainFormMessageInputObj.style.color = "#ffffff";	
		emailFixedMainFormErrorBoxObj.innerHTML = "Please fill out the message.";
		
		return false;
	}
	else
	{
		emailFixedMainFormMessageInputObj.style.backgroundColor = "#ffffff";
		emailFixedMainFormMessageInputObj.style.color = "#000000";	
		submitInt++;
	}
	
	if(submitInt == 6)
	{
		emailFixedMainFormErrorBoxObj.style.color = "#ffffff";
		emailFixedMainFormErrorBoxObj.innerHTML = "Sending... please wait.";
		
		AjaxSubmitForm("EmailFixedMainFormNameInput=" + emailFixedMainFormNameInputObj.value + "&" + "EmailFixedMainFormEmailInput=" + emailFixedMainFormEmailInputObj.value + "&" + "EmailFixedMainFormMessageInput=" + emailFixedMainFormMessageInputObj.value + "&" + "EmailFixedMainFormValidationInput=" + emailFixedMainFormValidationInputObj.value);
	}
}

function ajaxRequest()
{
	if (window.XMLHttpRequest)
	{ 
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{ 
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		return false;
	}
}

function AjaxSubmitForm(request)
{	
	var emailFixedMainFormErrorBoxObj = document.getElementById("EmailFixedMainFormErrorBox");
	var emailFixedMainFormValidationInputObj = document.getElementById("EmailFixedMainFormValidationInput");
	var emailFixedMainFormValidationImageObj = document.getElementById("EmailFixedMainFormValidationImage");
	
	var httpRequest = new ajaxRequest();
	
	if(httpRequest != false)
	{
		httpRequest.open("GET", "mail.php?send&" + request);
		
		httpRequest.onreadystatechange = function() 
		{
			if(httpRequest.readyState == 4 && httpRequest.status == 200) 
			{
				if(httpRequest.responseText == "true")
				{
					ClearForm();
					emailFixedMainFormErrorBoxObj.innerHTML = "Your email has been sent.";
				}
				else if(httpRequest.responseText == "validation")
				{
					emailFixedMainFormErrorBoxObj.innerHTML = "The validation you entered was incorrect.";
					emailFixedMainFormErrorBoxObj.style.color = "#e55916";
					
					var date = new Date();
					emailFixedMainFormValidationImageObj.src = "mail.php?image&amp;" + date.getTime();
					emailFixedMainFormValidationInputObj.value = "";
					emailFixedMainFormValidationImageObj.style.backgroundColor = "#e55916";	
				}
				else
				{
					emailFixedMainFormErrorBoxObj.innerHTML = "Error: Please contact the site administrator.";
				}
			}
		}
		httpRequest.send(null);
	}
}

function OpenClearFormDialog()
{
	var pageGrayoutObj = document.getElementById("PageGrayout");
	var emailFixedConfirmDialogObj = document.getElementById("EmailFixedConfirmDialog");
	
	pageGrayoutObj.style.zIndex = "3";
	allowCloseAllDivs = false;
	emailFixedConfirmDialogObj.style.display = "block";
}

function CloseClearFormDialog()
{
	var pageGrayoutObj = document.getElementById("PageGrayout");
	var emailFixedConfirmDialogObj = document.getElementById("EmailFixedConfirmDialog");
	
	pageGrayoutObj.style.zIndex = "1";
	allowCloseAllDivs = true;
	emailFixedConfirmDialogObj.style.display = "none";
}

function ClearForm()
{
	var emailFixedMainFormNameInputObj = document.getElementById("EmailFixedMainFormNameInput");
	var emailFixedMainFormEmailInputObj = document.getElementById("EmailFixedMainFormEmailInput");
	var emailFixedMainFormMessageInputObj = document.getElementById("EmailFixedMainFormMessageInput");
	var emailFixedMainFormValidationInputObj = document.getElementById("EmailFixedMainFormValidationInput");
	var emailFixedMainFormErrorBoxObj = document.getElementById("EmailFixedMainFormErrorBox");	
	
	emailFixedMainFormNameInputObj.value = "";
	emailFixedMainFormNameInputObj.style.backgroundColor = "#ffffff";
	emailFixedMainFormEmailInputObj.value = "";
	emailFixedMainFormEmailInputObj.style.backgroundColor = "#ffffff";
	emailFixedMainFormMessageInputObj.value = "";
	emailFixedMainFormMessageInputObj.style.backgroundColor = "#ffffff";
	emailFixedMainFormValidationInputObj.value = "";
	emailFixedMainFormValidationInputObj.style.backgroundColor = "#ffffff";
	emailFixedMainFormErrorBoxObj.innerHTML = "";
	
	CloseClearFormDialog();
}

function WhiteBackground(bwObj)
{
	bwObj.style.backgroundColor = '#ffffff';
}

function CheckValidation(validationObj)
{		
	var httpRequest = new ajaxRequest();
	
	if(httpRequest != false)
	{
		httpRequest.open("GET", "mail.php?validate&EmailFixedMainFormValidationInput=" + validationObj.value);
		
		httpRequest.onreadystatechange = function() 
		{
			if(httpRequest.readyState == 4 && httpRequest.status == 200) 
			{
				if(httpRequest.responseText == "pass")
				{
					validationObj.style.backgroundColor = "#ffffff";
					validationObj.style.color = "#000000";
				}
				else
				{
					validationObj.style.backgroundColor = "#e55916";
					validationObj.style.color = "#ffffff";					
				}
			}
		}
		httpRequest.send(null);
	}
}

function CheckForm(inputObj)
{
	
	var emailFixedMainFormNameInputObj = document.getElementById("EmailFixedMainFormNameInput");
	var emailFixedMainFormEmailInputObj = document.getElementById("EmailFixedMainFormEmailInput");
	var emailFixedMainFormMessageInputObj = document.getElementById("EmailFixedMainFormMessageInput");
	
	var emailPass = 0;
	
	if(emailFixedMainFormNameInputObj == inputObj)
	{
		if(emailFixedMainFormNameInputObj.value == "")
		{
			emailFixedMainFormNameInputObj.style.backgroundColor = "#e55916";
			emailFixedMainFormNameInputObj.style.color = "#ffffff";	
			
			return false;
		}
		else
		{
			emailFixedMainFormNameInputObj.style.backgroundColor = "#ffffff";
			emailFixedMainFormNameInputObj.style.color = "#000000";
		}
	}
	
	if(emailFixedMainFormEmailInputObj == inputObj)
	{
		if(emailFixedMainFormEmailInputObj.value == "")
		{
			emailFixedMainFormEmailInputObj.style.backgroundColor = "#e55916";
			emailFixedMainFormEmailInputObj.style.color = "#ffffff";	
			
			return false;
		}
		else
		{
			emailPass++;
		}
		
		if(emailFixedMainFormEmailInputObj.value.length <= emailFixedMainFormEmailInputObj.value.lastIndexOf('.') + 1)
		{
			emailFixedMainFormEmailInputObj.style.backgroundColor = "#e55916";
			emailFixedMainFormEmailInputObj.style.color = "#ffffff";	
			
			return false;
		}
		else
		{
			emailPass++;
		}
		
		if(emailFixedMainFormEmailInputObj.value.indexOf('@') <= 0)
		{
			emailFixedMainFormEmailInputObj.style.backgroundColor = "#e55916";
			emailFixedMainFormEmailInputObj.style.color = "#ffffff";	
			
			return false;
		}
		else
		{
			emailPass++;
		}
		
		if(emailFixedMainFormEmailInputObj.value.lastIndexOf('.') <= emailFixedMainFormEmailInputObj.value.indexOf('@') + 1)
		{
			emailFixedMainFormEmailInputObj.style.backgroundColor = "#e55916";
			emailFixedMainFormEmailInputObj.style.color = "#ffffff";	
			
			return false;
		}
		else
		{
			emailPass++;
		}
		
		if(emailPass == 4)
		{
			emailFixedMainFormEmailInputObj.style.backgroundColor = "#ffffff";
			emailFixedMainFormEmailInputObj.style.color = "#000000";
		}
	}
	
	if(emailFixedMainFormMessageInputObj == inputObj)
	{
		if(emailFixedMainFormMessageInputObj.value == "")
		{
			emailFixedMainFormMessageInputObj.style.backgroundColor = "#e55916";
			emailFixedMainFormMessageInputObj.color = "#ffffff";
			
			return false;
		}
		else
		{
			emailFixedMainFormMessageInputObj.style.backgroundColor = "#ffffff";
			emailFixedMainFormMessageInputObj.color = "#000000";
		}
	}
}