var xmlHttp = new Object();
var idCont;

function _jsPage() {
	if (_jsPage.arguments.length == 1) idCont = "tdCont";
	else idCont = _jsPage.arguments[1];
	page = _jsPage.arguments[0];

	if (window.XMLHttpRequest) xmlHttp=new XMLHttpRequest()
	else if (window.ActiveXObject) xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
	xmlHttp.onreadystatechange = _jsDone
	xmlHttp.open("GET", page, true)
	xmlHttp.send(null)
}

function _jsDone() { 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById(idCont).innerHTML = xmlHttp.responseText;
	}
	else {
		document.getElementById(idCont).innerHTML = "<img src=\"../img/imgCarregando.gif\" style=\"margin:2px 2px 2px 2px;\">";
	}
}


function _jsGeraSelect(tabName, fieldName, searchKey, searchValue, paramJs, paramCss, fieldValue, resultText, resultValue, idCont) {
	_jsPage("../inc/geraSelect.php?tabName="+tabName+"&fieldName="+fieldName+"&searchKey="+searchKey+"&searchValue="+searchValue+"&paramJs="+paramJs+"&paramCss="+paramCss+"&fieldValue="+fieldValue+"&resultText="+resultText+"&resultValue="+resultValue,idCont)
}

function _jsGeraSelect2(tabName, fieldName, searchKey, searchValue, paramJs, paramCss, fieldValue, resultText, resultValue, idCont) {
	_jsPage("../inc/geraSelect.php?tabName="+tabName+"&fieldName="+fieldName+"&searchKey="+searchKey+"&searchValue="+searchValue+"&paramJs="+paramJs+"&paramCss="+paramCss+"&fieldValue="+fieldValue+"&resultText="+resultText+"&resultValue="+resultValue,idCont)
}

function _jsGeraSelect3(tabName, fieldName, searchKey, searchValue, paramJs, paramCss, fieldValue, resultText, resultValue, idCont) {
	_jsPage("../inc/geraSelect.php?tabName="+tabName+"&fieldName="+fieldName+"&searchKey="+searchKey+"&searchValue="+searchValue+"&paramJs="+paramJs+"&paramCss="+paramCss+"&fieldValue="+fieldValue+"&resultText="+resultText+"&resultValue="+resultValue,idCont)
}

function _jsGeraSelectIntro(tabName, fieldName, searchKey, searchValue, paramJs, paramCss, fieldValue, resultText, resultValue, idCont) {
	_jsPage("inc/geraSelect.php?tabName="+tabName+"&fieldName="+fieldName+"&searchKey="+searchKey+"&searchValue="+searchValue+"&paramJs="+paramJs+"&paramCss="+paramCss+"&fieldValue="+fieldValue+"&resultText="+resultText+"&resultValue="+resultValue,idCont)
}


function popup(x,n,w,h,s) {
    var l = ( (window.screen.width  - w) / 2 );
    var t = ( (window.screen.height - h) / 2 );
   janelinha = window.open(x,n,'leftmargin=-15,topmargin=-15,marginheight=0,marginwidth=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+s+',resizable=no,top='+t+',left='+l+',screenX='+l+',screenY='+t+',copyhistory=no,height='+h+',width='+w+'');
}

function _jsValidaCPF(CPF){ 
 	var i; 
	s = CPF  
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	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 false;   
	} 
	  
	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; 
}

function _jsGeraCidade(Estado_Id, Cidade_Id, idCont) {
	_jsPage("../admin/acoes.php?Acao=41&Estado_Id="+Estado_Id+"&Cidade_Id="+Cidade_Id,idCont)
}

function FormataValor(id,tammax,teclapres) {
   
    if(window.event) 
	{ // Internet Explorer
	 var tecla = teclapres.keyCode; 
	}
	else if(teclapres.which) 
	{ // Nestcape / firefox
	 var tecla = teclapres.which;
    }
	vr = document.getElementById(id).value;
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( "/", "" );
	vr = vr.toString().replace( ",", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	vr = vr.toString().replace( ".", "" );
	tam = vr.length;
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1; }
		if (tecla == 8 ){ tam = tam - 1; }
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
		document.getElementById(id).value = vr; }
		if ( (tam > 2) && (tam <= 5) ){
		document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 6) && (tam <= 8) ){
		document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 9) && (tam <= 11) ){
		document.getElementById(id).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 12) && (tam <= 14) ){
		document.getElementById(id).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 15) && (tam <= 17) ){
		document.getElementById(id).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
	}
}

function Mascara(tipo, campo, teclaPress) {
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}
 
	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
	tam = s.length + 1;
 
	if ( tecla != 9 && tecla != 8 ) {
		switch (tipo)
		{
		case 'CPF' :
			if (tam > 3 && tam < 7)
				campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
			if (tam >= 7 && tam < 10)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
		break;
 
		case 'CNPJ' :
 
			if (tam > 2 && tam < 6)
				campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
			if (tam >= 6 && tam < 9)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
			if (tam >= 9 && tam < 13)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
			if (tam >= 13 && tam < 15)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
		break;
 
		case 'TELEFONE' :
			if (tam > 2 && tam < 4)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
			if (tam >= 7 && tam < 11)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
		break;


		case 'DATA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
			if (tam > 4 && tam < 11)
				campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
		break;
		
		case 'CEP' :
			if (tam > 5 && tam < 9)
				campo.value = s.substr(0,5) + '-' + s.substr(5,tam-4);
		break;
		}
	}
}


function addFav(){
    var url      = "http://www.visionartes.com.br";
    var title    = "LDR Esportes ::  Esporte é com a Gente!!!";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}


