/**
 * @author mconway
 */
$(document).ready(function(){
	$('#loaderContainer').dialog({
		autoOpen: false,
		title: 'Loading, Please wait...',
		modal: true,
		closeOnEscape: false,
		overlay: {
			opacity: 0.5,
			background: 'white'
		},
		height: 100,
		width: 156,
		draggable: false,
		resizable: false
	});
	$('#loaderContainer').css('display','block');
	$('#messageDialog').dialog({
		autoOpen: false,
		modal: true,
		height: 150,
		width: 300,
		closeOnEscape: false,
		overlay: {
			background: 'white',
			opacity: 0.5
		},
		draggable: false,
		resizable: false
	});
	$('.ui-dialog .ui-dialog-titlebar-close').remove();
//	if ($('select').length > 0) {
//		$('.ui-dialog').bgiframe();
//	}
});
var ss = {
	displayMessage:function(text, title, buttons, height, width, draggable){
		$('#messageDialog').html(text);
		$('#messageDialog').dialog('option', 'title', title);
		if (!buttons) {
			buttons = {
				"OK":function(){
					$(this).dialog('close');
				}
			}
		};
		if (!height){
			height = 150; //default height
		}
		if (!width){
			width = 300; //default width
		}
		if (!draggable){
			draggable = false;
		}
		$('#messageDialog').dialog('option', 'height', height);
		$('#messageDialog').dialog('option', 'width', width);
		$('#messageDialog').dialog('option', 'buttons', buttons);

		$('#messageDialog').dialog('open');
	},
	showLoader: function(){
		$('#loaderContainer').dialog('open');
	},
	closeLoader: function(){
		$('#loaderContainer').dialog('close');
	},
	markRequired: function(){
		$('#content').prepend('<div><span style="color:red">*</span> denotes required fields.</div>');
		$('#content').append('<div><span style="color:red">*</span> denotes required fields.</div>');
		$(".required_field").each(function(){
			$(this).parents('tr:first').find('.display_label').prepend('<span style="color:red">* </span>');
		});
		$('td:has(select)').each(function(){
			if($(this).children('select').css('background-color')=='rgb(255, 255, 0)' ||$(this).children('select').css('background-color')=='#ffff00'){
				$(this).children('select').css('background-color','').parents('tr:first').find('.display_label').prepend('<span style="color:red">* </span>');
			}
		})
	},
	validateForm: function(form){
		var cancel = false;
		form.find('input:visible').each(function(){
			if($(this).val() == '' && $(this).next().text() == '*'){
				alert($(this).parent().prev().children('div').text().replace(':','')+" is required");
				cancel = true;
				return false;
			}
		})
		if(cancel==true){
			return false;
		}
	}
}
