function checkemail(checkThisEmail)
{
	var myEMailIsValid = true;
	var myAtSymbolAt = checkThisEmail.indexOf('@');
	var myLastDotAt = checkThisEmail.lastIndexOf('.');
	var mySpaceAt = checkThisEmail.indexOf(' ');
	var myLength = checkThisEmail.length;
	
	// at least one @ must be present and not before position 2
	// @yellow.com : NOT valid
	// x@yellow.com : VALID
	
	if (myAtSymbolAt < 1 ) 
	 {myEMailIsValid = false}
	
	// at least one . (dot) afer the @ is required
	// x@yellow : NOT valid
	// x.y@yellow : NOT valid
	// x@yellow.org : VALID
	
	if (myLastDotAt < myAtSymbolAt) 
	 {myEMailIsValid = false}
	
	// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
	// x.y@yellow. : NOT valid
	// x.y@yellow.a : NOT valid
	// x.y@yellow.ca : VALID
	
	if (myLength - myLastDotAt <= 2) 
	 {myEMailIsValid = false}
	
	// no empty space " " is permitted (one may trim the email)
	// x.y@yell ow.com : NOT valid
	
	if (mySpaceAt != -1) 
	 {myEMailIsValid = false}
	
	return myEMailIsValid;
}

function checkphone(input)
{
	var teststring = ("1234567890 ");
	var pass = true;
	for (var i = 0; i < input.length; i++)	{
		var found = false;
		for (var j = 0; j < teststring.length; j++)		{
			if (input.charAt(i) == teststring.charAt(j)) found = true;	}
			if (!found) pass = false;	}
   return (pass);
 }

function picpopup(type,picurl)
{
	switch(type)
	{
		case 'itm':
			picurl = picurl.replace(/m.jpg/, "l.jpg");
			var gotoURL = "/picview.htm?url=" + picurl;
			popWin = window.open(gotoURL,"", "left=200,top=200,width=10,height=10,resizable=yes,scrollbars=yes");
			popWin.focus();
		break;
	}
}

function tog(me)
{
	for (var i = 0; i < menuelements.length; i++){
		if (menuparents[i] == me.id){
			target = document.getElementById(menuelements[i]);
			if (target.style.display == ""){
				target.style.display == "none";
				dohide(menuelements[i]);}
			else if (target.style.display == "none"){
				target.style.display = "";}	} }
}

function dohide(elementid)
{
	document.getElementById(elementid).style.display = "none";
	for (var i = 0; i < menuelements.length; i++){
		if (menuparents[i] == elementid){
			document.getElementById(menuelements[i]).style.display = "none";
			dohide(menuelements[i]); } }
}

function preloadImages()
{
	var numpics = arguments.length;
	document.arrayImages = new Array(numpics) 
	for (var i=0; i < numpics; i++)
	{
    	var preload = new Image();
		document.arrayImages[i] = arguments[i];
    	preload.src = document.arrayImages[i];
	}
}

function swap(imgIndex) {
    document.main_img.src = document.arrayImages[imgIndex];
}



function dolink(part1,part2,ext,myclass) {
	document.write('\x3Cspan class="' + myclass + '"\x3E\x3Ca href=\"mailto:' + part1 + '@' + part2 + '.' + ext + '\" \x3E');
	document.write('' + part1 + '@' + part2 + '.' + ext + '\x3C/' + 'a>\x3C/span\x3E');
}

function writerecipient(part1,part2,ext)
{
	document.write('\x3Cinput type="hidden" name="recipient" value="' + part1 + '@' + part2 + '.' + ext + '"/\x3E');
}

function checkdigits(telno){
	var teststring = ("1234567890x- ");
	var pass = true;
	for (var i = 0; i < telno.length; i++){
		var found = false;
		for (var j = 0; j < teststring.length; j++){
			if (telno.charAt(i) == teststring.charAt(j)) found = true;}
			if (!found) pass = false;}
   return (pass);
}

function checkInputs(myForm) 
{
	var myalertstring = "";


	if (myForm.name.value == "")
	{
		myalertstring = myalertstring + "Please enter your name. \n";
	}
	
	if ((myForm.contmeth.value == "email")*(myForm.email.value == ""))
	{
		myalertstring = myalertstring + "You have requested contact by email \n but haven't entered your email address. \n";
	}
	
	if ( ((myForm.contmeth.value == "email")*(myForm.email.value != ""))*(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(myForm.email.value))))
	{
		myalertstring = myalertstring + "Please check your e-mail address is correct. \n";
	}


	if ((myForm.contmeth.value == "phone")*(myForm.telephone.value == ""))
	{
		myalertstring = myalertstring + "You have requested contact by telephone but haven't entered your number. \n";
	}
	
	if ((myForm.contmeth.value == "phone")*(!(checkdigits(myForm.telephone.value))))
	{
		myalertstring = myalertstring + "Please check telephone number only contains digits 0-9 or x for extension number. \n";
	}

	if (myalertstring != "")
	{
		alert(myalertstring + "Please check your entries and try again.\n");
		return (false);
	}
	
	if (myForm.email.value == "")
	{
		myForm.email.value = "enquiries@everythingegyptian.co.uk";
	}
	return (true);
}

function checkHol(myForm) 
{
	var myalertstring = "";


	if (myForm.name.value == "")
	{
		myalertstring = myalertstring + "Please enter your name. \n";
	}
	
	if ((myForm.contmeth.value == "email")*(myForm.email.value == ""))
	{
		myalertstring = myalertstring + "You have requested contact by email \n but haven't entered your email address. \n";
	}
	
	if ( ((myForm.contmeth.value == "email")*(myForm.email.value != ""))*(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(myForm.email.value))))
	{
		myalertstring = myalertstring + "Please check your e-mail address is correct. \n";
	}


	if ((myForm.contmeth.value == "phone")*(myForm.telephone.value == ""))
	{
		myalertstring = myalertstring + "You have requested contact by telephone but haven't entered your number. \n";
	}
	
	if ((myForm.contmeth.value == "phone")*(!(checkdigits(myForm.telephone.value))))
	{
		myalertstring = myalertstring + "Please check telephone number only contains digits 0-9 or x for extension number. \n";
	}

	if (myalertstring != "")
	{
		alert(myalertstring + "Please check your entries and try again.\n");
		return (false);
	}
	
	if (myForm.email.value == "")
	{
		myForm.email.value = "enquiries@everythingegyptian.co.uk";
	}
return (true);
}