var imageCounter = 0;
var running = false;
var timer;
var firstDone = false;
function runListingSlideShow(imageNumber) {
	if (imageNumber>=0) {
		imageCounter = imageNumber;
	} else {
		if (running) {
			if (imageCounter > 0 ){firstDone = true};
			imageCounter = ((imageCounter + 1) % imagesTotal);
		}
		if (imageCounter == 0 && firstDone == true ){
			onFin();
		}
	}
	if (document.all){
		document.images.ListingImage.style.filter="blendTrans(duration=2)";
		document.images.ListingImage.filters.blendTrans.Apply();
	}
	document.images.ListingImage.src = ListingImages[imageCounter].src;
	if (document.getElementById('ListingLink')){
		document.getElementById('ListingLink').href = ListingLinks[imageCounter];
	}
	if (document.images.ListingImage.alt){
		document.images.ListingImage.alt = ListingAlts[imageCounter];
	}
	if (document.getElementById('ListingDesc')){
		document.getElementById('ListingDesc').innerHTML = ListingDescs[imageCounter];
	}
	
	if (document.all){
		document.images.ListingImage.filters.blendTrans.Play();
	}
	if (running) {
		timer = setTimeout('runListingSlideShow(-1);', 6000);
	}
}
function controlSlideShow(command) {
	if (command=='pause') {
		if (running==true) {
			running=false;
			clearTimeout(timer);
		}
	}
	else if (command=='play') {
	 	if (running==false) {
			running=true;
			timer = setTimeout('runListingSlideShow(-1);', 6000);
	 	}
	}
	else if (command=='back') {
		clearTimeout(timer);
		if (imageCounter>0){
			runListingSlideShow((imageCounter - 1) % imagesTotal);
		}else{
			runListingSlideShow(imagesTotal-1);
		}
	}
	 else if (command=='forward') {
	 	clearTimeout(timer);
	 	runListingSlideShow((imageCounter + 1) % imagesTotal);
	}
}
function select_P(span){
	document.getElementById(span).onclick='';
	ajaxHTML('/Config/Actions.asp?Action=Paises', span ,'', '');
}
function select_Z(span){
	document.getElementById(span).onclick='';
	ajaxHTML('/Config/Actions.asp?Action=Zonas', span ,'', '');
}
var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE
function xhrRequest(type) {
	if (!type) {
		type = 'html';
	}
	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length; 
	
	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {
		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}
	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;
	// SET UP THE REQUEST
	if (window.ActiveXObject) {
		try {
			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (window.XMLHttpRequest) {
		xhr[xhrsend] = new XMLHttpRequest();
		if (xhr[xhrsend].overrideMimeType) {
			xhr[xhrsend].overrideMimeType('text/' + type);
		}
	}
	return (xhrsend);
}
function ajaxHTML(url, span, loading, alCargar) {
	if (loading){
		document.getElementById(span).innerHTML = loading;
	}
	var xhri = xhrRequest('html');			
	xhr[xhri].open('GET', url, true);
	xhr[xhri].onreadystatechange = function() {
		//if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
		if (xhr[xhri].readyState == 4) {
			document.getElementById(span).innerHTML = xhr[xhri].responseText;
			//alert(xhr[xhri].responseText);
			xi[xhri] = 1;
			xhr[xhri] = null;
			if (alCargar){
				setTimeout(alCargar, 0);
			}
		}
	};
	xhr[xhri].send(null);
}

function validator(form){
	if(document.getElementById(form+'_imgCaptcha')){
		if(document.getElementById(form+'_action')){
			document.getElementById(form+'_action').value=document.getElementById(form).action;
			document.getElementById(form).action='/Config/Actions.asp?Action=ValidForm';
		}
		
	}
	
	window.addEvent('domready', function(){
		new FormCheck(form,{
			submitByAjax:true,
			evalScripts:true,
			evalResponse:true,
			onAjaxRequest: function() {
				if (document.getElementById(form+'_Submit')){
					document.getElementById(form+'_Submit').style.visibility="hidden";
				}
				if (document.getElementById(form+'_res')){
					document.getElementById(form+'_res').style.visibility="visible";
					$(form+'_res').set("html", "<img src='/Admin_Inc/Imagenes/load_negro_trans24x24.gif' alt='...' />");
				}
			},
			onAjaxSuccess: function(response) {
				if(document.getElementById('alert')){
					alert(document.getElementById('alert').value);
				}
				if(document.getElementById('goto')){
					window.open(document.getElementById('goto').value, "_self");
				}
				if(response=='ValidFormOk'){
					document.getElementById(form).action=document.getElementById(form+'_action').value;
					document.getElementById(form).submit();
				}else{
					if (document.getElementById(form+'_res')){
						$(form+'_res').set('html', '');
						$(form+'_res').set('html', response);
					}
					if (document.getElementById(form+'_Submit')){
						document.getElementById(form+'_Submit').style.visibility="visible";
					}
					if(document.getElementById(form+'_imgCaptcha')){
						RefreshImage(form+'_imgCaptcha');
					}
				}
			},
			onAjaxFailure: function() {
				if (document.getElementById(form+'_res')){
					$(form+'_res').set('html', 'Error');
				}
				if (document.getElementById(form+'_Submit')){
					document.getElementById(form+'_Submit').style.visibility="visible";
				}
			}
		});
	});
}


function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
};
function Display(id) {
  if (!document.getElementById) return false;
  fila = document.getElementById(id);
  if (fila.style.display != "none") {
    fila.style.display = "none"; //ocultar fila 
	if (document.getElementById(id+'_show')){
		document.getElementById(id+'_show').src='/Admin_Inc/Imagenes/1000png/bullet_toggle_plus.png';
	}
  } else {
    fila.style.display = "block"; //mostrar fila 
	if (document.getElementById(id+'_show')){
	document.getElementById(id+'_show').src='/Admin_Inc/Imagenes/1000png/bullet_toggle_minus.png';
	}
  }
}
function DisplayFix(id) {
  if (!document.getElementById) return false;
  fila = document.getElementById(id);
    fila.style.display = "block"; //mostrar fila 
	if (document.getElementById(id+'_show')){
	document.getElementById(id+'_show').src='/Admin_Inc/Imagenes/1000png/bullet_toggle_minus.png';
	}
}

