var homeOn = new Image();
var homeOff = new Image();
var printingOn = new Image();
var printingOff = new Image();
var catalogueOn = new Image();
var catalogueOff = new Image();
var offersOn = new Image();
var offersOff = new Image();
var contactOn = new Image();
var contactOff = new Image();


var arrQuotes = new Array();
arrQuotes[0] = ['Thank you so much for the printing of the cheerleaders tops, they are great!.You really helped us achieve our goal of great new uniforms','Julie, Camps Hill School'];
arrQuotes[1] = ['We received the t-shirts today and they look amazing! Thank you so much. Service was superb from start to finish','Chris, HBS'];
arrQuotes[2] = ['Fantastic service and over the moon with the uniforms, thanks to everyone at P4','Elaine, Toad Hall Nursery'];

function SwapIMG(imageName, image, imagePath)
{
	if (image.src == '')
	{
		image.src = imagePath;
	}
	document.images[imageName].src = image.src;
}

function winPop(pageToLoad, winName, width, height, center, scroll, control)
{
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + ","
    + "height=" + height + ","
    + "location=0,"
    + "menubar=0,"
    + "resizable=" + control + ","
    + "scrollbars="+scroll+", "
    + "status=1,"
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    window.open(pageToLoad,winName,args );
}

function NumberOfChar(str,char)
{
	var ii, charCount;
	charCount = 0;
	for (ii=0; ii < str.length;ii++)
	{
		var cc = str.charAt(ii);
		if (cc == char)
		{
			charCount = charCount + 1;
		}
	}
	return charCount;
}

function validEmail(str)
{
	var bool;
	bool = true;
	if (str.length < 6)
	{
		bool = false;
		alert("Email address has too few characters.");
	}
	if ((bool) && ((NumberOfChar(str,'@')==0)||(NumberOfChar(str,'@')>1)))
	{
		bool = false;
		alert("Email address contains the wrong number of @'s.");
	}
	if ((bool) && (NumberOfChar(str,'.')==0))
	{
		bool = false;
		alert("Email address must contain at least one '.'.");
	}
	if ((bool) && (NumberOfChar(str,' ')!=0))
	{
		bool = false;
		alert("Email address must not contain any spaces.");
	}
	return bool;
}

function validateRecommendForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.yourname.value == ''))
	{
		alert('You must enter your Name so your friend knows who has recommended us to them!');
		bValid = false;
	}

	if ((bValid) && (pForm.name.value == ''))
	{
		alert('You must enter your Friend`s Name we know who to address the email too!');
		bValid = false;
	}

	if ((bValid) && (pForm.email.value == ''))
	{
		alert('You must enter your Friend`s Email Address so we can email our website link to them!');
		bValid = false;
	}
	else if (bValid)
	{
		bValid = validEmail(pForm.email.value);
	}	
	
	return bValid;		
}

function validateSavingsForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.propertyvalue.value == ''))
	{
		alert('You must enter the value of your property so we can calculate your savings!');
		bValid = false;
	}

	if ((bValid) && (pForm.commission.value == ''))
	{
		alert('You must enter the high street agents commission so we can calculate your savings!');
		bValid = false;
	}
	
	return bValid;		
}

function validateHipsForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.fullname.value == ''))
	{
		alert('You must enter your Full Name so we know who we are speaking to!');
		bValid = false;
	}

	if ((bValid) && ((pForm.email.value == '') && (pForm.phonenumber.value == '') && (pForm.mobilephonenumber.value == '') && (pForm.address.value == '')))
	{
		alert('You must enter at least one method of contact so we can get hold of you.  We require at least one of the following:\n\nEmail Address\nPhoneNumber\nMobilePhoneNumber\nAddress');
		bValid = false;
	}
	
	if ((bValid) && (pForm.email.value != ''))
	{
		bValid = validEmail(pForm.email.value);
	}	
	
	return bValid;		
}

function validateContactForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.fullname.value == ''))
	{
		alert('You must enter your Full Name so we know who we are speaking to!');
		bValid = false;
	}

	if ((bValid) && ((pForm.email.value == '') && (pForm.phonenumber.value == '') && (pForm.mobilephonenumber.value == '')))
	{
		alert('You must enter at least one method of contact so we can answer your enquiry.  We require at least one of the following:\n\nEmail Address\nPhoneNumber\nMobilePhoneNumber');
		bValid = false;
	}
	
	if ((bValid) && (pForm.email.value != ''))
	{
		bValid = validEmail(pForm.email.value);
	}	

	if ((bValid) && (pForm.enquiry.value == ''))
	{
		alert('You need to enter your enquiry/question!');
		bValid = false;
	}	
	
	return bValid;		
}

function validateQuestionnaireForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.Owner1Name.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.Owner1Email.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.Owner1PhoneNumber.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyAddress.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyType.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyLease.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyAge.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyBedrooms.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyEnSuite.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyBath.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyWCs.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyReceptions.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyConservatory.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyAttic.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyGaraging.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyHeating.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyServices.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.PropertyOwned.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.MovingPropertyOnMarket.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.MovingPropertyFound.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.MovingRegisteredBuyer.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	if ((bValid) && (pForm.MovingDate.value == ''))
	{
		alert('Please enter all required fields (marked *)');
		bValid = false;
	}
	
	return bValid;		
}

function Left(pString, pLength)
{
	if (pLength <= 0)
	{
	    return "";
	}
	else if (pLength > String(pString).length)
	{
	    return pString;
	}
	else
	{
	    return String(pString).substring(0,pLength);
	}
}

function Right(pString, pLength)
{
    if (pLength <= 0)
    {
		return "";
	}
    else if (pLength > String(pString).length)
    {
    	return pString;
    }
    else 
    {
       var iStringLength = String(pString).length;
       return String(pString).substring(iStringLength, iStringLength - pLength);
    }
}

/*********************************************************/
/****************** Savings Calculator *******************/
/*********************************************************/

function calculateSavings(pValue,pCommission)
{
	setTimeout('calculateSavingsValue(' + pValue + ',' + pCommission + ')',3000);
}

function calculateSavingsValue(pValue,pCommission)
{
	var dAgentCost = (pValue * (pCommission/100)) * 1.15;
	//var dGetSetGoCost = ((pValue * 0.0025) + 199) * 1.15;
	var dGetSetGoCost = ((pValue * 0.0025)) * 1.15;
	var dSaving = (dAgentCost - dGetSetGoCost).toFixed(0);
	var sHTML = '';

	sHTML += '<div class="pricetxt">&pound;' + dAgentCost.toFixed(2).toString() + '<br/>&pound;' + dGetSetGoCost.toFixed(2).toString() + '</div>';
	sHTML += '<p>Your High Street Agents fees:';
	sHTML += '<br/>Get-Set-Go fees:</p>';	

	if (dSaving > 0)
	{
		sHTML += '<div class="largeorangetxt">&pound;' + dSaving.toString() + '</div>';
		sHTML += '<h2>We can save ';
		sHTML += '<br/>you over....</h2>';		
	}
	else
	{
		sHTML += '<h2>WOW!</h2>';		
		sHTML += '<p>It would appear you have found a High Street Agent who is cheaper than we are.  Please check that they are offering you the same amazing service that we will becuase we think we are the best in the business!</p>';	
	}
	
	sHTML += '<p class="getsetgobtn"><br/><a href="sell_register.aspx" title="I want to Get-Set-Go!" onmouseover="SwapIMG(\'getsetgo3\', getsetgo3On, \'images/btn_getsetgo3_on.gif\')" onmouseout="SwapIMG(\'getsetgo3\', getsetgo3Off, \'images/btn_getsetgo3_off.gif\')"><img id="getsetgo3" src="images/btn_getsetgo3_off.gif" alt="I want to Get-Set-Go!"/></a></p>';
	
	document.getElementById('savings-result').innerHTML = sHTML;
}

/*********************************************************/
/******************** Random Quotes ********************/
/*********************************************************/

function OutputQuote()
{
	var iRandom = Math.floor(Math.random() * arrQuotes.length);
	var shtml;
	
	shtml = '<img src="images/quote_top.gif" alt="">';
	shtml += '<p>' + arrQuotes[iRandom][0] + '</p>';
	shtml += '<p class="quotefrom">' + arrQuotes[iRandom][1] + '</p>';
	
	document.getElementById('quote').innerHTML = shtml;
}
