function exibe(id){
	document.getElementById(id).style.display = "block";
}

function oculta(id){
	document.getElementById(id).style.display = "none";
}

function zeraCampo(thefield){
	if (thefield.defaultValue == thefield.value)
	thefield.value = ""
} 
function voltaCampo(thefield){
	if (thefield.value == "")
	thefield.value = thefield.defaultValue
}

function proximaFoto(){
	if (fotoCorrente<strImg.length-1){
		fotoCorrente++;
		document.images.imgThumb.src = strImg[fotoCorrente];
		escreveLnk(fotoCorrente);
	}
}
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 proximaFoto2(){
	if (fotoCorrente2<strImg2.length-1){
		fotoCorrente2++;
		document.images.imgThumb2.src = strImg2[fotoCorrente2];
		escreveLnk2(fotoCorrente2);
	}
}
function fotoAnterior2(){
	if (fotoCorrente2>0){
		fotoCorrente2--;
		document.images.imgThumb2.src = strImg2[fotoCorrente2];
		escreveLnk2(fotoCorrente2);
	}
}
function escreveLnk2(id){
	for(i=0; i<strImg2.length; i++)
	{
		document.getElementById("fotos2_"+i).style.display = "none";
	}
	document.getElementById("fotos2_"+id).style.display = "block";
}

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 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 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 saltarCampo( field , length , nextfield )
{
	if (field.value.length == length)
	{
		nextfield.focus();
	}
}
