/**

	DTprototype CLASS
	Descrição: Funções bases do DTInteractive
	© 2006 - Direct Talk Comércio e Tecnologia Ltda
	*/
	
var DTprototype = {
	Version: '1.0',
	require: function(libraryName) {
		document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
	},
	load: function() {
		$("script").each(function(i){
			if(this.src && this.src.match(/DTprototype\.js(\?.*)?$/))
			{
				var path = this.src.replace(/DTprototype\.js(\?.*)?$/,'');
				var includes = this.src.match(/\?.*load=([A-Za-z,]*)/);
				if(includes){
					var plugins = includes[1].split(",");
					for(var i = 0; i < plugins.length; i++)
					{
						DTprototype.require(path+plugins[i]+'.js');
					}
				}
			}
		});
		
	}
}

DTprototype.load();

var Class = {
	create: function() {
		return function() {
			this.constructor.apply(this, arguments);
		}
	}
};

function $$() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
};

/*
	Regex
	Executa uma Expressão Regular e retorna o valor do "match"
	
	@valor - Valor que será analisado na expressão regular
	@regExpression - Expressão Regular
	
	@throw - Valor do teste (TRUE/FALSE)
*/
var Regex = {
	match : function(valor,regExpression)
	{
		var regex = regExpression;
		var validated = regex.test(valor);
		return validated;
	}
};

/*
	Extend -> String.prototype.isCPF
	Executa uma Expressão Regular e retorna o valor do "match"
	
	@valor - Valor que será analisado na expressão regular
	@regExpression - Expressão Regular
	
	@throw - Valor do teste (TRUE/FALSE)
*/
String.prototype.isCPF = function(){
    var c = this;
    if((c = c.replace(/[^\d]/g,"").split("")).length != 11) return false;
    if(new RegExp("^" + c[0] + "{11}$").test(c.join(""))) return false;
    for(var s = 10, n = 0, i = 0; s >= 2; n += c[i++] * s--);
    if(c[9] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    for(var s = 11, n = 0, i = 0; s >= 2; n += c[i++] * s--);
    if(c[10] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    return true;
};

/*
	Extend -> String.prototype.isCNPJ
	Executa uma Expressão Regular e retorna o valor do "match"
	
	@valor - Valor que será analisado na expressão regular
	@regExpression - Expressão Regular
	
	@throw - Valor do teste (TRUE/FALSE)
*/
String.prototype.isCNPJ = function(){
    var b = [6,5,4,3,2,9,8,7,6,5,4,3,2], c = this;
    if((c = c.replace(/[^\d]/g,"").split("")).length != 14) return false;
    for(var i = 0, n = 0; i < 12; n += c[i] * b[++i]);
    if(c[12] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    for(var i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
    if(c[13] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    return true;
};

function saveCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000))
		var expires = "; expires="+date.toGMTString()
	}
	else expires = ""
	document.cookie = name+"="+value+expires+"; path=/"
}

function readCookie(name) {
	var nameEQ = name + "="
	var ca = document.cookie.split(';')
	for(var i=0;i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length)
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
	}
	return null
}

function deleteCookie(name) {
	saveCookie(name,"",-1)
}