
// Disable a form's submit/cancel button and submit the form. Before submitting, 
// we'll execute a callback function, if applicable...
var disableAndSubmit = function(submitIds, formId, callback){
	var oldSubmitIds = {} ;
	$.each(jQuery.makeArray(submitIds), function(ind, arg){
		if ($('#'+arg).length) {
			var eArg = $('#'+arg) ;
			if (eArg.is('input')) {
				eArg.attr('disabled', true) ;
			} else if (eArg.is('a')) {
				oldSubmitIds[arg] = eArg.attr('href') ;
				eArg.attr('href','javascript:void(0)') ;
			} else if (eArg.is('img') || eArg.is('div')) {
				oldSubmitIds[arg] = eArg.attr('onClick') ;
				eArg.attr('onClick','void(0)') ;
			} 
			eArg.css({ opacity: 0.5, filter: 'alpha(opacity = 50)' }) ;
		}
	}) ;

	var callback_retval = true ;
	if (typeof(callback) == 'function') {
		callback_retval = callback(formId) ;
	}

	if (callback_retval == true) {
		return true ; 
	} else {
		$.each(jQuery.makeArray(submitIds), function(ind, arg){
			if ($('#'+arg).length) {
				var eArg = $('#'+arg) ;
				if (eArg.is('input')) {
					eArg.attr('disabled', false) ;
				} else if (eArg.is('a')) {
					eArg.attr('href', oldSubmitIds[arg]) ;
				} else if (eArg.is('img') || eArg.is('div')) {
					eArg.attr('onClick', oldSubmitIds[arg]) ;
				} 
				eArg.css({ opacity: 1, filter: 'alpha(opacity = 100)' }) ;
			}
		}) ;
		return false ;
	}
} ;

var confirmAction = function(el_name, el_action, el_url) {
	var do_it = confirm("Do you really want to " + el_action + " " + el_name + "?") ;
	if (do_it) {
		location.href = el_url ;
	}
} ;

$(document).ready(function() {
	initFormPlaceholders() ;
}) ;

var initFormPlaceholders = function(){
	if (Modernizr.input.placeholder) {
		return ;
	}

	$('input[placeholder]').focus(function(){
		if ($(this).hasClass('placeholder')) {
			if ($(this).val() == $(this).attr('placeholder')) {
				$(this).val('') ;
			}
			$(this).removeClass('placeholder') ;
		}
	}) ;

	$('input[placeholder]').keypress(function(){
		if ($(this).hasClass('placeholder')) {
			if ($(this).val() == $(this).attr('placeholder')) {
				$(this).val('') ;
			}
			$(this).removeClass('placeholder') ;
		}
	}) ;

	$('input[placeholder]').blur(function(){
		if ($(this).val() != '') {
			return ;
		}
		$(this).addClass('placeholder') ;
		$(this).val($(this).attr('placeholder')) ;
	}) ;

	$('input[placeholder]').each(function() {
		if ($(this).val() != '' && $(this).val() != $(this).attr('placeholder')) {
			return ;
		}
		$(this).val($(this).attr('placeholder')).addClass('placeholder') ;
	}) ;

	$('form').submit(function() {
		$(this).find('.placeholder').each(function() {
			if ($(this).val() != '' && $(this).val() == $(this).attr('placeholder')) {
				$(this).removeClass('placeholder') ;
				$(this).val('') ;
			}
		}) ;
	}) ;
} ;


