//utils.js
function confirm(msg,callback) {
  $('#confirm')
    .jqmShow()
    .find('p.jqmConfirmMsg')
      .html(msg)
    .end()
    .find(':submit:visible')
      .click(function(){
        if(this.value == 'yes')
          (typeof callback == 'string') ?
            window.location.href = callback :
            callback();
        $('#confirm').jqmHide();
      });
}
$(document).ready(function(){
	
	if ( $("div.authentication").length > 0 ) {
		$('div.authentication').load($("#widgetAuthenticationLoader").attr("class"),function() {;
			if ( $("#dialog").length > 0 ) {
				$('#dialog').jqm({overlay: 93,modal: true, trigger: false}).jqmShow();
			}
		});
	} else {
		if($("#widgetAuthenticationLoader").length > 0) {
			$("#widgetAuthenticationLoader").fadeOut(2500);
		}	
	}
	if ( $("div.widgetLoaderControl").length > 0 ) {
		$('div.widgetLoaderControl').load($("#widgetLoader").attr("class"));
	} else {
		if($("#widgetLoader").length > 0) {
			$("#widgetLoader").fadeOut(2500);
		}	
	}
	if ( $("div.subscriptionLoader").length > 0 ) {
		$('div.subscriptionLoader').replaceWith("<iframe scrolling='no' frameborder='0' width='500px' height='350px' src='" + $("#widgetSubscriptionLoader").attr("class") + "'></iframe>");		
	} else {
		if($("#widgetSubscriptionLoader").length > 0) {
			$("#widgetSubscriptionLoader").fadeOut(2500);
		}	
	}
	if ( $("div.unSubscriptionLoader").length > 0 ) {
		$('div.unSubscriptionLoader').replaceWith("<iframe scrolling='no' frameborder='0' width='500px' height='225px' src='" + $("#widgetUnSubscriptionLoader").attr("class") + "'></iframe>");
	} else {
		if($("#widgetUnSubscriptionLoader").length > 0) {
			$("#widgetUnSubscriptionLoader").fadeOut(2500);
		}	
	}
	$('#authenticate').live('click',function(){
		//alert('hiding...');
		if($('#username').val() == 'teekay_forms_testing' && $('#password').val() == '15243') {
			$('#dialog').jqmHide();
		} else {
			$('#error_output').text('Incorrect username or password');
		}
	});
});