function dump(obj ,returnOnly){
	var str = typeof obj + obj + '<br/>';
	if (returnOnly == undefined){ returnOnly = ''}
	for (elm in obj){
		if (returnOnly == typeof obj[elm] || '' == returnOnly){
			valor = '';
			if (typeof obj[elm] == 'number' || typeof obj[elm] == 'string'){valor = obj[elm]}
			str += '<strong>' +(typeof obj[elm]) +'</strong> ' +elm +' <i>' +valor +'</i><br/>';
		}
	}
	return str;
}

//===========================================================================
//
function printDump(obj ,returnOnly){
	document.body.innerHTML += dump(obj ,returnOnly);
}

//===========================================================================
//
function writeEmail(nome, provedor, fim) {
	if(fim == null) fim = '.com.br';
	if(fim.charAt(0) != '.') fim = '.' + fim;
	window.document.write('<a href="mailto:');
	window.document.write(nome);
	window.document.write('@');
	window.document.write(provedor);
	window.document.write(fim);
	window.document.write('">');
	window.document.write(nome);
	window.document.write('@');
	window.document.write(provedor);
	window.document.write(fim);
	window.document.write('</a>');
}
//===========================================================================
//
var janela = null;

function popup_img(url, title, w, h){
	var property, screenW, screenY, janela, w, h, title;
	
	// stellt die Bildschirmabmessungen fest
	// find window size
	var ns6 = (!document.all && document.getElementById);
	var ie4 = (document.all);
	var ns4 = (document.layers);
	
	if(ns6||ns4) {
		screenW = innerWidth;
		screenY = innerHeight;
	}
	else if(ie4) {
		screenW = document.body.clientWidth;
		screenY = document.body.clientHeight;
	}
	
	x = (screenW-w)/2;
	y = (screenY-h)/2;
	
	property="scrollbars=no,left="+x+",top="+y+",screenX="+x+",screenY="+y+",width="+w+",height="+h+",menubar=no,toolbar=no";
	
	if(janela != undefined) janela.close();
	
	janela=window.open("","",property);
	janela.focus();
	janela.document.open();
	with (janela) {
	  document.write("<html><head>");
	  // geändert 2004 für Mozilla
	  document.write('<scr' + 'ipt type="text/javascr' + 'ipt" language="JavaScr' + 'ipt">');
	  // bei click  schliessen , on click close
	  document.write("function click() { window.close(); } ");
	  document.write("document.onblur=click ");
	  // geändert 2004 für Mozilla
	  document.write('</scr' + 'ipt>');
//	  document.write('<link href="../css/global.css" rel="stylesheet" type="text/css" />');
	  document.write("<title>"+title+"</title></head>");
	  // bei Focusverlust schliessen, close if window looses focus
	  // Zeile geändert Aug 2003 (Dreamweaver machte Probleme)
	  document.write("<" + "body onblur='window.close()';");
	  document.write("marginwidth='0' marginheight='0' leftmargin='0' topmargin='0' style='background: url("+url+")'>");
//	  document.write("<center>");
//	  document.write("<img src='"+ url +"' border='0'>");
//	  document.write("<center>");
	  document.write("</body></html>");
	  janela.document.close();
	}
}
//===========================================================================
//
function popupWindow(url, w, h) {
	var width  = w;
    var height = h;
    
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top  = parseInt((screen.availHeight/2) - (height/2));

	var	windowFeatures = "width=" + width + ",height=" + height + 
        	",status=0,resizable=0,left=" + left + ",top=" + top + 
        	",screenX=" + left + ",screenY=" + top;
	
	if(janela != undefined) janela.close();
	

	janela = window.open(url, "subWind", windowFeatures);
	janela.focus();
}
function popupWindow2(url, w, h) {
	var width  = w;
    var height = h;
    
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top  = parseInt((screen.availHeight/2) - (height/2));

	var	windowFeatures = "width=" + width + ",height=" + height + 
        	",status=0,resizable=1,scrollbars=1,left=" + left + ",top=" + top + 
        	",screenX=" + left + ",screenY=" + top;
	
	if(janela != undefined) janela.close();
	

	janela = window.open(url, "subWind", windowFeatures);
	janela.focus();
}
//===========================================================================
//
function closeWindow() {
	window.close();		
}
//===========================================================================
//
function isAlpha(strChar) {
  var i, blnValid;

  blnValid = false;
  for (i = 0; i < strChar.length; i++) {
    if ((strChar.charAt(i) >= "a" && strChar.charAt(i) <= "z")
    || (strChar.charAt(i) >= "A" && strChar.charAt(i) <= "Z") )
    blnValid = true;
  }
  return blnValid;
}

//===========================================================================
//
function aSplit(strString, charSep) {
  var arrAux = new Array(), i, j;


 if (charSep.length == 1) {
   j = 0;
   arrAux[j] = "";
   for (i = 0; i < strString.length; i++) {
     if (strString.charAt(i) != charSep) {
       arrAux[j] = arrAux[j] + strString.charAt(i);
     }
     else {
       j++;
       arrAux[j] = "";
     }
   }

   return arrAux;
  }
  else return NaN;
}

//===========================================================================
//
function isEmail(email) {
   var Valid, strDomain, strUser, i, intCount;
   var arrAux;

   if (email == "") {
       return false;
   }
   else {
       Valid = false;

       if (email.charAt(email.length - 1) == ".") {
         email = email.substr(0, email.length - 1);
       }

       if (email.indexOf("@") > 0) {
           strDomain = email.substr(email.indexOf("@") + 1, email.length - (email.indexOf("@") + 1));
           strUser = email.substr(0, email.indexOf("@"));

           arrAux = aSplit(strUser, ".");

       intCount = -1;
       for (i = 0; i <= arrAux.length - 1; i++) {
         if (arrAux[i] > "" && arrAux[i].indexOf("@") == -1) {
             intCount++;
         }
       }

       if (intCount == arrAux.length - 1) Valid = true;

       if (Valid) {

         Valid = false;
         arrAux = aSplit(strDomain, ".");

           intCount = -1;
           for (i = 0; i <= arrAux.length - 1; i++) {

             if (arrAux[i] > "" && isAlpha(arrAux[i].charAt(0)) && arrAux[i].indexOf("@") == -1) {
             intCount++;
             }
           }

         if (intCount == arrAux.length - 1) Valid = true;

         }

       }
       if (!Valid) {
           return false;
       }
       else {
           return true;
       }

   }
}

//===========================================================================
//
function desviaJS(url) {
	window.location.href = url;
}

//===========================================================================
//
function trim(string){
	return string.replace(/(^\s*)|(\s*$)/g,'');
}

//===========================================================================
//
function campoObrigatorio(string) {
	return 'O campo " '+string+' " é obrigatório!';
}
//===========================================================================
//
function campoInvalido(string) {
	return 'O campo " '+string+' " é inválido!';
}

//===========================================================================
// CHANGE o tempo do tempo agora
function selectCidade(elem) {
	var cidade = elem.options[elem.selectedIndex].value;
	var tempo = document.getElementById('tempo');
	tempo.src = tempo.src.replace(/\?cid=.*/g, '?cid=' + cidade);
}

// VALIDA Newletter

function validaNewletter(elem) {
	
	if(!isEmail(elem.value)) {
		alert('Email inválido!');
		return false;
	}

	return true;
}
