function isDefined( variable) { return (typeof(window[variable]) != "undefined");}

function AbrirPopUp(Cual,Nombre,width,height,left,top,sb) {
 if (sb==1){ sb='yes'; } else { sb='no'; }
 if (Nombre==undefined) { Nombre='MercadoFiesta' }
 Abre=open(Cual,Nombre,'width='+width+',height='+height+',left='+left+',top='+top+',scrollbars='+sb+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,titlebar=no');
}
function verprov(){
 if (Buscador.pr.value!=1) { 
  AbrirPopUp('futprovincia.htm','MFFutProvincia',300,175,200,225,0);
  Buscador.pr.value=1;
 }
}
function verform(){
 if (document.getElementById("FrmBuscador").b.value!="") {
  document.getElementById("FrmBuscador").submit();
 }
 return false;
}
function ContactoEntidad(Cual) { Abre=open('contactoentidad.asp?ce='+Cual,'MFContactoEntidad','width=575,height=525,left=95,top=5,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,titlebar=no'); }
function MasInfoWeb(Cual) {
 AbrirPopUp('avisos/'+Cual+'.htm','MFPubWeb',718,500,25,25,1)
}
function MasInfoTex(Cual) {
 AbrirPopUp('veraviso.asp?ce='+Cual,'MFPubTex',475,400,150,100,1)
}

function Colorear(idcel,idccol) {
 var c=eval("document.all."+idcel);
 if (c && c.style) c.style.background=idccol;
}
function mClk(src,cual) {
// if(event.srcElement.tagName=='TD'){
  src.children.tags('A')[0].click();
// }
}

function getViewportSize() {
 var x, y;
 if (self.innerHeight) { // MOS
  y = self.innerHeight;
  x = self.innerWidth;
 } else if (document.documentElement && document.documentElement.clientWidth) { // IE6 Strict
  x = document.documentElement.clientWidth;
  y = document.documentElement.clientHeight;
 } else if (document.body.clientHeight) { // IE quirks
  y = document.body.clientHeight;
  x = document.body.clientWidth;
 }
 return {x: x, y: y};
}
function AbreVentana(Fondo,Frente) {
 document.getElementById(Fondo).style.display='block';
 document.getElementById("VentanaFlotante").style.display='block';
 document.getElementById(Frente).style.display='block';
 getViewportSize();
 ventana=getViewportSize();
 document.getElementById(Fondo).style.height=document.body.scrollHeight+"px";
}
function CierraVentana(Fondo,Frente) {
 document.getElementById(Fondo).style.display='none';
 document.getElementById(Frente).style.display='none';
 document.getElementById("VentanaFlotante").style.display='none';
// document.getElementById('VentanaFlotante').innerHTML='';
}

function Ubicar(Inicial,Posicion) {
 if (window.innerHeight) { heightActual = window.innerHeight; } else { heightActual = document.body.offsetHeight; }
 if (window.innerWidth) { AnchoActual = window.innerWidth+4; } else { AnchoActual = document.body.offsetWidth; }
 if (AnchoActual>1024) {
  document.getElementById('Desplegable').style.left = AnchoActual/2+Posicion;
//  alert(document.getElementById('Desplegable').style.left);
 } else {
  document.getElementById('Desplegable').style.left = 802;
 }
}
function CuentaCaracterV2(field, countfield, maximo) {
 if (typeof(field)!='object') {
  campo = document.getElementById(field);
 } else {
  campo=field;
 }
 if (typeof(countfield)!='object') {
  contador=document.getElementById(countfield);
 } else {
  contador=countfield;
 }
 if (campo.value.length > maximo)
  campo.value = campo.value.substring(0, maximo);
 else
  contador.innerHTML = maximo - campo.value.length;
}
function RedimImg(IdImg,AnchoMax,AltoMax) {
 Imagen=document.getElementById("FotoSlider"+IdImg);
 MetaData=document.getElementById("PhotoMetaData"+IdImg);
 Ancho=Imagen.width;
 Alto=Imagen.height;
 if (Ancho>Alto){
  if (Ancho>AnchoMax){
   Alto=parseInt(Alto/Ancho*AnchoMax);
   Ancho=AnchoMax;
  }
 } else {
  if (Alto>AltoMax){
   Ancho=parseInt(Ancho/Alto*AltoMax);
   Alto=AltoMax;
  }
 }
 Imagen.width=Ancho;
 Imagen.height=Alto;
//If Ancho>Alto Then
// If Ancho>AnchoMax Then
//  Alto=Int(Alto/Ancho*AnchoMax)
//  Ancho=AnchoMax
// End If
// 'Tiene que dar: 424x318
//Else
// If Alto>AltoMax Then
//  Ancho=Int(Ancho/Alto*AltoMax)
//  Alto=AltoMax
// End If
//Response.Write Ancho &"-"& Alto
// 'Tiene que dar: 233x322
//End If

// if (AltoImg>AnchoImg){
//  alert("M: "+Imagen.id+" - Ancho: "+AnchoImg+" - Alto:"+AltoImg+" - "+AltoImg/AnchoImg*Alto);
// 394 x 545
// 420 x 581
//  Imagen.height=parseInt(AltoImg/AnchoImg*Alto);
//  Imagen.width=parseInt(AltoImg/AnchoImg*Alto);
//  alert(Imagen.height);
//  alert("C: "+Imagen.id+" - Ancho: "+Imagen.width+" - Alto:"+Imagen.height+" - Ancho: "+AnchoImg+" - Alto:"+AltoImg);
//  alert(MetaData.class);
//  MetaData.class="photo-meta-dataV";
//  alert(MetaData.class);
//  alert(AnchoImg+" "+AltoImg);
//  return;
// } else {
//  if (Imagen.width>Ancho) Imagen.width=Ancho;
//  if (Imagen.height>Alto) Imagen.height=Alto;
//  Imagen.width=Int(AltoImg/AnchoImg*Alto);
//  Imagen.width=AnchoImg;
// }
}
function MuestraOculta(Muestra,Oculta) {
 if (Mostro==undefined) Mostro="";
 if (Oculto==undefined) Oculto="";
 if (Mostro!="" && Oculto!="") {
  document.getElementById(Oculto).style.display='block';
  document.getElementById(Mostro).style.display='none';
 }
 if (Muestra!="" && Oculta!="") {
  document.getElementById(Muestra).style.display='block';
  document.getElementById(Oculta).style.display='none';
 }
 Mostro=Muestra;
 Oculto=Oculta;
}
function ValidaEmail(email){
 //var filtro = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
 var filtro = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i;
 if (!filtro.test(email)) return false;
 return true;
}
