// JavaScript Document


//var pc_url = escape("http://"+server_url+"/mercado/");

var NS = (document.getElementById && !document.all);
var IE = (document.all);
var FF = navigator.userAgent.match("Firefox");

var server_url = "http://www.shampoocosmeticos.com.br";
//var server_url = "http://localhost/shampoo";

function checkBrowser() {
var iemin = 5.5; // versão mínima do IExplorer
var nsmin = 7.0; // versão mínima do Netscape
//var ffmin = "1.0.6";  //versão mínima do FireFox
//alert(navigator.userAgent);
// mensagem para o alert, em caso de falta de suporte
var msg = 'Este sistema foi desenvolvido para Internet Explorer '+iemin+'+ ou Netscape '+nsmin+'+. Seu navegador ['+navigator.appName+' '+navigator.appVersion+'] não responderá corretamente a todos os comandos.';
          
var msgns8 = "ATENÇÃO USUÁRIO NETSCAPE 8.0!\nNão deixe de ver o link 'Navegando no Netscape 8.0', em nossa\npágina principal, para garantir uma correta navegação em nosso site";
          
var ieok = (/msie ?(\d\.\d)/i.test(navigator.userAgent) && RegExp.$1 >= iemin);
var nsok = (/netscape\/?(\d\.\d)/i.test(navigator.userAgent) && RegExp.$1 >= nsmin);
//var ffok = (/Firefox\/?(\d\.\d\.\d)/i.test(navigator.userAgent)&& RegExp.$1 == ffmin);
// 
//com Gecko é motor Firefox, sem é motor IE, no Netscape 8
with (navigator){
	if((userAgent.match("Netscape/8.0.3.3") || userAgent.match("Netscape/8.0.2")) && userAgent.match("Gecko")){
	 ns8FF = true;
	//alert(msgns8);
	}
	if((userAgent.match("Netscape/8.0.3.3") || userAgent.match("Netscape/8.0.2")) && !userAgent.match("Gecko")){
	 ns8IE = true;
//alert(msgns8);
 //return false;
	}

}
 //|| FF ** && !ffok
if(!FF && (NS || IE)){
//alert("yeap");
	  if(!ieok && !nsok) {
	  if(checkBrowser.arguments[0]) alert(msg);
	  return false;
	  } else{
		return true;	 
	 }
}
	return true;
	
//return true
};// /280105


function GetMonth(intMonth){
    var MonthArray = new Array("Janeiro", "Fevereiro", "Março",
                               "Abril", "Maio", "Junho",
                               "Julho", "Agosto", "Setembro",
                               "Outubro", "Novembro", "Dezembro") 
    return MonthArray[intMonth] 	  	 
    }

var today = new Date();
// relogio
function clock() {
var dayTwo = new Date();
var hour = dayTwo.getHours();
var mnNow = dayTwo.getMinutes();  
var scNow = dayTwo.getSeconds();
var miNow = dayTwo.getTime();
var hour = hour <= 9 ? "0" + hour : hour;
var mins = mnNow <= 9 ? "0" + mnNow : mnNow;
var secs = scNow <= 9 ? "0" + scNow : scNow;
var time = hour + ":" + mins; // + ":" + secs;
//$GEBId("clockdisplay").innerHTML = time;
//return time;
setTimeout('clock()', 1000);
}

// data
function mydate() {
var dayarray = new Array("Domingo","Segunda","Terça","Quarta","Quinta","Sexta","Sábado")
var mydate = new Date();
var year = (NS || FF) ? mydate.getYear() + 1900 : mydate.getYear();
var day = dayarray[mydate.getDay()];
var month = (GetMonth(today.getMonth()) + 1) < 10 ? "0" + (GetMonth(today.getMonth())) : (GetMonth(today.getMonth()));
var daym = mydate.getDate() < 10 ? "0" + mydate.getDate() : mydate.getDate();
return day+", "+daym+" de " +month+" de "+year;
}

// mostra relogio e data
function printDate() {
$GEBId("theclock").innerHTML = mydate(); //+' - <span id="clockdisplay"></span></td></tr></table>'; 
//clock();
};


// fim clock

/*
function always_0(){
document.forme.tipo.options[0].selected = true;
}
*/


function walk(page){ // mantem os divs absolutes corretos no resize - sites centralizados

w=document.body.clientWidth;
w2 = w / 2;
laypos = (w2 + 210)+"px";
laypos_indadm = (w2 + 170)+"px";
laypos_news = (w2 - 388)+"px";

iw=window.innerWidth;
iw2 = iw / 2;
lpos = (iw2 + 200)+"px";
lpos_indadm = (iw2 + 160)+"px";
lpos_news = (iw2 - 396)+"px";



	if(page == "ind"){
		$GEBId('theclock').style.left = IE ? laypos : lpos;
		if($GEBId('newsmain')){
			$GEBId('newsmain').style.left = IE ? laypos_news : lpos_news;
			$GEBId('newsmain').style.display = "";
		}
	}
	if(page == "ind_adm") $GEBId('admtitle').style.left = IE ? laypos_indadm : lpos_indadm;
}

function walkprods(elem){ // mantem os divs absolutes corretos no resize - sites centralizados	
	
	if(IE)	iw=document.body.clientWidth;
	else iw=window.innerWidth;		
		
		iw2 = iw / 2;
		factor = IE ? (iw2 - 238) :  (iw2 - 246);
		lpos = factor+"px";
		$GEBId(elem).style.top = "118px";
		$GEBId(elem).style.left = lpos;	
	
}

function GB_Foc(){
document.f2.login.focus();
}

function checkFileInput(oTema){
	if($GEBId(oTema).value == ''){ alert('Selecione a nova imagem'); return false;}
}

function checkTexInput(oTex){
	if(oTex == ''){ alert('Insira um texto'); return false;}
	else { $GEBId("retaction_tex1_site_texts").innerHTML = ""; return true;}
}


function light(ele){
	
	/*if(ele == "ins"){
		//if($GEBId('insfoto').style.display=='none') $GEBId('insfoto').style.display= '';
		//else $GEBId('insfoto').style.display= 'none';
	}

	if(ele == "atua"){
		
		//if($GEBId('insfotoup').style.display=='none') $GEBId('insfotoup').style.display= '';
		//else $GEBId('insfotoup').style.display= 'none';
	}
*/
	var el = document.getElementById("secs_"+ele);
	if(el.style.display == "none") el.style.display = "";	
	else el.style.display = "none";	
	
}




function confere(maxlen,elemid) {
var mypath = $GEBId(elemid);
var count = mypath.value.length;
  if(count > maxlen) {  
  return "(você atingiu 600 caracteres.<br />Se prosseguir poderá comprometer a visualização.)"; 
  //alert();
  /*mypath.value = mypath.value.substring(0,maxlen);
  count = maxlen;*/
  }else{	  
	  document.getElementById('description_count_prodatu').innerHTML = "";
	  return "";
	 }

};



function checkParamsSrchProds(){
var procs = 0;
var prods = 0;
var brands = 0;
var cats = 0;

var oTab = $GEBId("tab").value;
var rads = $GEBTn("input");
var radcheck = 0;
var wcolumn = "";
	
	if($GEBId("keyword").value != ""){ var oWhat = $GEBId("keyword").value; procs++;}
	
	if($GEBId("selcats").value != "00") var oCat = $GEBId("selcats").value;	
	else var oCat = "";
	
		for(p=0; p < rads.length; p++){		
			if(rads[p].name=="column" && rads[p].checked){ wcolumn = rads[p].value; radcheck++; break;}		
		}		
		
		<!-- no if abaixo(ativar o for acima): && radcheck > 0 -->
	if(procs > 0 && radcheck > 0){
	ajax("shp_util/search_prods.php", cardsfunc, "tab="+oTab+"&column="+wcolumn+"&what="+oWhat+"&cat="+oCat+"&thisone=1&forwards=1&page_nums_js=1", "POST");
	}else{
		
		alert("Você deve optar por 'Produto' ou 'Marca' e digitar pelo menos uma letra em 'Palavra-chave'\nO filtro por categoria é opcional"); return false;
		
	}
radcheck = 0;
procs = 0;


}/**/



function cleanParamsSrchProds(){
//$GEBId("proc").value = "";
$GEBId("selcats").options.selectedIndex = 0;
$GEBId("keyword").value = "";
var rads = $GEBTn("input");
	for(k=0; k < rads.length; k++){
		if(rads[k].name=="column")rads[k].checked=false;
	}	
}


function checkacentos(){
var count=0;
form=document.form2;
var inpts = $GEBTn("input");
	for(i = 0; i < inpts.length; i++){
		if(inpts[i].type == "file"){
			if(inpts[i].name.match(/^userfile_/)){
				if(inpts[i].value != "" && count < 7){
				var oName = inpts[i].value;
				var nName = oName.split("\\");
				var rName = nName[nName.length-1];
				newnom = tiracentos(oName);				
				//eval("inpts[i].value="+newnom);
				//alert(form.userfile_0.value);			
				//document.form2.userfile_0.value="MMM";
				//alert(document.form2.userfile_0.value);
				//break;
				//count++;
				}
			}
		
		}
		
	}


}

function tiracentos(name) {
var fordel = "áàâãäÁÀÂÃÄçÇéèêÉÈÊíìïÍÌÏóòöôõÓÒÖÔÕúùûüÚÙÛÜ";
var forsub = "aaaaaAAAAAcCeeeEEEiiiIIIoooooOOOOOuuuuUUUU";
var newname = "";
  for(i = 0; i < name.length; i++){
  var nc = false;
  var oc = name.charAt(i);
    for(j = 0; j < fordel.length; j++){
    var fd = fordel.charAt(j);
      if(oc == fd) nc = forsub.charAt(j);
    }
  newname += nc ? nc : oc;
  }
  //alert();
return newname;
};




function intoView(elID){
      var el = $GEBId(elID);
      el.scrollIntoView();
    }
	
function ajax_history(line, ledoc){
ajaxHistory.add("ajax('shp_util/"+ledoc+".php', cardsfunc, '"+line+"', 'POST');");	
//oHistnum++;
}




function setSubCat(which){ // gera as listagens de adm_prods para atualizacao de produtos
	var oCateg = $GEBId("selcategs").options[$GEBId("selcategs").options.selectedIndex].value;
	document.form_atu_prod.category_prodatu.value = oCateg;
	ajax("../shp_util/generate_sub_prods.php", retSubProdAction, "categ="+oCateg+"&tipo="+which, "POST");
	
	
}// fim setSubCat

function getProds(which1, cat){ // gera as listagens dos produtos

	var oSubCateg = $GEBId("subcat").options[$GEBId("subcat").options.selectedIndex].value;
	$GEBId("subcategory_prodatu").value = oSubCateg;
	ajax("../shp_util/generate_sub_prods.php", retSubProdAction, "subcateg="+oSubCateg+"&cats="+cat+"&tipo="+which1, "POST");
	
	
}// fim getProds

function setsubins(){
	
	var maincat = $GEBId("category_prodins").options[$GEBId("category_prodins").options.selectedIndex].value;
	
	ajax("../shp_util/generate_sub_prods.php", retSubProdAction, "categins="+maincat+"&tipo=subins", "POST");
}



function setid(tab){ // coloca os itens do produto em "Atualizar produto"
	//alert("hui");
	var idnum = $GEBId("selprods").options[$GEBId("selprods").options.selectedIndex].value;
	if(tab == "products") $GEBId("secs_atua").style.display="";
	ajax("collect_prod_items.php", retCollectAction, "whichtab="+tab+"&oId="+idnum, "POST");
	
}

function cleandrops(){ // limpa as listas para atualizar produto em adm_prod.php
$GEBId("elsubcats").innerHTML = "<select disabled='disabled' class='sel_cards'> <option selected value='00'>Subcategorias</option>  </select>";
$GEBId("elprods").innerHTML = "<select disabled='disabled' class='sel_cards'> <option selected value='00'>Produtos</option>  </select>";
		  
$GEBId("selcategs").selectedIndex = 0;	
}

function cleanextras(money,qual){
		
	if(money.length > 0){
		
		money = money.replace(/\s*/g,""); //.replace(/\s*$/,"")
		if(money.match(/^R\$/ig)) money = money.replace(/^R\$/ig,"");
		if(money.match(/^0+$/)) return false;
		if(money.match(/^[\,\.]+$/)) return false;
		if(money.match(/^0+[\,\.]+$/)) return false;
		if(money.match(/^\,+0+$/)) return false;
		if(money.match(/^0+[\,\.]+0+$/)) return false;
		if(money.match(/\.\d{2}$/)) return false;
		/*if(money.match(/^\d{1,}\,$/)) money+="00";
		if(money.match(/^\d{1,}\,0$/)) money+="0";
		if(money.match(/^\d{1,}$/)){money+=",00";}// $GEBId("price"+qual).value= money; return;}*/
		
	
	

	//alert(money.length);
		if(money.length < 2 && money == "0") return false;
		
		/*if(money.match(/(\.\d{2})$/)){
			alert("Valor invalido");
			return false;
		}*/
		
		if(!money.match(/\,\d{2}$/)) money+=",00";
		
		
		
		//ZZZZZZZZZZZZZZZZZZ
		
		//var oldstring="(304)434-5454"
		//newstring=oldstring.replace(/[\(\)-]/g, "")
		//returns "3044345454" (removes "(", ")", and "-")
		//ZZZZZZZZZZZZZZZZ
		
		
		/*alert(money);
		
		
		
		money = money.replace(/(\.)\d{2}$/,", $1");
			alert(money);
		}
		
	*/
		if(money.length > 0 && money.length < 7){		
			var regex=/^\d{1,3}\,\d{2}$/;
		}
		
		if(money.length >= 7 && money.length < 11) {		
			var regex=/^\d{1,3}\.\d{3}\,\d{2}$/;
		}
		
		if(money.length > 10 && money.length < 14) {		
			var regex=/^\d{1,3}\.\d{3}\.\d{3}\,\d{2}$/;
		}
		
		if(money.length > 13) {
			return false;
		}
		
		if(!regex.test(money)){			
		return false;		
		}else{
				
			var moneytemp = money.replace(/\.*/ig,"");
			var cash = moneytemp.replace(/\,/,".");
			var mopricetemp = cash.replace(/\d{2}$/,"");
			var moprice = mopricetemp.replace(/\.*/g,"");
			//$GEBId("price"+qual).value= cash;
			$GEBId("pricemoney"+qual).value = moprice ;
			return true;
		}
		
		
		
	}else{
		return false;
	}
}



function makemail(addr,id){
if(!$GEBId("elMail"+id).innerHTML.match("<")) 
make_form(addr,id);		
}

function getParentName(ref)
	{
	ok=0;  
	while (!ok)
		{
		ref = ref.parentNode;
		if (ref.nodeType==1) //check that the node is a tag, not text (type=3)
			{
			if (String(ref.nodeName)=="TD")
				{
				return ref.id.toString();
				}
			if (String(ref.nodeName)=="BODY")
				{
				return alert('nothing found');
				}
			}
		}
	}


var ermail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
function checkmailform(form){
	//if(form.email.value!="" && form.textodivform.value!=""){
		if(ermail.test(form.email.value)){ return true;}
		else{ alert("e-mail inválido"); return false;}
	//} else {
		//alert("Todos os campos são obrigatórios");
		//return false;
	//}
}

function GB_FocNome(){

document.f2.nome.focus();

}


function GB_IsValid2(ofor){	
df=ofor;
d1=df.nome.value;
de=df.email.value;
dr=df.tex.value;
t1=df.tel.value;

p1=de.indexOf(".")== -1;
z1=de.indexOf(" ")== -1;

  if(de==""||d1==""||dr=="") {
  alert('Todos os campos são obrigatórios, exceto "Telefone"');
  return false;
  }
  
  if(p1 || !z1) {
  alert('e-mail inválido');
  return false;
  }
  
  if(t1.match(/\D/)) {
  alert('Somente números no campo "Telefone"');
  return false;  
  } 
  
  if(d1.match(/\d/)) {
  alert('Somente letras no campo "Nome"');
  return false;  
  }  
}

function GB_IsValid3(oform){	

	/*var prfs = $GEBTn("input");
	var list = "";
	for(p=0; p < prfs.length; p++){	  
	  if(prfs[p].type == "checkbox" && prfs[p].checked) list+=$prfs[p].value+"_";
	}
  
  list = list.replace(/_$/, "");
  $GEBId("prefs").value = list;*/
  
  
  return true;  
  
}




function valform(myform){	

var slect = $GEBTn('select',myform);

	for(d=0;d < slect.length;d++){
		
		if(slect[d].value == "00"){
			alert("Selecione a logo, a categoria e subcategoria");
			return false;
		}
	}



 if(myform.name_prodins.value == ""){
 alert('Todos os campos com * vermelho são obrigatórios');
 return false;
 }
 
 if(myform.brand_prodins.value == ""){
 alert('Todos os campos com * vermelho são obrigatórios');
 return false;
 }

 if(myform.price_prodins.value == ""){
  alert('Todos os campos com * vermelho são obrigatórios');
  return false;
  }else{
	
	if(!cleanextras(myform.price_prodins.value,'_prodins')){
	alert('Formato do Preço inválido');
	return false;
	}
	  
  }
  
 if(myform.descri_prodins.value == ""){
  alert('Todos os campos com * vermelho são obrigatórios');
  return false;
  }

return true;
}




function valformatu(myform){
	
		if(!cleanextras(myform.price_prodatu.value,'_prodatu')){
			alert("Formato de preço inválido");
			return false;
		}



return true;
}


function  cover(point){	 
	defaultStatus = "www.shampoo.com.br";
return true;
}


function showLoad () {
	$GEBId('contents').innerHTML = "<div id='load'>Carregando...</div>";
	$GEBId('load').style.display = 'block';
}

function showResponse (originalRequest) { // not in use
	var newData = originalRequest;
	$GEBId('load').style.display = 'none';
	$GEBId('contents').innerHTML = newData;
}

function cleanContents(){
	
	$GEBId('contents').innerHTML = "";
	showLoad();
	} 

//support funcs

/*var regs = [
//'&apos;', '&quot;', 
'&iexcl;', '&cent;', '&pound;', '&curren;', '&yen;', '&brvbar;', '&sect;', 
'&uml;', '&copy;', '&ordf;', '&laquo;', '&not;', '&shy;', '&reg;', '&macr;', '&deg;', '&plusmn;', 
'&sup2;', '&sup3;', '&acute;', '&micro;', '&para;', '&middot;', '&cedil;', '&sup1;', '&ordm;', 
'&raquo;', '&frac14;', '&frac12;', '&frac34;', '&iquest;', '&Agrave;', '&Aacute;', '&Acirc;', 
'&Atilde;', '&Auml;', '&Aring;', '&AElig;', '&Ccedil;', '&Egrave;', '&Eacute;', '&Ecirc;', '&Euml;', 
'&Igrave;', '&Iacute;', '&Icirc;', '&Iuml;', '&ETH;', '&Ntilde;', '&Ograve;', '&Oacute;', '&Ocirc;', 
'&Otilde;', '&Ouml;', '&times;', '&Oslash;', '&Ugrave;', '&Uacute;', '&Ucirc;', '&Uuml;', '&Yacute;',
'&THORN;', '&szlig;', '&agrave;', '&aacute;', '&acirc;', '&atilde;', '&auml;', '&aring;', '&aelig;', 
'&ccedil;', '&egrave;', '&eacute;', '&ecirc;', '&euml;', '&igrave;', '&iacute;', '&icirc;', '&iuml;',
'&eth;', '&ntilde;', '&ograve;', '&oacute;', '&ocirc;', '&otilde;', '&ouml;', '&divide;', '&oslash;', 
'&ugrave;', '&uacute;', '&ucirc;', '&uuml;', '&yacute;', '&thorn;', '&yuml;', '&euro;'/*, '&amp;'*/ /*];

var reps = [
//"'", '"', 
'¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', '°', '±', '²', 
'³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 
'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 
'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 
'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ', '€'/*, '&'*//* ];

String.prototype.ASCIIDecode = function() {
var s = this.replace(/&#(\d+);/g, function(str, s1) { return String.fromCharCode(s1); });
  for(var i = 0; i < regs.length; i++) 
		s = s.replace(new RegExp(regs[i], 'g'), reps[i]);
return s;
};

String.prototype.ASCIIEncode = function(tags, spaces) {
	if(tags) { reps.push('<', '>'); regs.push('&lt;', '&gt;'); }
	if(spaces) { reps.push(' '); regs.push('&nbsp;'); }
var cooked = "";
  for (var i = 0; i < this.length; i++) {
	var ind = reps.searchFor(this.charAt(i));
		if(ind > -1) cooked += regs[ind];
    else cooked += this.charAt(i); 
  }
return cooked;
};

Array.prototype.searchFor = function(str, icompare) {//inarray que devolve se tem e o indice
  for(var i = 0; i < this.length; i++) {
    if(icompare && (this[i].toLowerCase() == str.toLowerCase())) return i;
    else if(this[i] == str) return i;
	}
return -1;
};
*/


//permite o metodo .Click() no FF / netscape para tag a
function linkClick () {
  var executeAction = true;
  if (this.onclick) {
    executeAction = this.onclick({type: 'click'});
  }
  if (executeAction) 
    open (this.href, this.target ? this.target : '_self');
}
function initLinkClick () {
  if (document.getElementById && document.links.length > 0)
    document.links[0].constructor.prototype.click = linkClick;
}




function getColors(){
	var bar = $GEBId("thecolor").style.backgroundColor;
	var tex = $GEBId("thetex").style.backgroundColor;
	//alert(bar+" - "+tex); 
	ajax('setcolors.php', infocolors, 'b_color='+bar+'&t_color='+tex, 'POST');
}

//seta e desseta a session var com os ids para o agrupamento
function groupDegroup(me, mode){
	
	if(mode == "dgrp"){
		if(me.checked == true) ajax("shp_util/degrouper.php", nothing, "prodid="+me.id, "POST");
		else ajax("shp_util/grouper.php", nothing, "prodid="+me.id, "POST");	
	}else{
		 if(me.checked == true) ajax("shp_util/grouper.php", nothing, "prodid="+me.id, "POST");
		else ajax("shp_util/grouper.php", nothing, "prodid="+me.id, "POST");	
	}
		
	
}

// SUPPORT FUNCS and VARS
function $GEBId(id,doc) { return (doc || document).getElementById(id); }

function $GEBTn(nome,doc) { return (doc || document).getElementsByTagName(nome); }

function $DCElem(nome,doc) { return (doc || document).createElement(nome); }

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



