// JavaScript Document
function load(){
	$(".externalControl .jCarouselLite").jCarouselLite({
	    visible: 4,
	    circular: true,
	    start: 0,
	    btnGo:
	    [".externalControl .a1", ".externalControl .a2",
	    ".externalControl .a3", ".externalControl .a4"],
	    afterEnd: function(e){
	    	id = e[0].id.split('_');
	    	id = id[1];
	    	createCookie('donde',id,999999)
//	    	location.href += '&reload=1';
//	    	window.location.reload();
			
			if (window.location.href.indexOf('rl=1')>=0){
		    	window.location.reload();
			} else {
				if (window.location.href.indexOf('?')>=0){
					n = window.location.href.split('#');
					if (n.length > 1){
				    	window.location.href = n[0]+'&rl=1#'+n[1];
					} else {
				    	window.location.href += '&rl=1';
					}
				} else{
			    	window.location.href += '?rl=1';
				}
			}
	    }
	});

	$(".externalControl2 .jCarouselLite2").jCarouselLite({
	    visible: 3,
	    start: 0,
	    circular: true,
	    btnGo:
	    [".externalControl2 .a1", ".externalControl2 .a2",
	    ".externalControl2 .a3", ".externalControl2 .a4"],
	    afterEnd: function(e){
	    	id = e[0].id.split('_');
	    	id = id[1];
	    	createCookie('que',id,999999)
//	    	location.href += '&reload=1';
//	    	window.location.reload();
			if (window.location.href.indexOf('rl=1')>=0){
		    	window.location.reload();
			} else {
				if (window.location.href.indexOf('?')>=0){
					n = window.location.href.split('#');
					if (n.length > 1){
				    	window.location.href = n[0]+'&rl=1#'+n[1];
					} else {
				    	window.location.href += '&rl=1';
					}
				} else{
			    	window.location.href += '?rl=1';
				}
			}
//	    	window.location.href += '&rl=1';
	    }
	});
}



$(function() {
	
		$( "#example_1" ).accessNews({
	        headline : "",
	        speed : "normal",
			slideBy : 2
	    });
		
		
	});
$(function() {
	
		$( "#example_2" ).accessNews({
	        headline : "",
	        speed : "normal",
			slideBy : 2
	    });
		
		
	});
$(function() {
	
		$( "#example_3" ).accessNews({
	        headline : "",
	        speed : "normal",
			slideBy : 1
	    });
		
		
	});


/*******Aca van los TABS*********/
/*$(function () { setTimeout('func1()',5000);
                });*/

function func1(){
                       var tabContainers = $('div.tabs > div');
                       tabContainers.hide().filter(':first').show();
                        
                        $('div.tabs ul.tabNavigation a').click(function () {
                                tabContainers.hide();
                                tabContainers.filter(this.hash).show();
                                $('div.tabs ul.tabNavigation a').removeClass('selected');
                                $(this).addClass('selected');
                                return false;
                        }).filter(':first').click();
	
}


/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});

// Imprimir
function imprimir() {
if (window.print)
window.print()
else
alert("Para imprimir presione Crtl+P.");
}

/****************** COOKIE *******************/

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
	

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//ver videos
function doWin(id) {  //popup  for browse function
	location.replace('index.php?video='+id+'#video');
}

//llenador por ajax
function lookup(inputString,box,list,type1,extraParam1) {
        $('#'+box).hide();
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $('#'+box).hide();
    } else {
        $.post("http://www.webuniversitaria.com/rpc.php", {queryString: inputString,type: type1, extraParam: extraParam1}, function(data){
            if(data.length >0) {
                $('#'+box).show();
                $('#'+list).html(data);
            }
        });
    }
} // lookup

function fill(thisValue,box,input) {
    $('#'+input).val(thisValue);
   $('#'+box).hide();
}


/* id es el identificador a buscar, y val tiene un numero que es la tabla adonde se va a buscar el id_parent como 'id' */
function fillSelect(id,val){
//	alert(id + "--"+val);
	arr = val.split('_');
	num = arr[1];
//	loc = $('#'+val)[0];
//	alert(loc.id);
	newid = parseInt(num)+1;
	$('#'+val).load('get_data.php?id='+id+'&tabla='+num, function (){
		fillSelect($('#'+val)[0].value,'lugar_'+newid);
//		alert(num);
		if (document.getElementById('cercanias') != null && num == 5){
			actualizarCercania();
		}
	});
//	new Ajax.Updater(loc, 'get_data.php?id='+id+'&tabla='+num,{onComplete: function (){
//		fillSelect($(val).value,'lugar_'+newid);
//	}
//	});
}


/* id es el identificador a buscar, y val tiene un numero que es la tabla adonde se va a buscar el id_parent como 'id' */
function fillSelect2(id,val){
//	alert(id + "--"+val);
	arr = val.split('_');
	num = arr[1];
//	loc = $('#'+val)[0];
//	alert(loc.id);
	newid = parseInt(num)+1;
	$('#'+val).load('get_data3.php?id='+id+'&tabla='+num, function (){
		fillSelect2($('#'+val)[0].value,'lugar_'+newid);
//		alert(num);
		if (document.getElementById('cercanias') != null && num == 5){
			actualizarCercania();
		}
	});
//	new Ajax.Updater(loc, 'get_data.php?id='+id+'&tabla='+num,{onComplete: function (){
//		fillSelect($(val).value,'lugar_'+newid);
//	}
//	});
}


function fillSelect3(id,val){
//	alert(id + "--"+val);
	arr = val.split('_');
	num = arr[1];
//	loc = $('#'+val)[0];
//	alert(loc.id);
	newid = parseInt(num)+1;
	$('#'+val).load('get_data4.php?id='+id+'&tabla='+num, function (){
		fillSelect3($('#'+val)[0].value,'lugar_'+newid);
//		alert(num);
		if (document.getElementById('cercanias') != null && num == 5){
			actualizarCercania();
		}
	});
//	new Ajax.Updater(loc, 'get_data.php?id='+id+'&tabla='+num,{onComplete: function (){
//		fillSelect($(val).value,'lugar_'+newid);
//	}
//	});
}


/* id es el identificador a buscar, y val tiene un numero que es la tabla adonde se va a buscar el id_parent como 'id' */
function fillSelect4(id,val){
//	alert(id + "--"+val);
	arr = val.split('_');
	num = arr[1];
//	loc = $('#'+val)[0];
//	alert(loc.id);
	newid = parseInt(num)+1;
	$('#'+val).load('get_data3.php?id='+id+'&tabla='+num, function (){
		fillSelect2($('#'+val)[0].value,'lugar2_'+newid);
//		alert(num);
		if (document.getElementById('cercanias') != null && num == 5){
			actualizarCercania();
		}
	});
//	new Ajax.Updater(loc, 'get_data.php?id='+id+'&tabla='+num,{onComplete: function (){
//		fillSelect($(val).value,'lugar_'+newid);
//	}
//	});
}


function actualizarCercania(){
	l1 = $('#lugar_1')[0].value;
	l2 = $('#lugar_2')[0].value;
	l3 = $('#lugar_3')[0].value;
	$('#cercanias').load('get_data2.php?l1='+l1+'&l2='+l2+'&l3='+l3);
}

function recuPass(){
	$('#res_env')[0].style.display = 'none';
	$('#res_no')[0].style.display = 'none';
	$('#res_nomail')[0].style.display = 'none';
	
	mail1 = $('#mail_pass')[0].value;
	$('#mailenv')[0].innerHTML = mail1;
	$.post("recuperar-psw.php", {mail: mail1}, function(data){
	    $('#res_'+data)[0].style.display = '';
	    if (data == 'env'){
	    	setTimeout("jQuery(document).trigger('close.facebox');",1500);
	    }
	});

}

function sendConsulta(tipo1){
	$('#res_si')[0].style.display = 'none';
	$('#res_no')[0].style.display = 'none';
	
	id_prop1 = $('#id_prop')[0].value;
	id_user1 = $('#id')[0].value;
	tel11 = $('#tel1')[0].value;
	tel21 = $('#tel2')[0].value;
	consulta1 = $('#consulta')[0].value;
	$.post("consultar.php", {id_prop:id_prop1, id_user:id_user1, tel1:tel11, tel2:tel21, consulta:consulta1, tipo:tipo1}, function(data){
	    $('#res_'+data)[0].style.display = '';
	    if (data == 'si'){
	    	setTimeout("jQuery(document).trigger('close.facebox');",1500);
	    }
	});
}

function sendConsulta2(tipo1){
	$('#res_si')[0].style.display = 'none';
	$('#res_no')[0].style.display = 'none';
	
	id_prop1 = $('#id_prop')[0].value;
	id_user1 = $('#id')[0].value;
	nombre1 = $('#nombre')[0].value;
	mail1 = $('#mail')[0].value;
	consulta1 = $('#consulta')[0].value;
	$.post("consultar2.php", {id_prop:id_prop1, id_user:id_user1, nombre:nombre1, mail:mail1, consulta:consulta1, tipo:tipo1}, function(data){
	    $('#res_'+data)[0].style.display = '';
	    if (data == 'si'){
	    	setTimeout("jQuery(document).trigger('close.facebox');",1500);
	    }
	});
}

function compararPropiedades(){
	inp = document.getElementsByTagName('input');
	len = inp.length;
	ids1 = new Array;
	maxp = 4;
	j = 0;
	for (i = 0; i < len; i++){
		arr = inp[i].id.split('_');
		if (arr[0] == 'prop' && inp[i].checked == true){
			ids1[j] = arr[1];
			j++;
		}
	}
	if (j <= maxp){
		if (j > 1){
			$('#ids')[0].value = ids1.join('|');
			$('#form_comparar').submit();
		} else {
			alert('Debe seleccionar por lo menos dos propiedades para ser comparadas.')
		}
	} else {
		alert('No se pueden comparar mas de '+maxp+' propiedades a la vez. Por favor quita alguna.')
	}
}
