//Préfixo do client ID 
var _strPreClientID = 'ctl00_ContentPlaceHolder1_';

function getValue(campo)
{	
    var objCampo = null;
    
    try
    {
        objCampo = document.getElementById(_strPreClientID + campo);	
	    objCampo = (objCampo == null)? document.getElementById(campo):objCampo;	
	}	
	catch(ex)
	{
	    gravarErro(ex.message + ' ; HTMLControls.getValue; campo: ' + campo);
	}
	
	if(objCampo  != null)
	{		
		return objCampo.value; 
	}
	
	return null;
}


function setValue(campo, valor)
{	
    var objCampo = null;
    
	try
	{
	    objCampo = document.getElementById(_strPreClientID + campo);
	    objCampo = (objCampo == null)? document.getElementById(campo):objCampo;	
	}
	
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.setValue; campo: ' + campo + ' valor: ' + valor);
	}
	
	if(objCampo  != null)
	{
		objCampo.value = valor; 
	}
}


function getValueCombo(campo)
{	
    var objCampo = null;
    
    try
    {
	    objCampo = document.getElementById(_strPreClientID + campo);	
	    objCampo = (objCampo == null)? document.getElementById(campo):objCampo;		
	}	
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.getValueCombo; campo: ' + campo );
	}
	
	if(objCampo != null)
	{			
		return objCampo.options[objCampo.selectedIndex].value; 
	}
	
	return null;
}

function setOptionCombo(campo, valor)
{
    var objCampo = null;
    
    try
    {
	    objCampo = document.getElementById(_strPreClientID + campo);	
	    objCampo = (objCampo == null)? document.getElementById(campo):objCampo;	
    	               	
	    var strAux = new String('');
	    var intFimTag = new Number('0');
	    if(objCampo  != null)
	    {		    
		    if(objCampo.outerHTML != null && objCampo.outerHTML.toUpperCase().indexOf('<SELECT') >= 0)
		    {
			    intFimTag = objCampo.outerHTML.indexOf('>') + 1;		
			    strAux += objCampo.outerHTML.substring(0, intFimTag);		
			    strAux += valor + '</select>'
			    strAux = strAux.replace('"', '');		
			    objCampo.outerHTML = strAux;
		    }		
		    else if(objCampo.innerHTML.toUpperCase().indexOf('<OPTION') >= 0)
		    {	
			    strAux += valor ;
			    strAux = strAux.replace('"', '');					
			    objCampo.innerHTML = strAux;
		    }	
	    }	
	}	
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.setOptionCombo; campo: ' + campo + ' valor: ' + valor);
	}
}

function setValueDisable(campo, valor)
{	
    var objCampo = null;
    
    try
    {
	    objCampo = document.getElementById(_strPreClientID + campo);	
	    objCampo = (objCampo == null)? document.getElementById(campo):objCampo;	
	}	
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.setValueDisable; campo: ' + campo + ' valor: ' + valor);
	}
	              
	if(objCampo  != null)
	{
		objCampo.value = valor; 
	}
}

//desabilita/habilita controle
function disableField(campo, status)
{
    var objCampo = null;
    
    try
    {	    
	    objCampo = document.getElementById(_strPreClientID + campo);
	    objCampo = (objCampo == null) ? document.getElementById(campo) : objCampo;

	    if (campo == 'reqValSenhaCel') {
	        alert('to qui')
	        alert(objCampo == null)
	    }
    }	
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.disableField; campo: ' + campo + ' status: ' + status);	    
	}
                 
	if(objCampo  != null)
	{
		objCampo.disabled = status; 
	}
}

function tamanhoCombo(campo)
{
    var objCampo = null;
    
    try
    {
	    objCampo = document.getElementById(_strPreClientID + campo);	
	    objCampo = (objCampo == null)? document.getElementById(campo):objCampo;	
	}
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.tamanhoCombo; campo: ' + campo);
	}
	               
	if(objCampo  != null)			
		return objCampo.options.length;
	
}

//Altera foco automaticamente assim que atingir o nr de carateres mx do campo
//campo de ter propriedade maxlength  habilitada
//Funciona somente para Campo text e textArea
function alteraFocoAuto(campo, proximoCampo )
{
    var objCampo = null;
    var objProxCampo = null;
    
    try
    {
	    objCampo = document.getElementById(_strPreClientID + campo);	
	    objCampo = (objCampo == null)? document.getElementById(campo):objCampo;	
	    	
	    objProxCampo = document.getElementById(_strPreClientID + proximoCampo);	
	    objCampo = (objCampo == null)? document.getElementById(proximoCampo):objCampo;	
	    
	    if(objCampo != null && objProxCampo != null)
	    {			
		    if( objCampo.value.length == objCampo.getAttribute('maxlength') )
		    {			
			    objProxCampo.focus();			
		    }
	    }
	
	}
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.alteraFocoAuto; campo: ' + campo + ' proximoCampo: ' + proximoCampo);
	}	
	
}

function getRefElementoId(campo)
{
    var objCampo = null;
    
    try
    {
        objCampo = document.getElementById(_strPreClientID + campo);	
        objCampo = (objCampo == null)? document.getElementById(campo):objCampo;	    
    }
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.getRefElementoId; campo: ' + campo);
	}
	
	return objCampo;
}

function getAtributo(objElemento, strAtributo )
{
    try
    {
	    return objElemento.getAttribute(strAtributo);
	}
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.getAtributo; strAtributo: ' + strAtributo);
	}
}

function setAtributo(objElemento, strAtributo, strValor )
{
	try
	{
	    return objElemento.setAttribute(strAtributo, strValor);
	}
	catch(ex)
	{
	    gravarErro(ex + ' ; HTMLControls.setAtributo; strAtributo: ' + strAtributo + ' strValor' + strValor);
	}
}

