﻿function setMenu(which)
{
document.getElementById(which).className = which + 'On';
document.getElementById(which + 'Span').style.color = '#ffffff';
}

function checkPhoneNum(phoneNum,which,phoneType)
{
phoneNum = phoneNum.replace(/(\(|\))/g,' ');//Replace brackets with spaces
phoneNum = phoneNum.replace(/\-/g,' ');//Replace dashes with spaces
phoneNum = phoneNum.replace(/\//g,' ');//Replace '/' with spaces
var midNum = phoneNum.substr(1,phoneNum.length);
midNum = midNum.replace(/\+/g,' ');//Replace '+' with spaces unless it's the first character
phoneNum = phoneNum.charAt(0) + midNum;

//remove all non-numerics except '+- '
var ValidChars ='"0123456789+- ';
var Char;
var thePhoneNum = '';

for (var i = 0; i < phoneNum.length; i++) 
    { 
    Char = phoneNum.charAt(i); 
    if (ValidChars.indexOf(Char) != -1) 
        {
        thePhoneNum += Char;
        }
    }

thePhoneNum = thePhoneNum.replace(/(\s)+/g,'$1');//Remove multiple spaces
thePhoneNum = thePhoneNum.replace(/(\+)+/g,'$1');//Remove multiple '+'s
thePhoneNum = thePhoneNum.replace(/\s$/,'');//Remove final trailing space
thePhoneNum = thePhoneNum.replace(/(\+)\s/,'$1');//Replace initial '+ ' with '+'

if(thePhoneNum.length < 5)
	{
	alert('Please enter your '+phoneType+' number in the format "+44 1234 123654"\nor"01234 123456"');
	document.getElementById(which).focus();
	return false;
	}
else
	{
	document.getElementById(which).value = thePhoneNum;
	}
}

function checkEmail(emailAddress)
{

//Match emailAddress
var regex = /([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})/;
if(emailAddress.search(regex))
	{	
	return false;
	}
else
	{
	return true;
	}
}

//--------Anti-Spam Email Addresses--------
function writeAddress(who)
{
document.write('<a href="mailto:' + who + '@prestbury' + 'parties.co.uk">' + who + '@prestbury' + 'parties.co.uk</a>');
}

function writeAddressMask(who,text)
{
document.write('<a href="mailto:' + who + '@prestbury' + 'parties.co.uk">' + text + '</a>');
}
//--------End of Email Addresses--------




