/*
 * 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;


/*
 * 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 + '&ccano=2009';
}

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 + '&ccano=2009';
}





/*
 * 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 + '&ccano=2209';
  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(step) {

  //alert(marid);
  var marid = document.getElementById('upid2').value;
 // alert(marid);
  //ajxurl = 'primeros.php?marid=' + marid + '&step=' + step + '&ccano=2009';
  //alert(marid);
  //var step = 0;
  ajxurl = 'primeros.php?marid=' + marid + '&step=' + step + '&ccano=2009';
//  return callToServer(ajxurl);
  callToServer(ajxurl);
}

function primeros()
{
	alert('marid');
	//var upid2 = document.getElementById('marid').value;
	//alert('hola');
	var upid2 = 1;
	//var prueba = 1;
	 //ajxurl2 = 'thumb.php?upid2=' + upid2 + '&step=' + step + '&ccano=2009';
	 ajxurl2 = 'primeros.php?upid2=' + upid2;
	 //alert('mundillo');
	//sendRequest(ajxurl2);
	callToServer(ajxurl2);
	//alert('mundollos' + ajxurl2);
	//callToServer(ajxurl2);
}


//function ajx_llenarPrimeros(upids,step,primerosRegMax,limiteMin,limiteMax) {
//function ajx_llenarPrimeros(upids,step,primerosRegMax,limiteMin,limiteMax,depnom,iddep) {
function ajx_llenarPrimeros(upids,step,primerosRegMax,limiteMin,limiteMax) {
//  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, flecha2;
  var limiteMin;
  var limiteMax;
  
  globalupids = upids;
 /*
  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/thumb_nofoto.gif';
    
  }
  */
  
  // LLENO CELDAS CON DATOS
  ix = 0
  for (var upid in upids) {
    ix++;
//    localTime = d.getTime();
	
    modnom = upids[upid];
    id = 'modnom' + ix;
    etiqueta = document.getElementById(id);
	//var upid2 = document.getElementById('upid2').value; 
    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>";
	etiqueta.innerHTML = "<a class='anuncioverPrimero' onclick='iss_verAnuncio(" + upid +")'></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&ccano=2009'></a>";		
	//alert(ix + upid);
	if(ix == 1)
	{	
		var valor = upid;
	}		
  }
	upid = valor;
		//alert('contador' + contador + upid);
	iss_verAnuncio(upid);
	//alert(upid);
  // 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'>";

    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/btnregre.jpg' width='69' height='21' />"; }
  else 
  { 
		flecha.innerHTML = "<a href='javascript:iss_stepPrimeros(-1)' onmouseout='MM_swapImgRestore()'><img id = 'Image12' src='Galeria/btnregre.jpg' border=0 width='69' height='21' onmouseover=" + '"' + "MM_swapImage('Image12','','Galeria/btnregre_on.jpg',1)" + '"' + "onmouseout='MM_swapImgRestore()'/></a>"; 		
  }
 // document.datos.getElementById('Image12');
 //else { flecha.innerHTML = "<a href='javascript:iss_stepPrimeros(-1)' onmouseout='MM_swapImgRestore()' onmouseover=" + '"' + "MM_swapImage('Image12','','Galeria/btnregre_on.jpg',1)" + '"' + "><img src='Galeria/btnregre_on.jpg' border=0 width='53' height='25' /></a>"; }
  //else { flecha.innerHTML = "<a href='javascript:iss_stepPrimeros(-1)' onmouseout='MM_swapImgRestore()' onmouseover=" + '"' + "MM_swapImage('Image38','','images/botones/btnant_off.gif',1)" + '"' + "><img src='images/botones/btnant_off.gif' border=0 width='53' height='25' /></a>"; }
	//onmouseover="MM_swapImage('Image12','','Galeria/btnregre_on.jpg',1)" onmouseout="MM_swapImgRestore()"
  
  
  flecha = document.getElementById('flechaDerecha');
  if (limiteMax == 1) { flecha.innerHTML = "<img src='Galeria/btnsigui.jpg' width='69' height='21' />"; }
  else 
  { 
		//flecha.innerHTML = "<a href='javascript:iss_stepPrimeros(1)' onmouseout='MM_swapImgRestore()' onmouseover=" + '"' + "MM_swapImage('Image11','','Galeria/btnsigui.jpg',1)" + '"' + "><img src='Galeria/btnsigui.jpg' border=0  width='69' height='21'  /></a>"; 
		flecha.innerHTML = "<a href='javascript:iss_stepPrimeros(1)' onmouseout='MM_swapImgRestore()'><img id = 'Image11' src='Galeria/btnsigui.jpg' border=0 width='69' height='21' onmouseover=" + '"' + "MM_swapImage('Image11','','Galeria/btnsigui_on.jpg',1)" + '"' + "onmouseout='MM_swapImgRestore()'/></a>"; 			
  }
  document.datos2.step.value = step;


}
/*
function mouseOver(element)
{
	alert('mouse over');
	document.getElementById(element).style.background = 'url(Galeria/btnregre_on.jpg) ';
	//document.getElementById(element).innerHTML = "<a href='#'><img src='Galeria/btnregre_on.jpg' border=0  width='69' height='21'  /></a>";
} 

function mouseOut(element)
{
	document.getElementById(element).style.backgroundColor = 'blue'
	//document.getElementById(element).innerHTML = "<a href='#'><img src='Galeria/btnregre.jpg' border=0  width='69' height='21'  /></a>";
} 
*/

function iss_step(step) {

  secid = document.datos2.secid.value;
  stepact = parseInt(document.datos2.step.value);
  step = stepact + step;

  iss_cargarDestacados(secid,step);
}


function iss_stepPrimeros(step) {
//alert(step);
var marid = document.getElementById('upid2').value;
 // marid = document.datos2.marid.value;
  stepact = parseInt(document.datos2.step.value);
  step = stepact + step;

  iss_cargarPrimeros(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.datos2.foto.src = 'foto.php?id=' + upid + '&ccano=2009';
  
}


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;
}


