var HasW3CDOM = (document.createElement != null && document.getElementsByTagName != null);
var retval;

window.onload = CommonLoad;

function CommonLoad() {
	if (!HasW3CDOM) return;
	
	try {
	  document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {
		//Do Nothing
	}
	
	HandleCommon();
	HandleGiftSelections();
	HandleMembershipLevels(); //For - /DonationArea/JoinAnnualFund.aspx
	HandleTributeCardPage();
	HandleTreeOfLifePage();
	HandleYahrzeitPage();
	
	try {
		HandleDynamicJS();
	} catch(e) {
		//Do Nothing
	}
	
	try {
		mcds_HebrewYearChanged();
		mcds_HebrewMonthChanged();
	} catch(e) {
		//Do Nothing
	}
}
function HandleCommon() {
	HandleNewWindowLinks();
	HandlePopupDiv();
	HandleSameAsBilling();
}

function HandleNewWindowLinks() {
	var strTemp = new String;
	var arrLinks = window.document.getElementsByTagName("a");
	
	for (var i = 0; i < arrLinks.length; i++) {
		if (arrLinks[i].className != null) {
			if (arrLinks[i].className.match(/js_NewWindow/)) {
				//Save [href] before replaceing [onclick] or [href] will return [null]
				strTemp = arrLinks[i].href;
				
				arrLinks[i].onclick = function() {
					window.open(strTemp, "");
					
					return false;
				};
			}
		}
	}
}

function HandlePopupDiv() {
	if (window.document.getElementById("PopupDiv") != null && window.document.getElementById("CaptionBar_Close") != null) {
		window.document.getElementById("CaptionBar_Close").onmouseover = function() {this.className = 'Close_Hover';};
		window.document.getElementById("CaptionBar_Close").onmouseup = function() {this.className = 'Close';};
		window.document.getElementById("CaptionBar_Close").onmouseout = function() {this.className = 'Close';};
		window.document.getElementById("CaptionBar_Close").onmousedown = function() {this.className = 'Close_Active';};
		window.document.getElementById("CaptionBar_Close").onclick = function() {TogglePopupDisplay(this, 'PopupDiv', '', 0, 0);};
		
		//Drag.init([Handle], [Root]);
		Drag.init(window.document.getElementById("CaptionBar"), window.document.getElementById("PopupDiv"));
	}
}

function ShowPopupImage(url, imageWidth, imageHeight) {
	window.document.getElementById('PopupImage').src = "/images/1pxclear.gif";
	window.document.getElementById('PopupImage').style.width = imageWidth + "px";
	window.document.getElementById('PopupImage').style.height = imageHeight + "px";
	window.document.getElementById('PopupImage').src = url;
	TogglePopupDisplay(this, 'PopupDiv', 'center', 0, 0, 500, 500);
}

function HandleSameAsBilling() {
	if (window.document.getElementById("Shipping_SameAsBilling") != null) {
		window.document.getElementById("Shipping_SameAsBilling").onclick = function() {
			if (window.document.getElementById("ShippingTable") != null) {
				if (this.checked) {
					ElementHideState(window.document.getElementById("ShippingTable"), true);
				} else {
					ElementHideState(window.document.getElementById("ShippingTable"), false);
				}
			}
		};
		
		window.document.getElementById("Shipping_SameAsBilling").onkeypress = window.document.getElementById("Shipping_SameAsBilling").onclick;
		
		window.document.getElementById("Shipping_SameAsBilling").onclick();
	}
}

function HandleGiftSelections() {
	if (window.document.getElementById("GiftSelections") != null) {
		var arrElements = window.document.getElementById("GiftSelections").getElementsByTagName("input");
		
		for (var i = 0; i < arrElements.length; i++) {
			if (arrElements[i].type == "button") {
				if (arrElements[i].id.match(/^btnAddToOrder/)) {
					arrElements[i].onclick = function() {
						if (window.document.getElementById("GiftSelected") != null) {
							window.document.getElementById("GiftSelected").value = this.id.substr(this.id.lastIndexOf("_") + 1, this.id.length - this.id.lastIndexOf("_") + 1);
						}
						
						if (window.document.getElementById("GiftPackSelected") != null) {
							window.document.getElementById("GiftPackSelected").value = "";
						}
						
						this.form.submit();
					};
				} else if (arrElements[i].id.match(/^btnAddPackToOrder/)) {
					arrElements[i].onclick = function() {
						if (window.document.getElementById("GiftSelected") != null) {
							window.document.getElementById("GiftSelected").value = "";
						}
						
						if (window.document.getElementById("GiftPackSelected") != null) {
							window.document.getElementById("GiftPackSelected").value = this.id.substr(this.id.lastIndexOf("_") + 1, this.id.length - this.id.lastIndexOf("_") + 1);
						}
						
						this.form.submit();
					};
				}
			}
		}
	}
}

//START - /DonationArea/JoinAnnualFund.aspx
function HandleMembershipLevels() {
	if (window.document.getElementById("MembershipLevels") != null && window.document.getElementById("MemberInformationSection") != null) {
		var objFunctions = new JoinAnnualFundPageFunctions;
		var arrElements = window.document.getElementById("MembershipLevels").getElementsByTagName("input");
		
		for (var i = 0; i < arrElements.length; i++) {
			if (arrElements[i].name == "MembershipLevel") {
				if (arrElements[i].checked) {
					if (arrElements[i].id != "MembershipLevel_None") {
						window.document.getElementById("MemberInformationSection").style.display = "";
					}
				}
				
				arrElements[i].onclick = objFunctions.MembershipLevelChanged;
				arrElements[i].onkeypress = objFunctions.MembershipLevelChanged;
			}
		}
	}
}

function JoinAnnualFundPageFunctions() {
	this.MembershipLevelChanged = function() {
		if (window.document.getElementById("MembershipLevel_None") != null && window.document.getElementById("MemberInformationSection") != null) {
			if (window.document.getElementById("MembershipLevel_None").checked) {
				window.document.getElementById("MemberInformationSection").style.display = "none";
			} else {
				window.document.getElementById("MemberInformationSection").style.display = "";
			}
		}
	}
}
//STOP - /DonationArea/JoinAnnualFund.aspx

//START - /DonationArea/TributeCard.aspx, /DonationArea/TreeOfLifePlaque.aspx
function HandleTributeCardPage() {
	if (window.document.getElementById("AddressUnknown") != null) {
		window.document.getElementById("AddressUnknown").onclick = function() {
			if (window.document.getElementById("AddressSection") != null) {
				if (this.checked) {
					ElementHideState(window.document.getElementById("AddressSection"), true);
				} else {
					ElementHideState(window.document.getElementById("AddressSection"), false);
				}
			}
		};
		
		window.document.getElementById("AddressUnknown").onkeypress = window.document.getElementById("AddressUnknown").onclick;
		
		window.document.getElementById("AddressUnknown").onclick();
	}
	
	if (window.document.getElementById("Inscription_Occasion") != null) {
		window.document.getElementById("Inscription_Occasion").onchange = function() {
			if (window.document.getElementById("Inscription_Occasion_Other_Section") != null) {
				if (this.value == "Other") {
					ElementHideState(window.document.getElementById("Inscription_Occasion_Other_Section"), false);
				} else {
					ElementHideState(window.document.getElementById("Inscription_Occasion_Other_Section"), true);
				}
			}
		};
		
		window.document.getElementById("Inscription_Occasion").onchange();
	}
	
	if (window.document.getElementById("TributeCardSample") != null) {
		window.document.getElementById("TributeCardSample").onclick = function() {TogglePopupDisplay(window.document.getElementById("Inscription_Type_InMemoryOf"), 'PopupDiv', 'down', -313, -6, 300, 300); return false;};
	}
	
	if (window.document.getElementById("TreeOfLifePlaqueSample") != null) {
		window.document.getElementById("TreeOfLifePlaqueSample").onclick = function() {TogglePopupDisplay(this, 'PopupDiv', 'center', 0, 0, 300, 300); return false;};
	}
}
//STOP - /DonationArea/TributeCard.aspx, /DonationArea/TreeOfLifePlaque.aspx

//START - /DonationArea/TreeOfLife.aspx
function HandleTreeOfLifePage() {
	if (window.document.getElementById("TreeOfLifePlaquePopup_Tree_1") != null) {
		window.document.getElementById("TreeOfLifePlaquePopup_Tree_1").onclick = function() {
			ShowPopupImage('/images/TreeOfLife_Large.gif', 598, 386);
			return false;
		};
		
		if (window.document.getElementById("TreeOfLifePlaquePopup_Tree_2") != null) {
			window.document.getElementById("TreeOfLifePlaquePopup_Tree_2").onclick = function() {
				window.document.getElementById("TreeOfLifePlaquePopup_Tree_1").onclick();
				return false;
			};
		}
	}
}
//STOP - /DonationArea/TreeOfLife.aspx

//START - /DonationArea/Yahrzeit.aspx
function HandleYahrzeitPage() {
	if (window.document.getElementById("Additional_SendReminder") != null) {
		window.document.getElementById("Additional_SendReminder").onclick = function() {
			if (window.document.getElementById("DODSection") != null) {
				if (this.checked) {
					ElementHideState(window.document.getElementById("DODSection"), false);
				} else {
					ElementHideState(window.document.getElementById("DODSection"), true);
				}
			}
		};
		
		window.document.getElementById("Additional_SendReminder").onkeypress = window.document.getElementById("Additional_SendReminder").onclick;
		
		window.document.getElementById("Additional_SendReminder").onclick();
	}
}
//STOP - /DonationArea/Yahrzeit.aspx

function sm(loc) {
    var vReturnValue;
    
    vReturnValue  = window.showModalDialog('/donationarea/cf_agreement.aspx?loc=' + loc,null,'status:no;dialogWidth:370px;dialogHeight:190px;dialogHide:true;help:no;scroll:no');

    if(vReturnValue != null)
    {
       //__doPostBack('#1','');
       //alert(vReturnValue);
       //return vReturnValue 
       location.href = vReturnValue;   
       return true;
    }
}

function cfWin() {
	var positionX = (screen.width - 180) / 2;
	var positionY = (screen.height - 180) / 2;	
	
    winP = window.open("conveniencefees.aspx","fees","top=" + positionY + ", left=" + positionX + ", width=180,height=300,scrollbars=1,resizable=0");
    winP.focus();
}