var newWin = null;

// Portfolio Photo Pop Up...
function showPopUp(pageurl, theWidth, theHeight, title) {
	
if (newWin) newWin.close();
    newWin = window.open('','newWin','scrollbars=no,resizable=no,width='+theWidth+',height='+theHeight+',status=no,location=no,left=20,top=20,menubar=no');
    newWin.document.write('<HTML><HEAD><TITLE>"'+title+'"</TITLE><link href="css/main.css" rel="stylesheet" type="text/css"></HEAD><BODY>');
    newWin.document.write('<TABLE width="100%" align="center"><TR><TD align="center"><IMG SRC="'+pageurl+'" border="1"><BR><BR><A HREF="javascript:window.close();">close this window</A></TD></TR></TABLE>');
    newWin.document.write('</BODY></HTML>');
    newWin.focus();
}
    
function showText() {

    var txt = new Array();

    // Winter
    txt[0] = "While plants are dormant during winter it’s a good time to do your hard landscaping – e.g. paving, walling and fencing. It’s also time to plant trees and shrubs and prune fruit trees."    
    // Spring
    txt[1] = "Spring is an exciting time in the garden as nature comes out of hibernation and bulbs make a colourful display.  It is time to tidy up garden beds and attend to any problems with your lawn.";
    // Summer
    txt[2] = "Summer is here and it is time to really enjoy your garden.  There are many ways to make improvements i.e. decking or paving.   To save water keep garden beds topped up with mulch.";    
    // Autumn
    txt[3] = "In autumn you need to curtail the enthusiasms of summer. It is a good time for turfing, planting, feeding lawns and mulching your garden beds. Autumn is harvest time so don’t let your produce go to waste!";    
    
    var theDate = new Date();
    var theTxt = document.getElementById('txtRight');
    //alert(theDate.getMonth());
    if ((theDate.getMonth() == 11) || (theDate.getMonth() < 2)) theTxt.innerHTML = txt[0]; //winter
    if ((theDate.getMonth() >= 2) && (theDate.getMonth() < 5)) theTxt.innerHTML = txt[1]; //spring
    if ((theDate.getMonth() >= 5) && (theDate.getMonth() < 8)) theTxt.innerHTML = txt[2]; //summer
    if ((theDate.getMonth() >= 8) && (theDate.getMonth() < 11)) theTxt.innerHTML = txt[3]; //autumn
    
    //theTxt.innerHTML = txt[0];
}



// Form Validation Scripts
var sErrMessage = "";


function ValidateContactForm()
{
    sErrMessage = "";
    
    var ret = false;
    
    ret = ValidateText("name", "Name");
    ret = ValidateEmail("email", "Email");
    ret = ValidateIsNumeric("telephone", "Telephone");
    ret = ValidateText("query", "Query");
    
    if (!(sErrMessage == ""))
        alert("There have been errors with the information that you've entered, please check: \n" + sErrMessage);
   
    return sErrMessage == "";
}



function ValidateText(controlName, controlText){
	var result = true;
	var control;
	if (document.getElementById(controlName))
	{
		control = document.getElementById(controlName)
		if (control.value.length == 0)
		{
			sErrMessage += "\n- " + controlText + " is required.";
			result = false;
		}
	}
	
	return result;
}

function ValidateEmail(controlName, controlText){
	var result = true;
	var control;
	if (document.getElementById(controlName))
	{
		control = document.getElementById(controlName)
		if (control.value.length == 0)
		{
			sErrMessage += "\n- " + controlText + " is required.";
			result = false;
		}
		else if (!IsValidEmail(control.value))
		{
			sErrMessage += "\n- " + controlText + " doesn't appear to be a valid address.";
			result = false;
		}
	}
	
	return result;
}

function ValidatePhone(controlName, controlText){
	var result = true;
	var control;
	if (document.getElementById(controlName))
	{
		control = document.getElementById(controlName)
		if (control.value.length == 0)
		{
			sErrMessage += "\n- " + controlText + " is required.";
			result = false;
		}
		else if (!IsNumeric(control.value))
		{
			sErrMessage += "\n- " + controlText + " can only contain numeric characters.";
			result = false;
		}
	}
	
	return result;
}

function ValidateIsNumeric(controlName, controlText){
	var result = true;
	var control;
	if (document.getElementById(controlName))
	{
		control = document.getElementById(controlName)
		if (!IsNumeric(control.value))
		{
			sErrMessage += "\n- " + controlText + " can only contain numeric characters.";
			result = false;
		}
	}
	
	return result;
}

function IsNumeric(sString){
	
	var sValidChars = "0123456789.- ";
	var sChar;
	var bResult = true;
	
	if (sString.length == 0) return false;
	
	for (i = 0; i < sString.length && bResult == true; i++)
	{
		sChar = sString.charAt(i);
		if (sValidChars.indexOf(sChar) == -1)
		{
			bResult = false;
		}
	}
	return bResult;
}

function IsValidEmail(sEmail){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if (sEmail.search(validRegExp) == -1) 
	{
	  return false;
	} 
    return true; 
}