
// Custom jQuery functions
$.fn.exists = function(){return this.length>0;}
//
var EmailPat = /^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
var PhonePat = /^\D*\d{3}\D*\d{3}\D*\d{4}\D*$/;
var ZipPat = /^\d{5}([\-]\d{4})?$/;

function isValidZipCode(value) {
   return value.match(ZipPat);
}
function isValidEmail(value){
	return value.match(EmailPat);
}
function isValidPhone(value){
	return value.match(PhonePat);
}

function loadDialog(ttl, html) {
	$('#UIModalContent').dialog('destroy').html(html).dialog({
		title: ttl, modal: true, width: 450, height:300, resizable: false,
		buttons:{"Close": function() { $(this).dialog("close"); }},
		open: function(event, ui) {
			$(this).parent().css("left",($(window).width()-$(this).width())/2+"px");
			$(this).parent().css("top",($(window).height()-$(this).height())/2-50+"px");
			$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
		},
		dragStop: function(event, ui){
			$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
		}
	});
}

function loadBlockDialog(ttl, html) {
	$('#UIModalContent').dialog('destroy').html(html).dialog({
		title: ttl, modal: true, width: 450, height:300, resizable: false, closeOnEscape: false,
		open: function(event, ui) {
			$(this).parent().children().children('.ui-dialog-titlebar-close').hide(); 
			$(this).parent().css("left",($(window).width()-$(this).width())/2+"px");
			$(this).parent().css("top",($(window).height()-$(this).height())/2-50+"px");
			$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
		},
		dragStop: function(event, ui){
			$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
		}
	});
}

function ajax(argurl, div, functionName) {
	$.ajax({
		url:argurl,
		cache:false,
		success: function(data){
			$('#'+div).html(data);
			if (functionName) {
				eval(functionName+"(data)");	
			}
		}
	})
}

function getCheckedValue(myOption) {
	myValue = $("input[name='"+myOption+"']:checked").val();
	if (myValue == undefined) {
		return "";	
	} else {
		return myValue;
	}
}

var currentBanner = "banner_1"
function swapBanner(bannerID){
	if (bannerID != currentBanner) {
		var $active = $('#'+currentBanner);
		var $next = $('#'+bannerID);
		currentBanner = bannerID;
		$active.fadeOut(600);
		$next.fadeIn(600, function(){
			$active.removeClass('active');
			$next.addClass('active');
		});
	}
}

