/**
* From http://www.carlosleopoldo.com
* Copyright (c) 2006 Carlos Leopoldo Magaña Zavala
**/
var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	 try {
	  xmlhttp = new XMLHttpRequest();
	 } catch (e) {
	  xmlhttp=false
	 }
	}
	function myXMLHttpRequest() {
	  var xmlhttplocal;
	  try {
	    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	    xmlhttplocal=false;
	  }
	 }

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
	 try {
	  var xmlhttplocal = new XMLHttpRequest();
	 } catch (e) {
	  var xmlhttplocal=false;
	  alert('No se puede crear el objeto xmlhttp');
	 }
	}
	return(xmlhttplocal);
}

function handleResponse() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
            changeText(update[0], update[1]);
        }
		}
    }
}

function changeText( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"
    if (DOM) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML = text;
    }  else if(IE) {
        document.all[div2show].innerHTML = text;
    }
}

function RateShwMsg(message) {
	if (message==0) {
		alert('Solamente los usuarios anónimos pueden calificar las fotos');
	} else if (message==1) {
		alert('Debes iniciar sesión cómo usuario para poder calificar las fotos');
	}
}

function RateSndReq(vote,id_num,ip_num,units) {
	var theUL = document.getElementById('unit_long'+id_num);
	
	theUL.innerHTML = '<div class="loadingrate ratingblock">cargando</div>';
	
    xmlhttp.open('get', rpc_url+'ajax.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);	
}

function FavoriteShwMsg() {
	alert('Debes iniciar sesión para poder agregar esta foto a tu galería personal');
}

function FavoriteSndReq(id,user_id,action) {
	var theSPAN = document.getElementById('favorite_'+id); // the UL
	
	if (action==0 || action==2) {
		theSPAN.innerHTML = '<span>Quitando...</span>';
	} else if (action==1) {
		theSPAN.innerHTML = '<span>Guardando...</span>';
	}
    xmlhttp.open('get', rpc_url+'ajax.php?id='+id+'&user_id='+user_id+'&action='+action);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);	
}
