/**
 * @author Marwan
 */

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

String.prototype.format = function()
{
    var str = this;
 
    for(var i=0;i<arguments.length;i++)
    {
        var re = new RegExp('\\{' + (i) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }
 
    return str;
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function confirmDelete() {
	return confirm("Are you sure continue delete operation?");
}

function submitFormById(id) {
	var frm = document.getElementById(id);
	frm.submit();
}

function removeDefault(field, _default, flag ) {
	if (field.value == _default && !flag) {
		field.value = "";
	} else if (this.value == "") {
		this.value = _default;
	}
}

var esExplorer = (navigator.appName == "Microsoft Internet Explorer");
function setFocusListenerDefaultValue(e, _default) {
	if (esExplorer) {
		e.onfocusin = function(){
			if (e.value == _default) {
				e.value = "";
			}
		}
		e.onfocusout = function() {
			if (e.value == "") {
				e.value = _default;
			}
		}
	}
	else {
		function focoActivo (evt) {
			if (e.value == _default) {
				e.value = "";
			}
		}
		function focoPerdido (evt) {
			if (e.value == "") {
				e.value = _default;
			}
		}
		e.addEventListener('DOMFocusIn', focoActivo, false);
		e.addEventListener('DOMFocusOut', focoPerdido, false);
		e.addEventListener('focus', focoActivo, true);
		e.addEventListener('blur', focoPerdido, true);
	}
}



