// JavaScript Document

/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("navprimaria").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate


//Máscara para moeda
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function validarCompra(){
	
	var d = document.formCompraPart1;

	if(d.elements['quantidade[1]'].value == 0 && d.elements['quantidade[2]'].value == 0 && d.elements['quantidade[4]'].value == 0 && d.elements['quantidade[5]'].value == 0 && d.elements['quantidade[6]'].value == 0){
		
		alert("Entre com a quantidade de L130, L230, X350, X550 ou U170");
		return false;
		d.txtQuantL130.focus();
	
	}
	
	if(d.elements['quantidade[1]'].value == "" || d.elements['quantidade[2]'].value == "" || d.elements['quantidade[4]'].value == "" || d.elements['quantidade[5]'].value == "" || d.elements['quantidade[6]'].value == ""){
		
		alert("Entre com a quantidade de L130, L230, X350, X550 ou U170");
		return false;
		d.txtQuantL130.focus();
	
	}
	
	
	if(d.txtContato.value == ""){
		
		alert("Entre com o nome do contato");
		return false;
		d.txtContato.focus();
	
	}
	
	if(d.txtCPF_CNPJ.value == ""){
		
		alert("Entre com o CPF / CNPJ do contaro ou empresa respectivamente");
		return false;
		d.txtCPF_CNPJ.focus();
	
	}
	
	if(d.txtRG_INSC.value == ""){
		
		alert("Entre com o RG / INSC. ESTADUAL do contaro ou empresa respectivamente");
		return false;
		d.txtRG_INSC.focus();
	
	}
	
	if(d.txtCEP.value == ""){
		
		alert("Entre o CEP do endereço de entrega");
		return false;
		d.txtCEP.focus();
	
	}
	
	if(d.txtEndereco.value == ""){
		
		alert("Entre com o endereço de entrega");
		return false;
		d.txtEndereco.focus();
	
	}
	
	if(d.txtNumero.value == ""){
		
		alert("Entre com o número do endereço de entrega");
		return false;
		d.txtNumero.focus();
	
	}
	
	if(d.txtBairro.value == ""){
		
		alert("Entre com o bairro do endereço de entrega");
		return false;
		d.txtBairro.focus();
	
	}
	
	if(d.txtCidade.value == ""){
		
		alert("Entre com a cidade do endereço de entrega");
		return false;
		d.txtCidade.focus();
	
	}
	
	if(d.txtUF.value == ""){
		
		alert("Entre com a UF do endereço de entrega");
		return false;
		d.txtUF.focus();
	
	}
	
	if(d.txtDDD.value == ""){
		
		alert("Entre com DDD do telefone para contato");
		return false;
		d.txtDDD.focus();
	
	}
	
	if(d.txtTelefone.value == ""){
		
		alert("Entre com o número de telefone para contato");
		return false;
		d.txtTelefone.focus();
	
	}

	if(d.txtEmail.value == ""){
		
		alert("Entre com o endereço de e-mail do contato");
		return false;
		d.txtEmail.focus();
	
	}
	
	if(d.selIdicacao.value == ""){
		
		alert("Informe como que nos conheceu");
		return false;
		d.selIdicacao.focus();
	
	}

	return true;
	
}
