
function IsValidEmail(val) {
	var iLen = val.length;
	if 	((iLen < 6) || (val.indexOf('@') < 1) || ((val.charAt(iLen - 3) != '.') && (val.charAt(iLen - 4) != '.')) ) return false
	return true
}
/***************************************************************
	Form Validation: general
***************************************************************/
function formVal(){
	var msg = "";
	var typeList = "text,password,select-one,textarea";
	if (arguments.length > 0)  {
		var curForm = eval("document.forms[arguments[0]]");
	} else {
		var curForm = document.forms["form"];
	}
	for (var i=0; i<curForm.elements.length; i++){
		tag = curForm.elements[i];
		if (typeList.indexOf(tag.type) >= 0 && tag.getAttribute('required') == 1 && tag.value == "") {
			msg = msg + "<li>" + tag.title + "</li>";
		};
		 
		if (tag.type == "text" && tag.name.search(/[eE]mail/) > -1 && tag.value.length != 0) {  
	//	if (tag.name.indexOf("email") > -1 && tag.value.length != 0) {
			flag = IsValidEmail(tag.value);
			if (!flag) {
				msg = msg + "<li>" + tag.title + ": invalid email address</li>";
			}
		};
		if (tag.type == "password" && tag.value.length > 0  && tag.value.length < 4) {
			msg = msg + "<li>" + "Password is too short: four-character minimum" + "</li>";
		}
		if (tag.name == "password2" 
			&& (tag.value != "")
			&& (tag.value != document.getElementById('password').value))
			msg = msg + "<li>" + "Password confirmation" + "</li>";
	};
	if (msg != "") {
		document.getElementById('err').innerHTML = "These fields are required: <ul>" + msg + "</ul>";
		window.scrollTo(0,0); 
		return false;
	} else {
		return true;
	}
}

// reset password validation
function formValPasswords() {
	var msg = "";
	var curForm = document.forms["reset"];
	for (var i = 0; i < curForm.elements.length; i++) {
		tag = curForm.elements[i];
		if (tag.getAttribute("required") == 1 && tag.value == "") {
			msg = msg + "<li>" + tag.title + "</li>";  
		} else if (tag.value.length > 0  && tag.value.length < 4) {
			msg = msg + "<li>Password is too short: four-character minimum</li>";
		}
	}
	if (msg == "" && curForm.elements["newPword"].value != curForm.elements["newPword2"].value) {
		msg = "<ul><li>Please confirm new password</li></ul>";
	} else if (msg != "") {
		msg = "These fields are required: <ul>" + msg + "</ul>";
	}
	if (msg != "") {
		document.getElementById("err").innerHTML = msg;
		return false;
	} else {
		return true;
	}
}
function Search() {
	var curForm = document.forms["siteSearch"]; 
	if (curForm.keyword.value == 'Search' || curForm.keyword.value == 'search') {
		curForm.keyword.value = "";
	}
}
/***************************************************************
	Country & State reset
	2007.2.12, Ye Wang - differs from the national site!!!
***************************************************************/
usaID = 215;	
function resetState(obj) {
	countryObj = obj;
	var stateObj = document.getElementById("state");
	var stateLabel = document.getElementById("stateLabel");
	var provinceObj = document.getElementById("province"); 
	var provinceLabel = document.getElementById("provinceLabel");

	var stateRow = document.getElementById("stateDIV");
	var provinceRow = document.getElementById("provinceDIV");
	 
	if (countryObj.value != usaID) {
		provinceObj.setAttribute("required", "1"); 
		provinceObj.removeAttribute("disabled");
		//provinceLabel.setAttribute("className", "label-required");
		provinceLabel.className = "label-required";
		provinceLabel.innerHTML = "Province: ";
		//stateLabel.setAttribute("class", "label");
		stateLabel.className = "label";
		stateObj.setAttribute("required", "0"); 
		stateObj.setAttribute("disabled", "disabled");
		/*
		stateRow.style.display = "none";
		provinceRow.style.display = "";
		*/
	} else { 
		provinceObj.setAttribute("required", "0");
		provinceObj.setAttribute("disabled", "disabled"); 
		//provinceLabel.setAttribute("className", "label");
		provinceLabel.className = "label";
		//provinceLabel.innerHTML = "";
		stateObj.setAttribute("required", "1");
		stateObj.removeAttribute("disabled");
		//stateLabel.setAttribute("class", "label-required");
		stateLabel.className = "label-required";
		stateLabel.innerHTML = "State: ";
		
		/*
		stateRow.style.display = "";
		provinceRow.style.display = "none";		
		*/
	} 
}
function resetCountry(obj) {
	stateObj = obj;
	countryObj = document.getElementById("country");
	if (obj.selectedIndex != 0) {
		countryObj.value = usaID;
	}
}
/***************************************************************
	END OF Country & State reset
***************************************************************/

/***************************************************************
	END OF FORM VALIDATION: GENERAL
***************************************************************/

/***************************************************************
	2007.12.3, Ye Wang: global function
	- Print-Friendly;
	- Email page 
***************************************************************/
function Print() {
	var urls = window.location.href;
	var flagStr = "ispf=0";
	var printStr = "ispf=1"; 
	urls = urls.replace(/[&]*ispf=[^&]/gim, "");
	if (urls.indexOf("?") < 0) {
		urls = urls + "?" + printStr;
	} else {
		urls = urls + "&" + printStr;
	}
	WinPrint = window.open(urls, "", "width=600,height=500,toolbar=no,resizable=yes,scrollbars=yes,location=no");
}
function Load() {
	if (window.location.href.indexOf("ispf=1") != -1) {
		setTimeout("window.print()", 500);
	}
}
function Email() {
/*
	var urls = "pop_email.cfm?urls=" + window.location.href;
	WinEmail = window.open(urls, "", "width=440,height=400,toolbar=no,resizable=no,scrollbars=yes,location=no");
*/
	var contentTitle = document.title; 
	webroot = window.location.href; 
	if (webroot.indexOf("www/") > 0) {
		webroot = webroot.substring(0, webroot.indexOf("www/")+4);
	} else if (webroot.indexOf("com/") > 0) {
		webroot = webroot.substring(0, webroot.indexOf("com/")+4);
	};
	urls = webroot + "pop_email.cfm?urls=" + window.location.href + "&contentTitle=" + contentTitle;
	WinEmail = window.open(urls, "", "width=440,height=400,toolbar=no,resizable=no,scrollbars=yes,location=no");
}
function Share() {
	alert("Coming Soon!");
}
/***************************************************************
	END OF GLOBAL PRINTBANNAR FUNCTIONS
***************************************************************/


function toggle(id) { 
	curDIV = document.getElementById(id);
	if (curDIV.style.display == "") {
		curDIV.style.display = "none";
	} else {
		curDIV.style.display = "";
	} 
}



/***************************************************************
	2009.7.7, Ye Wang: dynamically set image captions 
***************************************************************/ 
/*
function setImageCaption(obj) { 
	$(obj).each(function() {  	
		imgWidth = $(this).width(); 
		imgFloat = $(this).css("float");
		if (imgFloat == "none") {
			imgFloat = "center";
		} 
		$(this).css({margin: 0}).wrap("<div class=\"caption-" + imgFloat + "\"></div>");
		$(this).parent("div[className^=caption]")
					.css({ width: imgWidth })
					.hover( function() {$(this).addClass("on")}, function() {$(this).removeClass("on")} );		// IE; 
		imgCaption = $(this).attr("title");
		if ($(this).attr("large")) {
			$(this).attr("title", "Click to see large image");
			imgCaption = imgCaption + " <a href=\"" + $(this).attr("large") + "\" onclick=\"openImage('" + $(this).attr("large") + "');return false;\" title=\"Click to see large image\">Large Image</a>"; 
		} 
		if (imgCaption != "") 
			$(this).after("<div style=\"width:" + eval(imgWidth-5) + "px;\">" + imgCaption + "</div>");
		if ($(this).attr("large"))
			$(this).wrap("<a href=\"" + $(this).attr("large") + "\" onclick=\"openImage('" + $(this).attr("large") + "');return false;\" title=\"Click to see large image\"></a>");
	}); 	
}  
*/
function setImageCaption() {    
	if (arguments.length == 0) {
		obj = "#contentBody p img,#contentBody div img";
	} else {
		obj = arguments[0];
	}
	  
	var maxWidth = 0;
	
	$(obj).each(function() {   
		imgWidth = $(this).width(); 
		imgFloat = $(this).css("float");
		imgCaption = $(this).attr("title"); 
		if (imgFloat == "none") imgFloat = "center";
 		
		if (this.tagName == "IMG") {    
			if ($(this).parents("div[class^=image]").length) {
				imgFloat = $(this).parents("div[class^=image]").css("float"); 
				$(this).parents("div[class^=image]").removeClass().addClass("caption-" + imgFloat);
			} else if ($(this).parents("div[class^=caption]").length == 0) {
				$(this).css({margin: 0}).wrap("<div class=\"caption-" + imgFloat + "\"></div>");
			}  
		 	var $curParent = $(this).parents("div[className^=caption]");
			 
			// reset width: 
			if (maxWidth < imgWidth) {
				maxWidth = imgWidth;
				$curParent.css({width: maxWidth});
			} 
			
			// border
		 	if ($(this).attr("border") === 0) $curParent.css({border: 0});
		 
		 	// large image popup: 
			if ($(this).attr("large")) {
				$(this).attr("title", "Click to see large image");
				imgCaption = imgCaption + " <a href=\"" + $(this).attr("large") + "\" onclick=\"openImage('" + $(this).attr("large") + "');return false;\" title=\"Click to see large image\">Large Image</a>"; 
			}  
			// caption: 
			if (imgCaption != "") {
				$(this).after("<div style=\"width:" + eval(imgWidth-5) + "px;\">" + imgCaption + "</div>");
				
				// reset caption alignment:
				if ($(this).attr("captionalign") == "center") 
					$("~ div", this).css("text-align", "center");  
			
				// large image popup on image:
				if ($(this).attr("large")) {
					$(this).wrap("<a href=\"" + $(this).attr("large") + "\" onclick=\"openImage('" + $(this).attr("large") + "');return false;\" title=\"Click to see large image\"></a>");
	
			 		// IE: mouseover highlight
					$curParent.hover( function() {$(this).addClass("on")}, function() {$(this).removeClass("on")} );	
				} 			
			} 
		}  
	}); 	
}  
 
function openImage(img) {
	photoWin = window.open("", "", "status=yes,toolbar=no,menubar=no,location=no,resizable=yes,height=300,width=400");
	photoWin.document.write("<html><title>Sadlier Religion :: Large Image</title>");
	photoWin.document.write("<style>body { margin: 0; text-align:center; vertical-align: middle; background-color:black; color:white; font: 10px Tahoma, Verdana; line-height:1.5em} img{border:0; margin:auto; margin-bottom:0.5em; vertical-align:middle} a{color:white;}</style>");
	photoWin.document.write("<script language=\"JavaScript\" src=\"../inc_site/js/jquery.min.js\" type=\"text/javascript\"></script>");
	photoWin.document.write("</head>");
	photoWin.document.write("<body><img src=\"" + img + "\" id=\"photo\" /><br />[ <a href=\"javascript:window.close()\">Close</a> ]");
	photoWin.document.write("<script>resize();");
	photoWin.document.write("function resize() { curPhoto = document.getElementById('photo'); ");
	photoWin.document.write("x = curPhoto.width + 11; ");
	photoWin.document.write("y = curPhoto.height + 110; ");
	if (jQuery.browser.safari == false) photoWin.document.write("window.resizeTo(x, y);");
	photoWin.document.write("window.focus(); }"); 
	photoWin.document.write("</body></html>");
}
/***************************************************************
	END OF DYNAMICALLY SET IMAGE CAPTIONS 
***************************************************************/ 