/**
 * VisãoI Sistemas
 * visaoi@visaoi.com.br
 * 
 * Rua Marcílio Dias, 26
 * Bairro Americano - Lajeado - RS
 * (51)3011-7001 | (51)8424-4494
 * 
 * DESCRIÇÃO
 * Javascripts com funções genéricas, comuns aos módulos dos sites
 *
 * @author		Francisco Schwertner
 * @copyright   Copyright (c) 2005-2008 VisãoI Sistemas. (http://www.visaoi.com)
 */
 
$(function() {
	
	/**	
	 * cria o datepiker para os inputs do tipo data, elementos com a classe 'input_date' 
	 */
	
	$('INPUT[@class=input_date]').each(function() {
		$(this).datepicker({
			dateFormat:'dd/mm/yy',
			showOn: "both", 
		    buttonImage: iconspath+'/silk_icons/date_magnify.png', 
		    buttonImageOnly: true 
		});
	});
	
	/**	
	 * cria máscara do para inputs do tipo hora, elemetnos com a classe 'input_time' 
	 */
	$('INPUT[@class=input_time]').each(function(){$(this).mask('99:99');});
	
	/**	
	 * cria máscara do para inputs do tipo timestamp, elemetnos com a classe 'input_timestamp' 
	 */
	$('INPUT[@class=input_timestamp]').each(function(){$(this).mask('99/99/9999 99:99:99');});
	

	/**	
	 * cria máscara do para inputs do tipo fone, elementos com a classe 'input_fone' 
	 */
	$('INPUT[@class=input_fone]').each(function(){$(this).mask('(099)9999-9999');});
	
	/**	
	 * cria máscara para inputs para cpf, input comecando com 'cpf_'
	 */	
	$('INPUT[@class=input_cpf]').each(function(){$(this).mask('999.999.999-99');});
	
	/**	
	 * cria máscara para inputs para cnpj
	 */
	$('INPUT[@class=input_cnpj]').each(function(){$(this).mask('99.999.999/9999-99');});
	
	
	/**	
	 * cria a formatação e mascaramento para campos numeric
	 */
	$('INPUT[@class=input_numeric]').each(function() {
		$(this).maskMoney({
			symbol: "",
			decimal: ",",
			precision: 2,
			thousands: ".",
			showSymbol:true
		});
	});
	
	/**
	 * cria textareahtml, para elementos com a class 'textarea_html'
	 * 
	 *
	 */
	$('TEXTAREA[@class=textarea_html]').each(function(count) {
		var textareahtml_id = $(this).attr('id');
		tinyMCE.execCommand("mceAddControl", false, textareahtml_id);
	});
	
	/**
	 * cria máscara para inputs do tipo CPF, elementos com o atributo ID começando com "cpf"
	 *
	 */
	$('INPUT[@class=input_cep]').each(function(){$(this).mask('99999-999');});
	

	/**
	 * cria colorpicker , elementos com o atributo ID começando com "cor_"
	 *
	 */
	$('INPUT[@class=input_color]').each(function(){
		var id = $(this).attr('id');
		$(this).ColorPicker({
			onSubmit: function(hsb, hex, rgb) {
				$('#'+id+'').val(hex);
				$("#square_"+id).css('background-color', "#"+hex);
			},
			onBeforeShow: function () {
				$(this).ColorPickerSetColor(this.value);
				
			}
		})
		.bind('keyup', function(){
			$(this).ColorPickerSetColor(this.value);
		});	
		
	});
	
	
	
	
	
	
	
}); // fim jquery

/**
 * abre uma janela popUp 
 * para abrie a pop up no centro da tela os parâmetros top e left devem ser 0 
 *
 * @param string url : endereço
 * @param string name : nome da janela
 * @param int width : largura da janela
 * @param int height : altura da janela
 * @param int top : posição em relação ao topo 
 * @param int left : posição em relação a esquerda
 */
// TODO terminar esta função
function abrePopUp(url, name, width, height, top, left) {
	var winl = (screen.width - width)/2;
	var wint = (screen.height - height)/2;

	if((top == 0)&&(left == 0)) {
		window.open(url,null,"height="+height+",width="+width+",top="+wint+",left="+winl+",status=yes,toolbar=no,menubar=no,location=no");	
	} else {
		window.open(url,null,"height="+height+",width="+width+",status=yes,toolbar=no,menubar=no,location=no");
	}
}

function abrePopTelaInteira(url, name) { 
	
	var width = window.screen.width;
	var height = window.screen.height;
	
	window.open(url,name,'status=no,resizable=yes,scrollbars=no,menubar=no,width='+width+',height='+height+',left=15,top=20') ;
}