var baseURL    = "http://www.elijoroundup.com.ar/ajax/";
var $loadingImg = '<img src="images/various/loading.gif">';

function checkCapabilities(){
  var xmlHttp2;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp2=new XMLHttpRequest();
  }
  catch (e){
    // Internet Explorer
    try{
      xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e){
      try{
    	    xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e){
    	    alert("Your browser does not support AJAX!");
    	    return false;
	  }
    }
  }
  return xmlHttp2;
}

function control(){ 
  return true; 
} 

window.onerror = control; 

/* FLASH LOGIN BOX */
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function loginScreen_DoFSCommand(command, args) {
	switch(command){
		case 'openBox':
			$('loginScreen').height = 220;
			Element.setStyle($('loginbox'), {'zIndex': 10000});
			if(window.console)
				window.console.debug('openLogin');
			break;
		case 'closeBox':
			$('loginScreen').height = 40;
			Element.setStyle($('loginbox'), {'zIndex': 1});
			if(window.console)
				window.console.debug('closeLogin');
			break;
		case 'login':
			var _data = args.split(',');
			login(_data[0], _data[1]);
			if(window.console){
				window.console.debug('login: ' + _data[0] + ', ' + _data[1]);
			}
			break;
		case 'register':
			window.location.href='/registro.php';
			if(window.console)
				window.console.debug('register');
			break;
		case 'forgot':
			var objLink = document.createElement('a');
			objLink.setAttribute('href', 'recuperaPass.php');
			objLink.setAttribute('rel', 'lightbox');
			objLink.setAttribute('title', 'Olvido su contraseña');
			var _ln = new lightbox(objLink);
			_ln.displayLightbox("block");

			if(window.console)
				window.console.debug('forgot');
			break;
	}
}

// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub loginScreen_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call loginScreen_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
/* FLASH LOGIN BOX */

function login(user, pass){
	try{  
	  var xmlHttp = checkCapabilities();
	  var $user = user;
	  var $psw  = pass;
	  //var $url  = document.getElementById('url');
		if(window.console)
			window.console.debug('login2: ' + $user + ', ' + $psw);
			
	  if( $user && $psw && ($psw.length >= 6 ) ){
		  xmlHttp.onreadystatechange=function(){
			  if(xmlHttp.readyState < 4){
				  ///document.getElementById('loginBtn').innerHTML = $loadingImg;
			  }
			  if(xmlHttp.readyState == 4){
				  var $showMsg = xmlHttp.responseText;
				  if($showMsg == ''){
					  window.location.href = '/';
				  }else{
					  alert($showMsg); 
				  }
			  }
		  }
		  xmlHttp.open("GET",baseURL+"login.php?user="+$user+"&psw="+$psw,true);  
		  xmlHttp.send(null);            
	  }else{
		  alert('Por favor complete los datos y vuelva a intentarlo');    
	  }
	}catch($err){
	  alert($err);
	}
}



/*function login(){
	try{  
	  var xmlHttp = checkCapabilities();
	  var $user = document.getElementById('user');
	  var $psw  = document.getElementById('psw');
	  var $url  = document.getElementById('url');
  
	  if( $user.value && $psw.value && ($psw.value.length >= 6 ) ){
		  xmlHttp.onreadystatechange=function(){
			  if(xmlHttp.readyState < 4){
				  document.getElementById('loginBtn').innerHTML = $loadingImg;
			  }
			  if(xmlHttp.readyState == 4){
				  var $showMsg = xmlHttp.responseText;
				  if($showMsg == ''){
					  window.location.href = $url.value;
				  }else{
					  alert($showMsg); 
				  }
			  }
		  }
		  xmlHttp.open("GET",baseURL+"login.php?user="+$user.value+"&psw="+$psw.value,true);  
		  xmlHttp.send(null);            
	  }else{
		  alert('Por favor complete los datos y vuelva a intentarlo');    
	  }
	}catch($err){
	  alert($err);
	}
}*/



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

	
var contTime = 0;
function contar(){			
	if(contTime == 10){
		clearTimeout(v);
		lightbox.prototype.deactivate(); 
		return;
	}
	contTime++;
	v = setTimeout("contar()",1000);
}

function recuperar() {
   	var mail = document.getElementById('recuperaMail').value ;
	if(!mail) {
		alert("Debe ingresar un email");
		return;
	}	
	document.formu.submit();
}


function recuperaPass(mail) {
    var xmlHttp;
   
	xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdRecupera").innerHTML = $loadingImg;
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("tdRecupera").innerHTML = xmlHttp.responseText;
			getComentarios();
		} 
	}
	xmlHttp.open("GET",baseURL+"recuperaPass.php?mail="+mail,true);   
	
	xmlHttp.send(null);	
}

function nuevoWeather(){
    var xmlHttp;
   
	xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdWeatherCant").innerHTML = $loadingImg;
		} 
		if(xmlHttp.readyState == 4){
			getWeather(); 
		} 
	}
	xmlHttp.open("GET",baseURL+"newWeather.php",true);   
	
	xmlHttp.send(null);	  
}

function getWeather(){
    var xmlHttp;
   
	xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdWeatherCant").innerHTML = $loadingImg;
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("tdWeatherCant").innerHTML = xmlHttp.responseText;
		} 
	}
	xmlHttp.open("GET",baseURL+"getWeather.php",true);   
	
	xmlHttp.send(null);	  
}

function deleteWeather($id){
	if(!confirm('¿Desea eliminar este Widget?')) {
		return;
	}
    var xmlHttp;
   
	xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdWeatherCant").innerHTML = $loadingImg;
		} 
		if(xmlHttp.readyState == 4){
			getWeather(); 
		}
	}
	xmlHttp.open("GET",baseURL+"deleteWeather.php?id="+$id,true);   
	
	xmlHttp.send(null);	   
}

function getRSSBox(){
    var xmlHttp;
   
	xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdRSSCant").innerHTML = $loadingImg;
		} 
		if(xmlHttp.readyState == 4){
			document.getElementById("tdRSSCant").innerHTML = xmlHttp.responseText;
		} 
	}
	xmlHttp.open("GET",baseURL+"getRssBox.php",true);   
	
	xmlHttp.send(null);	  
}

function deleteRSSBox($id){  
    if(!confirm('¿Desea eliminar este Widget?')) {
		return;
	}
	var xmlHttp;
   
	xmlHttp = checkCapabilities();
		
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState < 4){
			document.getElementById("tdRSSCant").innerHTML = $loadingImg;
		} 
		if(xmlHttp.readyState == 4){
			getRSSBox(); 
		}
	} 
	xmlHttp.open("GET",baseURL+"deleteRss.php?id="+$id,true);   
	
	xmlHttp.send(null);	   
}

function boxLoad( boxName, boxClass, replaceDoc, params ) {

    var $xmlHttp    = checkCapabilities();
    var $box        = document.getElementById( boxName );
    var $loadBox
    
    if( boxClass ){
        $loadBox    = boxClass
    }else{
        $loadBox    = 'ajaxLoad';
    }
    
    //$loadBox    = 'ajaxLoad';
    //alert($loadBox);
    
    if( $xmlHttp && $box ){
        
        $xmlHttp.onreadystatechange =
        function(){
            
            if( $xmlHttp.readyState < 4 ){
                $box.innerHTML = $loadingImg;
            }
            
            if( $xmlHttp.readyState == 4 ){
                $box.innerHTML = $xmlHttp.responseText;
            }
        }
        
        if( params ) params = '?'+params;
        $xmlHttp.open( "GET", baseURL + replaceDoc +  params , true ); 
        $xmlHttp.send(null);
    }
}

function boxLoadAction( boxName, boxClass, replaceDoc, params, getFunction ) {

    var $xmlHttp    = checkCapabilities();
    var $box        = document.getElementById( boxName );
    var $loadBox;
    
    if( boxClass ){
        $loadBox    = boxClass
    }else{
        $loadBox    = 'ajaxLoad';
    }
    
    //$loadBox    = 'ajaxLoad';
    //alert($loadBox);
    
    if( $xmlHttp && $box ){
        
        $xmlHttp.onreadystatechange =
        function(){
            
            if( $xmlHttp.readyState < 4 ){
                $box.innerHTML = $loadingImg;
            }
            
            if( $xmlHttp.readyState == 4 ){
                $box.innerHTML = $xmlHttp.responseText;
                getFunction();
            }
            
        }
        
        if( params ) params = '?'+params;
        
        $xmlHttp.open( "GET", baseURL + replaceDoc +  params , true ); 
        $xmlHttp.send(null);
    }
}

function changeMenuDesp( id ){ 
	
	for( var $i = 0 ; $i <= 6 ; $i++  ){
		var $elemID	= 'menu-desp-' + $i;
		var $obj	= document.getElementById( $elemID );

		if( $obj ){
			if( $i != id ){
				if(id != 6 )
				$obj.style.display = 'none';
			}else{
				$obj.style.display = '';			
			}
		}
	}
	
	
	//return false;
}


function changeMenuOut(){
	for( var $i = 0 ; $i <= 6 ; $i++  ){
		var $elemID	= 'menu-desp-' + $i;
		
		var $obj	= document.getElementById( $elemID );
		if( $obj ){
				$obj.style.display = 'none'; 
		}
	}
	return false;
}

