// 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('<object type="application/x-shockwave-flash" data="'+ objUrl +'" width="'+ objWidth +'" height="'+ objHeight +'" id="'+ objCreate +'">')
	document.write('<param name="movie" value="'+ objUrl +'" />')
	document.write('<param name="allowScriptAcess" value="sameDomain" />')
	document.write('<param name="quality" value="best" />')
	document.write('<param name="menu" value="false" />')
	document.write('<param name="wmode" value="transparent" />')
	document.write('<param name="bgcolor" value="#FFFFFF" />')
	document.write('<param name="scale" value="noScale" />')
	document.write('<param name="salign" value="TL" />')
	document.write('<param name="FlashVars" value="playerMode=embedded" />')
	document.write('</object>')

	/*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 openNewsletter() {
	openPopUp('http://www.arno.com.br/news/newsletter.asp?site=cg', 'newsletter', '450', '350', false, false)
}

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 closePage() {
	if (Object(window.opener)) {
		opener.focus();
	}
	self.close();	
}

function printPage(hasOpener, closeSelf) {
	self.print();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
  x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve conter um endereço de e-mail válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve conter somente números.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve conter números entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é de preenchimento obrigatório.\n'; }
  } if (errors) alert('Erros:\n'+errors);
  document.MM_returnValue = (errors == '');
}


//Arno ####################
function openComparison(familyId) {
	if (familyId != '') {
		window.open('/prod/productsFunctions.asp?show=comparison&familyId='+familyId+'', 'compare', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=600,height=520').focus();
	} else {
		alert('Código de família inválido.');
		window.opener.focus();
		self.close();
	}
}
	
/* sourceSite:
2 = Casa Gourmet */

function openProductDemo(flashSource, sourceSite) {
	if (sourceSite == 2) {
		sourcePath = '/cgn/'
	} else {
		sourcePath = '/prod/'
	}

	if (flashSource != '') {
		window.open(sourcePath+'productsFunctions.asp?show=productDemo&flashSource='+flashSource+'', 'demonstration', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=300,height=200,left=250,top=200').focus();
	} else {
		alert('Endereço de filme inválido.');
		window.opener.focus();
		self.close();
	}
}

function openProductDiscover(imgDescription, imgSource, sourceSite) {
	if (sourceSite == 2) {
		sourcePath = '/cgn/'
	} else {
		sourcePath = '/prod/'
	}

if (imgDescription != '' & imgSource != '') {
		window.open(sourcePath+'productsFunctions.asp?show=productDiscover&description='+imgDescription+'&imgSource='+imgSource+'', 'discover', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=340,height=400,left=305,top=100').focus();
	} else {
		alert('Descrição e endereço de imagem inválidos.');
		window.opener.focus();
		self.close();
	}
}

function openProductElements(productId, sourceSite) {
	if (sourceSite == 2) {
		sourcePath = '/cgn/'
	} else {
		sourcePath = '/prod/'
	}

	if (productId != '') {
		window.open(sourcePath+'productsFunctions.asp?show=productElements&productId='+productId+'', 'elements', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=330,height=400,left=305,top=200').focus();
	} else {
		alert('Código de produto inválido.');
		window.opener.focus();
		self.close();
	}
}

function sendProduct(productId, sourceSite) {
	if (sourceSite == 2) {
		sourcePath = '/cgn/'
		windowWidth = 450
		windowHeight = 300
	} else {
		sourcePath = '/prod/'
		windowWidth = 462
		windowHeight = 233
	}
	
	if (productId != '') {
		window.open(sourcePath+'productsFunctions.asp?show=sendProduct&productId='+productId+'', 'sendproduct', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,width='+windowWidth+',height='+windowHeight+',left=250,top=200').focus();
	} else {
		alert('Código de produto inválido.');
		window.opener.focus();
		self.close();
	}
}

function openStylesQuiz(sourceSite) {
	if (sourceSite == 2) {
		sourcePath = '/cgn/stylesQuiz.asp'
		windowWidth = 452
		windowHeight = 496
	} else {
		sourcePath = '/quiz/stylesQuiz.asp'
		windowWidth = 452
		windowHeight = 496
	}
	openPopUp(sourcePath, 'styleQuiz', windowWidth, windowHeight)
}

function openPublicityVideo(videoSource, productName) {
	openPopUp('/home/publicityVideos.asp?videoSource='+videoSource+'&productName='+productName+'', 'publicityVideo', 320, 305)
}

/* Casa Gourmet #################### */
function openCourses(toInscribe, locationId) {
    if (Boolean(toInscribe) == true) {
        openPopUp('/cgm/courses02.asp?inscription=1', 'courses', 720, 400)
    } else {
        openPopUp('/cgm/courses02.asp?inscription=2', 'courses', 720, 400)
    }
}

function openMap(locationId) {
    openPopUp('/cga/showMap.asp?locationId='+locationId+'', 'showMap', 720, 400)
}

function openRecipesBook() {
    openPopUp('/cgm/recipesBook.asp', 'recipesBook', 450, 330)
}

function printRecipe(recipeId, sourceSite) {
	if (sourceSite == 3) {
		sourcePath = '/cgm/recipes.asp?recipeId='+recipeId+''
		windowWidth = 770
	} else {
		sourcePath = '/cgm/recipes.asp?recipeId='+recipeId+'&action=printRecipe'
		windowWidth = 675
	}
	openPopUp(sourcePath, 'printRecipe', windowWidth, 400, true);
}

function openRecipesSearch() {
	openPopUp('/cgm/recipesSearch.asp', 'searchRecipes', 770, 440, true, true);
}

function openDocument(URL) {
	openPopUp(URL, 'document', 675, 450, true, true);
}

function addToRecipesBook(recipeId) {
   openPopUp('/cgm/recipesBook.asp?action=addToBook&recipeId='+recipeId+'', 'recipesBook', 450, 330);
}

function sendRecipe(recipeId) {
	if (recipeId != '') {
		window.open('/cgm/recipesFunctions.asp?show=sendRecipe&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 openContact(contactType) {
    if (contactType == 'pratica') {
        openPopUp('/cga/contact.asp?contactType='+contactType+'', 'contact', 480, 520)
    } else {
        openPopUp('/cga/contact.asp', 'contact', 480, 520)
    } 
}

function openUseTerms() {
    openPopUp('/cga/termos.asp', 'useTerms', 470, 540)
}

function openSocialProject() {
   openPopUp('/cga/rs/', 'socialProject', 615, 375)
}

function openTourInstructions() {
    openPopUp('/cgt/instr.asp', 'tourInstructions', 462, 478)
}

function openKidsPlay() {
    openPopUp('/cga/play01.asp', 'kidsPlay', 760, 520)
}   

/*itens devem ser apagados em breve*/
function back_page()
{
	frmback.submit()
}

function next_page()
{
	frmnext.submit()
}
/*fim*/


/* Casa Gourmet .TV #################### */
function openVideo(videoSource, videoTitle, videoDescription, windowHeight) {
   openPopUp('/cgm/cgartvPopUp.asp?videoSource='+videoSource+'&videoTitle='+videoTitle+'&videoDescription='+videoDescription+'', 'cgartvVideo', 360, windowHeight)
} 

function openRecipe(recipeId) {
    openPopUp('/cgm/cgartvRecipe.asp?recipeId='+recipeId+'', 'cgartvRecipe', 360, 400)
}

/* 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 sendFormContato(formName) {
	var fields = new Array(formName.selSubject.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;
	}
}



// FUNÇÕES ANTIGAS
function OpenBook() { 
janela=window.open('/cgm/book01.asp','question','width=462,height=390,status=yes,toolbar=no,scrollbars=no,resizable=no,directory=no,location=no'); 
}

function OpenContact01() { 
janela=window.open('/cga/contact01.asp','question','width=452,height=424,status=no,toolbar=no,scrollbars=no,resizable=no,directory=no,location=no'); 
}

function OpenRio() { 
janela=window.open('/casario.asp','question','width=468,height=540,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
}

function OpenTermos() { 
janela=window.open('/cga/termos.asp','question','width=470,height=540,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
}

function OpenText() { 
janela=window.open('/cga/pratica.asp','question','width=760,height=520,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenFriends() { 
janela=window.open('/cga/friends.asp','question','width=760,height=520,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenPlay() { 
janela=window.open('/cga/play01.asp','question','width=760,height=520,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
}

function OpenRecipes() { 
janela=window.open('/cga/recipes.asp','question','width=760,height=520,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
}

function OpenContact02() { 
janela=window.open('/cga/contact02.asp','question','width=480,height=520,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
}

function MapaSpIn(codigo)
{
janela=window.open('/cga/spin_map.asp?'+codigo+'','mapa','width=750,height=500,top='+ topo +',left='+ esquerda +',scrollbars=yes,resizable=no');
}

function janela()
{
janela=window.open('/cga/spps_map.asp?map=1','Teste','width=750,height=500,top='+ topo +',left='+ esquerda +',scrollbars=no,resizable=no');
}

function janela2()
{
janela=window.open('/cga/spps_map.asp?map=2','Teste','width=750,height=500,top='+ topo +',left='+ esquerda +',scrollbars=no,resizable=no');
}

function OpenSend07() { 
janela=window.open('/cgn/brides.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenSend08() { 
janela=window.open('/cgn/brides01.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenSend09() { 
janela=window.open('/cgn/brides02.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenSend10() { 
janela=window.open('/cgn/brideserror.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenSend11() { 
janela=window.open('/cgn/list01.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenSend12() { 
janela=window.open('/cgn/list02.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenSend13() { 
janela=window.open('/cgn/list03.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenSend14() { 
janela=window.open('/cgn/list04.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=yes,resizable=no,directory=no,location=no'); 
} 

function OpenSend15() { 
janela=window.open('/cgn/styles.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=no,resizable=no,directory=no,location=no'); 
} 

function OpenSend16() { 
janela=window.open('/cgn/styles01.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=no,resizable=no,directory=no,location=no'); 
} 

function OpenSend17() { 
janela=window.open('/cgn/styles02.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=no,resizable=no,directory=no,location=no'); 
} 

function OpenSend18() { 
janela=window.open('/cgn/styleerror.asp','question','width=462,height=355,status=no,toolbar=no,scrollbars=no,resizable=no,directory=no,location=no'); 
} 

function OpenCgm01() { 
janela=document.location='/cga/','question','width=800,height=600,status=yes,toolbar=yes,scrollbars=yes,resizable=yes,directory=yes,location=yes'; 
}

function OpenInstr() { 
janela=window.open('/cgt/instr.asp','question','width=462,height=478,status=no,toolbar=no,scrollbars=no,resizable=no,directory=no,location=no'); 
}
// FIM FUNÇÕES ANTIGAS