/*
 * VARIABLES UTILIZADAS PARA VALIDACION
 ***************************************/
re = new RegExp("^ *\n*$");
rews = new RegExp(' ','g');
rewlf = new RegExp('\n','g');
rewcr = new RegExp('\r','g');
comillas = '"';

var globalupids;
var globalupids2;


/*
 * Ajax via iFrame
 ***************************************************/

var IFrameObj;
var IFrameObjAd;
var IFrameObjAd2;
var IFrameObjBtn;

function callToServer(URL) {
	if (!document.createElement) {return true};
	var IFrameDoc;
//	var URL = 'server.html';
	if (!IFrameObj && document.createElement) {
		// create the IFrame and assign a reference to the
		// object to our global variable IFrameObj.
		// this will only happen the first time 
		// callToServer() is called
		try {
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id','RSIFrame');
			tempIFrame.style.border='0px';
			tempIFrame.style.width='0px';
			tempIFrame.style.height='0px';
			IFrameObj = document.body.appendChild(tempIFrame);
			
			if (document.frames) {
				// this is for IE5 Mac, because it will only
				// allow access to the document object
				// of the IFrame if we access it through
				// the document.frames array
				IFrameObj = document.frames['RSIFrame'];
			}
		} catch(exception) {
			// This is for IE5 PC, which does not allow dynamic creation
			// and manipulation of an iframe object. Instead, we'll fake
			// it up by creating our own objects.
			iframeHTML='<iframe id="RSIFrame" style="';
			iframeHTML+='border:0px;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;


			IFrameObj = new Object();
			IFrameObj.document = new Object();
			IFrameObj.document.location = new Object();
			IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
			IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		}
	}
	
	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
		// we have to give NS6 a fraction of a second
		// to recognize the new IFrame
		setTimeout('callToServer()',10);
		return false;
	}
	
	if (IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = IFrameObj.contentDocument; 
	} else if (IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		// For IE5
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}
	
	IFrameDoc.location.replace(URL);
	return false;
}




function iss_cambiarIMG(upid,ix) {
  /* CACHE NO EXP MOZILLA */
  d = new Date();
  localTime = d.getTime();
  document.datos.upfotothumb.src = 'thumb.php?upid=' + upid + '&upfotoix=' + ix + '&ctl=' + localTime;
  document.datos.upfoto.src = 'foto.php?upid=' + upid + '&upfotoix=' + ix + '&ctl=' + localTime;
}

function iss_cambiarOpenerIMG(upid,ix) {
  /* CACHE NO EXP MOZILLA */
  d = new Date();
  localTime = d.getTime();

  opener.window.document.datos.upfotothumb.src = 'thumb.php?upid=' + upid + '&upfotoix=' + ix + '&ctl=' + localTime;
  opener.window.document.datos.upfoto.src = 'foto.php?upid=' + upid + '&upfotoix=' + ix + '&ctl=' + localTime;
}





/*
 * FUNCIONES PARA SITIO (L&F)
 ***************************************/

function iss_cargarIMG() {

  upid = document.datos.upid.value;
  ix = document.datos.upfotoix.options[document.datos.upfotoix.selectedIndex].value;

  archivo = 'cargarfoto.php?upid=' + upid + '&upfotoix=' + ix;
  window.open(archivo,'cargar','width=300,height=100,toolbar=no,menubar=no,status=no,resizable=no,scrollbars=no,screenX=0,screenY=0,top=0,left=0')
}

function iss_cambiarFoto(ix) {

  var srcfoto;

  /* CACHE NO EXP MOZILLA
  d = new Date();
  localTime = d.getTime();
*/
  upid = document.datos.upid.value;
  ixval = ixs[ix];
  document.datos.ix.value = ix + 1;

  srcfoto = 'foto.php?upid=' + upid + '&upfotoix=' + ixval;
  document.datos.foto.src = srcfoto;
  iss_rotacion();
//  document.datos.upfoto.src = 'foto.php?upid=' + upid + '&upfotoix=' + ix + '&ctl=' + localTime;

}


function iss_rotacion() {

  var ix;
  var strfn;
  var ixsln = ixs.length;
  if (ixsln > 1) {

    ix = document.datos.ix.value;

    if (ix == ixsln) { ix = 0; }
    strfn = 'iss_cambiarFoto(' + ix + ')';
    setTimeout(strfn,2500);
  }

}



function iss_cargarPrimeros(marid,step) {

 
  ajxurl = 'ajxdata/primeros.php?marid=' + marid + '&step=' + step;
  //alert(ajxurl);
//  return callToServer(ajxurl);
  callToServer(ajxurl);

}



//function ajx_llenarPrimeros(upids,step,primerosRegMax,limiteMin,limiteMax) {
function ajx_llenarPrimeros(upids,step,primerosRegMax,limiteMin,limiteMax,depnom,iddep,upids2) {
//  d = new Date();
/* NOTA uso de var ctl para problema cache no usar con usurios finales (max tiempo de respuesta) */

//  var upids = new Array();
  var primerosRegMax;
  var step;
  var modnom;
  var txtNode;
  var id; 
  var etiqueta; 
  var idthumb;
  var thumb;
  var flecha;
  var limiteMin;
  var limiteMax;
  
  globalupids = upids;
  globalupids2 = upids2;

 
  var iddepact = document.datos.marid.value;
  document.datos.marid.value = iddep;
    
  /*  
  depnomid = document.getElementById('depnom');
  depnomid.innerHTML = depnom;
*/
  if (iddepact != iddep) {
    descripid = document.getElementById('descrip');
    descripid.innerHTML = '';
    
    fotoid = document.getElementById('foto');
    fotoid.src = '../images/nada.gif';
    
  }
  
  
  // LLENO CELDAS CON DATOS
  ix = 0
  for (var upid in upids) {
  //alert(upid);
    ix++;
//    localTime = d.getTime();

    modnom = upids[upid];
    id = 'modnom' + ix;
    etiqueta = document.getElementById(id);
    etiqueta.innerHTML = modnom;
    /*etiqueta.innerHTML = "<a class='anuncioverPrimero' href='veranuncio.php?upid=" + upid + "' target='verAnuncio' onclick='iss_verAnuncio(" + upid + ")'>" + modnom + "</a>";*/
    etiqueta.innerHTML = "<a class='anuncioverPrimero' onclick='iss_verAnuncio(" + upid + ")'>" + modnom + "</a>";

    idthumb = 'thumb' + ix;
    thumb = document.getElementById(idthumb);
    //thumb.innerHTML = "<a class='anuncioverPrimero' href='veranuncio.php?upid=" + upid + "' target='verAnuncio' onclick='iss_verAnuncio(" + upid + ")'><img border=0 src='thumb.php?upid=" + upid + "&upfotoix=1'></a>";
    thumb.innerHTML = "<a class='anuncioverPrimero' onclick='iss_verAnuncio(" + upid + ")'><img border=0 src='thumb.php?upid=" + upid + "&upfotoix=1'></a>";
  }





  // SOBRAN CELDAS SIN DATOS ENTONCES LIMPIAR
  if (ix < primerosRegMax) {

    ix++;
    for (ix; ix <= primerosRegMax; ix++) {

    idthumb = 'thumb' + ix;
    thumb = document.getElementById(idthumb);
    //thumb.innerHTML = "<img src='images/thumb_nofoto.gif'>";
    thumb.innerHTML = "<img src='galeria/nofoto.jpg'>";

    id = 'modnom' + ix;
    etiqueta = document.getElementById(id);
    etiqueta.innerHTML = '<br>'; // Espacio <br> es para que se ajuste la tabla

    }

  }


  // DEFINE FLECHA A MOSTRAR
/*
  flecha = document.getElementById('flechaIzquierda');
  if (limiteMax == 1) { flecha.innerHTML = "<img border=0 src='../images/flecha_izq.gif' width='19' height='30' />"; }
  else { flecha.innerHTML = "<a href='javascript:iss_stepPrimeros(1)' onmouseout='MM_swapImgRestore()' onmouseover=" + '"' + "MM_swapImage('Image38','','images/flecha-izq2.gif',1)" + '"' + "><img src='../images/flecha_izq.gif' border=0 width='19' height='30' /></a>"; }


  flecha = document.getElementById('flechaDerecha');
  if (limiteMin == 1) { flecha.innerHTML = "<img src='../images/flecha_der.gif' border=0 width='19' height='30' />"; }
  else { flecha.innerHTML = "<a href='javascript:iss_stepPrimeros(-1)' onmouseout='MM_swapImgRestore()' onmouseover=" + '"' + "MM_swapImage('Image39','','images/flecha-der2.gif',1)" + '"' + "><img src='../images/flecha_der.gif' border=0 width='19' height='30' /></a>"; }
  document.datos.step.value = step;
*/
  flecha = document.getElementById('flechaIzquierda');
  if (limiteMin == 1) { flecha.innerHTML = "<img src='galeria/btnatras.jpg' width='53' height='25' />"; }
  else { flecha.innerHTML = "<a href='javascript:iss_stepPrimeros(-1)' onmouseout='MM_swapImgRestore()' onmouseover=" + '"' + "MM_swapImage('Image38','','galeria/btnatras.jpg',1)" + '"' + "><img src='galeria/btnatras.jpg' border=0 width='53' height='25' /></a>"; }


  flecha = document.getElementById('flechaDerecha');
  if (limiteMax == 1) { flecha.innerHTML = "<img src='galeria/btnSiguiente.jpg' width='53' height='25' />"; }
  else { flecha.innerHTML = "<a href='javascript:iss_stepPrimeros(1)' onmouseout='MM_swapImgRestore()' onmouseover=" + '"' + "MM_swapImage('Image39','','galeria/btnSiguiente.jpg',1)" + '"' + "><img src='galeria/btnSiguiente.jpg' border=0 width='53' height='25' /></a>"; }
  document.datos.step.value = step;



}






function iss_step(step) {

  secid = document.datos.secid.value;
  stepact = parseInt(document.datos.step.value);
  step = stepact + step;

  iss_cargarDestacados(secid,step);
}


function iss_stepPrimeros(step) {

  marid = document.datos.marid.value;
  stepact = parseInt(document.datos.step.value);
  step = stepact + step;

  iss_cargarPrimeros(marid,step);
}


function iss_stepMarca(step) {

  secid = document.frmBotonera.secid.value;
  stepact = parseInt(document.frmBotonera.step.value);
  step = stepact + step;

  iss_cargarMarcas(secid,step);
}




function iss_verAnuncio(upid) {
/*
  window.open('','verAnuncio','width=665,height=600,toolbar=yes,menubar=no,status=no,resizable=no,scrollbars=yes,screenX=0,screenY=0,top=0,left=0')
  return null;
  
*/
  
  var texto = globalupids[upid];
  var descrip = document.getElementById('descrip');
  descrip.innerHTML = texto;
  
  //document.getElementById('depnom').innerHTML = globalupids2[upid];
  document.getElementById('logo').src = 'img/logo' + globalupids2[upid] + '.jpg';
  
  document.datos.foto.src = 'foto.php?id=' + upid;
  
}


function iss_popup(target) {

  var resizable = 'no';
  var params;

  switch(target) {
    case 'accesar':
      resizable = 'yes';
    break;
  }

  params = 'width=550,height=500,toolbar=yes,menubar=no,status=no,resizable=' + resizable + ',scrollbars=yes,screenX=0,screenY=0,top=0,left=0'
  window.open('',target,params)
  return null;
}


function muestra_url(url) {
  url = 'modulos/muestra_url.php?url=' + url
  window.open(url,'muestra_url','width=800,height=500,toolbar=no,menubar=no,status=yes,resizable=yes,scrollbars=yes,screenX=0,screenY=0,top=0,left=0')
}







/*
 * LIBRERIAS VARIAS
 ************************/
function verAyuda() {
  window.open('cvv.html','verAyuda','width=350,height=350,toolbar=no,menubar=no,status=yes,resizable=no,scrollbars=no,screenX=0,screenY=0,top=0,left=0')
}


function Trim(STRING){
STRING = LTrim(STRING);
return RTrim(STRING);
}

function RTrim(s){
/*
while(STRING.charAt((STRING.length -1))==" "){
STRING = STRING.substring(0,STRING.length-1);
}
*/

while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
   	 { s = s.substring(0,s.length-1); }



return s;
}


function LTrim(s){
/*
while(STRING.charAt(0)==" "){
STRING = STRING.replace(STRING.charAt(0),"");
}
*/

while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
   	 { s = s.substring(1,s.length); }

return s;
}


