var Tools = new Object();

Tools = {
	helloWorld:function(e){
		alert(e);
	},
	Form:{
			send:function(form_id,url,options){
			
				new Ajax.Request(url,{method:'post',postBody:$(form_id).serialize(),onComplete:function(res){
					if(options &&options.modalbox){
					Modalbox.hide();
					}
					if(options && options.update){
						Tools.Data.replace(options.update,res.responseText);
						}
						else{
						return true;
					}
					}});
			}
	},
	
	Data:{
			replace:function(div_id,content){
				$(div_id).innerHTML = content;
			},
			
			step:function(prefix,this_number,next_number,options){
			
			
				if(options && options.checkInputs){
					if(!Tools.Data.checkForEmptyFields(prefix+this_number)){
						return false;
						}
				}
				new Effect.Fade(prefix+this_number);
				new Effect.Appear(prefix+next_number, {queue:'end',limit:1,afterUpdate:function(){
				if(options && options.modalbox){
					Modalbox.resizeToContent();
					}
				}});
			},
			
			checkForEmptyFields:function(container_id){
			//Checks all inputs in the container_id
			//If it is empty, triggers boolean
			//If boolean is triggered, returns false
			//Else returns true
				tmp=false;
				$$('#'+container_id+' input').each(function(e){
					if(e.value == ''&&tmp==false&&e.className.indexOf("optional") == -1){
						alert('Please enter all required fields');
						tmp=true;
						}
				});
				  return tmp ? false : true;
				
			}
	},
	Object :{
	findPos:function(obj) {
				var curleft = curtop = 0;
				if (obj.offsetParent) {
					curleft = obj.offsetLeft
					curtop = obj.offsetTop
					while (obj = obj.offsetParent) {
						curleft += obj.offsetLeft
						curtop += obj.offsetTop
					}
				}
				return [curleft,curtop];
			}
	},
	
	Visual:{
		showLoading:function(text){
			Modalbox.show("<p align='center'>"+text+"</p><p align='center'><img src='/images/icons/ajax-loader.gif'></p>",{title:"Please wait..."});
			
			Modalbox.deactivate();
			
		},
		
		hideLoading:function(){
			Modalbox.activate();
			setTimeout("Modalbox.hide();",1000);
		},
		
		showLoadingBar:function(){
			$('loadingBar').show();
		},
		hideLoadingBar:function(){
			$('loadingBar').hide();
		},
		process:function(tmp){
			box = new Element('div',{
				style:'background-color:#ffffee;color:black;font-weight:bold;margin:0px;padding:10px;position:absolute;top:0;right:0;'
			}).update(tmp||"Loading");
			$(document.getELementByTagName('body')).insert({bottom :box});
			alert(box);
		},
		
		showFailure:function(text){
			//Modalbox.activate();
			Modalbox.show("<div class='stop'><h1>Sorry, we've had an error.</h1><p>"+text+"</p></div>",{title:'An error has occurred.'});
		}
	}


}



var User = new Object();
	User ={
		Design:{
			destroy:function(id,visualQue){
				if(confirm("Are you sure you want to delete this design?") && confirm("This is permanent! All data will be lost.")){
					new Ajax.Request('/engine/deleteOrder/'+id,{onSuccess:function(res){
						if(res.responseText == 'true'){
							if(visualQue){
								$$('td.design_'+id).each(function(e){
									new Effect.Fade(e);
									});
							}
						} else {
							Tools.Visual.tell(res.responseText);
						}
					}});
				}
			
			}
		}
	}
	

