// 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 printRecipe(recipeId, sourceSite) {

		sourcePath = 'http://www.casagourmet.com.br/receitas/recipes.asp?site=rochedo&recipeId='+recipeId+'&action=printRecipe'
		windowWidth = 675
	
	openPopUp(sourcePath, 'printRecipe', windowWidth, 400, true);
}


function sendRecipe(recipeId) {
	if (recipeId != '') {
		window.open('http://www.casagourmet.com.br/cgm/recipesFunctions.asp?show=sendRecipe&site=rochedo&recipeId='+recipeId+'', 'sendproduct', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=453,height=301').focus();
	} else {
		alert('Código de receita inválido.');
		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 openNewsletter() {
	openPopUp('http://www.arno.com.br/news/newsletter.asp?site=ro', 'newsletter', '450', '350', false, false)
}

function show(el,m) {
	if (document.getElementById(m)) {
		document.getElementById(m).style.display='';
		//if(m == 'magazine'){
			document.getElementById(m).style.left = (getPos(el,"Left")+158)+"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")+2+"px"
	}
	if ((m!=cm) && (cm)) document.getElementById(cm).style.display='none'
	cm=m
}

function show2(el,m) {
	if (document.getElementById(m)) {
		document.getElementById(m).style.display='';
		myString = new String(document.getElementById('produtos').style.left)
		posLeft = myString.replace('px', '')
		document.getElementById(m).style.left = (Number(posLeft)+113)+"px";
		document.getElementById(m).style.top = 27+"px"
	}
	if ((m!=cm) && (cm)) document.getElementById(cm).style.display='none'
	cm=m
}

function show3(el,m) {
	if (document.getElementById(m)) {
		document.getElementById(m).style.display='';
		myString = new String(document.getElementById('produtos').style.left)
		posLeft = myString.replace('px', '')
		document.getElementById(m).style.left = (Number(posLeft)+113)+"px";
		document.getElementById(m).style.top = 45+"px"
	}
	if ((m!=cm) && (cm)) document.getElementById(cm).style.display='none'
	cm=m
}

function show4(el,m) {
	if (document.getElementById(m)) {
		document.getElementById(m).style.display='';
		myString = new String(document.getElementById('produtos').style.left)
		posLeft = myString.replace('px', '')
		document.getElementById(m).style.left = (Number(posLeft)+113)+"px";
		document.getElementById(m).style.top = 63+"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.")
		document.getElementById(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 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 (document.getElementById(fieldName).value != "") {
		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){
		document.getElementById(fieldName).value = ""
		alert(erro);
		document.getElementById(fieldName).focus();
		return false;
	}
	return true;
	}
}

function returnKeyCode(e) {
  if(!e) e=window.event;
  key = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
  return key
}