// 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 historia() {
	window.open('/co/history.asp', 'História', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=500,height=400,left=0,top=0')
};

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 == 'sac'){
			document.getElementById(m).style.left = (getPos(el,"Left"))+"px";
		/*} else {
			document.getElementById(m).style.left = (getPos(el,"Left")-0)+"px";
		}*/
		}
		if(m == 'novidades'){
			document.getElementById(m).style.left = (getPos(el,"Left")-0)+"px";
		}
		
		if(m == 'produtos'){
			document.getElementById(m).style.left = (getPos(el,"Left")+2)+"px";
		}
		if(m == 'casa-gourmet'){
			document.getElementById(m).style.left = (getPos(el,"Left")+14)+"px";
		}
		if(m == 'seu-estilo'){
			document.getElementById(m).style.left = (getPos(el,"Left")-14)+"px";
		}
		if(m == 'arno'){
			document.getElementById(m).style.left = (getPos(el,"Left")-4)+"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";
		}*/
		if(m == 'sac'){
			document.getElementById(m).style.top = getPos(el,"Top")+5+"px"
		} else {
			document.getElementById(m).style.top = getPos(el,"Top")+10+"px"
		}
	}
	if ((m!=cm) && (cm)) document.getElementById(cm).style.display='none'
	cm=m
}
function sendForm(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 show2(el,m) {
	if (document.getElementById(m)) {
		document.getElementById(m).style.display='';
		myString = new String(document.getElementById('produtos').style.left)
		posLeft = myString.replace('px', '')
		
		/*myString2 = new String(document.getElementById(el).style.top)*/
		posTop = 0

if(m == 'sua-cozinha'){
			document.getElementById(m).style.top = (Number(posTop)+58)+"px";
		} else if(m == 'seu-conforto'){
			document.getElementById(m).style.top = (Number(posTop)+82)+"px";
		} else if(m == 'seus-cuidados-pessoais'){
			document.getElementById(m).style.top = (Number(posTop)+106)+"px";
		} else if(m == 'a-limpeza-seu-lar'){
			document.getElementById(m).style.top = (Number(posTop)+130)+"px";
		} else if(m == 'cuidados-suas-roupas'){
			document.getElementById(m).style.top = (Number(posTop)+154)+"px";
		}
		document.getElementById(m).style.left = (Number(posLeft)+155)+"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)+45)+"px";
		document.getElementById(m).style.top = 0 +"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='#8CD1E8';
}
function menuSecundarioSaida(obj) {
	obj.style.background='#CCEBF5';
}

function menuSecundarioCozinhaSobre(obj) {
	obj.style.background='#FFFFFF';
}
function menuSecundarioCozinhaSaida(obj) {
	obj.style.background='#FAE140';
}

/* 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 contadorSpan(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.innerText = maxlimit - field.value.length;
	}
}



/*
 *	Implementado em 25/02/2011
 *
 */


function validateEmail2() {
    var str = document.getElementById("txtEmail").value;
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if(filter.test(str))
      return true;
    else
      return false;
}

function validateCNPJ() {
	var c = document.getElementById("txtCnpj").value; 
	var b = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	var val = false;
	if( (c = c.replace(/[^\d]/g,"").split("")).length != 14 )
		val = true;
	for( var i = 0, n = 0; i < 12; n += c[i] * b[++i]); 
	if(c[12] != (((n %= 11) < 2) ? 0 : 11 - n))
		val = true;
	for(var i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
	if(c[13] != (((n %= 11) < 2) ? 0 : 11 - n))
		val = true;
	if(val == true) {
		return false;
	}
	else return true;
}

/* 09/03/2011 - comentario das linhas para retirada da inclusão de categorias de produtos a pedido do cliente
function confirmLineProduct() {
	var itens = 0;
	document.getElementById("opt").value = "";
	for(var i = 0 ; i < document.formMail.elements.length ; i++) {
		if( document.formMail.elements[i].type == "checkbox" ) {
			if( document.formMail.elements[i].checked ) {
				document.getElementById("opt").value += document.formMail.elements[i].title + ",";
				itens++;
			}
		}
	}
	if(itens == 0) {
		val = true;
		return false;
	}
	else {
		return true;
	}
}
*/

function validateForm() {
	var alertMsg = "";
	var formName = document.formMail;
	var val = false;
	
	if(formName.txtRSocial.value == "") {
		alertMsg += formName.txtRSocial.title+".\n";
		val = true;
	}
	if(formName.txtCnpj.value == "") { 
		alertMsg += formName.txtCnpj.title+".\n";
		val = true;
	}
	if(formName.txtContato.value == "") {
		alertMsg += formName.txtContato.title+".\n";
		val = true;
	}
	if(formName.txtEmail.value == "") {
		alertMsg += formName.txtEmail.title+".\n";
		val = true;
	}
	if(formName.txtFoneDDD.value == "") {
		alertMsg += formName.txtFoneDDD.title+".\n";
		val = true;
	}
	if(formName.txtFone.value == "") {
		alertMsg += formName.txtFone.title+".\n";
		val = true;
	}
	if(formName.txtFaxDDD.value == "") {
		alertMsg += formName.txtFaxDDD.title+".\n";
		val = true;
	}
	if(formName.txtFoneFax.value == "") {
		alertMsg += formName.txtFoneFax.title+".\n";
		val = true;
	}
	if(formName.txtEndereco.value == "") {
		alertMsg += formName.txtEndereco.title+".\n";
		val = true;
	}
	if(formName.txtCidade.value == "") {
		alertMsg += formName.txtCidade.title+".\n";
		val = true;
	}
	if(formName.txtEstado.value == "") {
		alertMsg += formName.txtEstado.title+".\n";
		val = true;
	}
	if(formName.txtInscrEstadual.value == "") {
		alertMsg += formName.txtInscrEstadual.title+".\n";
		val = true;
	}
	/* 09/03/2011 - comentario das linhas para retirada da inclusão de categorias de produtos a pedido do cliente
	if(!confirmLineProduct()) {
		alertMsg += "Pelo menos uma linha de produtos deve ser marcada.\n";
		val = true;
	}
	*/
	if( !validateEmail2() && document.getElementById("txtEmail").value != "" ) { 
		document.getElementById("txtEmail").value="";
		document.getElementById('txtEmail').focus();
		alertMsg += "E-mail inválido. Digite novamente.\n";
		val = true;
	}
	if(!validateCNPJ() && document.getElementById("txtCnpj").value != "" ) {
		document.getElementById("txtCnpj").value="";
		document.getElementById("txtCnpj").focus();	
		alertMsg += "CNPJ inválido. Digite novamente.\n";
		val = true;
	}
	if( document.getElementById("txtFoneDDD").value.length < 2 && document.getElementById("txtFoneDDD").value != "" ) {
		alertMsg += "O DDD do telefone deve conter 2 dígitos.\n";
		val = true;
	}
	if( document.getElementById("txtFone").value.length < 8 && document.getElementById("txtFone").value != "" ) {
		alertMsg += "O telefone deve conter no mínimo 8 dígitos.\n";
		val = true;
	}
	if( document.getElementById("txtFaxDDD").value.length < 2 && document.getElementById("txtFaxDDD").value != "") {
		alertMsg += "O DDD do fax deve conter 2 dígitos.\n";
		val = true;
	}
	if( document.getElementById("txtFoneFax").value.length < 8 && document.getElementById("txtFoneFax").value != "") {
		alertMsg += "O Fax deve conter no mínimo 8 dígitos.\n";
		val = true;
	}
	if(val == true)	{
		alert(alertMsg);
		return false;
	}
	else {
		var ret1 = document.getElementById("Layer1");
		var ret2 = document.getElementById("div1");				
		ret1.style.display = "block";
		ret2.style.display = "block";
		formName.submit();
		return true;
	}
}


/*
 *	funções para uso de mascaras para preenchimento
 *  de campos de formularios
 */
 
function mascara(o,f){
	v_obj=o
	v_fun=f
	setTimeout("execmascara()",1)
}

function execmascara(){
	v_obj.value=v_fun(v_obj.value)
}

function leech(v){
	v=v.replace(/o/gi,"0")
	v=v.replace(/i/gi,"1")
	v=v.replace(/z/gi,"2")
	v=v.replace(/e/gi,"3")
	v=v.replace(/a/gi,"4")
	v=v.replace(/s/gi,"5")
	v=v.replace(/t/gi,"7")
	return v
}

function soNumeros(v){
	return v.replace(/\D/g,"")
}

function soLetras(v){
	return v.replace(/\d/g,"")
}

function telefone(v){
	v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
	v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
	v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
	return v
}

function cpf(v){
	v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
											 //de novo (para o segundo bloco de números)
	v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
	return v
}

function cep(v){
	v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
	v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
	return v
}

function cnpj(v){
	v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
	v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
	v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
	v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
	v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
	return v
}

function romanos(v){
	v=v.toUpperCase()             //Maiúsculas
	v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
	while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
		v=v.replace(/.$/,"")
	return v
}

function site(v){
	//Esse sem comentarios para que você entenda sozinho ;-)
	v=v.replace(/^http:\/\/?/,"")
	dominio=v
	caminho=""
	if(v.indexOf("/")>-1)
		dominio=v.split("/")[0]
		caminho=v.replace(/[^\/]*/,"")
	dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
	caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
	caminho=caminho.replace(/([\?&])=/,"$1")
	if(caminho!="")dominio=dominio.replace(/\.+$/,"")
	v="http://"+dominio+caminho
	return v
}

