// JavaScript Document
/*
	UPLOADER: Función que recarga elementos html, con la respuesta de una url que le pasamos.
	La url puede ser un fichero php al que le pasamos parámetros de variables php
*/
function actualizar(contenedor,url,parametros)
{
	$(contenedor).innerHTML='';
	new Ajax.Updater(contenedor, url, {
  		parameters: parametros,
		method: 'post'
	});	

}


function requester(url, params)
{
	xmlhttp=null;
	if (window.XMLHttpRequest)
 	{// code for IE7+, Firefox, Chrome, Opera, Safari
 		xmlhttp=new XMLHttpRequest();
 	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
	url=url+"?"+params;
	
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	if(xmlhttp.responseText!="Error")
	{
		var votos = xmlhttp.responseText;
		$('star').innerHTML="<img src=\"../imagenes/star.png\" /> "+votos+" Votos"; 
		$('btn_votar').style.display='none';
	}
} 

function validar(url,parametros,div, div2)
{
	
	xmlhttp=null;
	if (window.XMLHttpRequest)
 	{// code for IE7+, Firefox, Chrome, Opera, Safari
 		xmlhttp=new XMLHttpRequest();
 	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
	url=url+"?"+parametros;
	
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	if(xmlhttp.responseText=="")
	{
		window.document.getElementById(div).style.display='none';
		if(window.document.getElementById(div2)){
			window.document.getElementById(div2).style.display='none';
		}
	}
	
}

function comprobarMunicipio(valor){
	xmlhttp=null;
	if (window.XMLHttpRequest)
 	{// code for IE7+, Firefox, Chrome, Opera, Safari
 		xmlhttp=new XMLHttpRequest();
 	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
	url="http://chupachuck.overalia.com/ajax/municipios.php?municipio="+valor;
	
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	return xmlhttp.responseText;
}

function comprobarCodigoPostal(valor){
	xmlhttp=null;
	if (window.XMLHttpRequest)
 	{// code for IE7+, Firefox, Chrome, Opera, Safari
 		xmlhttp=new XMLHttpRequest();
 	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
	var municipio = document.getElementById('ciudad').value;
	url="http://chupachuck.overalia.com/ajax/codigos_postales.php?codigo-postal="+valor+'&municipio='+municipio;
	
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	return xmlhttp.responseText;
}

function comprobarNumeroTelefono(valor){
	xmlhttp=null;
	if (window.XMLHttpRequest)
 	{// code for IE7+, Firefox, Chrome, Opera, Safari
 		xmlhttp=new XMLHttpRequest();
 	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
	var municipio = document.getElementById('ciudad').value;
	url="http://chupachuck.overalia.com/ajax/telefonos_fijos.php?telefono="+valor+'&municipio='+municipio;
	
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	return xmlhttp.responseText;
}

/*function noaceptar(url,parametros,div)
{
	
	xmlhttp=null;
	if (window.XMLHttpRequest)
 	{// code for IE7+, Firefox, Chrome, Opera, Safari
 		xmlhttp=new XMLHttpRequest();
 	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
	url=url+"?"+parametros;
	
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	if(xmlhttp.responseText=="")
	{
		window.document.getElementById(div).style.display='none';
	}
	
}*/

/*
	REQUEST: Función de respuesta, no carga ningún objeto, solo devuleve un resultado 
*/


/* DESACTVIAR BOTONES AL DETECTAR Javascript*/

function desactivar(elementos)
{
	elementos.each(function(name){
		$(name).hide();
	});
	
	
	//each(myObject).hide();
}

function recuperarDescendentes(div)
{
	/*firstDescendant($(div)).each(function(n) {
		alert($(n).id);									   
	});*/
	var imagenes = $(div).childElements();
	//alert($(imagenes).id);
	imagenes.each(function(img){
      alert($(img).getStyle('left'));
	  alert($(img).getStyle('top'));
	});


	
}
function posicionarCapaEnAreaVisible(posicionTop, capa){
   var posicionRespectoViewport = posicionTop - document.viewport.getScrollOffsets()[1] + capa.offsetHeight;
   if(posicionRespectoViewport > document.viewport.getDimensions().height){
      posicionTop = document.viewport.getDimensions().height + document.viewport.getScrollOffsets()[1] - capa.offsetHeight;
   }
   alert( posicionTop);
}

function posicion(div_contenedor)
{
   var arr = $(div_contenedor).positionedOffset();
   //$('chuckcaretos').absolutize();
//$('img_careto2').relativize();

   var arr1 = $('img_careto1').positionedOffset();
   var arr2 = $('img_careto2').positionedOffset();
   
	var arr3 = $('img_careto3').positionedOffset();
   var arr4 = $('img_careto4').positionedOffset();
   var arr5 = $('img_careto5').positionedOffset();
   var arr6 = $('img_careto6').positionedOffset();
   var arr7 = $('img_careto7').positionedOffset();
   var arr8 = $('img_careto8').positionedOffset();
   var arr9 = $('img_careto9').positionedOffset();
   var arr10 = $('img_careto10').positionedOffset();
   var arr11 = $('img_careto11').positionedOffset();
   var arr12 = $('img_careto12').positionedOffset();
   var arr13 = $('img_careto13').positionedOffset();
   var arr14 = $('img_careto14').positionedOffset();
   var arr15 = $('img_careto15').positionedOffset();
   var arr16 = $('img_careto16').positionedOffset();
   var arr17 = $('img_careto17').positionedOffset();
   var arr18 = $('img_careto18').positionedOffset();
   var arr19 = $('img_careto19').positionedOffset();
   var arr20 = $('img_careto20').positionedOffset();
   
   var img1_x = (arr1[0]-arr[0]);
   var img1_y = (arr1[1]-arr[1]);
   var img2_x = (arr2[0]-arr[0]);
   var img2_y = (arr2[1]-arr[1]);
   var img3_x = (arr3[0]-arr[0]);
   var img3_y = (arr3[1]-arr[1]);

   var img4_x = (arr4[0]-arr[0]);
   var img4_y = (arr4[1]-arr[1]);
   var img5_x = (arr5[0]-arr[0]);
   var img5_y = (arr5[1]-arr[1]);
   var img6_x = (arr6[0]-arr[0]);
   var img6_y = (arr6[1]-arr[1]);
   var img7_x = (arr7[0]-arr[0]);
   var img7_y = (arr7[1]-arr[1]);
   var img8_x = (arr8[0]-arr[0]);
   var img8_y = (arr8[1]-arr[1]);
   var img9_x = (arr9[0]-arr[0]);
   var img9_y = (arr9[1]-arr[1]);
   var img10_x = (arr10[0]-arr[0]);
   var img10_y = (arr10[1]-arr[1]);
   var img11_x = (arr11[0]-arr[0]);
   var img11_y = (arr11[1]-arr[1]);
   var img12_x = (arr12[0]-arr[0]);
   var img12_y = (arr12[1]-arr[1]);
   var img13_x = (arr13[0]-arr[0]);
   var img13_y = (arr13[1]-arr[1]);
   var img14_x = (arr14[0]-arr[0]);
   var img14_y = (arr14[1]-arr[1]);
   var img15_x = (arr15[0]-arr[0]);
   var img15_y = (arr15[1]-arr[1]);
   var img16_x = (arr16[0]-arr[0]);
   var img16_y = (arr16[1]-arr[1]);
   var img17_x = (arr17[0]-arr[0]);
   var img17_y = (arr17[1]-arr[1]);
   var img18_x = (arr18[0]-arr[0]);
   var img18_y = (arr18[1]-arr[1]);
   var img19_x = (arr19[0]-arr[0]);
   var img19_y = (arr19[1]-arr[1]);
   var img20_x = (arr20[0]-arr[0]);
   var img20_y = (arr20[1]-arr[1]);
   
   
   $('img1_x').value = img1_x;
   $('img1_y').value = img1_y;
   $('img2_x').value = img2_x;
   $('img2_y').value = img2_y;
   $('img3_x').value = img3_x;
   $('img3_y').value = img3_y;
   $('img4_x').value = img4_x;
   $('img4_y').value = img4_y;
   $('img5_x').value = img5_x;
   $('img5_y').value = img5_y;
   $('img6_x').value = img6_x;
   $('img6_y').value = img6_y;
   $('img7_x').value = img7_x;
   $('img7_y').value = img7_y;
   $('img8_x').value = img8_x;
   $('img8_y').value = img8_y;
   $('img9_x').value = img9_x;
   $('img9_y').value = img9_y;
   $('img10_x').value = img10_x;
   $('img10_y').value = img10_y;
   $('img11_x').value = img11_x;
   $('img11_y').value = img11_y;
   $('img12_x').value = img12_x;
   $('img12_y').value = img12_y;
   $('img13_x').value = img13_x;
   $('img13_y').value = img13_y;
   $('img14_x').value = img14_x;
   $('img14_y').value = img14_y;
   $('img15_x').value = img15_x;
   $('img15_y').value = img15_y;
   $('img16_x').value = img16_x;
   $('img16_y').value = img16_y;
   $('img17_x').value = img17_x;
   $('img17_y').value = img17_y;
   $('img18_x').value = img18_x;
   $('img18_y').value = img18_y;
   $('img19_x').value = img19_x;
   $('img19_y').value = img19_y;
   $('img20_x').value = img20_x;
   $('img20_y').value = img20_y;
   
	$('form_foto2').submit();
}


function mostrarEmailPadres() {

	var fecha = $('fecha_nacimiento').value;
	var A_fecha = fecha.substr(6,4);
	var M_fecha = fecha.substr(3,2);
	var D_fecha = fecha.substr(0,2);
	
	var hoy = $('hoy').value;
	var A_hoy = hoy.substr(6,4);
	var M_hoy = hoy.substr(3,2);
	var D_hoy = hoy.substr(0,2);
	
	var comparar = (parseInt(A_fecha)+14);
	
//alert(comparar+' < '+parseInt(A_hoy)+' && '+parseInt(M_fecha)+' <= '+parseInt(M_hoy)+' && '+parseInt(D_fecha)+' <= '+parseInt(D_hoy));	
  if((parseInt(comparar) < parseInt(A_hoy)) ||  ((parseInt(comparar) == parseInt(A_hoy)) && (parseInt(M_fecha) <= parseInt(M_hoy)) && (parseInt(D_fecha) <= parseInt(D_hoy)))){
	  // ocultamos email padres
	$('fecha_nacimiento_li').addClassName('clear_both');
	$('email_padres_li').hide();
	$('texto_email_padres').hide();
  }else{
	  // mostramos email padresa	  
  	$('fecha_nacimiento_li').removeClassName('clear_both');
	$('email_padres_li').show();  
	$('texto_email_padres').show();
  }
 // return fecha1.getTime() - fecha2.getTime();

}

