dojo.provide("max_base");

// Anything that happens with xhrPOST/xhrGET 
// inherits from this class
// All data is thought to be handled as json

// Everything before any AJAX calls comes from this class
// This class is basically the caller
dojo.declare('max_base', null, {
	get_bg_color: function (id)
	{
		var org_color = dojo.style(id, 'backgroundColor'); 
		if (org_color == 'transparent')
		{
			if(dojo.byId(id).parentNode){
				return this.get_bg_color(dojo.byId(id).parentNode);
			}
		}
		return org_color;
	},

	flashAnim: function (id, flash_clr, duration_time)
	{
		dojo.require('dojox.fx');

        return dojox.fx.highlight({node: id, color: flash_clr, duration: duration_time});

		var flash_id = dojo.byId(id);
		if (!flash_id){
			return false;
		}
		
		var org_color = this.get_bg_color(flash_id);
		if (!flash_clr)
		{
			flash_clr = "#E7E7FF";
		}
		if (!duration_time)
		{
			duration_time = 2000;
		}
	
		var endClr = dojo.style(flash_id, 'color');
		var middleClr = "#300030";
		//dojo.style(flash_id, 'color', org_color);
	
		var color1 = dojo.animateProperty({ 
			node: flash_id, 
			duration: (duration_time/2),
			properties: { 
				backgroundColor: 	{  start: org_color, end: flash_clr }
				,color:  { start: endClr, end: org_color} 
			} 
		});
		
		var color2 = dojo.animateProperty({ 
			node: flash_id, 
			duration: (duration_time/2),
			properties: { 
				backgroundColor: 	{  start: flash_clr, end: org_color }
				,color:  { start: org_color, end: endClr} 
			} 
		});
		
		return dojo.fx.chain([color1, color2]);
	},

	deleteWarning: function (id, msg)
	{
		dojo.require('dojo.fx');
	
		var id = dojo.byId(id);
		if (!id){
			return false;
		}

        var org_bg_color = this.get_bg_color(id);
		var org_color= dojo.style(id, 'color');
		
		var flash_clr = "#FF0000";
		var duration_time = 2000;
	
		var orgFontWeight = dojo.style(id, 'fontWeight');
	
		var middleClr = "#300030";
        dojo.style(id, "backgroundColor", flash_clr);
        dojo.style(id, "color", middleClr);

		var confirm_ret = confirm(msg);
		if(!confirm_ret)
		{
			var color2 = dojo.animateProperty({ 
				node: id, 
				duration: duration_time,
				properties: { 
					backgroundColor: 	{  start: flash_clr, end: org_bg_color },
					color:  { start: middleClr, end: org_color}
				} 
			});
			color2.play();
		}
		
		return confirm_ret;	
	},
	
	attachFormDivs: function(){
		var form_div = dojo.byId("formDivElement");
		if (form_div)
		{
			// Add the submit lock
			dojo.query('form', form_div).forEach(
			function(form){
				if (form.id) {
					var classEval = 'new max_validate_' + form.id.substr(5) + '("' + url_root + '")';
					new max_formValidator(form, dojo.eval(classEval));
				}
			});
		}
	}
});

