﻿$(document).ready(function() {
	$(window).resize(function() {
		centerPopup();
	});
});
function flashSDWAF() {
	centerPopup();
	loadPopup();
}
function loadpage() {
	window.location = window.location;
}
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
//loading popup with jQuery magic!
function loadPopup() {
	//loads popup only if it is disabled
	if (popupStatus == 0) {
		$(".backgroundPopup").css({
			"opacity": "0.7"
		});
		$(".backgroundPopup").fadeIn("slow");
		$(".popupContact").fadeIn("slow");
		popupStatus = 1;
		if ($(".select-size").val() != "") {
			$(".select-size").val("");
			$(":checkbox").attr("checked", "");
			$("#ctl00_ShareDesignControl_ddlCountry:selected").text("");
		}
		$("span[style]").hide();
		$("#ctl00_ShareDesignControl_CurrentWindowLocation").val(window.location);
	}
}
//disabling popup with jQuery magic!
function disablePopup() {
	//disables popup only if it is enabled
	if (popupStatus == 1) {
		$(".backgroundPopup").fadeOut("slow");
		$(".popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}
//centering popup
function centerPopup() {
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(".popupContact").height();
	var popupWidth = $(".popupContact").width();
	var top = windowHeight/2 - (popupHeight/2);
	var left = windowWidth/2 - popupWidth/2;
	//centering
	$(".popupContact").css({
		"position": "absolute",
		"top": parseInt(top),
		"left": parseInt(left)
	});
	//only need force for IE6
	$(".backgroundPopup").css({
		"height": $(document).height(),
		"width":$(document).width(),
		"top": "0",
		position:'absolute'
	});
}
function chkEmail(source, args) {
	var isValid = true;
	if ($("#ctl00_ShareDesignControl_tbReceiverEmailAddress").length > 0) {
		var CommaSep = $("#ctl00_ShareDesignControl_tbReceiverEmailAddress").val();
		if (CommaSep.indexOf(",") > -1) {
			var wordArray = CommaSep.split(',');
			$.each(wordArray, function() {
				isValid = isValid && ValidateEmail(this);
			});
			if (wordArray.Length > 5) {
				var multitxt = $("#multifld").val(); ;
				$("#ctl00_ShareDesignControl_MultipleEmailValidator").text(multitxt);
				args.IsValid = false;
				return;
			}
		} else {
			isValid = ValidateEmail(CommaSep)
		}
	}
	if (!isValid) {
		var invalidtxt = $("#invalidfld").val();
		$("#ctl00_ShareDesignControl_MultipleEmailValidator").text(invalidtxt);
		args.IsValid = false;
		return;
	} else {
		$("#ctl00_ShareDesignControl_MultipleEmailValidator").text("");
		args.IsValid = true;
		return;
	}
}
function ValidateEmail(email) {
	var regexp = /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z][ \t]*?$/
	return (email.indexOf(".") > 2) && (email.indexOf("@") > 0) && (regexp.test(email)) && (email.indexOf(".") < parseInt(email.length) - 2);
}
