var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 11;

var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
var check=/@[\w\-]+\./;
var checkend=/\.[a-zA-Z]{2,3}$/;
var postexclude=/[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {1}[0-9][A-Za-z]{2}/;
var phoneexclude=/[0-9]{10,11}/;

function aG()
{
    var a=new Object();var aa=document.location.search.substring(1);var ab=aa.split("&");for(var ac=0;ac<ab.length;ac++){var ad=ab[ac].indexOf("=");if(ad==-1)continue;var ae=ab[ac].substring(0,ad);var af=ab[ac].substring(ad+1);af=af.replace(/\+/g," ");a[ae]=_unesc(af)}return a
}

function _gel(a) {return document.getElementById ? document.getElementById(a) : null}
//get querystring
function _esc(a)
{
    return window.encodeURIComponent?encodeURIComponent(a):escape(a)
}

function blnCheckEmail(pstrEmail)
{
	var k, intFirstAtSignPos, intFirstDotPos, strLastDomainInAddress
	var strValidChar = new String("abcdefghijklmnopqrstuvwxyz1234567890-_.@");
	pstrEmail = Trim(pstrEmail);
	for (k = 0; k <= pstrEmail.length; k++)
		if (strValidChar.indexOf((pstrEmail.substr(k, 1)).toLowerCase()) == -1) return false;
	if (pstrEmail.indexOf("..") >= 0) return false;		
	intFirstAtSignPos = pstrEmail.indexOf("@")
	if(intFirstAtSignPos < 1) return false;
	if (pstrEmail.indexOf("@", (intFirstAtSignPos+1)) >= 0) return false;
	intFirstDotPos = pstrEmail.indexOf(".")
	if(intFirstDotPos < 0) return false;
	if (pstrEmail.indexOf("_", intFirstAtSignPos) != -1) return false;
	strLastDomainInAddress = pstrEmail.substr((pstrEmail.lastIndexOf(".") + 1))
	if (strLastDomainInAddress.length < 2 || strLastDomainInAddress.length > 4) return false;
	return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function checkInternationalPhone(strPhone)
{
	s = stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function Trim(StrValue)
{
  var st = StrValue;
  while ((st.length > 0) && (st.charAt(0) == " ")) 
	st = st.substring(1, st.length);
  while ((st.length > 0) && (st.charAt(st.length-1) == " "))    
    st = st.substring(0, st.length-1);  
  return st;
}

function CheckTelNo(pstrTelNo)
{
	pstrTelNo = Trim(pstrTelNo);
	var IsValid = true;
	
	if (pstrTelNo.length >= 4)
	{
		if (IsValid && pstrTelNo.substring(0, 4) == "0704")
			IsValid = false;
		if (IsValid && pstrTelNo.substring(0, 1) != "0")
			IsValid = false;
		if (IsValid && (pstrTelNo.substring(0, 3) != "020" && pstrTelNo.substring(0, 3) != "023" && pstrTelNo.substring(0, 3) != "024" && pstrTelNo.substring(0, 3) != "028" && pstrTelNo.substring(0, 3) != "029" && pstrTelNo.substring(0, 2) != "07" && pstrTelNo.substring(0, 2) != "08" && pstrTelNo.substring(0, 2) != "01") )
			IsValid = false;
	}

	return IsValid;
}


function ValidateForm()
{
	var form = document.getElementById("side");
	with (form)
	{
		if (name.value == "")
		{
			alert("Please enter your name");
			name.focus();
		}
		else if (((mobile.value==null)||(mobile.value==""))&&((phone.value==null)||(phone.value=="")))
		{
			alert("Please enter either a telephone or mobile number")
			phone.focus()
		}
		else if (((phone.value!=null)&&(phone.value!=""))&&checkInternationalPhone(phone.value)==false)
		{
			alert("Please enter a valid phone number - must be 11 digits")
			phone.value=""
			phone.focus()
		}
		else if (!CheckTelNo(phone.value))
		{
			alert("Please enter a valid phone number");
			phone.focus();
		}
		else if (((mobile.value!=null)&&(mobile.value!=""))&&checkInternationalPhone(mobile.value)==false)
		{
			alert("Please enter a valid phone number - must be 11 digits")
			mobile.value=""
			mobile.focus()
		}
		else if (!CheckTelNo(mobile.value))
		{
			alert("Please enter a valid phone number");
			mobile.focus();
		}
		else
		{
			return true;
		}
	}
	return false;
}

function ValidateMainForm()
{
	var form = document.getElementById("side");
	with (form)
	{
		if (name.value == "")
		{
			alert("Please enter your name");
			name.focus();
		}
		else if (((mobile.value==null)||(mobile.value==""))&&((phone.value==null)||(phone.value=="")))
		{
			alert("Please enter either a telephone or mobile number")
			phone.focus()
		}
		else if (((phone.value!=null)&&(phone.value!=""))&&checkInternationalPhone(phone.value)==false)
		{
			alert("Please enter a valid phone number - must be 11 digits")
			phone.value=""
			phone.focus()
		}
		else if (!CheckTelNo(phone.value))
		{
			alert("Please enter a valid phone number");
			phone.focus();
		}
		else if (((mobile.value!=null)&&(mobile.value!=""))&&checkInternationalPhone(mobile.value)==false)
		{
			alert("Please enter a valid phone number - must be 11 digits")
			mobile.value=""
			mobile.focus()
		}
		else if (!CheckTelNo(mobile.value))
		{
			alert("Please enter a valid phone number");
			mobile.focus();
		}
		else if (email.value == "")
		{
			alert("Please enter your email address");
			email.focus();
		}
		else if (moveDay.value == "")
		{
			alert("Please enter a moving date");
			moveDay.focus();
		}
		else if (moveMonth.value == "")
		{
			alert("Please enter a moving date");
			moveMonth.focus();
		}
		else if (moveYear.value == "")
		{
			alert("Please enter a moving date");
			moveYear.focus();
		}
		else if (noOfMovers.value == "0")
		{
			alert("Please select number of movers required");
			noOfMovers.focus();
		}
		else
		{
			return true;
		}
	}
	return false;
}

function SwapIn()
{
            var tempSrc, tempExt
            tempSrc = window.event.srcElement.src;
            tempExt = tempSrc.substring(tempSrc.length-4)
            window.event.srcElement.src = tempSrc.substring(0,tempSrc.length-4) + '01' + tempExt;
}

function SwapOut()
{
            var tempSrc, tempExt
            tempSrc = window.event.srcElement.src;
            tempExt = tempSrc.substring(tempSrc.length-4)
            window.event.srcElement.src = tempSrc.substring(0,tempSrc.length-6) + tempExt;
}

function show(id) {
var el;
if (typeof document.all != 'undefined') el = document.all(id);
else if (typeof document.getElementById != 'undefined') el = document.getElementById(id);
if (el && el.style) el.style.display = '';
}

function hide(id) {
var el;
if (typeof document.all != 'undefined') el = document.all(id);
else if (typeof document.getElementById != 'undefined') el = document.getElementById(id);
if (el && el.style) el.style.display = 'none';
}

