
function formCheckFrete(formobj){
	/*Nome dos Campos*/ var fieldRequired = Array("Envio");
	/* Nome p/ Exibição*/ var fieldDescription = Array("Forma de Envio");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v

	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("O seguinte campo é obrigatório:\n" + alertMsg);return false;}else{return true;}
}

function formCheckLogin(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("login","senha");
	/* Nome p/ Exibição*/var fieldDescription = Array("Login","Senha");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
	if(formobj.senha.value !="" && formobj.senha.value.length<5){alertMsg += " - Senha deve ter no mínimo 5 caracteres\n";}
		
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Os seguintes campos são obrigatórios:\n" + alertMsg);return false;}else{return true;}
}


function validacnpj(Campo)
{
	if (Campo != ""){
		var i;
		var Valida=true;
		var s = Campo;
		var c = s.substr(0,12);
		var dv = s.substr(12,2);
		var d1 = 0;
		for (i = 0; i < 12; i++){d1 += c.charAt(11-i)*(2+(i % 8));}
		if (d1 == 0) Valida=false;
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(0) != d1){Valida=false;}
		d1 *= 2;
		for (i = 0; i < 12; i++){d1 += c.charAt(11-i)*(2+((i+1) % 8));}
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(1) != d1){Valida=false;}
		return Valida; 
	}
}

function validaemail(pStr)
{
	if (pStr != ""){
		reEmail = /^[\w!#$%&*+\/=?^`{|}~-]+(\.[\w!#$%&*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
		if (reEmail.test(pStr) && pStr.length>0) {return true;} else{return false;}
	}
}

function Val(field,tipo)
{
if (tipo=="txt")pat=/[0-9]/;
if (tipo=="num")pat=/[^0-9]/;
if (tipo=="tel")pat=/[^0-9\-]/;
if (tipo=="dt")pat=/[^0-9\/]/;
idx = field.value.search( pat );
while ( idx > -1 ) {field.value = field.value.replace( pat, '' ); idx = field.value.search( pat );}
}

function formCheck(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Login","Senha");
	/* Nome p/ Exibição*/var fieldDescription = Array("Login","Senha");
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
	//EXTRas - Não vazios, mas inválidos --------------------^
	if (alertMsg!=""){alert("Os seguintes campos são obrigatórios:\n" + alertMsg);return false;}else{return true;}
}


function formCheckCadastro(formobj){
	if (document.all.Tipo_franquia.style.display=='' || document.all.Tipo_franquia.style.display=='inline') {
	/*Nome dos Campos*/var fieldRequired = Array("Razao_Social","DDD_Tel1","Tel1","Email","End_Fatura","Numero","Bairro_Fatura","Cidade_Fatura","Estado_Fatura","CEP_Fatura","Login","Senha");
	/* Nome p/ Exibição*/var fieldDescription = Array("Razão Social","DDD Telefone 1","Telefone 1","E-mail","Endereço","Número","Bairro","Cidade","Estado","CEP","Login","Senha");
	}
	if (document.all.Tipo_varejo.style.display=='' || document.all.Tipo_varejo.style.display=='inline' ) {
	/*Nome dos Campos*/var fieldRequired = Array("CPF","Contato","DDD_Tel1","Tel1","Email","End_Fatura","Numero","Bairro_Fatura","Cidade_Fatura","Estado_Fatura","CEP_Fatura","Login","Senha");
	/* Nome p/ Exibição*/var fieldDescription = Array("CPF","Nome para Contato","DDD Telefone 1","Telefone 1","E-mail","Endereço","Número","Bairro","Cidade","Estado","CEP","Login","Senha");
	}
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
		if(validaemail(formobj.Email.value)==false){alertMsg += " - E-mail Inválido\n";}
		if(validacnpj(formobj.CNPJ_Fatura.value)==false){alertMsg += " - CNPJ Inválido\n";}
		if(formobj.CEP_Fatura.value !="" && (formobj.CEP_Fatura.value.length<8 || formobj.CEP_Fatura.value.length>8)){alertMsg += " - CEP para Fatura Inválido. \n";}
		//if(formobj.CEP_Entrega.value !="" && (formobj.CEP_Entrega.value.length<8 || formobj.CEP_Entrega.value.length>8)){alertMsg += " - CEP para Entrega Inválido. \n";}
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Os seguintes campos são obrigatórios:\n" + alertMsg);return false;}else{return true;}
}


function formCheckAtualiza(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Razao_Social","End_Fatura","Cidade_Fatura","Estado_Fatura","CEP_Fatura","DDD_Tel1","Tel1","Email","Login","Senha");
	/* Nome p/ Exibição*/var fieldDescription = Array("Razão Social","Endereço","Cidade","Estado","CEP","DDD Telefone 1","Telefone 1","E-mail","Login","Senha");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
		if(formobj.Login.value !="" && formobj.Login.value.length<3){alertMsg += " - Login deve ter no mínimo 3 caracteres\n";}
		if(formobj.Senha.value !="" && formobj.Senha.value.length<5){alertMsg += " - Senha deve ter no mínimo 5 caracteres\n";}
		if(validaemail(formobj.Email.value)==false){alertMsg += " - E-mail Inválido\n";}
		if(validacnpj(formobj.CNPJ_Fatura.value)==false){alertMsg += " - CNPJ Inválido\n";}
		if(formobj.CEP_Fatura.value !="" && (formobj.CEP_Fatura.value.length<8 || formobj.CEP_Fatura.value.length>8)){alertMsg += " - CEP para Fatura Inválido. \n";}
		//if(formobj.CEP_Entrega.value !="" && (formobj.CEP_Entrega.value.length<8 || formobj.CEP_Entrega.value.length>8)){alertMsg += " - CEP para Entrega Inválido. \n";}
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Os seguintes campos são obrigatórios:\n" + alertMsg);return false;}else{return true;}
}



function formCheckFecha(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Razao_Social","End_Fatura","Cidade_Fatura","Estado_Fatura","CEP_Fatura","DDD_Tel1","Tel1","Email","Envio");
	/* Nome p/ Exibição*/var fieldDescription = Array("Razão Social","Endereço","Cidade","Estado","CEP","DDD Telefone 1","Telefone 1","E-mail","Forma de envio");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
		if(validaemail(formobj.Email.value)==false){alertMsg += " - E-mail Inválido\n";}
		if(validacnpj(formobj.CNPJ_Fatura.value)==false){alertMsg += " - CNPJ Inválido\n";}
		if(formobj.CEP_Fatura.value !="" && (formobj.CEP_Fatura.value.length<8 || formobj.CEP_Fatura.value.length>8)){alertMsg += " - CEP para Fatura Inválido. \n";}
		if(validaemail(formobj.transporte_email.value)==false){alertMsg += " - E-mail da Transportadora Inválido\n";}
		if(formobj.Obs.value !="" && formobj.Obs.value.length>500){alertMsg += " - Observações deve conter no máximo 500 caracteres. \n";}
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Os seguintes campos são obrigatórios:\n" + alertMsg);return false;}else{return true;}
}



function formCheckEsqueci(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Login");
	/* Nome p/ Exibição*/var fieldDescription = Array("Login");
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	if (alertMsg!=""){alert("O seguinte campo é obrigatório:\n" + alertMsg);return false;}else{return true;}
	//EXTRas - Não vazios, mas inválidos --------------------^
}

	
function formCheckContato(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Nome","Empresa","Email","DDD_Tel","Tel","Assunto","Mensagem");
	/* Nome p/ Exibição*/var fieldDescription = Array("Nome","Empresa","E-mail","DDD Telefone","Telefone","Assunto","Mensagem");
	
	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
		if(validaemail(formobj.Email.value)==false){alertMsg += " - E-mail Inválido\n";}
	//EXTRas - Não vazios, mas inválidos --------------------^

	if (alertMsg!=""){alert("Os seguintes campos são obrigatórios:\n" + alertMsg);return false;}else{return true;}
}			


function formCheckIndique(formobj){
	/*Nome dos Campos*/var fieldRequired = Array("Amigo1","Email_Amigo1","Nome","Email");
	/*Nomes para Exibição*/	var fieldDescription = Array("Nome do amigo","E-mail do amigo","Seu nome","Seu e-mail");

	var alertMsg = "";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
		switch(obj.type){//Um case pra cada tipo de campo
		case "select-one":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "select-multiple":if (obj.selectedIndex == -1 ||  obj.options[obj.selectedIndex].value == ""){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "text":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "password":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		case "textarea":if (obj.value == "" || obj.value == null){alertMsg += " - " + fieldDescription[i] + "\n";}break;
		default:if (obj.type == undefined){var blnchecked = false;for (var j = 0; j < obj.length; j++){if (obj[j].checked){blnchecked = true;}}if (!blnchecked){alertMsg += " - " + fieldDescription[i] + "\n";}}
		}
		}
	}
	//EXTRas - Não vazios, mas inválidos --------------------v
	if(validaemail(formobj.Email.value)==false){alertMsg += " - E-mail Inválido\n";}
	if(validaemail(formobj.Email_Amigo1.value)==false){alertMsg += " - E-mail do Amigo Inválido\n";}
	//EXTRAS - Não brancos, mas inválidos --------------------^

	if (alertMsg!=""){alert("Os seguintes campos são obrigatórios:\n" + alertMsg);return false;}else{return true;}
}	
	
	
function AutoNext(who, maxLength) 
{
	if (who.value.length == maxLength) 
	{
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) 
		{
			for (j=0; j<document.forms[i].elements.length; j++) 
			{
				if (document.forms[i].elements[j].name == who.name) 
				{
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == who.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				break;
			}
		}
	}
}

