// Created with MAX's HTML Beauty++ 2004

Number.prototype.isIn = function(arr)
{
	for(var i = 0; i< arr.length; i++)
		if(arr[i]==this) return true;
	return false;
}
Number.prototype.percent = function(p)
{
   return ((this*p)/100);
}

Number.prototype.toMyLocaleString = function(pr)
{
	if(this < 1000)
		return this.toFixed(pr).replace('.',',');
	else if(this >= 1000 && this < 10000)
		return this.toFixed(pr).replace('.',',').insertInto(1,'.');
	else if(this >= 10000 && this < 100000)
		return this.toFixed(pr).replace('.',',').insertInto(2,'.');
	else if(this >= 100000 && this < 1000000)
		return this.toFixed(pr).replace('.',',').insertInto(3,'.');
	else if(this >= 1000000 && this < 10000000)
		return this.toFixed(pr).replace('.',',').insertInto(1,'.').insertInto(5,'.');
	else(this >= 10000000 && this < 100000000)
		return this.toFixed(pr).replace('.',',').insertInto(2,'.').insertInto(6,'.');
	//else if(this >= 10000 && this < 100000)
	//	return .insertInto(2,'.').insertInto(6,',');
}


// em conjunto com a DVCalendar, formatação para mysql
String.prototype.toMySQLDate = function()
{
	var a = this.substr(0,pos);
	var b = this.substr(pos);
	return a+str+b;
}

String.prototype.insertInto = function(pos,str)
{
	var a = this.substr(0,pos);
	var b = this.substr(pos);
	
	return a+str+b;
}

String.prototype.parseDouble = function()
{
	var x = this;
	//num  < 1000
	if(!x.indexOfAll('.'))
		return eval(x.replace(',','.'));
	else
		return eval(x.replace('.','').replace('.','').replace(',','.'));
}


String.prototype.indexOfAll = function(s)
{
	var q = 0;
	var o = new String(this);
	while(o.indexOf(s) != -1)
	{
		q++;
		o = o.substr(o.indexOf(s)+s.length);
	}
	
	return q;
}

String.prototype.equals = function(comp)
{
	return (this == comp) ? true : false;
}

String.prototype.equalsIgnoreCase = function(comp)
{
	return (this.toUpperCase() == comp.toUpperCase()) ? true : false;
}

window.gE = function(id){return document.getElementById(id)}

String.prototype.normalize = function()
{
	try{return 	this.match(/[a-zA-Z0-9]/g).join('');}
	catch(err){return this}
}
String.prototype.fillMask = function(arr,str)
{
	var ret = '';
	var _this = this;
	for(var i = 0; i< arr.length; i++)
	{
		ret  +=  _this.substr(0,arr[i])+str;
		_this = _this.slice(arr[i]);
	}
	return ret.substr(0,ret.length-str.length);
}
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.zeroNum = function()
{
	return (parseFloat(this) <= 9) ? '0'+this : this; 
}

