$(document).ready(function(){
    //$(".windowopen").popupwindow();
});

function getGets(){
	var string = document.location.search;
	var getVars = [];
	tGet = [];//global
	getVars = string.substr(1, string.length);
	getVars = getVars.split('&');
	var t, n, tmpV;
	for (t=0,n=getVars.length;t<n;t++){
		tmpV=getVars[t].split('='); tGet[tmpV[0]]=tmpV[1];
	}
}

function redirect(url){
	document.location.href = url;
}

Number.prototype.formatMoney = function(c, d, t){ //Serve para formatar um number em formato dinheiro
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t,
i = parseInt(n = (+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
return (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t)
+ (c ? d + (n - i).toFixed(c).slice(2) : "");
}; 

String.prototype.dateFormat = function(){
	var day = this.substring(8,10);
	var month = this.substring(5,7);
	var year = this.substring(0,4);
	return day+'/'+month+'/'+year;
}

var elemento = {
	preview : function(find){
		var val = $(find).attr('title');
		$(find).val(val)
		$(find).focus(function(){
			if($(this).val()==val)
				$(this).val('')
			else
				$(this).select();
		});
		$(find).blur(function(){
			if($(this).val()=='')
				$(this).val(val)
		});		
	}
};

var font = {
	el		: 'body',
	size	: null,
	min		: 10,
	max 	: 18,
	init: function(el){
		this.el = el;
		font.size = parseInt($(el).css('font-size'));	
	},
	inc : function(){
		if (font.size < this.max-1)
			this.loop('+');
	},
	dec : function(){
		if (font.size > this.min+1)
			this.loop('-');
	},
	loop : function(percentage){
		$(this.el).each(function(){
			font.size = parseInt($(this).css('font-size'));
			$(this).css('font-size', percentage=='+' ? font.size+1 : font.size-1);
		});
	}
};


/**
 * Formulario
 * @class	Formulario
 * @autor	Giolvani de Matos
 */
function Formulario(){
	var code;
	var name;
	var classe = '.ckinput';	//classe do elemento checkbox
	
	/**
	 * envia formulario do objeto
	 * @name	submit
	 * @param	object
	 * @return	void
	 */
	this.submit = function(object){
		$(object).submit();
	}
	
	/**
	 * Insere elemento input em outro elemento
	 * @name 	insertInput
	 * @param	object
	 * @param	string
	 * @param	string
	 * @param	string
	 * @return	void
	 */
	this.insertInput = function(object,type,name,value,id){
		var elId = '';
		if (id != undefined){
			elId = 'id = "'+id+'"';
		}
		$(object).prepend('<input type="'+type+'" name="'+name+'" '+elId+' value="'+value+'"/>');	
	}
	
	/**
	 * seleciona todos registro de uma grid
	 * @name	checkAll
	 * @param	object
	 * @param	boolean
	 * @return	void
	 */
	this.allCheckBox = function(el,bol){
		$(el).each(function(){
			if(bol == true) $(this).get(0).checked = true;
        	else $(this).get(0).checked = false;
		});
	}
	
	/**
	 * retorna a quantidade de elementos selecionados e seta o codigo e o nome do elemento
	 * @name	getSelections
	 * return	integer
	 */
	this.getSelections = function(){
		var codigo;
		var nome;
		var length = 0;
		$(classe).each(function(){
			if( $(this).get(0).checked ){
				length++;
				nome = $(this).get(0).name;
				codigo = $(this).val();
			}
		});
		this.code = codigo;
		this.name = nome;
		return length;
	}
	
	/**
	 * retorna codigo selecionado
	 * @name getCode
	 */
	this.getCode = function(){
		return this.code;
	}
	
	/**
	 * retorna nome selecionado
	 * @name getName
	 */
	this.getName = function(){
		return this.name;
	}
	
}


