function nuevoAjax(){ 
	var objeto=false; 

	if(window.XMLHttpRequest){
		objeto = new XMLHttpRequest(); 
	}else{ 
		try{
			objeto = new ActiveXObject("Microsoft.XMLHTTP"); 
		}
		catch (e){
			alert('El navegador utilizado no cumple los requisitos para ver esta página.');
		}
	}

	return objeto; 
}

function cargaContenido(ori,des){
	
		ajax=nuevoAjax();
		
		ajax.open("GET",ori, true);
		ajax.onreadystatechange=function() { 
			if ((ajax.readyState==4) && (ajax.status==200) ){ 		
				document.getElementById(des).innerHTML=ajax.responseText;
			} 
			if (ajax.readyState==1) { 
				document.getElementById(des).innerHTML = "cargando...";
			} 		
		}
		ajax.send(null);
}

function cargaContenido2(ori,valores, des){
	
		ajax=nuevoAjax();
		ajax.open("POST",ori, true);
		ajax.onreadystatechange=function() { 
			if ((ajax.readyState==4) && (ajax.status==200) ){ 
				document.getElementById(des).innerHTML=ajax.responseText;

			} 
			if (ajax.readyState==1) { 
				document.getElementById(des).innerHTML = "<div align='center'>Cargando...</div>";
			} 		
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(valores);
}

function cargaContenidoc(m,a)
{

		ajax=nuevoAjax();
		ajax.open("GET","calendario2.php?van=s&m="+m+"&a="+a, true);
		ajax.onreadystatechange=function() { 
			if ((ajax.readyState==4) && (ajax.status==200) )
			{ 
				document.getElementById("calen").innerHTML=ajax.responseText;
				
			
			} 
			if (ajax.readyState==1) { 
			  document.getElementById("calen").innerHTML="<DIV align='center'><br><br><br>Cargando...</DIV>"; 
			} 
		}
		ajax.send(null);
}


function eMsg(msg,id){
    var div = document.getElementById(id);
    div.style.color='red';
    div.style.fontSize="16";
    //remove old messages
    if(div.hasChildNodes()){
        div.removeChild(div.firstChild);
    }
    div.appendChild(document.createTextNode(msg));

}

function ventana (url){
	var newWindow;
	newWindow = window.open(url,'','height=570,width=900,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=yes')
}
function ventana2 (url){
	var newWindow;
	newWindow = window.open(url,'','height=120,width=260,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=yes')
}

function seleccionar(i,p,c,id,t,f,e){
	
	opener.document.form1.idc.value=id
	opener.document.form1.institucion.value=i
	opener.document.form1.prescriptor.value=p
	opener.document.form1.contacto.value=c
	opener.document.form1.telefono.value=t
	opener.document.form1.fax.value=f
	opener.document.form1.email.value=e
	close()
	
}


function seleccionar_fac(i,id,c,d,l,p,cp,pa){
	
	opener.document.form1.idc.value=id
	opener.document.form1.institucion.value=i
	opener.document.form1.cif.value=c
	opener.document.form1.direccionfacturacion.value=d
	opener.document.form1.localidad.value=l
	opener.document.form1.provincia.value=p
	opener.document.form1.cp.value=cp
	opener.document.form1.pais.value=pa
	close()
	
}
function seleccionar_fac2(id){
	var p=opener.document.getElementById('anio').value
	opener.document.location.href='reservas.php?idc='+id+'&ano='+p
	close()
	
}
function seleccionar_pro(n,id){
	
	opener.document.form1.idp.value=id
	opener.document.form1.proveedor.value=n
	close()
	
}


function cerrar(){
	close()	
}

function eliminar(){

	document.form1.validar.value='no'	
	document.form1.eliminar.value='si'
	
	document.form1.submit()
}

function eliminar3(){
	if (confirm('Se va a eliminar esta reserva')){
		document.form1.validar.value='no'	
		document.form1.eliminar.value='si'
		document.form1.submit()
	}
}

function nuevoArtista(){
	var n=document.getElementById('nombre').value
	var t=document.getElementById('tipo2').value
	
	var valores='guardar=si&nombre='+n+'&tipo='+t

cargaContenido2('nuevoArtista.php',valores,'artista')	
	
	
}

function nuevoArtista2(){
	var n=document.getElementById('nombre').value
	var t=document.getElementById('tipo2').value
	var ida=document.getElementById('ida').value
	
	var valores='nuevo=si&nombre='+n+'&tipo='+t+'&ida='+ida

cargaContenido2('editarArtista.php',valores,'artista')	
	
	
}

function editarArtista(){
	var n=document.getElementById('nombre').value
	var t=document.getElementById('tipo2').value
	var id=document.getElementById('id').value
	var ida=document.getElementById('ida').value
	
	var valores='guardar=si&nombre='+n+'&tipo='+t+'&id='+id+'&ida='+ida

cargaContenido2('editarArtista.php',valores,'artista')	
	
	
}

function eliminar2(p,t){
	if (confirm('Se va a eliminar '+t)){
		document.location.href=p+"&eliminar=si"
	}
}

function nuevoContacto(){
	var n=document.getElementById('nombre').value
	var t=document.getElementById('telefono2').value
	var e=document.getElementById('email').value
	var p=document.getElementById('p').value
	
	var valores='guardar=si&nombre='+n+'&telefono2='+t+'&email='+e+'&p='+p

	if(p==1){
		cargaContenido2('nuevoContacto.php',valores,'pres')	
	}else{
		cargaContenido2('nuevoContacto.php',valores,'con')	
	}
	
}

function nuevoContacto2(){
	var n=document.getElementById('nombre').value
	var t=document.getElementById('telefono2').value
	var e=document.getElementById('email').value
	var p=document.getElementById('p').value
	var idc=document.getElementById('idc').value
	
	var valores='nuevo=si&nombre='+n+'&telefono2='+t+'&email='+e+'&p='+p+'&idc='+idc

	if(p==1){
		cargaContenido2('editarContacto.php',valores,'pres')	
	}else{
		cargaContenido2('editarContacto.php',valores,'con')	
	}
	
}


function ftotal(){
	
	var c=document.getElementById('cantidad').value	
	var p=document.getElementById('precio').value
	var i=document.getElementById('iva').value
	
	var t=0
	
	t=(c*p)+(c*p*i/100)
	
	document.getElementById('total').value=Math.round(t*100)/100
}

function ftotal2(){
	
	var c=document.getElementById('cantidad').value	
	var p=document.getElementById('precio').value
	var i=document.getElementById('iva').value
	
	var t=0
	
	t=(c*p)+(c*p*i/100)
	
	document.getElementById('total').value=Math.round(t*100)/100
}
function nuevoConcepto(){
	
	var co=document.getElementById('concepto').value
	var c=document.getElementById('cantidad').value	
	var p=document.getElementById('precio').value
	var i=document.getElementById('iva').value
	var t=document.getElementById('total').value
	var idf=document.getElementById('idf').value
	var valores='guardar=si&concepto='+co+'&cantidad='+c+'&precio='+p+'&iva='+i+'&total='+t+'&idf='+idf


	cargaContenido2('nuevoConcepto.php',valores,'conc')	

	
}


function nuevoConcepto5(){
	
	var co=document.getElementById('concepto').value
	var c=document.getElementById('cantidad').value	
	var p=document.getElementById('precio').value
	var i=document.getElementById('iva').value
	var t=document.getElementById('total').value

	var valores='guardar=si&concepto='+co+'&cantidad='+c+'&precio='+p+'&iva='+i+'&total='+t


	cargaContenido2('nuevoConcepto5.php',valores,'conc')	

	
}

function nuevoConcepto2(){
	
	var co=document.getElementById('concepto').value
	var c=document.getElementById('cantidad').value	
	var p=document.getElementById('precio').value
	var i=document.getElementById('iva').value
	var t=document.getElementById('total').value
	var idf=document.getElementById('idf').value
	
	var valores='guardar=si&concepto='+co+'&cantidad='+c+'&precio='+p+'&iva='+i+'&total='+t+'&idf='+idf


	cargaContenido2('verConcepto2.php',valores,'conc')	

	
}

function nuevoConcepto3(){
	
	var co=document.getElementById('concepto').value
	var c=document.getElementById('cantidad').value	
	var p=document.getElementById('precio').value
	var i=document.getElementById('iva').value
	var t=document.getElementById('total').value
	var idf=document.getElementById('idf').value
	var id=document.getElementById('idco').value
	var valores='guardar=si&concepto='+co+'&cantidad='+c+'&precio='+p+'&iva='+i+'&total='+t+'&idf='+idf+'&id='+id

	cargaContenido2('verConcepto3.php',valores,'conc')	

	
}
function nuevoConcepto4(){
	
	var co=document.getElementById('concepto').value
	var c=document.getElementById('cantidad').value	
	var p=document.getElementById('precio').value
	var i=document.getElementById('iva').value
	var t=document.getElementById('total').value
	var idf=document.getElementById('idf').value
	var id=document.getElementById('idco').value
	var valores='guardar=si&concepto='+co+'&cantidad='+c+'&precio='+p+'&iva='+i+'&total='+t+'&idf='+idf+'&id='+id

	cargaContenido2('verConcepto4.php',valores,'conc')	

	
}
function editarContacto(){
	var n=document.getElementById('nombre').value
	var t=document.getElementById('telefono2').value
	var e=document.getElementById('email').value
	var p=document.getElementById('p').value
	var id=document.getElementById('id2').value
	var idc=document.getElementById('idc').value
	
	var valores='guardar=si&nombre='+n+'&telefono2='+t+'&email='+e+'&p='+p+'&id='+id+'&idc='+idc

	if(p==1){
		cargaContenido2('editarContacto.php',valores,'pres')	
	}else{
		cargaContenido2('editarContacto.php',valores,'con')	
	}
	
}


function listarContactos(id){
	

	var p2='editarContacto.php?id='+id+'&p=0'
	cargaContenido(p2,'con')

	
}

function listarPrescriptores(id){
	
	var p='editarContacto.php?id='+id+'&p=1'
	cargaContenido(p,'pres')
	
}



      function compare_dates(fecha, fecha2)
      {
        var xMonth=fecha.substring(3, 5);
        var xDay=fecha.substring(0, 2);
        var xYear=fecha.substring(6,10);
        var yMonth=fecha2.substring(3, 5);
        var yDay=fecha2.substring(0, 2);
        var yYear=fecha2.substring(6,10);
        if (xYear> yYear)
        {
            return(true)
        }
        else
        {
          if (xYear == yYear)
          { 
            if (xMonth> yMonth)
            {
                return(true)
            }
            else
            { 
              if (xMonth == yMonth)
              {
                if (xDay> yDay)
                  return(true);
                else
                  return(false);
              }
              else
                return(false);
            }
          }
          else
            return(false);
        }
    }


function valida_reserva(){
	var f1=document.getElementById('fecha').value
	var f2=document.getElementById('hoy').value
	var bien=false

	if(compare_dates(f1,f2)){
		bien=true
		eMsg('','error1')
	}else{
		bien=false	
		eMsg('No puede seleccionar una dia anterior a hoy','error1')
	}
	
	if(bien){
		document.form1.submit()	
	}
}
function valida_reserva2(){
	var f1=document.getElementById('fecha').value
	var f2=document.getElementById('hoy').value
	
	var c=document.getElementById('contacto').value
	var m=document.getElementById('email').value
	var t=document.getElementById('telefono').value
	var h=document.getElementById('hora').value
	var p=document.getElementById('personas').value
	var v=document.getElementById('actividad').options[document.getElementById('actividad').selectedIndex].value
	
	var bien=true


	if(c!=''){
		eMsg('','error2')		
	}else{
		bien=false	
		eMsg('Debes introducir el nombre de la Persona de Contacto','error2')
		return		
	}

	if(isEmail (m)){
		eMsg('','error3')		
	}else{
		bien=false	
		eMsg('Debes introducir un email','error3')
		return		
	}

	if(t!=''){
		eMsg('','error4')		
	}else{
		bien=false	
		eMsg('Debes introducir un telefono','error4')
		return		
	}

	if(compare_dates(f1,f2)){
		eMsg('','error1')
	}else{
		bien=false	
		eMsg('No puede seleccionar una dia anterior a hoy','error1')
		return
	}
	
	if(h!=''){
		eMsg('','error1')		
	}else{
		bien=false	
		eMsg('Debes introducir la hora de la reserva','error1')
		return		
	}	

	if(p!=''){
		eMsg('','error5')		
	}else{
		bien=false	
		eMsg('Debes introducir el numero de personas','error5')
		return		
	}

	if(v>0){
		eMsg('','error5')		
	}else{
		bien=false	
		eMsg('Debes seleccionar el tipo de Actividad/Visita','error5')
		return		
	}
	
	if(bien){
		document.form1.submit()	
	}
}

function nuevoPro(){
	var p=document.getElementById('producto').value
	var c=document.getElementById('cantidad').value

	
	var valores='guardar=si&producto='+p+'&cantidad='+c

cargaContenido2('nuevoPro2.php',valores,'ven')	
	
	
}

function buscaAnio(){
	var p=document.getElementById('anio').value
	document.location.href='reservas.php?ano='+p
}

function codigo(){
	
		var a=document.getElementsByName("a")
		var cod=document.getElementById('cod')
		var c=""
		
		for(i=0;i<a.length;i++){
			if(a[i].checked==true){
				c=c+"_"+a[i].value
			}
		}
		
		cod.value=c
	
}

function selec(){
	
	var cod=document.getElementById('cod').value
	var cod2=opener.document.getElementById('cod')

	cod2.value=cod
	
	close()
		
}

function movil(){
	
	var f1=document.getElementById('fecha1').value
	var f2=document.getElementById('fecha2').value
	var bien=false
	
	if(f1!=''){
		bien=true
		eMsg('','error1')
	}else{
		eMsg('Debe seleccionar una fecha','error1')
	}
	if(f2!=''){
		bien=true
		eMsg('','error2')
	}else{
		eMsg('Debe seleccionar una fecha','error2')
	}	
	
	if(bien){
		document.form1.submit()	
	}
	
}


 function fcaja(){
	 
	var c=document.getElementById('entrada').value 
	
	if(c==0){
		document.location.href='caja.php'	
	}else{
		document.location.href='caja2.php'	
	}
 }
 
 
 function fvideo(){

	var t=document.getElementById('titulo').value
	var d=document.getElementById('descripcion').value
	var p=document.getElementById('categoria').value


	var valores="titulo="+t+"&descripcion="+d+"&categoria="+p
	
	cargaContenido2('video2.php',valores,'vi')

}
