/*
function enviarNoticia(npixeis){
	var pos_left = findPos(document.getElementById('div_buttons'))[0];	
	var pos_top = findPos(document.getElementById('div_buttons'))[1];	

	if(npixeis > 0){
		window.scrollTo("0", "425");
		showBlockDiv();
		document.getElementById('div_noticia_enviar').style.top = pos_top + "px";
		document.getElementById('div_noticia_enviar').style.left = pos_left + "px";	
	}else{	
		document.getElementById('div_noticia_enviar').style.top = npixeis + "px";
		document.getElementById('div_noticia_enviar').style.left = npixeis + "px";	
	}

	
	Drag.init(document.getElementById("div_noticia_enviar"));
}
*/
function findPosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
      while(1) 
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}

function showBlockDiv(divName, anchor, left, top) { 
	//Se o left ou o top não forem definidos vais buscar a posição do anchor
	posX = 0;
	posY = 0;
	
	if(left != undefined) posX = left;
	if(top != undefined) posY = top;

	left = parseInt(getAnchorPosition(anchor).x) + parseInt(posX);
	top = parseInt(getAnchorPosition(anchor).y) + parseInt(posY);
	
	//Se o left ou o top e anchor não forem definidos vais buscar a posição do rato
	if(anchor == undefined && (left == undefined || left == 0)) left = tempX;
	if(anchor == undefined && (top == undefined || top == 0)) top = tempY;

	width = screen.width;
	height = screen.height;

	if(height < findPosY(document.getElementById('div_footer')))
		height = parseInt(findPosY(document.getElementById('div_footer'))) + 30;
		
	document.getElementById(divName).style.left = left + "px";
	document.getElementById(divName).style.top = top + "px";

	document.getElementById('div_block').style.left = "0px";
	document.getElementById('div_block').style.top = "0px";
	document.getElementById('div_block').style.width = width + "px";
	document.getElementById('div_block').style.height = height + "px";
	
	Drag.init(document.getElementById("topo_enviar_amigo"), document.getElementById("div_enviar_amigo"));

	
}
/*
function closeEnviarNoticia(){
	hideBlockDiv();
	
	showBlockDiv(-10000);

	document.getElementById('index').value = -1;
}*/

function hideBlockDiv(divName) { 
	document.getElementById(divName).style.left = "-10000px";
	document.getElementById(divName).style.top = "-10000px";

	document.getElementById('div_block').style.left = "-10000px";
	document.getElementById('div_block').style.top = "-10000px";
	document.getElementById('div_block').style.width = "0px";
	document.getElementById('div_block').style.height = "0px";
}

function getForm(formName) {
    // Test if is IE or Netscape (document.layers)
    if(document.all)
        return eval(formName);
    else
        return document.forms[formName];
}

function validarEnvioNoticia () {
    reg = new RegExp('([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z])');
    regtelef = /[^0-9\s]/;
    
    boolvalidarEnvio = true;
	try{document.getElementById('nome_enviaramigo_erro').innerHTML = "";}catch(e){}
	try{document.getElementById('nome_enviaramigo').className = "";}catch(e){}
	try{document.getElementById('email_enviaramigo_erro').innerHTML = "";}catch(e){}
	try{document.getElementById('email_enviaramigo').className = "";}catch(e){}

    var searchForm = getForm("enviar_amigo");

	try{	
		if(searchForm.nome_enviaramigo.value.length < 2){
			document.getElementById('nome_enviaramigo_erro').innerHTML = "A indicação do seu nome é obrigatória.";
			document.getElementById('nome_enviaramigo').className = "inputs_erro";
			boolvalidarEnvio = false;
		}
	}catch(e){}
	
	try{	
		if(searchForm.email_enviaramigo.value == "" || !reg.test(searchForm.email_enviaramigo.value)){
			document.getElementById('email_enviaramigo_erro').innerHTML = "Verifique que o email está correctamente preenchido.";
			document.getElementById('email_enviaramigo').className = "inputs_erro";
			boolvalidarEnvio = false;
		}
	}catch(e){}

   return boolvalidarEnvio;
}

