
// 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 validateNumeric(number) {
	return !isNaN(parseFloat(number)) && isFinite(number);
}

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 applyFancyBox() {
	$("a.imgbox").fancybox({
		'padding': 5,
		'imageScale': false,
		'frameWidth': 740,
		'frameHeight': 400,
		'zoomOpacity' : false,
		'zoomSpeedIn': 600,
		'zoomSpeedOut': 400,
		'zoomSpeedChange' : 400,
		'easingIn' : 'swing',
		'easingOut' : 'swing',
		'easingChange' : 'swing',
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'overlayShow' : true,
		'overlayOpacity' : 0.9,
		'overlayColor' : '#000000',
		'enableEscapeButton' : true,
		'showCloseButton' : true,
		'hideOnOverlayClick' : true,
		'hideOnContentClick' : false,
		'centerOnScroll' : true,
		'showNavArrows' : true, 
		'titlePosition' : 'outside'
	});
	$("a.vidbox").fancybox({
		'padding': 0,
		'autoScale': false,
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'width' : 420,
		'height' : 320,
		'hideOnOverlayClick' : true,
		'hideOnContentClick' : false,
		'overlayOpacity' : 0.9,
		'overlayColor' : '#000000',
		'titlePosition' : 'outside',
		'showCloseButton' : true,
		'showNavArrows' : true, 
		'type' : 'swf',
		'swf' : {
			'wmode' : 'transparent',
			'background-color' : 'red',
			'allowfullscreen' : 'true'
		}
	});
	$("a.audbox").fancybox({
		'padding': 0,
		'autoScale': false,
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'width' : 420,
		'height' : 150,
		'hideOnOverlayClick' : true,
		'hideOnContentClick' : false,
		'overlayOpacity' : 0.9,
		'overlayColor' : '#000000',
		'titlePosition' : 'outside',
		'showCloseButton' : true,
		'showNavArrows' : true, 
		'type' : 'swf',
		'swf' : {
			'wmode' : 'transparent',
			'background-color' : 'red',
			'allowfullscreen' : 'true'
		}
	});
}

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');
		});
	}
}

