// JavaScript Document


function mudaImg (img,path,elemento) {
	var caminho = "_imgs/_produtos/" + img;
	document.getElementById(elemento).src= caminho;
}


var selected;

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.checkout_payment.payment[0]) {
    document.checkout_payment.payment[buttonSelect].checked=true;
  } else {
    document.checkout_payment.payment.checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function check_form98() {
  var error = 0;
  var error_message = "ATENÇÃO:\n\n";
  var error_field = '*';
  var payment_value = null;
  if (document.checkout_payment.payment.length == null) {
    if (!document.checkout_payment.payment.checked) {
	  error_message = error_message + "Informe a forma de pagamento disponível.\n";
      error = 1;
	  if (error_field == '*') error_field = document.checkout_payment.payment;
	}
  }
  else {
  if (document.checkout_payment.payment.length) {
    for (var i=0; i<document.checkout_payment.payment.length; i++) {
      if (document.checkout_payment.payment[i].checked) {
        payment_value = document.checkout_payment.payment[i].value;
      }
    }
  } else if (document.checkout_payment.payment.checked) {
    payment_value = document.checkout_payment.payment.value;
  } else if (document.checkout_payment.payment.value) {
    payment_value = document.checkout_payment.payment.value;
  }


  if (payment_value == null) {
    error_message = error_message + "Informe uma forma de pagamento para a sua compra.\n";
    error = 1;
	if (error_field == '*') error_field = document.checkout_payment.payment[0];
  }
  }

  if (error == 1) {
    alert(error_message);
	error_field.focus();
	error_field.select();
    return false;
  } else {
    return true;
  }
}

function popupImageWindow(url) {
		document.close();
  		window.open(url,'popupImageWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
	}

function changeType(tp) {
	if (tp == 1) {
		$('n1pj').style.visibility = 'hidden';
		$('n1pf').style.visibility = 'visible';
		$('n2pj').style.visibility = 'hidden';
		$('n2pf').style.visibility = 'visible';
		$('n3pj').style.visibility = 'hidden';
		$('n3pf').style.visibility = 'visible';
		$('n4pj').style.visibility = 'hidden';
		$('n4pf').style.visibility = 'visible';
	}
	else {
		$('n1pf').style.visibility = 'hidden';
		$('n1pj').style.visibility = 'visible';
		$('n2pf').style.visibility = 'hidden';
		$('n2pj').style.visibility = 'visible';
		$('n3pf').style.visibility = 'hidden';
		$('n3pj').style.visibility = 'visible';
		$('n4pf').style.visibility = 'hidden';
		$('n4pj').style.visibility = 'visible';		
	}
}

function resetStateText(theForm) {
  theForm.state.value = '';
  if (theForm.zone_id.options.length > 1) {
    theForm.state.value = "-- Selecione Acima --";
  }
}

function resetZoneSelected(theForm) {
  if (theForm.zone_id.options.length > 1) {
    theForm.state.value = "-- Selecione Acima --";
  }
}

function update_zone(theForm) {
  var NumState = theForm.zone_id.options.length;
  var SelectedCountry = '';

  while(NumState > 0) {
    NumState--;
    theForm.zone_id.options[NumState] = null;
  }         

  SelectedCountry = theForm.country.options[theForm.country.selectedIndex].value;
            
  if (SelectedCountry == "30") {
    theForm.zone_id.options[0] = new Option("--", "");
    theForm.zone_id.options[1] = new Option("Acre", "193");
    theForm.zone_id.options[2] = new Option("Alagoas", "202");
    theForm.zone_id.options[3] = new Option("Amapá", "198");
    theForm.zone_id.options[4] = new Option("Amazonas", "196");
    theForm.zone_id.options[5] = new Option("Bahia", "200");
    theForm.zone_id.options[6] = new Option("Ceará", "206");
    theForm.zone_id.options[7] = new Option("Distrito Federal", "192");
    theForm.zone_id.options[8] = new Option("Espírito Santo", "189");
    theForm.zone_id.options[9] = new Option("Goiás", "191");
    theForm.zone_id.options[10] = new Option("Maranhão", "208");
    theForm.zone_id.options[11] = new Option("Mato Grosso", "183");
    theForm.zone_id.options[12] = new Option("Mato Grosso do Sul", "190");
    theForm.zone_id.options[13] = new Option("Minas Gerais", "182");
    theForm.zone_id.options[14] = new Option("Pará", "197");
    theForm.zone_id.options[15] = new Option("Paraiba", "204");
    theForm.zone_id.options[16] = new Option("Paraná", "186");
    theForm.zone_id.options[17] = new Option("Pernambuco", "203");
    theForm.zone_id.options[18] = new Option("Piauí", "207");
    theForm.zone_id.options[19] = new Option("Rio de Janeiro", "185");
    theForm.zone_id.options[20] = new Option("Rio Grande do Norte", "205");
    theForm.zone_id.options[21] = new Option("Rio Grande do Sul", "187");
    theForm.zone_id.options[22] = new Option("Rondônia", "194");
    theForm.zone_id.options[23] = new Option("Roraima", "195");
    theForm.zone_id.options[24] = new Option("Santa Catarina", "188");
    theForm.zone_id.options[25] = new Option("São Paulo", "184");
    theForm.zone_id.options[26] = new Option("Sergipe", "201");
    theForm.zone_id.options[27] = new Option("Tocantins", "199");
  }
  else if (SelectedCountry == "38") {
    theForm.zone_id.options[0] = new Option("--", "");
    theForm.zone_id.options[1] = new Option("Alberta", "66");
    theForm.zone_id.options[2] = new Option("British Columbia", "67");
    theForm.zone_id.options[3] = new Option("Manitoba", "68");
    theForm.zone_id.options[4] = new Option("New Brunswick", "70");
    theForm.zone_id.options[5] = new Option("Newfoundland", "69");
    theForm.zone_id.options[6] = new Option("Northwest Territories", "72");
    theForm.zone_id.options[7] = new Option("Nova Scotia", "71");
    theForm.zone_id.options[8] = new Option("Nunavut", "73");
    theForm.zone_id.options[9] = new Option("Ontario", "74");
    theForm.zone_id.options[10] = new Option("Prince Edward Island", "75");
    theForm.zone_id.options[11] = new Option("Quebec", "76");
    theForm.zone_id.options[12] = new Option("Saskatchewan", "77");
    theForm.zone_id.options[13] = new Option("Yukon Territory", "78");
  }
  else if (SelectedCountry == "81") {
    theForm.zone_id.options[0] = new Option("--", "");
    theForm.zone_id.options[1] = new Option("Baden-Württemberg", "80");
    theForm.zone_id.options[2] = new Option("Bayern", "81");
    theForm.zone_id.options[3] = new Option("Berlin", "82");
    theForm.zone_id.options[4] = new Option("Brandenburg", "83");
    theForm.zone_id.options[5] = new Option("Bremen", "84");
    theForm.zone_id.options[6] = new Option("Hamburg", "85");
    theForm.zone_id.options[7] = new Option("Hessen", "86");
    theForm.zone_id.options[8] = new Option("Mecklenburg-Vorpommern", "87");
    theForm.zone_id.options[9] = new Option("Niedersachsen", "79");
    theForm.zone_id.options[10] = new Option("Nordrhein-Westfalen", "88");
    theForm.zone_id.options[11] = new Option("Rheinland-Pfalz", "89");
    theForm.zone_id.options[12] = new Option("Saarland", "90");
    theForm.zone_id.options[13] = new Option("Sachsen", "91");
    theForm.zone_id.options[14] = new Option("Sachsen-Anhalt", "92");
    theForm.zone_id.options[15] = new Option("Schleswig-Holstein", "93");
    theForm.zone_id.options[16] = new Option("Thüringen", "94");
  }
  else if (SelectedCountry == "195") {
    theForm.zone_id.options[0] = new Option("--", "");
    theForm.zone_id.options[1] = new Option("A Coruña", "158");
    theForm.zone_id.options[2] = new Option("Alava", "130");
    theForm.zone_id.options[3] = new Option("Alicante", "138");
    theForm.zone_id.options[4] = new Option("Almeria", "139");
    theForm.zone_id.options[5] = new Option("Asturias", "140");
    theForm.zone_id.options[6] = new Option("Avila", "141");
    theForm.zone_id.options[7] = new Option("Badajoz", "142");
    theForm.zone_id.options[8] = new Option("Baleares", "164");
    theForm.zone_id.options[9] = new Option("Barcelona", "136");
    theForm.zone_id.options[10] = new Option("Burgos", "143");
    theForm.zone_id.options[11] = new Option("Caceres", "144");
    theForm.zone_id.options[12] = new Option("Cadiz", "145");
    theForm.zone_id.options[13] = new Option("Cantabria", "146");
    theForm.zone_id.options[14] = new Option("Cantabria", "165");
    theForm.zone_id.options[15] = new Option("Castellon", "147");
    theForm.zone_id.options[16] = new Option("Ceuta", "148");
    theForm.zone_id.options[17] = new Option("Ciudad Real", "149");
    theForm.zone_id.options[18] = new Option("Cordoba", "150");
    theForm.zone_id.options[19] = new Option("Cuenca", "151");
    theForm.zone_id.options[20] = new Option("Girona", "152");
    theForm.zone_id.options[21] = new Option("Granada", "133");
    theForm.zone_id.options[22] = new Option("Guadalajara", "154");
    theForm.zone_id.options[23] = new Option("Guipuzcoa", "155");
    theForm.zone_id.options[24] = new Option("Huelva", "156");
    theForm.zone_id.options[25] = new Option("Huesca", "157");
    theForm.zone_id.options[26] = new Option("Jaen", "134");
    theForm.zone_id.options[27] = new Option("La Rioja", "159");
    theForm.zone_id.options[28] = new Option("Las Palmas", "153");
    theForm.zone_id.options[29] = new Option("Leon", "160");
    theForm.zone_id.options[30] = new Option("Lleida", "162");
    theForm.zone_id.options[31] = new Option("Lugo", "161");
    theForm.zone_id.options[32] = new Option("Madrid", "163");
    theForm.zone_id.options[33] = new Option("Malaga", "131");
    theForm.zone_id.options[34] = new Option("Melilla", "181");
    theForm.zone_id.options[35] = new Option("Murcia", "166");
    theForm.zone_id.options[36] = new Option("Navarra", "167");
    theForm.zone_id.options[37] = new Option("Ourense", "168");
    theForm.zone_id.options[38] = new Option("Palencia", "169");
    theForm.zone_id.options[39] = new Option("Pontevedra", "170");
    theForm.zone_id.options[40] = new Option("Salamanca", "171");
    theForm.zone_id.options[41] = new Option("Segovia", "132");
    theForm.zone_id.options[42] = new Option("Sevilla", "135");
    theForm.zone_id.options[43] = new Option("Soria", "172");
    theForm.zone_id.options[44] = new Option("Tarragona", "173");
    theForm.zone_id.options[45] = new Option("Tenerife", "174");
    theForm.zone_id.options[46] = new Option("Teruel", "175");
    theForm.zone_id.options[47] = new Option("Toledo", "176");
    theForm.zone_id.options[48] = new Option("Valencia", "137");
    theForm.zone_id.options[49] = new Option("Valladolid", "177");
    theForm.zone_id.options[50] = new Option("Vizcaya", "178");
    theForm.zone_id.options[51] = new Option("Zamora", "179");
    theForm.zone_id.options[52] = new Option("Zaragoza", "180");
  }
  else if (SelectedCountry == "204") {
    theForm.zone_id.options[0] = new Option("--", "");
    theForm.zone_id.options[1] = new Option("Aargau", "104");
    theForm.zone_id.options[2] = new Option("Appenzell Ausserrhoden", "106");
    theForm.zone_id.options[3] = new Option("Appenzell Innerrhoden", "105");
    theForm.zone_id.options[4] = new Option("Basel-Landschaft", "108");
    theForm.zone_id.options[5] = new Option("Basel-Stadt", "109");
    theForm.zone_id.options[6] = new Option("Bern", "107");
    theForm.zone_id.options[7] = new Option("Freiburg", "110");
    theForm.zone_id.options[8] = new Option("Genf", "111");
    theForm.zone_id.options[9] = new Option("Glarus", "112");
    theForm.zone_id.options[10] = new Option("Graubünden", "113");
    theForm.zone_id.options[11] = new Option("Jura", "114");
    theForm.zone_id.options[12] = new Option("Luzern", "115");
    theForm.zone_id.options[13] = new Option("Neuenburg", "116");
    theForm.zone_id.options[14] = new Option("Nidwalden", "117");
    theForm.zone_id.options[15] = new Option("Obwalden", "118");
    theForm.zone_id.options[16] = new Option("Schaffhausen", "120");
    theForm.zone_id.options[17] = new Option("Schwyz", "122");
    theForm.zone_id.options[18] = new Option("Solothurn", "121");
    theForm.zone_id.options[19] = new Option("St. Gallen", "119");
    theForm.zone_id.options[20] = new Option("Tessin", "124");
    theForm.zone_id.options[21] = new Option("Thurgau", "123");
    theForm.zone_id.options[22] = new Option("Uri", "125");
    theForm.zone_id.options[23] = new Option("Waadt", "126");
    theForm.zone_id.options[24] = new Option("Wallis", "127");
    theForm.zone_id.options[25] = new Option("Zug", "128");
    theForm.zone_id.options[26] = new Option("Zürich", "129");
  }
  else if (SelectedCountry == "223") {
    theForm.zone_id.options[0] = new Option("--", "");
    theForm.zone_id.options[1] = new Option("Alabama", "1");
    theForm.zone_id.options[2] = new Option("Alaska", "2");
    theForm.zone_id.options[3] = new Option("American Samoa", "3");
    theForm.zone_id.options[4] = new Option("Arizona", "4");
    theForm.zone_id.options[5] = new Option("Arkansas", "5");
    theForm.zone_id.options[6] = new Option("Armed Forces Africa", "6");
    theForm.zone_id.options[7] = new Option("Armed Forces Americas", "7");
    theForm.zone_id.options[8] = new Option("Armed Forces Canada", "8");
    theForm.zone_id.options[9] = new Option("Armed Forces Europe", "9");
    theForm.zone_id.options[10] = new Option("Armed Forces Middle East", "10");
    theForm.zone_id.options[11] = new Option("Armed Forces Pacific", "11");
    theForm.zone_id.options[12] = new Option("California", "12");
    theForm.zone_id.options[13] = new Option("Colorado", "13");
    theForm.zone_id.options[14] = new Option("Connecticut", "14");
    theForm.zone_id.options[15] = new Option("Delaware", "15");
    theForm.zone_id.options[16] = new Option("District of Columbia", "16");
    theForm.zone_id.options[17] = new Option("Federated States Of Micronesia", "17");
    theForm.zone_id.options[18] = new Option("Florida", "18");
    theForm.zone_id.options[19] = new Option("Georgia", "19");
    theForm.zone_id.options[20] = new Option("Guam", "20");
    theForm.zone_id.options[21] = new Option("Hawaii", "21");
    theForm.zone_id.options[22] = new Option("Idaho", "22");
    theForm.zone_id.options[23] = new Option("Illinois", "23");
    theForm.zone_id.options[24] = new Option("Indiana", "24");
    theForm.zone_id.options[25] = new Option("Iowa", "25");
    theForm.zone_id.options[26] = new Option("Kansas", "26");
    theForm.zone_id.options[27] = new Option("Kentucky", "27");
    theForm.zone_id.options[28] = new Option("Louisiana", "28");
    theForm.zone_id.options[29] = new Option("Maine", "29");
    theForm.zone_id.options[30] = new Option("Marshall Islands", "30");
    theForm.zone_id.options[31] = new Option("Maryland", "31");
    theForm.zone_id.options[32] = new Option("Massachusetts", "32");
    theForm.zone_id.options[33] = new Option("Michigan", "33");
    theForm.zone_id.options[34] = new Option("Minnesota", "34");
    theForm.zone_id.options[35] = new Option("Mississippi", "35");
    theForm.zone_id.options[36] = new Option("Missouri", "36");
    theForm.zone_id.options[37] = new Option("Montana", "37");
    theForm.zone_id.options[38] = new Option("Nebraska", "38");
    theForm.zone_id.options[39] = new Option("Nevada", "39");
    theForm.zone_id.options[40] = new Option("New Hampshire", "40");
    theForm.zone_id.options[41] = new Option("New Jersey", "41");
    theForm.zone_id.options[42] = new Option("New Mexico", "42");
    theForm.zone_id.options[43] = new Option("New York", "43");
    theForm.zone_id.options[44] = new Option("North Carolina", "44");
    theForm.zone_id.options[45] = new Option("North Dakota", "45");
    theForm.zone_id.options[46] = new Option("Northern Mariana Islands", "46");
    theForm.zone_id.options[47] = new Option("Ohio", "47");
    theForm.zone_id.options[48] = new Option("Oklahoma", "48");
    theForm.zone_id.options[49] = new Option("Oregon", "49");
    theForm.zone_id.options[50] = new Option("Palau", "50");
    theForm.zone_id.options[51] = new Option("Pennsylvania", "51");
    theForm.zone_id.options[52] = new Option("Puerto Rico", "52");
    theForm.zone_id.options[53] = new Option("Rhode Island", "53");
    theForm.zone_id.options[54] = new Option("South Carolina", "54");
    theForm.zone_id.options[55] = new Option("South Dakota", "55");
    theForm.zone_id.options[56] = new Option("Tenessee", "56");
    theForm.zone_id.options[57] = new Option("Texas", "57");
    theForm.zone_id.options[58] = new Option("Utah", "58");
    theForm.zone_id.options[59] = new Option("Vermont", "59");
    theForm.zone_id.options[60] = new Option("Virgin Islands", "60");
    theForm.zone_id.options[61] = new Option("Virginia", "61");
    theForm.zone_id.options[62] = new Option("Washington", "62");
    theForm.zone_id.options[63] = new Option("West Virginia", "63");
    theForm.zone_id.options[64] = new Option("Wisconsin", "64");
    theForm.zone_id.options[65] = new Option("Wyoming", "65");
  }
  else {
    theForm.zone_id.options[0] = new Option("Digite abaixo", "");
  }

  resetStateText(theForm);
}

function validEmail(email) {
	invalidChars = " /:,;"
	if (email == "") {						// cannot be empty
		return false
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {					// and at least one "." after the "@"
		return false
	}
	if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
		return false
	}
	return true
}

function isNum(passedVal,tam) {					// Is this a number?
	if (passedVal == "") {
		return false
	}
	for (i=0; i<passedVal.length; i++) {
		if (passedVal.charAt(i) < "0") {
			return false
		}
		if (passedVal.charAt(i) > "9") {
			return false
		}
	}
	if (passedVal.length != tam) {
		return false
	}
	return true
}

function check_form_account() {
  var error = 0;
  var error_message = "Erro no formulário. Efetue as seguintes correções:\n\n";
  var error_field = '*';

  var first_name = document.account_edit.firstname.value;
  var last_name = document.account_edit.lastname.value;
  var dob = document.account_edit.dob.value;
  var email_address = document.account_edit.email_address.value;  
  var doc_id = document.account_edit.doc_id.value;
  var street_address = document.account_edit.street_address.value;
  var n_street_address = document.account_edit.n_street_address.value;
  var postcode = document.account_edit.postcode.value;
  var city = document.account_edit.city.value;
  var bairro = document.account_edit.suburb.value;
  var telephone = document.account_edit.telephone.value;
  var password = document.account_edit.password.value;
  var confirmation = document.account_edit.confirmation.value;

  if (document.account_edit.elements['person'].type != "hidden") {
    if (document.account_edit.person[0].checked || document.account_edit.person[1].checked) {
    } else {
      error_message = error_message + "Selecione Pessoa Física ou Jurídica.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.person[0];
    }
  }
 
  if (document.account_edit.elements['firstname'].type != "hidden") {
    if (first_name == '' || first_name.length < 4) {
      error_message = error_message + "O Nome ou Empresa deve ter no mínimo 4 caracteres.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.firstname;
    }
  }

  if (document.account_edit.elements['lastname'].type != "hidden") {
    if (last_name == '' || last_name.length < 4) {
      error_message = error_message + "O Sobrenome ou Responsável deve ter no mínimo 4 caracteres.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.lastname;
    }
  }

  if (document.account_edit.elements['dob'].type != "hidden") {
	if (dob != '') {
	  	if (!IsValidDate(dob,'dd/mm/yyyy')) {
			error_message = error_message + "Data de nascimento inválida. (formato: dd/mm/aaaa - dia/mês/ano).\n";
	      	error = 1;
		  	if (error_field == '*') error_field = document.account_edit.dob;
		}
	}
  	/*
    if (dob == '' || dob.length != 10) {
      error_message = error_message + "A data de nascimento deve ser no formato: xx/xx/xxxx (dia/mês/ano).\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.dob;
    }
	else {
	  if (dob.charAt(2) != '/' || dob.charAt(5) != '/') {
	  	error_message = error_message + "A data de nascimento deve ser no formato: xx/xx/xxxx (dia/mês/ano).\n";
      	error = 1;
	  	if (error_field == '*') error_field = document.account_edit.dob;
	  }
	}
	*/
  }
  if (document.account_edit.elements['email_address'].type != "hidden") {
    if (email_address == '' || email_address.length < 6) {
      error_message = error_message + "O email deve ter no mínimo 6 caracteres.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.email_address;
    }
	else {
	  if (!validEmail(email_address)) {
	  	error_message = error_message + "Seu endereço de email é inválido.\n";
		if (error_field == '*') error_field = document.account_edit.email_address;
	    error = 1;
	  }
	}
  }

  if (document.account_edit.elements['doc_id'].type != "hidden") {
  	if (!isNum(doc_id,11) && !isNum(doc_id,14)) {
		error_message = error_message + "CPF deve ter 11 dígitos e CNPJ deve ter 14 dígitos.\n";
		if (error_field == '*') error_field = document.account_edit.doc_id;
	    error = 1;
	}
	else {
		if (doc_id.length == 11 && !verifica_CPF(doc_id)) {
			error_message = error_message + "CPF inválido.\n";
			if (error_field == '*') error_field = document.account_edit.doc_id;
	    	error = 1;
		}
		if (doc_id.length == 14 && !verifica_CNPJ(doc_id)) {
			error_message = error_message + "CNPJ inválido.\n";
			if (error_field == '*') error_field = document.account_edit.doc_id;
	    	error = 1;
		}
	}
  }
  
  if (document.account_edit.elements['street_address'].type != "hidden") {
    if (street_address == '' || street_address.length < 5) {
      error_message = error_message + "O endereço deve ter no mínimo 5 caracteres.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.street_address;
    }
  }
  
  if (document.account_edit.elements['n_street_address'].type != "hidden") {
    if (street_address == '' || n_street_address.length < 1) {
      error_message = error_message + "O numero do endereço deve ser informado, caso seu endereço não possua numero informe S/N.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.n_street_address;
    }
  }

  if (document.account_edit.elements['postcode'].type != "hidden") {
    if (postcode == '' || postcode.length < 5) {
      error_message = error_message + "O CEP deve ter 8 números.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.postcode;
    }
  }  
  
  if (document.account_edit.elements['city'].type != "hidden") {
    if (city == '' || city.length < 3) {
      error_message = error_message + "A cidade deve ter no mínimo 3 caracteres.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.city;
    }
  }

  if (document.account_edit.elements['suburb'].type != "hidden") {
    if (bairro == '' || bairro.length < 3) {
      error_message = error_message + "O bairro deve ter no mínimo 3 caracteres.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.suburb;
    }
  }  
  
  if (document.account_edit.elements['zone_id'].type != "hidden") {
    if (document.account_edit.zone_id.options.length <= 1) {
      if (document.account_edit.state.value == '' || document.account_edit.state.value.length < 4 ) {
         error_message = error_message + "Selecione um estado.\n";
         error = 1;
		 if (error_field == '*') error_field = document.account_edit.zone_id;
      }
    } else {
      document.account_edit.state.value = '';
      if (document.account_edit.zone_id.selectedIndex == 0) {
         error_message = error_message + "Selecione o estado a partir da lista do país.\n";
         error = 1;
		 if (error_field == '*') error_field = document.account_edit.state;
      }
    }
  }

  if (document.account_edit.elements['country'].type != "hidden") {
    if (document.account_edit.country.value == 0) {
      error_message = error_message + "Escolha o país.";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.country;
    }
  }

  if (document.account_edit.elements['telephone'].type != "hidden") {
    if (telephone == '' || telephone.length < 6) {
      error_message = error_message + "O telefone deve ter no mínimo 6 caracteres.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.telephone;
    }
  }  
  
  if (document.account_edit.elements['password'].type != "hidden") {
    if ((password != confirmation) || (password == '' || password.length < 5)) {
      error_message = error_message + "A senha e a confirmação devem ser iguais e ter no mínimo 5 caracteres.\n";
      error = 1;
	  if (error_field == '*') error_field = document.account_edit.password;
    }
  }

  if (error == 1) {
    alert(error_message);
	error_field.focus();
	error_field.select();
    return false;
  } else {
    return true;
  }
}

function limpa_campo(S){
var Digitos = "0123456789";
var temp = "";
var digito = "";
    for (var i=0; i<S.length; i++){
      digito = S.charAt(i);
      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
    }
    return temp
}
                
function verifica_CPF(s)
{       
        var i;  
        s = limpa_campo(s);
        var c = s.substr(0,9);
        var dv = s.substr(9,2);
        var d1 = 0;
        for (i = 0; i < 9; i++)
        {
                d1 += c.charAt(i)*(10-i);
        }
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
        if (d1 > 9) d1 = 0;
        if (dv.charAt(0) != d1)
        {       
                return false;
        }
        
        d1 *= 2;
        for (i = 0; i < 9; i++)
        {
                d1 += c.charAt(i)*(11-i);
        }
        d1 = 11 - (d1 % 11);
        if (d1 > 9) d1 = 0; 
        if (dv.charAt(1) != d1)
        {
                return false;
        }

		if((s == "11111111111") || (s == "22222222222") || (s == "33333333333") || (s == "44444444444") || (s == "55555555555") 
		|| (s == "66666666666") || (s == "77777777777") || (s == "88888888888") || (s == "99999999999") || (s == "00000000000") )
		{
			return false;		
		}
		
		
        return true;
}
 
function verifica_CNPJ(s)
{
        var i;
        s = limpa_campo(s);
        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) return false;
        d1 = 11 - (d1 % 11);
        if (d1 > 9) d1 = 0; 
        if (dv.charAt(0) != d1)
        {
                return 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)
        {
                return false;
        }
        return true;
}


var selected;

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.checkout_address.shipping[0]) {
    document.checkout_address.shipping[buttonSelect].checked=true;
  } else {
    document.checkout_address.shipping.checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function check_form() {
  var error = 0;
  var error_field = '*';
  var error_message = "ATENÇÃO:\n\n";

  if (document.checkout_address.shipping.length == null) {
    if (!document.checkout_address.shipping.checked) {
	  error_message = error_message + "Selecione a forma de entrega disponível.\n";
      error = 1;
	  if (error_field == '*') error_field = document.checkout_address.shipping;
	}
  }
  else {
    var ok = false;
    for (var i = 0; i <= document.checkout_address.shipping.length-1; i++) {
	  if (document.checkout_address.shipping[i].checked) {
	    ok = true;
		break;
	  }
	}
	if (!ok) {
      error_message = error_message + "Selecione uma forma de entrega disponível.\n";
      error = 1;
      if (error_field == '*') error_field = document.checkout_address.shipping[0];
	}
  }

  if (error == 1) {
    alert(error_message);
	error_field.focus();
	error_field.select();
    return false;
  } else {
    return true;
  }
}

function session_win() {
  window.open("info_shopping_cart.cfm","info_shopping_cart","height=460,width=430,toolbar=no,statusbar=no,scrollbars=yes").focus();
}

function validEmail(email) {
	invalidChars = " /:,;"

	if (email == "") {						// cannot be empty
		return false
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {					// and at least one "." after the "@"
		return false
	}
	if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
		return false
	}
	return true
}	

function submitIt(fMail) {

	if (!validEmail(fMail.NmEmail.value)) {
		alert("Endereço de e-mail inválido.")
		fMail.NmEmail.focus()
		fMail.NmEmail.select()
		return false
	}		
}

