String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
};
String.prototype.ltrim = function() {
	return this.replace(/^\s+/g,"");
};
String.prototype.rtrim = function() {
	return this.replace(/\s+$/g,"");
};


var OneCommon = {
	url: 'www.app.net/',
	
  onlyFloat: function ( evt ) { 
		// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
		var objElem = evt.target;
		var blnPointExist = false;
		
		if(objElem.value.indexOf('.') > -1) blnPointExist = true;
		
		var key = !jQuery.browser.msie ? evt.which : evt.keyCode;

		return (key <= 13 || (key >= 48 && key <= 57) || (key == 46 && !blnPointExist));
	},
	
	emptyDropDown: function(objSelect){
		if(typeof(objSelect) == 'undefined') return false;
		
		var itemCount = objSelect.options.length;
		
		for(x=itemCount; x >= 0; x--){
			objSelect.remove(x);
		}
		
		return true;
	},
	
	sendForm: function(objForm){
		objForm.submit();
	},
	
	pager: function(intPage, strUrl){
		jQuery.ajax({
			type: "POST",
			url: strUrl + '/' + intPage,
			data: '',
			dataType: 'html',
			cache: false,
			success: function(strData){
				$('#div_itemslist').html(strData);
				OneCommon.Home.init_items();
			}
		 });
	}
};

OneCommon.Standard = {
	init: function(){
		//search input
		var strDefaultText = 'Enter Keyword';
		var objSearch = $('#txt_search');
		objSearch
			.bind('blur', function(e){
				var el = $(this);
				if(el.val().trim() == '') el.val(strDefaultText);
			})
			.bind('focus', function(e){
				$(this).val('');
			})
			.keyup(function(e){
				if (e.keyCode == 13) {
					$(this).parents('form').submit();
				}
			});
			
		$("#header_visit a.toggle").click(function(){
			$(this).next("ul").slideToggle();
		});
	},
	
	subscribe: function(){
		var el = jQuery('#txt_subscribe');
		
		if(el && el.val().trim() != ''){
			jQuery.ajax({
				type: "POST",
				url: 'http://' + OneCommon.url + 'home/subscribe',
				data: 'txt_subscribe='+el.val().trim(),
				dataType: 'html',
				cache: false,
				success: function(strData){
					if(strData.trim() == '') return false;
					
					
					jQuery('#div_subscribe').html(
						jQuery('<p />').addClass('msg').html(strData)
					);
				}
			 });
		}
		
		
	}
};

OneCommon.Home = {};
OneCommon.Home = {
	init: function(){
		$("#featured_news ul li img").wrap("<span><\/span>")
	    $("#featured_news ul li span").append("<span><\/span>");
	    
	    $("#twitter_updates ol li").append("<span><\/span>");
	    
	    OneCommon.Home.init_items();
	},
	
	init_items: function(){
		$("#latest_news_cont ul li img").wrap("<span><\/span>")
	    $("#latest_news_cont ul li span").append("<span><\/span>");
	    
		$("#pagination ol li:last").addClass("last");
	    
	    $("#select_news_timeline ul li:last").addClass("last");
	    
	    $("#select_news_timeline a.toggle").click(function(){
	      $(this).next("ul").slideToggle();
	    });
	},
	
	timeline: function(strUrl){
		jQuery.ajax({
			type: "POST",
			url: strUrl,
			data: '',
			dataType: 'html',
			cache: false,
			success: function(strData){
				$('#div_itemslist').html(strData);
				OneCommon.Home.init_items();
			}
		 });
	}
};