// JavaScript Document
function caracter(e,c,v) {//e->evento,c->tipo,v->valor
	
  switch (c) {
	case "d":  //data
	  if (e<47 || e>57) return event.keyCode="";
	  break;
	case "n":  //numero inteiro
	  if (e<48 || e>57) return event.keyCode="";
	  break;
	case "f":  //numero float
	  if ((e<48 || e>57) && e!=44){
			return event.keyCode="";
		}else if(e==44){
			if(strpos(v, ",", 0) >= 0){ // permite apenas uma vírgula
				return event.keyCode="";
			}
		}
		//if(strpos(v,",",0)>0){
		//	aux = v.split(",");
		//	if(aux[1].length >= 2){
		//		return event.keyCode="";
		//	}
		//}
	  break;
	case "t":  //telefone
	  if ((e<48 || e>57) && e!=32 && e!=40 && e!=41 ) return event.keyCode="";
	break;
  }
}
function strpos(texto,c,posInicial){
	if (posInicial<0) posInicial=0;
	for(var i=posInicial; i<texto.length;i++){
		if(texto.charAt(i)==c) return i;
	}
	return -1;
}

// valida e-mail
function validaEmail(emailAddress) {
	if ((emailAddress.indexOf("@",0) < 1) || (emailAddress.indexOf("@",0) == emailAddress.length - 1)) {
		return false; 
	}
	return true;
}


// todos os campos de um form são obrigatórios
function todosCampos(p_form){
	//auxCheckbox = "";
	//auxSelecionado = true;
	for(i=0; i<p_form.elements.length; i++){
      if(p_form.elements[i].name.substring(0,2)!="n_"){
   		if(p_form.elements[i].value==""){
	   		alert("Os campos marcados com (*) são de preencimento obrigatório!");
		   	p_form.elements[i].focus();
			   return false;
         }
		}
	}
	return true;
}

function currencyFormat(fld, milSep, decSep, e) { 
var sep = 0; 
var key = ''; 
var i = j = 0; 
var len = len2 = 0; 
var strCheck = '0123456789'; 
var aux = aux2 = ''; 
var whichCode = (window.Event) ? e.which : e.keyCode; 
if (whichCode == 13) return true; // Enter 
key = String.fromCharCode(whichCode); // Get key value from key code 
if (strCheck.indexOf(key) == -1) return false; // Not a valid key 
len = fld.value.length; 
for(i = 0; i < len; i++) 
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; 
aux = ''; 
for(; i < len; i++) 
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); 
aux += key; 
len = aux.length; 
if (len == 0) fld.value = ''; 
if (len == 1) fld.value = '0'+ decSep + '0' + aux; 
if (len == 2) fld.value = '0'+ decSep + aux; 
if (len > 2) { 
aux2 = ''; 
for (j = 0, i = len - 3; i >= 0; i--) { 
if (j == 3) { 
aux2 += milSep; 
j = 0; 
} 
aux2 += aux.charAt(i); 
j++; 
} 
fld.value = ''; 
len2 = aux2.length; 
for (i = len2 - 1; i >= 0; i--) 
fld.value += aux2.charAt(i); 
fld.value += decSep + aux.substr(len - 2, len); 
} 
return false; 
} 


// FUNÇÕES DOS BOTÕES FAVORITOS E IMPRIMIR
if(navigator.appName.indexOf('Netscape') == 0) isNS = true;
if(navigator.appName.indexOf('Microsoft') == 0) isIE = true;
isUNIX = (window.navigator.appVersion.indexOf("X11") != -1) ||
         (window.navigator.appVersion.indexOf("Linux") != -1) ||
         (window.navigator.appVersion.indexOf("SunOS") != -1) ||
         (window.navigator.appVersion.indexOf("IRIX") != -1) ||
         (window.navigator.appVersion.indexOf("HP-UX") != -1);
isMac = (window.navigator.appVersion.indexOf("Mac") != -1);
isWindows = navigator.userAgent.indexOf("Windows 95") != -1 ||
            navigator.userAgent.indexOf("Windows 98") != -1 ||
            navigator.userAgent.indexOf("Windows NT") != -1;
isMacIE = (isMac && isIE);

var isNS4 = false;
if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) <= 4) {
	isNS4 = true;
}

isNS6 = false;
if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 5) {
  isNS6 = true;
}

isMacIE = false;
if ((navigator.appVersion.indexOf("Mac") != -1) && (navigator.userAgent.indexOf("MSIE") != -1)) {
  isMacIE = true;
}

function bookmarkIt() { 
  var bookmarktitle = document.title;
  var bookmarkurl = document.location;
  var netscape
  var macintosh
  netscape="Pressione as teclas CTRL+D para inserir esta página aos seus Favoritos.";
  macintosh="Pressione as teclas CTRL+D para inserir esta página aos seus Favoritos.";

   if (isMac) {
    alert(macintosh);
  } else if (document.all) {
    window.external.AddFavorite(bookmarkurl, bookmarktitle);
  } else if (window.opera && window.print) {
    return true;
  } else if (window.sidebar&&window.sidebar.addPanel) { 
    alert(netscape);
    window.sidebar.addPanel(bookmarktitle, bookmarkurl,""); 
  }
}

function printIt() { 
  var macprint;
  macprint = "Esta funcionalidade infelizmente não está disponível para Macintosh.";

  if (isMac) { 
    alert(macprint);
  } else {
  self.print()
  }
}

function zoom(p_img){
   window.open('zoom.php?img='+p_img, 'zoomimg', 'top=50, left=50, width=100, height=100, status=yes');
}
