/*
*	Usage:
*	addLoadEvent( function () {
*		maskEffect.add(form_name2, element_id2, mask2)
*		maskEffect.add(form_name2, element_id2, mask2)
*		. . . . .
*		maskEffect.run();
*		}
*	);
*/
var maskEffect = {
	'myMask'	:	new Array(),
	'myForms'	:	new Array(),
	'run'		:	function () {
						/** Private Functions */
						
						var forms = function () {
							/*
							*	Let's go through all the forms and make sure that we get rid of the
							*	mask when we submit the form
							*/
							var myForms = maskEffect.myForms;
							for(x in myForms) {
								if(typeof myForms[x] != "function") {
									eval("var form = document."+myForms[x]+";");
									if(form) {
										var oldonload = form.onsubmit;
										form.onsubmit = function () {
											if(oldonload) {
												oldonload();
											}
											effects("disable");
										}
									}
								}
							}
						}
						
						var effects = function () {
							var myMask = maskEffect.myMask;
							
							/* Start of Private Functions */
							var addEvents = function(id, text) {
							    var elem = $(id);
							    if( !elem.style ) {
							        elem = $('#'+id)[0];
							    }
								if(elem.value == "")
								{	elem.value = text;
									elem.style.color = '#cccccc';
								}
								elem.onfocus = function () {
									if(this.value == text)
									{ 	this.value = '';
									} 
									this.style.color = '#000000';
								};
								elem.onblur = function () {
									if(this.value == '')
									{	this.value = text;
										this.style.color = '#cccccc';
									}
									
								};
							}
							/* End Private Functions */
							
							for(var i = 0; i < myMask.length; i++)	{
								var id = myMask[i][0];
								var text = myMask[i][1];
								
								// Replace "[", "]"
								id      = id.replace("[", "_").replace("]", "");
								elem    = $(id);
								if( !elem.style ) {
								    elem = $('#'+id)[0];
								}
								if(elem != null) {
									if(arguments[0] == "disable") {
										if(elem.value == text) {
											elem.value = "";
										}
									} else {
										addEvents(id, text);
									}
								}
							}
						}
						/** End of Private Functions */
						
						/** Let's start the show **/
						effects();
						forms();
					},
	'add'		:	function (form_name, ob_id, mask) {
	                    elem   = $(ob_id);
	                    if( !elem.style ) {
	                        elem   = $('#'+ob_id)[0];
	                    }
						// Check if object is valid
						if(elem) {
							this.myMask[this.myMask.length] = new Array(ob_id, mask);
						}
						this.myForms[form_name] = form_name;
					}
}
