/*
--------------------------------------------------

The Bradford Exchange
application.js

David Munger [david.munger@acquitygroup.com]
9/18/2008
3/6/2010

Copyright © 2010 Acquity Group LLC

--------------------------------------------------
*/
var $j = jQuery.noConflict();

$j(document).ready(function() {
	
	/* Scene7 dynamic URL switching */
	$j(".fieldGroup.viewerTrigger").click(function() {
		swfobject.removeSWF("scene7viewer");
		$j("#photos").append("<div id='scene7viewer'></div>");
		var newUrl = $j(this).find("a.viewerUrl").attr("href");
		swfobject.embedSWF(newUrl, 'scene7viewer', "461", "520", "9.0.0");
	});

	/* Set up a couple of rollover behaviors */
	$j("a#logoLink, #logoRollover").hover(function() {
		$j("#logoRollover").toggleReveal();
	});
	
	$j("a.productThumb, a.viewDetails").hover(function() {
		$j(this).closest(".item").find("a.viewDetails").toggleReveal();
	});

	/* Set up "pop-ins", which are regions that become visible within content when triggered */
	$j(".popin").each(function () {
		var triggerSelector = $j(this).find("span.triggerSelector").html();
		var killSelector = $j(this).find("span.killSelector").html();
		var popinId = $j(this).attr("id");
		$j(triggerSelector).click(function () {
			$j("#" + popinId).reveal();
		});
		$j(killSelector).click(function () {
			$j("#" + popinId).conceal();
		});
	});

	/* Set up inline prompting in appropriate input fields */
	$j("form.inlinePrompt").each(function() {
		$j(this).inlinePrompt();
	});

	/* Set up jqModal - what Bradford calls "smart windows" */
	$j(".trigger").click(function () {
		var contentSourceUrl = $j(this).attr("href");
		if(contentSourceUrl.length>0){
			// clean up elements remaining from old calls
			$j("#triggerModal").remove();
			
			var modalContainer = $j('<div class="modal" id="triggerModal"></div>');
			$j("body").append(modalContainer);
			modalContainer.jqm(
				{
					closeClass: 'closeModal',
					modal: true,
					onLoad: centerVertical,
					ajax: contentSourceUrl
				});
			modalContainer.jqmShow();
		}
		return false;
	});

	/* Apply some extra, dynamic styling on drop-down menus with sub-menus */
	$j("li.hasSub li a").mouseover(function() {
		$j(this).closest("li.hasSub").find("a").first().addClass("hoverPersist");
	});

	$j("li.hasSub li a").mouseout(function() {
		$j(this).closest("li.hasSub").find("a").first().removeClass("hoverPersist");
	});

	$j("a.printButton").click(function () {
		window.print();
		return false;
	});
	
	/* Subscription Toggle */
	
	/* user clicks checkbox to receive no e-mails, turns off brand-specific email checkboxes */
	$j("#emailPrefs-noEmails").click(function() {
		if ($j(this).attr("checked")) {
			$j(".emailPrefs-subscribe").attr("checked", "");
		}
	});
	
	/* conversely: user clicks brand-specific e-mail check, turns off no-emails pref */
	$j(".emailPrefs-subscribe").click(function() {
		var noEmails = true;
		$j(".emailPrefs-subscribe").each(function () {
			if($j(this).attr("checked")){
				noEmails = false;
			}
		});
		if(noEmails){
			$j("#emailPrefs-noEmails").attr("checked", true);
		}else{
			$j("#emailPrefs-noEmails").attr("checked", "");
		}
	});
	
	/* media tab switching for product detail (image/video) */
	$j(".media .tab a").live('click', function() {

		/* ID of target tab body to reveal is embedded in tab id */
		var targetTabBody = $j(this).parent().attr("id").split('-')[1];
		
		/* turn link into <span> on activated tab, and vice-versa
		 for previously-active tab */
		// First, turn any spans into <a> tags
		$j(".media .tab span").each(function() {
			$j(this).parent().append('<a href="#">' + $j(this).html() + '</a>');
			$j(this).remove();
		})

		// Now, turn the active tab <a> into a <span>
		$j(this).parent().append('<span>' + $j(this).html() + '</span>');
		$j(this).remove();

		/* remove "active" class from any tabs that have it, then 
			make newly-selected tab active */
		$j(".media .tab").removeClass("active");
		$j(".media .tab span").parent().addClass("active");

		/* hide all tab bodies, then reveal the newly-activated one */
		$j(".media .tabBody").removeClass("active");
		$j("#" + targetTabBody).addClass("active");
		
		return false;
	});
	
	
	/* country flag switching logic, triggered by user choice of state/province */
	
	$j(".fieldGroup.stateProvince select").change(function() {
		if ($j(this).val() != '[none]') {
			if(isProvince($j(this).val())) {
				$j("img.country.usa").hide();
				$j("img.country.canada").show();
			} else {
				$j("img.country.canada").hide();
				$j("img.country.usa").show();
			}
		} else {
			$j("img.country").hide();
		}
	});
	
	
	/* Browser-side form field validation */
	$j("form").submit(function() {

		var okayToSubmit = true;

		// clean up any error messages still hanging around
		$j(this).find(".fieldGroup").each(function() {
			$j(this).find(".errorMessage").remove();
			$j(this).find(".errorMessage3").remove();
			$j(this).find("input").removeClass("error");
			$j(this).find("textarea").removeClass("error");
			$j(this).find("select").removeClass("error");
		});

		$j(this).find(".fieldGroup.required:not(.inactive)").each(function() {
			if ($j(this).find("input").val() == "") {
				$j(this).find("input").after('<div class="errorMessage">Please provide</div>');
				$j(this).find("input").addClass("error");
				okayToSubmit = false;
			}
			if ($j(this).find("textarea").val() == "") {
				$j(this).find("textarea").after('<div class="errorMessage">Please provide</div>');
				$j(this).find("textarea").addClass("error");
				okayToSubmit = false;
			}
		});
		
		$j(this).find(".fieldGroup.stateProvince:not(.inactive)").each(function() {
			if ($j(this).find("select").val() == "[none]") {
				$j(this).find("select").after('<div class="errorMessage">Please select a state, province, or US Territory</div>');
				$j(this).find("select").addClass("error");
				okayToSubmit = false;
			}
		})

		$j(this).find(".fieldGroup.zip:not(.inactive)").each(function() {
			if ($j(this).find("input").val() == "") {
				$j(this).find("input").after('<div class="errorMessage">Please enter a valid zip or postal code</div>');
				$j(this).find("input").addClass("error");
				okayToSubmit = false;
			} else {
				var zipValue = $j(this).find("input").val();
				if (isProvince($j(this).closest("form").find(".fieldGroup.stateProvince select").val())) {
					var postalPattern = /^[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d$/;
					if (! zipValue.match(postalPattern)) {
						$j(this).find("input").after('<div class="errorMessage">Your postal code should be 6 characters</div>');
						$j(this).find("input").addClass("error");
						okayToSubmit = false;
					}
				} else {
					var zipPattern = /^\d{5}-?(\d{4})?$/;
					if (! zipValue.match(zipPattern)) {
						$j(this).find("input").after('<div class="errorMessage">Your zip code should be either 5 or 9 numbers</div>');
						$j(this).find("input").addClass("error");
						okayToSubmit = false;
					}
				}
			}
		});

		$j(this).find(".fieldGroup.phoneRequired:not(.inactive)").each(function() {
			if ($j(this).find("input").val() == "") {
				$j(this).find("input").after('<div class="errorMessage">Please enter a phone number (used to contact you about your order)</div>');
				$j(this).find("input").addClass("error");
				okayToSubmit = false;
			} else {
				var phonePattern = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
				if (! $j(this).find("input").val().match(phonePattern)) {
					$j(this).find("input").after('<div class="errorMessage">Your phone number may be missing numbers</div>');
					$j(this).find("input").addClass("error");
					okayToSubmit = false;
				}
			}
		});

		$j(this).find(".fieldGroup.phone:not(.inactive)").each(function() {
			if ($j(this).find("input").val() != "") {
				var phonePattern = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
				if (! $j(this).find("input").val().match(phonePattern)) {
					$j(this).find("input").after('<div class="errorMessage">Your phone number may be missing numbers</div>');
					$j(this).find("input").addClass("error");
					okayToSubmit = false;
				}
			}
		});

		$j(this).find(".fieldGroup.email:not(.inactive)").each(function() {
			if ($j(this).find("input").val() != "") {
				var emailPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
				if (! $j(this).find("input").val().match(emailPattern)) {
					$j(this).find("input").after('<div class="errorMessage">Please enter your e-mail address correctly. Example: abc@def.com</div>');
					$j(this).find("input").addClass("error");
					okayToSubmit = false;
				}
			}
		});
		
		$j(this).find(".fieldGroup.emailRequired:not(.inactive)").each(function() {
			if ($j(this).find("input").val() == "") {
				$j(this).find("input").after('<div class="errorMessage">Please enter your e-mail address</div>');
				$j(this).find("input").addClass("error");
				okayToSubmit = false;
			} else {
				var emailPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))*\s*$/;
				if (! $j(this).find("input").val().match(emailPattern)) {
					$j(this).find("input").after('<div class="errorMessage">Please enter your e-mail address correctly. Example: abc@def.com</div>');
					$j(this).find("input").addClass("error");
					okayToSubmit = false;
				}
			}
		});
		
		$j(this).find(".fieldGroup.emailConfirm:not(.inactive)").each(function () {
			if ($j(this).find("input").val() == "") {
				$j(this).find("input").after('<div class="errorMessage">Please confirm your e-mail address</div>');
				$j(this).find("input").addClass("error");
				okayToSubmit = false;
			} else {
				if ($j(this).closest("form").find(".fieldGroup.emailRequired input").val() !=
					$j(this).find("input").val()) {
						$j(this).find("input").after('<div class="errorMessage">Your e-mail addresses do not match</div>');
						$j(this).find("input").addClass("error");
						okayToSubmit = false;
					}
			}
		});

		$j(this).find(".fieldGroup.password:not(.inactive)").each(function () {
			if ($j(this).find("input").val() == "") {
				$j(this).find("input").after('<div class="errorMessage">Please enter your password</div>');
				$j(this).find("input").addClass("error");
				okayToSubmit = false;
			} else {
				var password = $j(this).find("input").val();
				var syntaxPattern = /.*\d.*/;
				if ((password.length < 7) || (password.length > 20) || (! password.match(syntaxPattern))) {
					$j(this).find("input").after('<div class="errorMessage">Your password must be must be 7-20 characters and contain letters and at least one number</div>');
					$j(this).find("input").addClass("error");
					okayToSubmit = false;
				}
			}
		});
		
		$j(this).find(".fieldGroup.newPassword:not(.inactive)").each(function () {
			if ($j(this).find("input").val() == "") {
				$j(this).find("input").after('<div class="errorMessage">Please enter your password</div>');
				$j(this).find("input").addClass("error");
				okayToSubmit = false;
			} else {
				var password = $j(this).find("input").val();
				var syntaxPattern = /.*\d.*/;
				
				if ($j(this).closest("form").find(".fieldGroup.password input").val() ==
					$j(this).find("input").val()) {
						$j(this).find("input").after('<div class="errorMessage">Your old and new passwords do match</div>');
						$j(this).find("input").addClass("error");
						okayToSubmit = false;
					} else {
					
					if ((password.length < 7) || (password.length > 20) || (! password.match(syntaxPattern))) {
						$j(this).find("input").after('<div class="errorMessage">Your password must be must be 7-20 characters and contain letters and at least one number</div>');
						$j(this).find("input").addClass("error");
						okayToSubmit = false;
					}
				}
			}
		});

		$j(this).find(".fieldGroup.confirmPassword:not(.inactive)").each(function () {
			if ($j(this).find("input").val() == "") {
				$j(this).find("input").after('<div class="errorMessage">Please confirm your password</div>');
				$j(this).find("input").addClass("error");
				okayToSubmit = false;
			} else {
				if ($j(this).closest("form").find(".fieldGroup.newPassword input").val() !=
					$j(this).find("input").val()) {
						$j(this).find("input").after('<div class="errorMessage">Your passwords do not match</div>');
						$j(this).find("input").addClass("error");
						okayToSubmit = false;
					}
			}
		});

		return okayToSubmit;
	});
	
	/* for State/Province error, clear the error state so that it 
		doesn't disrupt the visual flow when the country flag appears */
	$j(".fieldGroup.stateProvince select").change(function() {
		$j(this).removeClass("error");
		$j(this).closest(".fieldGroup").find(".errorMessage").remove();
	});
	
	/* Check for Canadian address on specific pages; trigger a smartwindow where appropriate */
	var canadaCheckoutModalUrl =  'checkoutcalink.html?vid=20100218003&checkout=y';
	var canadaAccountModalUrl = 'checkoutcalink.html?vid=20100218003';

	$j("form.canadaCheck").submit(function() {
		var okayToSubmit = true;
		if (isProvince($j(this).find(".fieldGroup.stateProvince select").val())) {
			
			// detect context and set appropriate html source for modal
			if ($j(this).hasClass("checkout")) {
				var modalSource = canadaCheckoutModalUrl;
			} else {
				// if not checkout, must be account
				var modalSource = canadaAccountModalUrl;
			}
			
			// clean up elements remaining from old calls
			$j("#canadaModal").remove();
			
			var modalContainer = $j('<div class="modal" id="canadaModal"></div>');
			$j("body").append(modalContainer);
			modalContainer.jqm(
				{
					closeClass: 'closeModal',
					modal: true,
					onLoad: centerVertical,
					ajax: modalSource
				});
			modalContainer.jqmShow();
			okayToSubmit = false;
		}
		if(okayToSubmit){
			$j(".next").each(function () {
				$j(this).attr("disabled", true);
			});
		}
		return okayToSubmit;
	});

	/* Filmstrip functionality */
	$j(".filmstripWrapper").each(function() {

		var maxVisibleCells = 4;

		if ($j(this).find(".filmstrip .item").length > maxVisibleCells) {

			var cellSize = 241; // includes right margin of slide cell
			var slideSpeed = 500;

			// Adds filmstrip navigation buttons with JavaScript, so they won't
			// exist for a user who does not have JavaScript, or doesn't have it enabled.
			// Due to beind within the length check block, they also don't get shown when
			// there aren't enough cells for a sliding effect to be relevant
			$j(this).prepend('<a class="previous" href="#" alt="Previous" title="Previous"><span>Previous</span></a>');
			$j(this).append('<a class="next" href="#" alt="Next" title="Next"><span>Next</span></a>');
			$j(this).find(".filmstripFrame").css("margin-left", "0");

			var maxVisibleOffset = maxVisibleCells - 1;
			var lastItemOffset = ($j(this).find(".filmstrip .item").length - 1);
			
			// flag what's visible within the strip frame initially
			$j(this).find(".filmstrip .item").eq(0).addClass("firstVisible");
			$j(this).find(".filmstrip .item").eq(maxVisibleOffset).addClass("lastVisible");

			$j(this).find("a.previous").click(function() {

				var itemList = $j(this).parent().find(".filmstrip .item");

				// If we're at the first cell in the list, loop the last one to prev position
				if (itemList.eq(0).hasClass("firstVisible")) {

					// quickly move the filmstrip to the left, to accomodate prepending of last item
					$j(this).parent().find(".filmstrip").animate({
						marginLeft: '-=' + cellSize
					}, 0);
					
					// now do the actual prepend, last item to first cell placing
					itemList.eq(lastItemOffset).prependTo($j(this).parent().find(".filmstrip"));
					
					// and now reset the itemList from the sequence
					itemList = $j(this).parent().find(".filmstrip .item");
				}
				
				// do the slide effect
				$j(this).parent().find(".filmstrip").animate({
					marginLeft: '+=' + cellSize
				}, slideSpeed);
				
				// move the first/last visible flags to the new positions
				oldFirstVisible = $j(this).parent().find(".filmstrip .item.firstVisible");
				oldFirstVisible.removeClass("firstVisible");
				oldFirstVisible.prev().addClass("firstVisible");
				oldLastVisible = $j(this).parent().find(".filmstrip .item.lastVisible");
				oldLastVisible.removeClass("lastVisible");
				oldLastVisible.prev().addClass("lastVisible");
				
				return false;
			});

			$j(this).find("a.next").click(function() {

				var itemList = $j(this).parent().find(".filmstrip .item");

				// If we're at the last cell in the list, loop the first one to next position
				if (itemList.eq(lastItemOffset).hasClass("lastVisible")) {

					// quickly move the filmstrip to the right, to accomodate appending of last item
					$j(this).parent().find(".filmstrip").animate({
						marginLeft: '+=' + cellSize
					}, 0);

					// now do the actual append, first item to last cell placing
					itemList.eq(0).appendTo($j(this).parent().find(".filmstrip"));
					
					// and now reset the itemList from the sequence
					itemList = $j(this).parent().find(".filmstrip .item");
				}

				// move the first/last visible flags to the new positions
				oldFirstVisible = $j(this).parent().find(".filmstrip .item.firstVisible");
				oldFirstVisible.removeClass("firstVisible");
				oldFirstVisible.next().addClass("firstVisible");
				oldLastVisible = $j(this).parent().find(".filmstrip .item.lastVisible");
				oldLastVisible.removeClass("lastVisible");
				oldLastVisible.next().addClass("lastVisible");

				$j(this).parent().find(".filmstrip").animate({
					marginLeft: '-=' + cellSize
				}, slideSpeed)

				return false;
			});
		}
	});
	
	/* Dynamic "add more lines" functionality for Quick Order */
	$j("a#addMoreLines").click(function() {
		var numToAdd = 2; // use this to define how many rows are added when user clicks
		var tableToMod = $j("table#itemEntry");
		var lastRow = $j("table#itemEntry tbody tr").last();
		var lastId = lastRow.find("input.itemNo").attr("id");
		var lastIdArray = lastId.split('-');
		var newRowNum = parseInt(lastIdArray.pop()) + 1;
		var idNumPrefix = lastIdArray.join('-');
		var quantityPrefix = lastRow.find("input.quantity").attr("id");
		quantityPrefix = quantityPrefix.split('-');
		quantityPrefix.pop();
		quantityPrefix = quantityPrefix.join('-');
		
		for (var i = 1; i <= numToAdd; i++) {
			var newRow = lastRow.clone();
			newRow.find("input.itemNo").attr("id", idNumPrefix + '-' + newRowNum);
			newRow.find("input.itemNo").attr("name", idNumPrefix + '-' + newRowNum);
			newRow.find("input.quantity").attr("id", quantityPrefix + '-' + newRowNum);
			newRow.find("input.quantity").attr("name", quantityPrefix + '-' + newRowNum);
			tableToMod.append(newRow);
			newRowNum++;
		}
		
		return false;
	});
	
});

function centerVertical(hash) {

	var currentTopOffset = $j(window).scrollTop();
	var viewportHeight = $j(window).height();
	var viewportWidth = $j(window).width();

	var newTop = currentTopOffset + ((viewportHeight / 2) - (hash.w.height() / 2));
	var newLeft = (viewportWidth / 2) - (hash.w.width() / 2);

	hash.w.css("top", newTop);
	hash.w.css("left", newLeft);

}

/* Accessible display/hide technique */
$j.fn.toggleReveal = function() {
	if ($j(this).hasClass("hidden")) {
		$j(this).removeClass("hidden");
	} else {
		$j(this).addClass("hidden");
	}
}

$j.fn.reveal = function() {
	
	// activate any fields requiring validation
	$j(this).find(".fieldGroup").each(function() {
		$j(this).removeClass("inactive");
	});
	
/*
	if ($j(this).hasClass("hidden")) {
		$j(this).removeClass("hidden");
	}
*/
	// changed above method, due to incompatibility with ie
	$j(this).show();
}

$j.fn.conceal = function() {

	// activate any fields requiring validation
	$j(this).find(".fieldGroup").each(function() {
		$j(this).addClass("inactive");
	});

//	$j(this).addClass("hidden");
// changed above method, due to incompatibility with ie
	$j(this).hide();
}

/*
	Automated inline prompting for inputs.
	Must be invoked on a <form> element.
*/
$j.fn.inlinePrompt = function() {

	/* set up some vars to work with */
	var promptValue = $j(this).find("div.prompt").html();
	var targetInput = $j(this).find("input.promptTarget");

	/*
		Set up the prompt value, using 
		what's in the hidden 'prompt'
		div
	*/
	targetInput.val(promptValue);

	/* Set up events to show/hide the prompt where appropriate */
	targetInput.focus(function() {
		if ($j(this).val() == promptValue) {
			$j(this).val("");
		}
	});
	targetInput.blur(function() {
		if ($j(this).val() == "") {
			$j(this).val(promptValue);
		}
	});
}

function isProvince(locationCodeIn) {
	var provinces = new Array("AB", "BC", "MB", "NB", "NL", "NS", "NT", "NU", "ON", "PE", "QC", "SK", "YT");
	for (var i = 0; i < provinces.length; i++) {
		if (provinces[i] == locationCodeIn || (parseInt(locationCodeIn)>=72)) {
			return true;
		}
	}
	return false;
}

function launchEnlargeModal() {
	
	// First, remove any lingering html left from a previous call to this function
	$j("#enlargeImageModal").remove();
	
	// Create html structure to contain modal
	var modalContainer = $j('<div class="modal" id="enlargeImageModal"></div>');
	$j("body").append(modalContainer);
	
	// instatiate modal functionality
	modalContainer.jqm(
		{
			closeClass: 'closeModal',
			modal: true,
			onLoad: adjustLiquidDimensions,
			toTop: true,
			ajax: "modal-source/enlarge-image.html"
		}
	);
	
	// trigger and show the modal
	modalContainer.jqmShow();
}

// Adjust modal's dimensions to user's browser viewport
function adjustLiquidDimensions (hash) {

	// get current dimensions and scroll position
	var currentTopOffset = $j(window).scrollTop();
	var viewportHeight = $j(window).height();
	var viewportWidth = $j(window).width();

	// set some defaults & measures
	var newWidth = maxWidth = 930;
	var newHeight = maxHeight = 900;
	var minWidth = 380;
	var minHeight = 600;
	var margin = 40;

	if (viewportHeight - (margin * 2) > minHeight) {
		// if there is room, we adjust height (up to max)
		if ((viewportHeight - (margin * 2)) < maxHeight) {
			newHeight = viewportHeight - (margin * 2);
		}
	} else {
		newHeight = minHeight;
	}
	
	if (viewportWidth - (margin * 2) > minWidth) {
		// if there is room, we adjust width (up to max)
		if ((viewportWidth - (margin * 2)) < maxWidth) {
			newWidth = viewportWidth - (margin * 2);
		} 
	} else {
		newWidth = minWidth;
	}

	var newObjectWidth = newWidth - 30;
	var newObjectHeight = newHeight - 50;

	// now apply new width and height;
	hash.w.css("height", newHeight);
	hash.w.find(".enlargeImageWrapper, .enlargeImage").css("height", newHeight);
	hash.w.find(".enlargeImageWrapper object").css("height", newObjectHeight);
	hash.w.css("width", newWidth);
	hash.w.find(".enlargeImageWrapper, .enlargeImage").css("width", newWidth);
	hash.w.find(".enlargeImageWrapper object").css("width", newObjectWidth);

	// now calculate values required to center it
	var newTop = currentTopOffset + ((viewportHeight / 2) - (hash.w.height() / 2));
	var newLeft = (viewportWidth / 2) - (hash.w.width() / 2);

	// and now apply values, centering the modal horizontally and vertically
	hash.w.css("top", newTop);
	hash.w.css("left", newLeft);
}

$j(document).ready(function() {
  
        $j('.onePageContentBox2').hide();
  		$j('a.showBox').click(function() {
		$j('.onePageContentBox2').fadeIn('fast');
  			 return false;
  		});
     });

function validateSignUp(emailSignUpId, frm) {
	var result = false;
	var email = document.getElementById(emailSignUpId).value;
	var emailPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))*\s*$/;
	if (email) {
		if (email=="") {
			alert("Please enter your e-mail address."); 
		} else if (!emailPattern.test(email)) {
			alert("Please enter your e-mail address correctly. Example: abc@def.com");  
		} else { 
			result = true; 
			frm.submit();
		}
	}
	return result;
}

function disableEnterKey(e, emailSignUpId, frm) {
    var key;
    if(window.event)
         key = window.event.keyCode;
    else
         key = e.which;     
    if(key == 13)
         return validateSignUp(emailSignUpId, frm);
    else
         return true;
}