function popup( a, w, h, s ){
	
	window.open( a, "jan", "width="+w+", height="+h+", scrollbars="+s+"" );	
	
}

function moveItemLista(campo1, campo2, info, disponivel) {
	
	var tamCampo2 = campo2.options.length;
	var itensRemover = [];
	var info_array = [];
	
	for( var i = 0; i<campo1.options.length; i++ ){

		if( campo1.options[i].selected ){
			
			campo2.options[tamCampo2++] = new Option(campo1.options[i].text, campo1.options[i].value, false, true);
			itensRemover.push( campo1.options[i].value );
			
		}
		
	}
	
	for( var i = 0; i<campo1.options.length; i++ ){		
		for( var t = 0; t<itensRemover.length; t++ ){			
			if( campo1.options[i].value == itensRemover[t] ){
				campo1.options[i] = null;		
			}	
		}	
	}
	
	for( var i = 0; i<disponivel.options.length; i++ ){
		info_array.push( disponivel.options[i].value );	
	}

	info.value = info_array.toString();
	
}

function validaExtensao( valor, extensoes_array ){

	var arquivo = valor.substr( valor.lastIndexOf( "\\" )+1, valor.length-valor.lastIndexOf( "\\" ) ).toLowerCase();
	var extArquivo = arquivo.split(".")[1];

	for( var i = 0; i<extensoes_array.length; i++ ){
		if( extArquivo == extensoes_array[i].toLowerCase() ){
			break;
		}
	}

	if( i<extensoes_array.length ){
		return true;	
	}else{
		return false;
	}
	
}

function quebraData( d ){
	
	var data = d.split( "/" );
	
	if( data.length != 3 )
		return false;
	
	return data[2].toString() + data[1].toString() + data[0].toString();

}

String.prototype._replace = function( mixed , _replace , qnt ){
	
	var $this = this.split('');
	
	if(qnt == undefined)
		qnt = this.lastIndexOf(mixed);

	for( var i = 0 , n = 0 ; i < $this.length && n < qnt ; i++ )
		if( $this[i] == mixed ){
			$this[i] = _replace;
			n++;
		}
	
	return $this.join('');
	
};

String.prototype.trim = function(){
	
	for( var i = 0 ; this.charAt(i) == " " ; i++ ){}
	
	var $this = this.substr( i , this.length );
	
	for ( var i = $this.length-1 ; $this.charAt(i) == " " ; i-- ){}

	return $this.substr(0, i+1);

};

String.prototype.truncaCharLeft = function( c ){
	
	for( var i = 0 ; i < this.length && this.charAt( i ) == c ; i++  ){}

	return this.substr( i , this.length );	
	
}

String.prototype.truncaCharRigth = function( c ){
	
	for( var i = this.length - 1 ; i >= 0 && this.charAt( i ) == c ; i-- ){}
		
	return this.substr( 0 , i + 1 );
	
}

String.prototype.truncaChar = function( tipo , c ){
	
	var result;

	if( tipo == "both" ){
		
		result = this.truncaCharLeft( c )
		result = result.truncaCharRigth( c )
	
	}else if( tipo == "left" )
		result = this.truncaCharLeft( c )
	else if( tipo == "rigth" )
		result = this.truncaCharRigth( c )
	
	return result;
	
}

function validaData( d ){

	var erData = /^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/[12][0-9]{3}$/;
	
	if( erData.test( d ) ){
		
		var diasArray = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ],
			data = d.split( "/" ),
			dia = data[0],
			mes = data[1],
			ano = data[2];
		
		diasArray[1] = isBissexto( ano ) ? 29 : 28;

		dia = dia.substr( 0 , 1 ) == "0" ? dia.substr( 1 , 1 ) : dia;
		mes = mes.substr( 0 , 1 ) == "0" ? mes.substr( 1 , 1 ) : mes;

		if( dia < 1 || dia > diasArray[mes-1] )
			return false
		
		return true
	}else
		return false

}

function isBissexto( ano ) {
	
    var multiploDeQuatro = ano % 4 == 0 ? true : false,
   		multiploDeCem = ano % 100 == 0 ? true : false,
    	multiploDeQuatrocentos = ano % 400 == 0 ? true : false;
		
	if( multiploDeQuatro && !multiploDeCem || multiploDeQuatrocentos )
		return true;
	else
		return false;	
	
}

/**
*	Funções para trabalhar com XMLHttpRequest - AJAX
*
*	@author		Thyago Mendes
*	@copyright  Facilit Tecnologia
*	@comment    Metodos para trabalhar com acesso ao servidor sem refresh
*/

var req;

function loadXMLDoc( url , funcao , param , callback ){

	req = null;

	if (window.XMLHttpRequest)
		req = new XMLHttpRequest();		
	else if (window.ActiveXObject)
		req = new ActiveXObject("Microsoft.XMLHTTP");		

	if(req){

		req.open("POST", url, true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.send("v=" + param);

		req.onreadystatechange = function(){
			
			if (req.readyState == 4)
				if (req.status == 200){
					if(callback != undefined)
						callback()
					funcao(req.responseText)
				}
				else
					alert("Houve um problema ao obter os dados:\n" + req.statusText);

		}
	}
	
}

function AjaxLoader( url , funcao , param , callback ){
	
	loadXMLDoc( url , funcao , param , callback );
	
}

function validaEmail( email ){
	
	var erEmail = /^[a-zA-Z0-9._-]{1,32}@([a-zA-Z0-9_-]{1,20}\.[a-zA-Z0-9_-]{1,32})(\.[a-zA-Z0-9_-]{1,32})*$/;
	
	return erEmail.test( email )

}

function verificarCPF(c){
	
	if( c.length != 11 ) 
		return false
	
	var i; 
	s = c;
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	var v = false;
	for (i = 0; i < 9; i++){ 
		d1 += c.charAt(i)*(10-i); 
	} 
	if (d1 == 0){ 
		return false; 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1){ 
		return true; 
	} 
	
	d1 *= 2; 
	for (i = 0; i < 9; i++) { 
		d1 += c.charAt(i)*(11-i); 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(1) != d1) { 
		return false; 
	} 
	
	return true
}

/**
*	Classe para adicionar eventos dinamicamente
*
*	@author		Thyago Mendes
*	@copyright  
*	@comment    métodos para trabalhar com eventos
*/

Evento = function(){}

Evento.prototype.addEvent = function( o , t , f ){

	o.addEventListener ? o.addEventListener( t , f , true ) : o.attachEvent( "on" + t , f )

}

/**
*	Classe para restringir um conjunto de caracteres atravês de funções
*
*	@author		Thyago Mendes
*	@copyright  
*	@comment    métodos para trabalhar com restrinções de teclas
*/

Restrict = function( f ){

	this.items = []
	this._function = f

}

Restrict.prototype = new Evento()

Restrict.prototype.addItem = function( o ){

	this.items.push( o )

}

Restrict.prototype.start = function(){

	for( var i = 0 ; i < this.items.length ; i++ ){

		this.addEvent( this.items[i] , "keypress" , this.restrict )
		this.items[i]._function = this._function
	
	}
	
}

Restrict.prototype.restrict = function( e ){

	var eDefault = e,
		e = typeof( e ) == "undefined" ? event : e,
		flag = true,
		$this = e.target ? e.target : e.srcElement
	
	if( e.srcElement )
			e.returnValue = $this._function( String.fromCharCode( e.keyCode ) )
		else{
	
			flag = !( e.keyCode == 9 || e.keyCode == 8 )
				
			e.cancelBubble = !flag ? false : !$this._function( String.fromCharCode( e.which ) );
	
			if( e.cancelBubble ){
			
				e.preventDefault()
				e.stopPropagation()				
			
			}
		
	}				

}