    function Continuar()
    {
        var OpcaoGarantia = -1;
        for (j=0; j<document.getElementsByTagName("input").length; j++)
        {
	        campo = document.getElementsByTagName("input")[j];

	        if (campo.type == "radio" && campo.id == "rbGarantia" && campo.checked)
	        {
                OpcaoGarantia = campo.value;
	        }
        }
        if(OpcaoGarantia == -1)
        {
            alert("Por favor, selecione uma opção de garantia.");          
        }
        else if(OpcaoGarantia > 0 && !document.getElementById("ckContrato").checked)
        {
            alert("Antes de continuar, é preciso aceitar os termos do contrato.");                      
        }
        else
        {
            garantiaEstendida.SalvarGarantia(OpcaoGarantia.toString(), callback_SalvarGarantia);       
        }
    }
    
    function callback_SalvarGarantia(res) 
    {
    	if (res.error)
		{
			alert(res.error.Type + " : " + res.error.Message);
		}
		else if(res.value[0] != '')
        {
            alert(res.value[0]);
            
            if(res.value[0] == 'Sessão Expirada!')
            {
                window.setTimeout(function(){document.location.href = res.value[1];}, 3000);
            }    
        }
        else
        {
            document.location.href = res.value[1];
        }
    } 
    
    function ExibeContrato(campo)
    {
        if(campo.value > 0)
        {
            document.getElementById("divContrato").style.display = "";
        }
        else
        {
            document.getElementById("divContrato").style.display = "none";        
        }
    }
    
                
    function RemoverGarantia(ItemCodigo)
    {
        if(confirm('Tem certeza que deseja remover a garantia deste item?'))
        {
            if(ItemCodigo == '')
	        {
		        alert('Item não encontrado!'); 
	        }
            else
            {
                index.RemoverGarantia(ItemCodigo, callback_RemoverGarantia);
            }
        }
    }
    
    function callback_RemoverGarantia(res) 
    {
        if (res.error)
		{
			alert(res.error.Type + " : " + res.error.Message);
		}
		else if(res.value[0] != '')
        {
            alert(res.value[0]);
            
            if(res.value[0] == 'Sessão Expirada!')
            {
                window.setTimeout(function(){document.location.href = res.value[1];}, 3000);
            }    
        }
        else
        {
            document.location.href = res.value[1];
        }
    }                 

