﻿$(document).ready(function() {
	$("#topNavEmailSend").addClass("selectedtab");

	var popupdevideValue = 2.5;
	var hdnMessage = $("#ctl00_ContentPlaceHolder1_hdnMessage").val();
	if (hdnMessage == "1") {
		text = "Mail has been successfully sent.";
		tb_show('', '#TB_inline?inlineId=errorContent&amp;width=400&amp;height=150', null);
		$("#errMsgArea").html(text).css("color", "black");
	}

	if (hdnMessage == "2") {
		text = "Some problems are occurred to send email. Please try again...";
		tb_show('', '#TB_inline?inlineId=errorContent&amp;width=400&amp;height=150', null);
		$("#errMsgArea").html(text).css("color", "red");
	}

	hdnlocation = $('#ctl00_ContentPlaceHolder1_hdnLocation').val();
	if (hdnlocation == '')
	{ hdnlocation = "United States" }
	var map = new GMap2(document.getElementById('myMap'));
	loadGoogleMap(hdnlocation, 1, map);
	setCenter("United States", map);
	function setCenter(address, map) {
		var geocoder = new GClientGeocoder();
		geocoder.getLatLng(address,
        function(point) {
        	if (!point) {
        		alert(point)
        	} else {
        		map.setCenter(point, 1);
        	}
        });
	}
	function loadGoogleMap(address, mapsize, map) {
		var geocoder = new GClientGeocoder();
		geocoder.getLatLng(address,
                function(point) {
                	if (!point) {
                		alert(address + " not found");
                	} else {
                		map.addControl(new GSmallMapControl());
                		marker = new GMarker(point);
                		map.addOverlay(marker);
                		GEvent.addListener(marker, "mouseover", function() {
                			marker.openInfoWindowHtml(address);
                		});
                	}
                });
	}


	Sys.Application.add_load(FirejQuery);
	function FirejQuery() {

	}

	$("#ctl00_ContentPlaceHolder1_BtnRecommend").click(function() {
		return (ValidateRecommendEmail());
	});



	function ValidateRecommendEmail() {
		var IsBlank = true;
		var IsValidEmail = true;
		var text = "";
		var len = 0

		var obj = $("#recommendTable").find("input[type='text']")
		obj.each(function() {
			$("input[id=" + obj[len].id + "]").removeClass("hightlight");
			if (obj[len].value != "") {
				if (!(isValidEmailAddress(obj[len].value))) {
					text = "Please enter valid email address.";
					$("#ctl00_ContentPlaceHolder1_lblSendMail").addClass("errMsg")
					$("input[id=" + obj[len].id + "]").addClass("hightlight");
					IsValidEmail = false;
					IsBlank = false;
				}
				else {
					text = "";
					$("input[id=" + obj[len].id + "]").removeClass("hightlight");
					IsBlank = false;
				}
			}
			else {
				if (IsBlank)
					IsBlank = true;
			}
			len++;
		});

		if (!IsValidEmail) {
			if (text == "") {
				text = "Mandatory information missing. Please, enter your email address and press send email button."

			}
			tb_show('', '#TB_inline?inlineId=errorContent&amp;width=400&amp;height=150', null);
			$("#errMsgArea").html(text).css("color", "red");
			return false;
		}
		else if (IsBlank) {
			if (text == "") {
				text = "Mandatory information missing. Please, enter your email address and press send email button."

			}
			$("input[id=" + obj[0].id + "]").addClass("hightlight")
			tb_show('', '#TB_inline?inlineId=errorContent&amp;width=400&amp;height=150', null);
			$("#errMsgArea").html(text).css("color", "red");
			return false;
		}
		else {

			$("#ctl00_ContentPlaceHolder1_msgBox").css("display", "block");
			return true;
		}
	}

	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	}
});


var b_version = navigator.appVersion;
if (b_version.indexOf("MSIE 6.0") >= 0) {
    document.write('<link href="css/recommendation_ie6.css" rel="stylesheet" type="text/css" media="all">');
}
else {
    document.write('<link href="css/recommendation.css" rel="stylesheet" type="text/css">');

}
