/* === Start Form Validation === */
function validateform(form) {
/*  Call the validation in blocks if all goes well and all required fields
	have been entered, then submit the form. */
	textobject1();
	textobject2();
	xobject();
	ovalobject();	
	dotsobject();	
	shadobject();	
	emailtext();
	delivery();
	CompleteAll();
	
	function CompleteAll() {
		/* All required fields have been populated. */
		if ( textobject1() == true && textobject2() == true && xobject() == true && ovalobject() == true && dotsobject() == true 
			&& shadobject() == true && emailtext() == true && delivery() == true ) {
			document.style3.description.value = "Free Logo Order - Style 3";
			document.style3.action = "../../includes/scripts/mail_style3.cfm"
			document.style3.submit();
		}
		else {
		/* Find out which required fields have been left blank and alert the user, 
			once such fields have been populated, then submit form. */
			var stext = "You did not complete these items: \n"
			if ( textobject1() == false ) {
				var stext = stext + '\n -  Text Object 1';
			}
			
			if ( textobject2() == false ) {
				var stext = stext + '\n -  Text Object 2';
			}
			
			if ( xobject() == false ) {
				var stext = stext + '\n -  X Object Color';
			}	
			
			if ( ovalobject() == false ) {
				var stext = stext + '\n -  Oval Object Color';
			}	
			
			if ( dotsobject() == false ) {
				var stext = stext + '\n -  Dots Object Color';
			}	
			
			if ( shadobject() == false ) {
				var stext = stext + '\n -  Shadow Color';
			}			
			
			if ( emailtext() == false ) {
				var stext = stext + '\n -  E-mail Address';
			}
						
			if ( delivery() == false ) {
				var stext = stext + '\n -  Delivery Method';
			}	
			alert(stext);	
		}
	}
	/* Make sure field is not blank */
	function textobject1() {
		if ( document.style3.TextObject1.value.length == 0 ) {
			return false;
		}
		else {
			return true;
		}
	}
	/* Make sure field is not blank */
	function textobject2() {
		if ( document.style3.TextObject2.value.length == 0 ) {
			return false;
		}
		else {
			return true;
		}
	}	
	
	/* Make sure a radio button has been checked */
	function xobject() {
		var count = 0;
		var chknum = document.style3.XObject.length;
		for (var i = 0; i < chknum; i++) {
			if (eval("document.style3.XObject[" + i + "].checked") == true) {
				count++
			}
		}
		if ( count == 0 ) {
			return false;
		}
		else {
			return true;
		}
	}	
	/* Make sure a radio button has been checked */
	function ovalobject() {
		var count = 0;
		var chknum = document.style3.OvalObject.length;
		for (var i = 0; i < chknum; i++) {
			if (eval("document.style3.OvalObject[" + i + "].checked") == true) {
				count++
			}
		}
		if ( count == 0 ) {
			return false;
		}
		else {
			return true;
		}
	}
	/* Make sure a radio button has been checked */
	function dotsobject() {
		var count = 0;
		var chknum = document.style3.DotsObject.length;
		for (var i = 0; i < chknum; i++) {
			if (eval("document.style3.DotsObject[" + i + "].checked") == true) {
				count++
			}
		}
		if ( count == 0 ) {
			return false;
		}
		else {
			return true;
		}
	}	
	
	/* Make sure a radio button has been checked */
	function shadobject() {
		var count = 0;
		var chknum = document.style3.ShadowObject.length;
		for (var i = 0; i < chknum; i++) {
			if (eval("document.style3.ShadowObject[" + i + "].checked") == true) {
				count++
			}
		}
		if ( count == 0 ) {
			return false;
		}
		else {
			return true;
		}
	}	
	
	/* Make sure email address field is not blank and formatted properly */
	function emailtext() {
	 	var str = document.style3.Email.value;
	  	// find out if regular expressions are supported by browser ?
		var supported = 0;
	  	if (window.RegExp) {
	    	var tempStr = "a";
	    	var tempReg = new RegExp(tempStr);
	    		if (tempReg.test(tempStr)) {
					supported = 1;
	  			}
		}
		// regular expressions not supported then check for the basics
		if (!supported) {
	    	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
		}
		// regular expressions are supported so check content of string entered
	  	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	  	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	  	return (!r1.test(str) && r2.test(str));
	}	
	
	/* Make sure delivery field is not blank */
	function delivery() {
		var count = 0;
		var chknum = document.style3.Delivery.length;
		for (var i = 0; i < chknum; i++) {
			if (eval("document.style3.Delivery[" + i + "].checked") == true) {
				count++
			}
		}
		if ( count == 0 ) {
			return false;
		}
		else {
			return true;
		}
	}	
}	

/* Additional help/instructions */
function DeliveryAlert() {
	message = "=====================================\n" +
	"Attention:\n" + "=====================================\n" + 
	"Double check your e-mail address. \nAfter you submit the form, a confirmation e-mail \nwill be sent to the e-mail you specified." + 
	"\n\nDouble check your delivery method. \nMake sure you selected the correct option." +
	"\n=====================================\n" +
	"Thank you.";
	alert(message);
}

