function exibe(id){
	document.getElementById(id).style.display = "block";
}

function oculta(id){
	document.getElementById(id).style.display = "none";
}

function mandaValor(campo,legenda,valor){
	var box = document.getElementById(campo);
	var frm = document.getElementById(campo+"_frm");

	box.innerHTML = legenda;
	frm.value = valor;
}

function submitValCamp(campo){
	if (document.getElementById(campo).value != '')
		location.href = document.getElementById(campo).value;
}

function proximaFoto(){
	if (fotoCorrente<strImg.length-1){
		fotoCorrente++;
		document.images.imgThumb.src = strImg[fotoCorrente];
		escreveLnk(fotoCorrente);
	}
}

function createPopUp(url, popName, isMaxArea, width, height, isToCenter, top, left, isScrollBars, isResizable) {
/*
	url -> pagina a ser aberta
	popName -> nome de controle do popup
	width e height -> respectiva largura e altura
	maxArea -> marcado como 'yes' utilizará a area total
	scrollbars -> 'yes' ou 'no'
	resizable -> 'yes' ou 'no'
	top e left -> coordenadas de abertura do popup na tela
	isToCenter -> Indica que deve ser aberto ao centro da tela
*/
	tW = screen.width;
	tH = screen.height;
	if (isMaxArea == 'yes') { W = tW; H = tH; }
	else { W = width; H = height; }
	popArea = 'Width='+ W + ', Height='+ H +', ';

	if (isToCenter == 'yes') 
	{
		L = (tW - width) / 2;
		T = (tH - height) / 2;
	}
	else { L = left; T = top; }
	popPosition = 'top='+ T +', left='+ L +', ';

	popCaracteres = 'scrollbars='+ isScrollBars +', resizable='+ isResizable;

	window.open(url, popName, popArea + popPosition + popCaracteres);
}


function fotoAnterior(){
	if (fotoCorrente>0){
		fotoCorrente--;
		document.images.imgThumb.src = strImg[fotoCorrente];
		escreveLnk(fotoCorrente);
	}
}

function escreveLnk(id){
	for(i=0; i<strImg.length; i++)
	{
		document.getElementById("fotos_"+i).style.display = "none";
	}
	document.getElementById("fotos_"+id).style.display = "block";
}

function limparCombo( objCombo , strSelecione )
{
	while(objCombo.options.length > 0) 
			objCombo.options[0]=null;
	objCombo.options[objCombo.options.length] = new Option( strSelecione , '' )
}

function soNumeros(e){
     var key;
     var keychar;

     if (window.event) {
        key = window.event.keyCode;
     } else if (e) {
        key = e.which;
     } else {
        return true;
     }

     keychar = String.fromCharCode(key);

     // teclas de controle
     if ((key==null) || (key==0) || (key==8) ||
          (key==9) || (key==13) || (key==27) ) {
        return true;
     } else if ((("0123456789").indexOf(keychar) > -1)) {
        return true;     
     } else {
        return false;
     }
}


function carregaComboAjax(link, destino, strSelecione) 
{
	AjaxRequest.get(
		{	'url': link
			,'onError': function (req){	alert ( req.responseText );	}
			,'onSuccess':function(req) { 

				var itens = new String ( req.responseText );

				if (itens == 'vazio')
				{
					while(destino.options.length > 0) 
						destino.options[0]=null;
					destino.options[destino.options.length] = new Option( strSelecione , '' )
					return;
				}

				//divide em vírgula
				var vet = itens.split( ',' );

				//Limpa Combo
				while(destino.options.length > 0) 
					destino.options[0]=null;

				//Verifica se o array possui itens

				if (vet.length > 0)
				{

					destino.options[destino.options.length] = new Option( strSelecione , '' )

					for ( i = 0 ; i < vet.length ; i++ )
					{
						var strId = vet[i].split( '|' );
						if (strId[1] != '' && strId[0] != '')
						{
							destino.options[destino.options.length] = new Option( strId[1] , strId[0] )
						}
					}
				}				
			}
		}
	);
}

function saltarCampo( field , length , nextfield )
{
	if (field.value.length == length)
	{
		nextfield.focus();
	}
}

/*Conta caracteres no campo*/
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	}
	else{ 
		document.getElementById(countfield).innerHTML = maxlimit - field.value.length;
	}
}

function validarForm()
{
	var str_erro = "";
	var frmValidator = new Validator("frmCadastro");

	if (!frmValidator.isValid()) {
		str_erro = frmValidator.errMsg;
	}

	if (document.frmCadastro.cep1.value == '' || document.frmCadastro.cep1.value == '')
	{
		str_erro += "\n - O campo CEP não foi informado.";
	}else{
		if (document.frmCadastro.cep1.value.length < 5 || document.frmCadastro.cep2.value.length < 3 )
		{
			str_erro += "\n - O campo CEP não foi informado corretamente.";
		}
	}

	if (document.frmCadastro.senha.value != '' && document.frmCadastro.confsenha.value != '')
	{
		if (document.frmCadastro.senha.value != document.frmCadastro.confsenha.value )
		{
			str_erro += "\n - A confirmação de senha não confere com a senha digitada.";
		}else{
			if (document.frmCadastro.senha.value.length < 4)
			{	
				str_erro += "\n - A senha informada deve ter mais do que 3 caracteres";
			}
		}
	}

	if (document.frmCadastro.estado.value == '')
	{
		str_erro += "\n - O campo estado não foi informado.";
	}

	if (str_erro != '')
	{
		alert ('Os seguintes erros foram encontrados:\n' + str_erro);

	}else{

		document.frmCadastro.submit();

	}

}

