function validateContactMeForm(form) {
   if (isNotEmpty(form.email)) {
	   if (!isEMailAddr(form.email)) {
		   alert("The 'Email Address' field does not contain a correctly formatted email address. I won't be able to respond to you at that address.");
		   return false;
	   }
   }
   return true;
}

function validateSiteCreationForm(form) {
   if (!isNotEmpty(form.email)) {
	   alert("The 'Email Address' field has been left empty. I'll need an email address to send your site mockup.");
	   return false;
   }
   if (!isEMailAddr(form.email)) {
       alert("The 'Email Address' field does not contain a correctly formatted email address. I'll need an email address to send your site mockup.");
	   return false;
   }
   return true;
}

function validateEmail(form) {
	if (isNotEmpty(form.email)) {
      if (isEMailAddr(form.email)) {
         return true;
      }
   }
}

// validates that the field value string has one or more characters in it
function isNotEmpty(elem) {
    var str = elem.value;
    var re = /.+/;
    if(!str.match(re)) {
//        alert("Please make sure that you have filled in all required fields.");
        return false;
    } else {
        return true;
    }
}
   
//validates that the entry is a positive or negative number
function isNumber(elem) {
    var str = elem.value;
    var re = /^[-]?\d*\.?\d*$/;
    str = str.toString( );
    if (!str.match(re)) {
        alert("Enter only numbers into the field.");
        return false;
    }
    return true;
}
   
// validates that the entry is 16 characters long when
// input field's maxlength attribute is set to 16
function isLen16(elem) {
    var str = elem.value;
    var re = /\b.{16}\b/;
    if (!str.match(re)) {
        alert("Entry does not contain the required 16 characters.");
        return false;
    } else {
        return true;
    }
}
   
// validates that the entry is formatted as an email address
function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
//        alert("Please verify the email address format.");
        return false;
    } else {
        return true;
    }
}

function setSampleColorsBACK() {
	document.getElementById('colorsSample').focus();
	var menu;
	menu = document.getElementById('look_pageBackGroundSelect');
	for (var i = 0; i < menu.length; i++) {
		if (menu[i].selected) {
			document.getElementById('colorsSample').style.backgroundColor = "#" + menu[i].value;
			menu.style.backgroundColor = menu[i].style.backgroundColor;
			menu.style.color = menu[i].style.color;
		}
	}
	menu = document.getElementById('look_siteBackGroundSelect');
	for (var i = 0; i < menu.length; i++) {
		if (menu[i].selected) {
			if (menu[i].value == "0") {
				document.getElementById('siteBg').style.backgroundColor = "#dddddd";
				menu.style.backgroundColor = "#ffffff";
				menu.style.color = "#000000";
			} else {
				var selectedValue = "#" + menu[i].value;
				document.getElementById('siteBg').style.backgroundColor = "#" + menu[i].value;
				menu.style.backgroundColor = menu[i].style.backgroundColor;
				menu.style.color = menu[i].style.color;
			}
		}
	}
	menu = document.getElementById('look_pageMainAccentSelect');
	for (var i = 0; i < menu.length; i++) {
		if (menu[i].selected) {
			document.getElementById('topMainAccent').style.backgroundColor = "#" + menu[i].value;
			document.getElementById('bottomMainAccent').style.backgroundColor = "#" + menu[i].value;
			menu.style.backgroundColor = menu[i].style.backgroundColor;
			menu.style.color = menu[i].style.color;
		}
	}
	menu = document.getElementById('look_pageSecondaryAccentSelect');
	for (var i = 0; i < menu.length; i++) {
		if (menu[i].selected) {
			document.getElementById('topMinorAccent').style.backgroundColor = "#" + menu[i].value;
			document.getElementById('secondMinorAccent').style.backgroundColor = "#" + menu[i].value;
			document.getElementById('bottomMinorAccent').style.backgroundColor = "#" + menu[i].value;
			menu.style.backgroundColor = menu[i].style.backgroundColor;
			menu.style.color = menu[i].style.color;
		}
	}
	menu = document.getElementById('look_pageFontSelect');
	for (var i = 0; i < menu.length; i++) {
		if (menu[i].selected) {
			document.getElementById('siteBg').style.color = "#" + menu[i].value;
			menu.style.backgroundColor = menu[i].style.backgroundColor;
			menu.style.color = menu[i].style.color;
		}
	}
}






function setSampleColors(selectMenu, element, stripeType) {
	document.getElementById('colorsSample').focus();  /* take focus off of select menu, for better look in IE6... */
	var menu;
	menu = document.getElementById(selectMenu);
	for (var i = 0; i < menu.length; i++) {
		if (menu[i].selected) {
			if (menu[i].value == "0") {
				if (selectMenu == 'look_pageFontSelect') {
					document.getElementById('siteBg').style.color = "#000000";
				} else {
					if (stripeType == 'right') {
						document.getElementById(element).style.backgroundImage = "url(images/stripes.gif)";
					} else {
						document.getElementById(element).style.backgroundImage = "url(images/stripes_left.gif)";
					}
				}
				menu.style.backgroundColor = "#ffffff";
				menu.style.color = "#000000";
			} else {
				var selectedValue = "#" + menu[i].value;
				if (selectMenu == 'look_pageFontSelect') {
					document.getElementById('siteBg').style.color = "#" + menu[i].value;
				} else {
					document.getElementById(element).style.backgroundImage = "none";
					document.getElementById(element).style.backgroundColor = "#" + menu[i].value;
				}
				menu.style.backgroundColor = menu[i].style.backgroundColor;
				menu.style.color = menu[i].style.color;
			}
		}
	}
	if (selectMenu == 'look_pageMainAccentSelect') {
		document.getElementById('bottomMainAccent').style.backgroundImage = document.getElementById('topMainAccent').style.backgroundImage;
		document.getElementById('bottomMainAccent').style.backgroundColor = document.getElementById('topMainAccent').style.backgroundColor;
	}
	if (selectMenu == 'look_pageSecondaryAccentSelect') {
		document.getElementById('bottomMinorAccent').style.backgroundImage = document.getElementById('secondMinorAccent').style.backgroundImage = document.getElementById('topMinorAccent').style.backgroundImage;
		document.getElementById('bottomMinorAccent').style.backgroundColor = document.getElementById('secondMinorAccent').style.backgroundColor = document.getElementById('topMinorAccent').style.backgroundColor;
	}
}

function setAllSampleColors() {
	setSampleColors('look_pageBackGroundSelect', 'colorsSample', 'left');
	setSampleColors('look_siteBackGroundSelect', 'siteBg', 'right');
	setSampleColors('look_pageMainAccentSelect', 'topMainAccent', 'right');
	setSampleColors('look_pageSecondaryAccentSelect', 'topMinorAccent', 'left');
	setSampleColors('look_pageFontSelect', 'siteBg', 'none');
}


