function br2nl(txt){
	var regexp = /\<br\s*\/?\>/g;
	console.log(regexp);
	return txt.replace(regexp, "\n");
}


///////////////////DATE////////////////////////
function getDateFromDisplay(dateDisplay){
	var dateDisplay = dateDisplay.split("/");
	return new Date(dateDisplay[2],dateDisplay[1],dateDisplay[0]);
}
function dateCompareDisplay(dateafter, datebefore){
	return dateCompare(getDateFromDisplay(dateafter), getDateFromDisplay(datebefore));
}

//   0 si date_1=date_2
//   1 si date_1>date_2
//  -1 si date_1<date_2
function dateCompare(date_1, date_2){
	diff = date_1.getTime()-date_2.getTime();
    return (diff==0?diff:diff/Math.abs(diff));
}


function date1BeforeDate2String(date1,date2){
	return dateCompare(getDateFromDisplay(date1), getDateFromDisplay(date2)) <= 0;
}
function date1AfterDate2String(date1,date2){
	return dateCompare(getDateFromDisplay(date1), getDateFromDisplay(date2)) >= 0;
}
///////////////////DATE////////////////////////



function convertToHtmlSpecial(theStr) {
    var newDiv = document.createElement(newDiv);
    newDiv.innerHTML = theStr;
    console.log('Entities:\n' + theStr + '\n\nCharacters:\n' + newDiv.innerHTML);
}
function HtmlEncode(s)
{
  var el = document.createElement("div");
  el.innerText = el.textContent = s;
  s = el.innerHTML;
  delete el;
  return s;
}







var Utils = {
	image : {
		loadImage : function(path, callback, returnValue){
			callback = callback || function(image,returnValue){};
			//console.log(callback);
			var returnValue = returnValue || null;
			returnValue = returnValue!=null?returnValue:(
					typeof Utils.image.loadImage.caller.prototype != 'undefined' && typeof Utils.image.loadImage.caller.prototype.returnValue != 'undefined'
			)?Utils.image.loadImage.caller.prototype.returnValue:null;
			
			var image = new Image();
			//console.log(path);
			image.data = {};
			image.data.returnValue = returnValue;
			image.data.callback = callback;
			image.onload = function(){
				this.data.callback(this,this.data.returnValue);
				this.data = null;
			};
			image.src = path;
		}
	},
	string : {
		htmlEncode : function(txt){
			var div = document.createElement('div');
			div.innerHTML = txt;
			return div.innerHTML;
		}
	},
	url : {
		getParams : function(url,name){
			var url = url || "";
			var name = name || null;
			var result = new Array();
			paramTab = url.split("?");
			if(paramTab.length>1){
				query = paramTab[1];
				queryTab = query.split("&");
				if(queryTab.length>0){
					for(i=0;i<queryTab.length;i++){
						param = queryTab[i];
						paramTab = param.split('=');
						if(paramTab.length>1){
							if(name!=null){
								if(name == paramTab[0]) return paramTab[1];
								continue;
							}
							result.push({name:paramTab[0],value:paramTab[1]});
						}
					}
				}
			}
			if(name != null) return null;
			return result;
		}
	},
	json:{
		clone:function(json){
			return $.extend({},json);
		}
	}
};


Utils.string.addslashes = function(string){return(string+'').replace(/([\\"'])/g,"\\$1").replace(/\0/g,"\\0");};
Utils.string.stripslashes = function(string){return(string+'').replace(/\\(.?)/g,function(s,n1){switch(n1){case'\\':return'\\';case'0':return'\u0000';case'':return'';default:return n1;}});}
Utils.string.ucfirst = function(str){try{var f=str.charAt(0).toUpperCase();return f+str.substr(1);}catch(e){console.log(e);}}
Utils.string.base64_decode = function(data){
	try{
		var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
		var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,dec="",tmp_arr=[];
		if(!data){return data;}
		data+='';
		do{
			h1=b64.indexOf(data.charAt(i++));h2=b64.indexOf(data.charAt(i++));h3=b64.indexOf(data.charAt(i++));h4=b64.indexOf(data.charAt(i++));
			bits=h1<<18|h2<<12|h3<<6|h4;o1=bits>>16&0xff;o2=bits>>8&0xff;o3=bits&0xff;
			if(h3==64){tmp_arr[ac++]=String.fromCharCode(o1);}
			else if(h4==64){tmp_arr[ac++]=String.fromCharCode(o1,o2);}
			else{tmp_arr[ac++]=String.fromCharCode(o1,o2,o3);}
		}while(i<data.length);
		dec=tmp_arr.join('');
		return dec;
	}catch(e){
		console.log(e);
	}
};


function rewriting(str){var spec=new Array('À','Á','Â','Ã','Ä','Å','Æ','à','á','â','ã','ä','å','æ','È','É','Ê','Ë','è','é','ê','ë','Ì','Í','Î','Ï','ì','í','î','ï','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','Ù','Ú','Û','Ü','ù','ú','û','ü','ß','Ç','ç','Ð','ð','Ñ','ñ','Þ','þ','Ý');var norm=new Array('A','A','A','A','A','A','A','a','a','a','a','a','a','a','E','E','E','E','e','e','e','e','I','I','I','I','i','i','i','i','O','O','O','O','O','O','o','o','o','o','o','o','U','U','U','U','u','u','u','u','B','C','c','D','d','N','n','P','p','Y');for(var i=0;i<spec.length;i++)
	str=str_replace(str,spec[i],norm[i]);return str;}
function urlRewriting(str){var spec=new Array('À','Á','Â','Ã','Ä','Å','Æ','à','á','â','ã','ä','å','æ','È','É','Ê','Ë','è','é','ê','ë','Ì','Í','Î','Ï','ì','í','î','ï','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','Ù','Ú','Û','Ü','ù','ú','û','ü','ß','Ç','ç','Ð','ð','Ñ','ñ','Þ','þ','Ý',' ',"'",'(',')',',','.',';','?','!');var norm=new Array('A','A','A','A','A','A','A','a','a','a','a','a','a','a','E','E','E','E','e','e','e','e','I','I','I','I','i','i','i','i','O','O','O','O','O','O','o','o','o','o','o','o','U','U','U','U','u','u','u','u','B','C','c','D','d','N','n','P','p','Y','-','-','-','-','-','-','-','-','-');for(var i=0;i<spec.length;i++){str=str_replace(str,spec[i],norm[i]);}
str=str_replace(str,'---','-');str=str_replace(str,'--','-');if(str.slice(-1)=='-')str=str.slice(0,-1);str=(str+'').toLowerCase();return str;}
function str_replace(haystack,needle,replacement){var temp=haystack.split(needle);return temp.join(replacement);}


function cloneJson(object){
	return $.extend({},object);
}
function typeOf(object){
	if(typeof(object)!='object' || object==null) return typeof(object);
	var obType = String(object.constructor).match(/function\s+(\w+)/);
	if(obType) return obType[1];
	return "undefined"; // just in case...
}

function addFunctionTo(fct, fctPlus) {
  var oldFct = fct;
  if (typeof window.onload != 'function') {
    fct = fctPlus;
  } else {
    window.onload = function() {
      if (oldFct) {
        oldFct();
      }
      fctPlus();
    }
  }
}


function findPos(obj){
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}while (obj = obj.offsetParent);
		return {
			posX: curleft,
			posY: curtop
		};
	}
}



//DISPLAY
function getAjaxLoading(name){
	var name = name || "ajax-loader";
	var ajaxLoad = $("<img src='"+SETTING_STATIC+"/img/"+name+".gif'/>");
	return ajaxLoad;
}

function reloadPage(){
	window.location.reload();
}


function displayBlackScreen(zIndex){
	var zIndex = zIndex || 10000;
	var $blackScreen = $("<div></div>");
	$blackScreen.css({
		position:'fixed',
		top:'0px',
		left:'0px',
		width:"100%",
		height:'100%',
		'background-color':'#000000',
		'z-index':zIndex
	});
	console.log("blackSCREEN");
	return $blackScreen.setOpacity(0.5).appendTo($(document.body));
}

function setOpacity(el,value){
	
}


(function($){
	$.extend($.fn, {
		setOpacity : function(value){
			value = value*1;
			var valueFilter = value*100;
			var style = $(this).attr('style');
			style += ""+
		        "-moz-opacity:"+value+";"+
		        "-khtml-opacity:"+value+";"+
		        "opacity:"+value+";";
			$(this).attr('style',style);
			$(this).css({"filter" : "alpha(opacity="+valueFilter+")"});
			return this;
		}
	});
})(jQuery);



























