// PopUp										: interface - abre uma janela popup
// Parâmetros								: I = link, W = width, H = height, S = scrollbar (0/yes)
function PopUp(I, W, H, S){
  lpos = (screen.availWidth/2) - (W/2);
  tpos = (screen.availHeight/2) - (H/2);
  window.open(I,'','status=1,scrollbars='+S+',left='+lpos+',top='+tpos+',width='+W+',height='+H).focus();
}

function mostraCamada(camada) {
	var obj = document.getElementById(camada);
	obj.style.visibility='visible';
	var posIni=0;
	if (document.body.scrollWidth>770) posIni = (document.body.scrollWidth - 770)/2;	
	obj.style.left = posIni + 116;
}

function mostraSubCamada(camada) {
	var obj = document.getElementById(camada);
	obj.style.visibility='visible';
	var posIni=0;
	if (document.body.scrollWidth>770) posIni = (document.body.scrollWidth - 770)/2;	
	obj.style.left = posIni + 100;
}

function escondeCamada(camada) {
	var obj = document.getElementById(camada);
	obj.style.visibility='hidden';
}

function mostraCamadaNovo(camada) {
	var obj = document.getElementById(camada);
	obj.style.display = '';
}

function escondeCamadaNovo(camada) {
	var obj = document.getElementById(camada);
	obj.style.display = 'none';
}

function validaFrmProdutoAdd(frm,idiomaCliente){
	var msg 
	var i = 0;
	var listaMarcados = document.getElementsByTagName("INPUT");
	for (loop = 0; loop < listaMarcados.length; loop++) {
		var item = listaMarcados[loop];
		if (item.type == "checkbox" && item.checked) {
			i =1
		}
	}

	if (i == 0){
		switch (idiomaCliente) {
			case "IN":
				msg = 'You must select at least 1 product';
				break;
			case "ES":
				msg = 'Debe seleccionar al menos un producto';
				break;
			case "CH":
				msg = 'You must select at least 1 product';
				break;
			case "CI":
				msg = 'You must select at least 1 product';	
				break;
			default:
				msg = 'É necessário selecionar no mínimo 1 produto';
				break;
		}		
		alert(msg);
		return false;
	}

	// Valida se foi selecionado um tamanho
	/*if (frm.idTamanho.length){
		if (! selecionoucheck(frm.idTamanho)){
			alert("Selecione um tamanho.");
			return false;
		}

	
	// Valida a quantidade
	if (frm.quantidade.value == "" || isNaN(frm.quantidade.value)){
		alert("Digite uma quantidade.");
		return false;
	}
	
	}*/
}

function validaFormaPagamento(idiomaCliente) {
	var radios = document.getElementsByTagName("INPUT");
	for (i = 0; i < radios.length; i++) {
		var item = radios[i];		
		if (item.type == "radio" && item.checked) {
			document.frmFinalizarPedido.submit();
			return true;
		}
	}

	switch (idiomaCliente) {
		case "IN":
			msg = 'You must select one of the forms of payment available';
			break;
		case "ES":
			msg = 'Usted debe seleccionar una de las formas de pago disponibles';
			break;
		case "CH":
			msg = 'You must select one of the forms of payment available';
			break;
		case "CI":
			msg = 'You must select one of the forms of payment available';	
			break;
		default:
			msg = 'É necessário selecionar uma das formas de pagamento disponíveis';
			break;
	}		
	alert(msg);
	return false;
} 


function validaQuantidadeComponentes(obj,qtMinima,vlAtual,idiomaCliente){
	if (obj.value == "0"){
		obj.value = "0";
		//obj.value = vlAtual;
	}else 
		if (obj.value < qtMinima){
			if (vlAtual=="" || vlAtual =="0"){
				vlAtual = qtMinima;	
			}
			obj.value = vlAtual;
			
			switch (idiomaCliente) {
				case "IN":
					msg = 'Minimum '+ qtMinima + ' units to purchase this product';
					break;
				case "ES":
					msg = 'Mínimo '+ qtMinima +' para la compra de unidades de este producto,';
					break;
				case "CH":
					msg = 'Minimum '+ qtMinima + ' units to purchase this product';
					break;
				case "CI":
					msg = 'Minimum '+ qtMinima + ' units to purchase this product';	
					break;
				default:
					msg = 'Mínimo '+ qtMinima +' unidades para compra deste produto';
					break;
			}		
			alert(msg);			
			//alert("Mínimo "+qtMinima+" unidades para compra deste produto");
			
	}
	return true;
}

function validaEmail(src) {
  emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[a-zA-Z]$"
  var regex = new RegExp(emailReg);
  return regex.test(src);
}

function digitos(event){
	if (window.event) {
		// IE
		key = event.keyCode;
	} else if ( event.which ) {
		// netscape
		key = event.which;
	}
	if ( key != 8 || key != 13 || key < 48 || key > 57 )
		return ( ( ( key > 47 ) && ( key < 58 ) ) || ( key == 8 ) || ( key == 13 ) );
	return true;
}