var a = new Array();
var ai = 0;
var iTimerID;

function prop(thisone) {
       var result="";
       for (var i in thisone) {
          result += "thisone" + "." + i + " = " + thisone[i] + "<BR>"
       }
       result += "<HR>";
       document.write(result);
		}
		
		
function maxpopup(thisone, maxx, maxy){	  
			  
			  	  
ai = ai+1;
a[ai]= thisone;
if(thisone.width!=0){
	if(thisone.height>maxy || thisone.width>maxx){
      		if(thisone.height>maxy) {
      		 auxx = thisone.width;
		                auxy = thisone.height;
				thisone.height = maxy;
			        thisone.width=auxx*maxy/auxy;
			        //thisone.offsetParent.style.position='fixed';
			        maxpopup(thisone, maxx, maxy);
			      }
		              else{
		                auxx = thisone.width;
		                auxy = thisone.height;
		                thisone.width = maxx; 
		                //thisone.offsetParent.style.position='fixed';
		                thisone.height= auxy *maxx /auxx;
		                maxpopup(thisone, maxx, maxy);
		                
			     } 
		           }else{
		             thisone.offsetParent.style.position='fixed';
		           }
		           
		        if(thisone.height <= maxy || thisone.width <= maxx){
			 	
			 	window.resizeTo(thisone.width + 30, thisone.height + 55)
			  	   
			  	thisone.offsetParent.style.position='fixed';
			  	    
			  }   
		        
		        }
		        else{
		          iTimerID = setTimeout("maxdelay("+ai+","+maxx+","+maxy+")", 1);
		        }
		       
     }
		
function max(thisone, maxx, maxy){	  
	  
	  	  
	  ai = ai+1;
	  a[ai]= thisone;
	  if(thisone.width!=0){
	  
	 
	  
	    if(thisone.height>maxy || thisone.width>maxx){
	      if(thisone.height>maxy) {
	        auxx = thisone.width;
                auxy = thisone.height;
		thisone.height = maxy;
	        thisone.width=auxx*maxy/auxy;
	        //thisone.offsetParent.style.position='fixed';
	        max(thisone, maxx, maxy);
	      }
              else{
                auxx = thisone.width;
                auxy = thisone.height;
                thisone.width = maxx; 
                //thisone.offsetParent.style.position='fixed';
                thisone.height= auxy *maxx /auxx;
                max(thisone, maxx, maxy);
                
	     } 
           }else{
             thisone.offsetParent.style.position='fixed';
           }
        }
         else{
          iTimerID = setTimeout("maxdelay("+ai+","+maxx+","+maxy+")", 25);
        }
       
     }

function maxdelay(indice, maxx, maxy){	  
    	max(a[indice],maxx,maxy);
    
    } 	  

function previewXX(link)
  {
     window.open(link, null, 'height=600, width=800, toolbar=yes, resizable=yes');
  }
  
  
function preview(link)
  {
     window.open(link,null,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=660, height=500')
  
      // window.open(link, null, 'height=600, width=800, toolbar=no, menubar=no, resizable=yes');
  }
     
function f1_on(menu){
   	    f1_off();
   	    document.getElementById(menu).style.visibility = "visible";
   	  }	 
function f1_off(){
   	    document.getElementById('menu_X').style.visibility = "hidden";	
   	  }
   	  




// Validações forms 

// Tópicos
function validate_topico_forum(form)
{


if (form.header.value == "" && form.description.value=="")
{

alert("Por favor insira o Tópico e a Mensagem");
form.description.focus();
return (false);
}

if ( form.description.value =="")
{

alert("Por favor insira o Tópico");
form.description.focus();
return (false);
}

if ( form.header.value=="")
{

alert("Por favor insira a Mensagem");
form.header.focus();
return (false);
}

if ( form.description.value.length>100 )
{

alert("O Tópico só pode ter no máximo 100 caracteres!");
form.description.focus();
return (false);
}


var str = form.description.value

if (str.length > 32){
form.name.value=str.substring(0,28) + "..."
}else{
form.name.value=str
}

return (true);
}


//Mensagens
function validate_msg_forum(form)
{

if (form.header.value == "")
{

alert("Por favor insira a Mensagem");
form.header.focus();
return (false);
}

var str = form.header.value

form.name.value=str.substring(0,12)

return (true);
}


// Artigos Opinião e Notícias
function validate_art_not(form)
{


if (form.header.value == "" && form.description.value=="")
{

alert("Por favor insira o Assunto e a Mensagem");
form.description.focus();
return (false);
}

if ( form.description.value =="")
{

alert("Por favor insira o Assunto");
form.description.focus();
return (false);
}

if ( form.header.value=="")
{

alert("Por favor insira a Mensagem");
form.header.focus();
return (false);
}

if ( form.description.value.length>100 )
{

alert("O Assunto só pode ter no máximo 100 caracteres!");
form.description.focus();
return (false);
}


var str = form.description.value

form.name.value=str.substring(0,32)

return (true);
}


//Classificados 

//geral  (imoveis, pessoais e diversos)

function validate_class_geral()
{

x=document.forms[1]

if (x.name.value == "")
{
alert("O Título não está preenchido.");
x.name.focus();
return (false);
}

if (x.contacto.value=="")
{
alert("O Contacto não está preenchido.");
x.contacto.focus();
return (false);
}


return (true);
}


//veiculos
function validate_class_veic()
{

x=document.forms[1]
if (x.name.value == "")
{

alert("O Título não está preenchido.");
x.name.focus();
return (false);
}

if (x.modelo.value=="")
{

alert("O Modelo não está preenchido.");
x.modelo.focus();
return (false);
}

if (x.contacto.value=="")
{

alert("O Contacto não está preenchido.");
x.contacto.focus();
return (false);
}

return (true);
}

// casa e jardim

function validate_class_cj()
{

x=document.forms[1]

if (x.name.value == "")
{
alert("O Título não está preenchido.");
x.name.focus();
return (false);
}

if (x.produto.value=="")
{
alert("O Produto não está preenchido.");
x.produto.focus();
return (false);
}

return (true);
}


// informatica

function validate_class_inf()
{

x=document.forms[1]

if (x.name.value == "")
{
alert("O Título não está preenchido.");
x.name.focus();
return (false);
}

if (x.contacto.value=="")
{
alert("O Contacto não está preenchido.");
x.contacto.focus();
return (false);
}

if (x.produto.value=="")
{
alert("O Produto não está preenchido.");
x.produto.focus();
return (false);
}


return (true);
}


//Anchors
function window_url(stranchor)
{

var pos = window.location.href.indexOf("#")
	if (pos >= 0){
		window.location = window.location.href.substr(0,pos) + stranchor
	}else{
		window.location = window.location + stranchor
	} 
}



// RETIRAR CLASSIFICADOS

function retirarclassificado(oid){
				var url = oid + "URL=" + window.location;
				window.location=url;
			}
