/*
    Copyright (c) 2005-2011 thankyou.com.au pty ltd
	All Rights Reserved
*/
$j(document).ready(function() {
	
	pausecomp = function(millis) {
		var date = new Date();
		var curDate = null;
		
		do { curDate = new Date(); } 
		while(curDate-date < millis);
	};
	
	activateLightWindow = function (width, height, content, title, showCloseButton, contentType, hideOnOverlayClick, enableEscapeButton, delay) {
		if (delay == null) {
			delay = 0;
		}
		$j.fancybox({
			href					: content,
			type					: contentType,
        	autoDimensions			: false,
			width         			: width,
			height        			: height,
			showCloseButton			: showCloseButton,
			title					: title,
			titlePosition			: 'over',
			padding					: 10,
			margin					: 10,
			centerOnScroll			: true,
			overlayOpacity			: 0.7,
			overlayColor			: '#333',
			hideOnOverlayClick		: hideOnOverlayClick,
			speedIn					: 200,
			speedOut				: 200,
			enableEscapeButton		: enableEscapeButton,
			onStart					: pausecomp(delay)
		});
	};
	
	closeLightBox = function () {
		$j.fancybox.close();
	};
});

/* LightWindow */
function activateLightWindow_old(width,height,content,title,overlayClose) {
	if (overlayClose == undefined) {
		overlay = false;
	}
	else {
		overlay = overlayClose;
	}
	myLightWindow.activateWindow({
		href: content, 
		title: title,
		width: width,
		height : height,
		overlayClose : overlay
	});
}
/* end LightWindow */
/* FAQs */
function selectFAQItem(the_id, the_panel) {
	fe = document.getElementById(the_id + "-faq");
	pe = document.getElementById(the_panel);
	if (fe.style.display == "none") {
		// hide all items
		l=pe.getElementsByTagName('div');
		c=[];
		for(i=0;i<l.length;i++){
			h=l[i].id;
			if(h.substr(h.indexOf('-')+1,h.length)=='faq') {
				c.push(h);
				document.getElementById(h).style.display = 'none';
			}
		}
		// show this item
		fe.style.display = "block";
		// adjust height of accordion panel
		ex1(pe, fe.offsetHeight);
	}
	setTimeout('window.scrollBy(0,680)', 500);
	// scroll to bottom of page
	//window.scrollTo(0,99999999999);
}
function selectEvent(the_id) {
	document.getElementById("event_id").value = the_id;
}

function changeSort(webroot, the_table, sort_code, display_type) {
	switch (the_table) {
		case "telegrams":
			location.href = webroot + 'oo/oo.cfm?page=messages&sort=' + sort_code;
			break;
		case "gifts":
			location.href = webroot + 'guest/guest.cfm?page=gift&sort=' + sort_code;
			break;
		case "manage":
			location.href = webroot + 'oo/oo.cfm?page=manage&sort=' + sort_code + '&display=' + display_type;
			break;
		case "contrib":
			location.href = webroot + 'oo/oo.cfm?page=contribution&sort=' + sort_code + '&display=' + display_type + '#sectiontop';
			break;
		case "rsvp":
			location.href = webroot + 'oo/oo.cfm?page=messages&panel=rsvp&rsvp_sort=' + sort_code;
			break;
	}
}

function confirmDeleteItem(webroot, check_id, item_id) {
	if (confirm("Are you sure you want to delete this item from your Gift Registry?\n\nAny Guest or purchase details associated with this item will also be deleted.")) {
		location.href = webroot + 'oo/a_deleteitem.cfm?check_id=' + check_id + '&item_id=' + item_id;
	}
}

function purchaseItem(the_id) {
	window.open('p_purchaseitem.cfm?the_id=' + the_id, 'purchaseitem','width=500,height=450,top=50,left=50');
}

function switchDisplay(webroot, display_type) {
	location.href = webroot + 'oo/oo.cfm?page=manage&display=' + display_type;
}

function submitPayment(the_btn) {
	document.getElementById(the_btn.id).disabled = "disabled";
	document.getElementById("paymentForm").submit();
}

function comingSoon() {
	alert("Service Coming Soon!");
}

function disableEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		return false;
	}
}

function prepareArgs() {
	oArgs = new Object();
	for(i=0;i<arguments.length;i=i+2) {
		eval("oArgs." + arguments[i] + " = \"" +	(arguments[i+1].toString()) + "\";");
	}
	return oArgs;
}

function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function confirmDeleteTelegram(webroot, check_id, telegram_id, the_name) {
	if (confirm("Are you sure you want to delete the telegram from " + the_name + "?")) {
		location.href = webroot + 'oo/a_deletetelegram.cfm?check_id=' + check_id + '&telegram_id=' + telegram_id;
	}
}

function overlay() {
	e1 = document.getElementById("overlay");
	e1.style.visibility = (e1.style.visibility == "visible") ? "hidden" : "visible";
}
function showDemoAlert() {
	alert('You cannot perform this function from the demo site.\nTo return to the previous screen click OK.');
}
function swapImage(o, newsrc) {
	o.src = newsrc;
}
function confirmDeleteRSVP(webroot, check_id, rsvp_id, the_name) {
	if (confirm("Are you sure you want to delete the RSVP from " + the_name + "?")) {
		location.href = webroot + 'oo/a_deletersvp.cfm?check_id=' + check_id + '&rsvp_id=' + rsvp_id;
	}
}
function switchRSVPDisplay(webroot, display_type) {
	location.href = webroot + 'oo/oo.cfm?page=messages&panel=rsvp&rsvp_display=' + display_type;
}
