/**
 * jquery dosnt have postJSON so here we go
 */
$.postJSON = function(url, data, callback) {
	$.post(url, data, callback, "json");
};

$(function() {
	// load the framework variables
	 owl.info.site_url = $('div#site_url').html();
	 owl.info.full_site_url = $('div#full_site_url').html();
	 owl.info.json_url = $('div#json_url').html();
});


var lock = {
	keys : {},
	get : function(key) {
		if (this.keys.key) {
			return true;
		} else {
			return false;

		}
	},
	add : function(key) {
		this.keys.key = true;
	},
	release : function(key) {
		this.keys.key = false;
	}
};

var owl = {
		
	tools : {
		redirect : function(url){
			window.location.href = url;
		},
		refresh:function(){
			window.location.reload(true);
		},
		alert : function(text){
			alert(text);
		}
	},
	info : {
		/* these are loaded after the dom onload event */
		site_url : null,
		full_site_url : null,
		json_url : null
		
	},
	load : {
		Html:function(page){
		
		},
		pageHtml : function(ele,page,noHash){					
			var mark = (page.search('\\?') > -1) ? '&' : '?';
			 
			$(ele).load(owl.info.site_url+'/'+page+mark+'frame=0',function(){
				// update location hash
				if(noHash != true){
					window.location.hash = page;
				}
			});
			
		}
	},
	
		
	 manipulate : {
		 version : 1,
			// show a element by ID
			show : function (element){
				$(element).show('slow');
				return false;
			},
			hide : function (element){
				$(element).hide('slow');
				return false;
			},
			toggle : function (element){

				$(element).toggle('slow');

				return false;
			},
			clearInputID : function (element){
				$("#" + element).val('');
			},
			clearInputClass : function (element){
				$("." + element).val('');
			},trim : function (stringToTrim) {
			    return stringToTrim.replace(/^\s+|\s+$/g,"");
			},cleanString : function  (str) {
			    return str.replace(/[^\d\.-]/g, "");
			},ltrim : function (stringToTrim) {
			    return stringToTrim.replace(/^\s+/,"");
			}, rtrim : function (stringToTrim) {
			    return stringToTrim.replace(/\s+$/,"");
			}, test : function(){
				alert("OWL Manipulate Version"+this.version);
			}

	},
	dialog : {
		deleteConfirm : function(callback,id,title,message){
			
			var $return = false;
			
			if($("div#dialog-confirm-"+id).length == false){
				$('body').append("<div id='dialog-confirm-"+id+"' title='"+title+"'><p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>"+message+"</p></div>");
				
			}
			
			 $("#dialog-confirm-"+id).dialog({
		     	autoOpen: false,
		 		resizable: false,
		 		width:350,
		 		modal: true,
		 		buttons: {
		 			'Yes Delete': function() {
				 	eval(callback+'()');
		 			
		 			},
		 			'Cancel Dont Delete': function() {
		 				$(this).dialog('close');
		 				return false;
		 			}
		 		}
			 
		 	});
			 
			 $("#dialog-confirm-"+id).dialog('open');
			 $(".ui-dialog-buttonpane button:contains('Yes Delete')").focus();
			 
		}
	,
	basic:function(id,title,message,width){
		var $return = false;
		
		if($("div#dialog-basic-"+id).length == false){
			$('body').append("<div id='dialog-basic-"+id+"' title='"+title+"'><p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span><span id='messageArea'>"+message+"</span></p></div>");
			
		}
		
		 $("#dialog-basic-"+id).dialog({
	     	autoOpen: false,
	 		resizable: true,
	 		width:width,
	 		modal: false,
	 		buttons: {
	 			'Apply': function() {
			 	//eval(callback+'()');
	 			
	 			},
	 			'Cancel': function() { 				
	 				$(this).dialog('close');
	 			//	eval(callback+'()');
	 				return false;
	 			}
	 		}
		 
	 	});
		 
		 $("#dialog-basic-"+id).dialog('open');
		 $(".ui-dialog-buttonpane button:contains('Yes Delete')").focus();
		 
	}
	}
		
};

var html = {};



var old_content = null;
function isNumeric(form_value)
{
    if (form_value.match(/[^\d\.-]/g) == null)
        return false;
    else
        return true;
}


/*function update_dom(json){

    $.each(json.items, function(i,item){
        if(item.key){
        	if($("span[field = '"+item.key+"'][object ='"+item.object+"'][rel ='"+item.id+"']")){
            	$("span[field = '"+item.key+"'][object ='"+item.object+"'][rel ='"+item.id+"']").html(item.value).effect('highlight',{},3000);
       		}
        }
    });
}*/


