// JavaScript Document
function openPopUp(windowUrl, windowName, windowWidth, windowHeight, scrolling, isResizable, posLeft, posTop) {
	if (windowUrl != '' && windowName != '' && windowWidth != '' && windowHeight != '') {
		if (Boolean(scrolling) == true) {
				scrolling = 'yes'
			} else {
				scrolling = 'no'
		}
		if (Boolean(isResizable) == true) {
				isResizable = 'yes'
			} else {
				isResizable = 'no'
		}
		myWindow = window.open(windowUrl, windowName, 'toolbar=no,location=no,status=yes,menubar=no,scrollbars='+scrolling+',resizable='+isResizable+',width='+windowWidth+',height='+windowHeight+',left='+posLeft+',top='+posTop+'').focus();
	} else {
		alert('Problemas ao abrir a Pop Up.');
		window.opener.focus();
		self.close();
	}
}

function loadFlash(objUrl, objWidth, objHeight, objCreate, objHide) {
	//alert('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=8,0,24,0" width="'+ objWidth +'" height="'+ objHeight +'"><param name="movie" value="../inc/'+ objUrl +'"><param name="menu" value="false"><param name="wmode" value="transparent"><param name="quality" value="high"><embed src="../inc/'+ objUrl +'" wmode="transparent" quality="high" menu="false" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+ objWidth +'" height="'+ objHeight +'"><\/object>')
	if(objHide != ''){
		document.getElementById(objHide).style.display = 'none';
	}
	document.write('<div id="'+ objCreate +'">')
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=8,0,24,0" width="'+ objWidth +'" height="'+ objHeight +'" id="'+ objCreate +'">')
	document.write('<param name="movie" value="'+ objUrl +'">')
	document.write('<param name="wmode" value="transparent">')
	document.write('<param name="menu" value="false">')
	document.write('<param name="quality" value="high">')
	document.write('<embed src="'+ objUrl +'" wmode="transparent" menu="false" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+ objWidth +'" height="'+ objHeight +'" id="'+ objCreate +'">')
	document.write('<\/object>')
	document.write('<\/div>')
}

var cm=null;
function getPos(el,sProp) {
	var iPos = 0
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos

}

function show(el,m) {
	if (document.getElementById(m)) {
		document.getElementById(m).style.display='';
		if(m == 'magazine'){
			document.getElementById(m).style.left = (getPos(el,"Left")-50)+"px";
		} else if(m == 'sac'){
			document.getElementById(m).style.left = (getPos(el,"Left")-69)+"px";
		} else if(m == 'produtos'){
			document.getElementById(m).style.left = (getPos(el,"Left")-57)+"px";
		} else if(m == 'panex'){
			document.getElementById(m).style.left = (getPos(el,"Left")-65)+"px";
		} else if(m == 'novidades'){
			document.getElementById(m).style.left = (getPos(el,"Left")+14)+"px";
		} else {
			document.getElementById(m).style.left = getPos(el,"Left")+"px";
		}
		document.getElementById(m).style.top = getPos(el,"Top") + el.offsetHeight +"px"
	}
	if ((m!=cm) && (cm)) document.getElementById(cm).style.display='none'
	cm=m
}

function hide(obj) {
	document.getElementById(obj).style.display='none'
}

function mOvr(src,clrOver) {
	if (!src.contains(event.fromElement)) {
	src.bgColor = clrOver;
	}
}

function mOut(src,clrIn) {
	if (!src.contains(event.toElement)) {
	src.style.cursor = 'default';
	src.bgColor = clrIn;
	}
}

function menuSecundarioSobre(obj) {
	obj.style.background='#F5F5F5';
}
function menuSecundarioSaida(obj) {
	obj.style.background='#FFFFFF';
}

/* Formulários de validação */
function validateNumber(fieldName, event) {
	var valor = document.getElementById(fieldName).value;
	var tecla = event.which;
	if (tecla == null) {
		tecla = event.keyCode;
	}
	//Somente números!
	if ((tecla < 48 || tecla > 59) && tecla != 0 && tecla != 8 && tecla != 13){
		event.returnValue = false;
		alert("Este campo aceita somente números.")
		return false;
	} else {
		event.returnValue = true;
		return true;
	}
}

function validateText(fieldName, event) {
	var tecla = event.which;
	if (tecla == null) {
		tecla = event.keyCode;
	}
	//Somente números!
	if (tecla > 32 && tecla < 65 && tecla != 39){
		event.returnValue = false;
		alert("Este campo não aceita números.")
		fieldName.focus
	return false;
	}
	event.returnValue = true;
	return true;
}

//# e-mail
function checkEmailStrucure(fieldName) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(fieldName)) 
		return (true);
	else 
		return (false);
}


function validateEmail(fieldName) {
	var valor = fieldName.value
	if(valor != '') {
		if (checkEmailStrucure(valor)==false) {
			alert("E-mail inválido. Digite novamente.");
			fieldName.focus();
			event.returnValue = false;
			return false;
		}
		
		if (valor.indexOf('@', 0) == -1 || valor.indexOf('.', 3) == -1) { 
			alert("Email inválido. Digite novamente.");
			fieldName.focus();
			event.returnValue = false;
			return false;
		} 
		return false;
	}
}

function sendForm(formName) {
	var fields = new Array(formName.selSubject.value, formName.txtName.value, formName.txtEmail.value, formName.txtDDD.value, formName.txtPhone.value, formName.txtEmail.value, formName.txtMessage.value)
	var alertMsg = ''
	var showAlert = false
	for(i=0; i<fields.length; i++){
		if(fields[i]=='' || fields[i]==' ' || fields[i]=='  ') {
			showAlert = true
		} 
	}
	if(Boolean(showAlert) == true) {
		alert('Por favor, preencha todos os campos obrigatórios.')
	} else {
		formName.submit();
	}
}
function openNewsletter() {
	openPopUp('http://www.arno.com.br/news/newsletter.asp?site=px', 'newsletter', '450', '350', false, false)
}

function contadorSpan(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.innerText = maxlimit - field.value.length;
	}
}

function validaCPF(fieldName) {
cpf = document.getElementById(fieldName).value;
erro = new String;
	if (cpf != "") {
		if (cpf.length < 11) erro += "São necessários 11 digitos para verificação do CPF. "; 
		var nonNumbers = /\D/;
		if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas números. "; 
		if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") {
			erro += "Número de CPF inválido. ";
			//'fieldName.value = ""
			//'fieldName.focus();
		}

var a = [];
var b = new Number;
var c = 11;
	for (i=0; i<11; i++) {
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] * --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
		b = 0;
		c = 11;
		for (y=0; y<10; y++) b += (a[y] * c--); 
		if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
			erro +="CPF inválido! ";
	}
	if (erro.length > 0){
		cpf = ""
		alert(erro);
		document.getElementById(fieldName).focus();
		return false;
	}
	return true;
	}
}

function tiraAcentuacao(fieldName, apostrofe){ 
	fieldName.value = tirarAcentos(fieldName.value.toUpperCase()); 
	if (Boolean(apostrofe) == true){
		var estranha = ",./\-=!@#$%¨&*()+=]}{[`´~^?/:><|;'"; 
	} else {
		var estranha = ",./\-=!@#$%¨&*()+=]}{[`´~^?/:><|;"; 
	}
	var correta =  "________________________________________"; 
	var retorno = ""; 
	  
	for(i=0;i<estranha.length;i++) { 
		for(j=0;j<fieldName.value.length;j++) { 
		retorno = fieldName.value.replace(estranha.substr(i,1),correta.substr(i,1)); 
		retorno = retorno.replace("   "," "); 
		retorno = retorno.replace("   "," "); 
		retorno = retorno.replace("  "," "); 
		retorno = retorno.replace("_",""); 
		fieldName.value = retorno; 
		}
	}
} 

function validaTexto(fieldName, event) {
    var valor = fieldName.value;
    var tecla = event.which;
    if (tecla == null) {
        tecla = event.keyCode;
	}
    //Somente números!
    if ( tecla > 32 && tecla < 65 && tecla != 39){
        event.returnValue = false;
		alert("Este campo não aceita números.")
	return false;
    }
    event.returnValue = true;
    return true;
}

function validaMail(fieldName) {
	var valor = fieldName.value
	if (valor != '') {
		if (checkMailStrucure(valor)==false) {
			alert("E-mail inválido. Digite novamente.");
			fieldName.value='';
			fieldName.focus();
			return false;
		}
		
		if (valor.indexOf('@', 0) == -1 || valor.indexOf('.', 3) == -1) { 
			alert("Email inválido. Digite novamente.");
			fieldName.value='';
			fieldName.focus();
			return false;
		} 
		return false;
	}
}

function checkMailStrucure(fieldName) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(fieldName)) 
		return (true);
	else 
		return (false);
}

function validaData(dateStr) {
	if (dateStr.value != '') {
		var objeto = dateStr
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; 
		var matchArray = dateStr.value.match(datePat); 
		if (matchArray == null) {
			alert("Digite um formato correto: DD/MM/AAAA!")
			objeto.focus();
			objeto.value = ""
		return false;
		}
	
		day = matchArray[1];
		month = matchArray[3];
		year = matchArray[4];
		if (month < 1 || month > 12) {
			alert("Meses válidos são de 1 a 12!");
			objeto.focus();
			objeto.value = ""
		return false;
		}
	
		if (day < 1 || day > 31) {
			alert("Dias válidos são de 1 a 31!");
			objeto.focus();
			objeto.value = ""
		return false;
		}
	
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			alert("Mês "+month+" não tem 31 dias!")
			objeto.focus();
			objeto.value = ""
		return false;
		}
	
		if (month == 2) { 
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
				alert("Fevereiro de " + year + " não tem " + day + " dias!");
				objeto.focus();
				objeto.value = ""
			return false;
			}
		}
		return true;
	}
}


function validaNumero(fieldName, event) {
    var valor = fieldName.value;
    var tecla = event.which;
    if (tecla == null) {
        tecla = event.keyCode;
	}
    //Somente números!
    if ( tecla < 48 || tecla > 59){
        event.returnValue = false;
		alert("Este campo aceita somente números.")
	return false;
    }
    event.returnValue = true;
    return true;
}

function tirarAcentos(texto, apostrofe){
	var intComp;
    var strSemAcento;
    var intponteiro;
    var strLetra;
	var strSemAcento = "";
    intComp = texto.length;

	for(i=0;i<intComp;i++){
    	strLetra = texto.charAt(i);
        switch(strLetra){
        	case "Á":
          		strSemAcento += "A";
				break;
        	case "À":
          		strSemAcento += "A";
				break;
        	case "Â":
          		strSemAcento += "A";
				break;
        	case "á":
          		strSemAcento += "A";
				break;
        	case "à":
          		strSemAcento += "A";
				break;
        	case "â":
          		strSemAcento += "A";
				break;
          	case "É":
            	strSemAcento += "E";
				break;
            case "È":
            	strSemAcento += "E";
				break;
            case "Ê":
            	strSemAcento += "E";
				break; 
           case "é":
            	strSemAcento += "E";
				break;
            case "è":
            	strSemAcento += "E";
				break;
            case "ê":
            	strSemAcento += "E";
				break;
            case "Í":
            	strSemAcento += "I";
				break;
            case "Ì":
            	strSemAcento += "I";
				break;
            case "Î":
            	strSemAcento += "I";
				break;
            case "í":
            	strSemAcento += "I";
				break;
            case "ì":
            	strSemAcento += "I";
				break;
            case "î":
            	strSemAcento += "I";
				break;
            case "Ó":
            	strSemAcento += "O";
				break;
            case "Ò":
            	strSemAcento += "O";
				break;
            case "Ô":
            	strSemAcento += "O";
				break;
            case "ó":
            	strSemAcento += "O";
				break;
            case "ò":
            	strSemAcento += "O";
				break;
            case "ô":
            	strSemAcento += "O";
				break;
            case "Ú":
            	strSemAcento += "U";
				break;
            case "Ù":
            	strSemAcento += "U";
				break;
            case "Û":
            	strSemAcento += "U";
				break;
            case "ú":
            	strSemAcento += "U";
				break;
            case "ù":
            	strSemAcento += "U";
				break;
            case "û":
            	strSemAcento += "U";
				break;
            case "!":
            	strSemAcento += "";
				break;
            case "#":
            	strSemAcento += "";
				break;
            case "$":
            	strSemAcento += "";
				break;
            case "£":
            	strSemAcento += "";
				break;
            case "%":
            	strSemAcento += "";
				break;
            case "¢":
            	strSemAcento += "";
				break;
            case "¨":
            	strSemAcento += "";
				break;
            case "¬":
            	strSemAcento += "";
				break;
            case "&":
            	strSemAcento += "";
				break;
            case "*":
            	strSemAcento += "";
				break;
            case "(":
            	strSemAcento += "";
				break;
            case ")":
            	strSemAcento += "";
				break;
            case "@":
            	strSemAcento += "";
				break;
            case "_":
            	strSemAcento += "";
				break;
            case "+":
            	strSemAcento += "";
				break;
            case "=":
            	strSemAcento += "";
				break;
            case "§":
            	strSemAcento += "";
				break;
            case "}":
            	strSemAcento += "";
				break;
            case "]":
            	strSemAcento += "";
				break;
            case "°":
            	strSemAcento += "";
				break;
            case "{":
            	strSemAcento += "";
				break;
            case "[":
            	strSemAcento += "";
				break;
            case "ª":
            	strSemAcento += "";
				break;
            case "^":
            	strSemAcento += "";
				break;
            case "~":
            	strSemAcento += "";
				break;
            case "?":
            	strSemAcento += "";
				break;
            case "/":
            	strSemAcento += "";
				break;
            case "°":
            	strSemAcento += "";
				break;
            case "<":
            	strSemAcento += "";
				break;
            case ">":
            	strSemAcento += "";
				break;
            case ";":
            	strSemAcento += "";
				break;
            case "€":
            	strSemAcento += "";
				break;
            case ">":
            	strSemAcento += "";
				break;
            case "º":
            	strSemAcento += "";
				break;
            case "@":
            	strSemAcento += "";
				break;
			
            default:
                strSemAcento += strLetra;
    	}
    }	
	return strSemAcento;
}