function Utils()
{
	this.className = 'Utils';
	this.error = false;
}

Utils.prototype.showHide = function(objId)
{
	var object = document.getElementById(objId);
	if (object.style.display == 'none')
	{
		object.style.display = '';
	}
	else
	{
		object.style.display = 'none';
	}
}

Utils.prototype.stringReplace = function(sp, rp, ss)
{
	if (ss.indexOf(sp) < 0)
	{
		return ss;
	}
	else
	{
		fp = ss.indexOf(sp);
		
		if (fp==0)
		{
			first = true;
		}
		else
		{
			first = false;
		}
		
		if (sp == ss.substr(-(sp.length)))
		{
			last = true;
		}
		else 
		{
			last = false;
		}
		
		rest = ss.split(sp);
		
		if (first == true)
		{
			fs = rp;
		}
		else
		{
			fs = '';
		}
				
		for (i = 0; i < rest.length; i++)
		{
			if (rest[i]!='')
			{
				fs = fs + rest[i] + rp;
			}
		}
		
		if (!last)
		{
			fs = fs.substr(0, (fs.length - rp.length));
		}
		
		return fs;
	}
}

Utils.prototype.showMessage = function(responseText, xmlDocument)
{
	if (responseText.indexOf('xml') > -1)
	{
		response = xmlDocument.getElementsByTagName('response')[0];

		messages = response.getElementsByTagName('message');
		message = messages[0].firstChild.nodeValue;
		
		errors = response.getElementsByTagName('error');
		error = errors[0].firstChild.nodeValue;
		
		if (error != '1')
		{
			this.showSuccessMessage(message);
		}
		else
		{
			this.showErrorMessage(message);
		}
	}
	else
	{	
		this.showErrorMessage('Ocorreu um erro desconhecido. Detalhes do erro: '+responseText.substring(0,100)+'...');
	}
}

Utils.prototype.showSuccessMessage = function(message)
{
	alert(message);
}

Utils.prototype.showErrorMessage = function(message)
{
	alert('Erro: '+message);
	this.error = true;
}

Utils.prototype.formatDate = function(dateSQL)
{
	var dateSQL = dateSQL.toString();
	var arrayDate = dateSQL.split("-");
	
	var year = arrayDate[0];
	var month = arrayDate[1];
	var day = arrayDate[2];
	
	var dateFormated = day+"/"+month+"/"+year;
	
	return dateFormated;
}

Utils.prototype.allTrim = function(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

Utils.prototype.countChar = function(description, spanCount, limit)
{
	var spanCount = document.getElementById(spanCount);
	var description = document.getElementById(description);
	
	if(spanCount && description)
	{
		var lengthDescription = description.value.length;
		if(lengthDescription>limit)
		{
			description.value = description.value.substring(0,limit);	
		}
		else
		{
			oDOMUtils.removeChilds(spanCount);
			spanCount.appendChild(document.createTextNode(lengthDescription));
		}
	}
}

Utils.prototype.setNextPrev = function(id, tipo)
{
	var link = document.getElementById(id);
	
	if(tipo=="proximo")
	{
		var linkNext = document.getElementById('linkNext');
		if(linkNext!=null)
		{
			var linkPaginate = linkNext.getAttribute('href');
			link.setAttribute("href", linkPaginate);
		}
	}
	else if("anterior")
	{
		var linkPrev = document.getElementById('linkPrev');
		if(linkPrev!=null)
		{
			var linkPaginate = linkPrev.getAttribute('href');
			link.setAttribute("href", linkPaginate);
		}
	}
}
	
oUtils = new Utils();