var j       = jQuery.noConflict();
defaultStep=5
step=defaultStep

var URx = 'http://www.fundesarte.org/new/';
loadProv = new ajax();
loadGal = new ajax();
loadIMG = new ajax();
function showhide(var1) {
    if (document.getElementById(var1).style.display == 'inline')
        document.getElementById(var1).style.display = 'none';
    else
        document.getElementById(var1).style.display = 'inline';
};

var min=8;
var max=18;
function resetFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      p[i].style.fontSize = "14px"
      p[i].style.lineHeight = "22px"
   }
}

function increaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
         var sx = parseInt(p[i].style.lineHeight.replace("px",""));
      } else {
         var s = 14;
         var sx = 22;
      }
      if(s!=max) {
         s += 4;
         sx += 6;
      }
      p[i].style.fontSize = s+"px"
      p[i].style.lineHeight = sx+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
         var sx = parseInt(p[i].style.lineHeight.replace("px",""));
      } else {
         var sx = 14;
         var sx = 22;
      }
      if(s!=min) {
         s -= 4;
         sx -= 6;
      }
      p[i].style.fontSize = s+"px"
      p[i].style.lineHeight = sx+"px"
   }
}

function getNumVar() {
    var str= window.location.toString();
    uri2 = str.split('#')
    uri2 = uri2[1];
    if (uri2 == undefined)
        uri2 = 'ESPANA';
    loadProv.get(URx+'loadProv.php?sel=1&prov='+uri2,'provDetails');
}

function changeProv(prov) {
    location.href='#/'+prov;
    loadProv.get(URx+'loadProv.php?sel=1&prov='+prov,'provDetails');
};

function scrollDivLeft(id){
document.getElementById(id).scrollLeft-=step
timerLeft=setTimeout("scrollDivLeft('"+id+"')",10)
}

function scrollDivRight(id){
document.getElementById(id).scrollLeft+=step
timerRight=setTimeout("scrollDivRight('"+id+"')",10)
}

function showClose() {
//    document.getElementById('showclose').style.display = 'inline';
};

function hideClose() {
    document.getElementById('showclose').style.display = 'none';
};

function showOver(url, win, wi, he) {
    document.getElementById(win).style.display = 'block';
    document.getElementById(win+'table').style.width = wi+'px';
    document.getElementById(win+'table').style.height = he+'px';
    document.getElementById(win+'2').style.display = 'block';
    loadGal.get(url, win+'2');
};

function closeOver(win, url1, win2) {
    document.getElementById(win).style.display = 'none';
    document.getElementById(win+'2').style.display = 'none';
    loadGal.clear(win+'2');
    if (url1 && win2)
        loadGal.get(url1,win2);
};

function showRecaptcha() {
  Recaptcha.create("6LcHhAgAAAAAALgWY3Y733PX_Vrugm65sG2qiqtw", 'div_captcha', {
        theme: 'white',
        tabindex: 0,
        callback: Recaptcha.focus_response_field
  });
}

function saveSuscribe() {
    if (!document.getElementById('bol_email').value) {
        alert('Debe completar el email para suscribirse');
        return false;
    } else
        return true;
};

function showCal(nc) {
    loadProv.get(URx+'loadCal.php?nc='+nc,'wid_cal');
};

function checkFiles(ftype, mid) {
    if (ftype == 234213234) {
    var var1 = document.getElementById('tfiles'+mid).value;
  	var a = var1.split(",");

    var nofile = '';
  	for (var i = 0; i < a.length; i++) {
          var x = document.getElementById(a[i]).value;
          var stlen = (x.length-3);
          var ext = x.substr(stlen,3);
          if (stlen > 1) {
              if (ext == 'doc' || ext == 'DOC' || ext == 'ocx' || ext == 'OCX' || ext == 'pdf' || ext == 'PDF') {
                var ok = 1;
              } else {
                  alert('Solo se permiten archivos DOC y PDF');

              };
          } else {
              nofile = (nofile*1)+1;
          };
    };
    if (nofile == a.length) {
        alert('Debe ingresar al menos un archivo para enviar');
    };
    if (ok == 1) {
        document.getElementById('form_modalidad'+mid).submit();
        document.getElementById('modal'+mid).style.display='none';
		document.getElementById('files_send').innerHTML = 'Enviando...';
    };
    } else {
        document.getElementById('form_modalidad'+mid).submit();
        document.getElementById('modal'+mid).style.display='none';
		document.getElementById('files_send').innerHTML = 'Enviando...';

    };
};

function checkImages() {
    var nofile = '';
  	for (var i = 1; i < 6; i++) {
          var x = document.getElementById('imagen'+[i]).value;
          var stlen = (x.length-3);
          var ext = x.substr(stlen,3);
          if (stlen > 1) {
              if (ext == 'jpg' || ext == 'JPG' || ext == 'peg' || ext == 'PEG') {
                var ok = 1;
              } else {
                  alert('Solo se permiten archivos JPG');

              };
          } else {
              nofile = (nofile*1)+1;
          };
    };
    if (nofile == 5) {
        alert('Debe ingresar al menos un archivo para enviar');
    };
    if (ok == 1) {
        document.getElementById('form_imagenes').submit();
        //document.getElementById('imgs').innerHTML = 'Enviando...';
		$('imgs').hide();
		$('img_message').innerHTML = 'Enviando ...';
    };

};

function checkVideo() {
    var x = document.getElementById('video').value;
    var stlen = (x.length-3);
    var ext = x.substr(stlen,3);
    if (stlen > 1) {
        if (ext == 'avi' || ext == 'AVI' || ext == 'peg' || ext == 'PEG' || ext == 'mpg' || ext == 'MPG' || ext == 'zip' || ext == 'ZIP') {
          var ok = 1;
        } else {
            alert('Solo se permiten archivos AVI o MPG');
        };
    } else {
        alert('Debe ingresar al menos un archivo para enviar');
    };
    if (ok == 1) {
        document.getElementById('form_video').submit();
        document.getElementById('vid_message').innerHTML = 'Enviando...';
    };

};

function loadUserDocs(idmodal) {
    var contenido = j("#moda"+idmodal);
    var data = new Object();
    contenido.load('includes/loadDocs.php?m='+idmodal,data,function(){ });
};


function removeFile(id, user_id){

 if(confirm("Realmente desea eliminar la imagen ?"))
 {
	var id_media = id;
	var url = "removeFiles.php";
	var params = 'id_media='+id_media;
	
	new Ajax.Request(url,{
		 method : 'post',
	 	 parameters : params,
		 asynchronous: 	true,

		onComplete : function (r) {
			var s = r.responseText
			updateFiles(user_id);
			alert(s);
		}
	});

 }
 
}


function removeDoc(id, user_id){

 if(confirm("Realmente desea eliminar el documento ?"))
 {
	var id_media = id;
	var url = "removeDoc.php";
	var params = 'id_media='+id_media;
	
	new Ajax.Request(url,{
		 method : 'post',
	 	 parameters : params,
		 asynchronous: 	true,

		onComplete : function (r) {
			var s = r.responseText
			updateDoc(user_id);
			alert(s);
		}
	});

 }
 
}


function removeVideo(id, user_id){

 if(confirm("Realmente desea eliminar el video ?"))
 {
	var id_media = id;
	var url = "removeVideo.php";
	var params = 'id_media='+id_media;
	
	new Ajax.Request(url,{
		 method : 'post',
	 	 parameters : params,
		 asynchronous: 	true,

		onComplete : function (r) {
			var s = r.responseText
			updateVideo(user_id);
			alert(s);
		}
	});

 }
 
}



function updateFiles(user_id)
{
    
	var url = 'updateFiles.php';
	var params = 'user_id='+user_id;
    var content = $("content_images");
	var arexc   = new Ajax.Updater( content, url,{ method: 'post', parameters : params, asynchronous: 	true});
}


function updateVideo(user_id)
{
   
	var url = 'updateVideo.php';
	var params = 'user_id='+user_id;
    var content = $("content_video");
	var arexc   = new Ajax.Updater( content, url,{ method: 'post', parameters : params, asynchronous: 	true});
}


function updateDoc(user_id)
{
    
	var url = 'updateDoc.php';
	var params = 'user_id='+user_id;
    var content = $("content_documents");
	var arexc   = new Ajax.Updater( content, url,{ method: 'post', parameters : params, asynchronous: 	true});
}



function showDownloadFiles(moda)
{

	var content = $('modal'+moda);
	
	if(content.style.display=='block')
	{
		content.style.display='none';
	}
	else
	{
		content.style.display='block';	
	}
}



function showUploadVideos(){

$('vid').show();
}

/*
Entero	^(?:\+|-)?\d+$
Correo electrónico

/[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/
*/

function validarEmail(valor) {
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		return 1;
	} 
	else {
		return 0;
	}
}

function validarEntero(valor){

	if (!/^(?:\+|-)?\d+$/.test(valor)){
		return 1;
	}else{
		return 0;
	} 
}

function validarClave(valor){

	if (!/^([a-zA-Z0-9]{8,10})$/.test(valor)){
		return 1;
	}else{
		return 0;
	} 
}



function validation(){


	var clave1  = document.getElementById('clave').value;
	var clave2  = document.getElementById('clave2').value;

	var empresa = $('empresa_candidata');
	var actividad = $('actividad');
	var cif = $('cif');
	var fecha = $('fecha_empresa');
	var facturacion = $('facturacion');
	var trabajadoresm = $('trabajadoresm');
	var trabajadoresh = $('trabajadoresh');
	var nombre = $('nombre');
	var apellido = $('apellido');
	var email = $('email');
	var clave = $('clave');
	var clave2 = $('clave2');
	var direccion = $('direccion');
	var localidad = $('localidad');
	var provincia = $('provincia');
	var codigopostal = $('codigopostal');
	var genero = $('genero');
	var entidad_presentadora = $('entidad_presentadora');
	var categoria = $('id_cat');

	var telefono = $('telefono');
	var fax = $('fax');



	var c1 = $('c1');
	var c2 = $('c2');

	var required = 'campo obligatorio';



	if(empresa.value=="" || empresa.value==required)
	{
		empresa.className="field_required";
		empresa.value=required;
		return false;
	}


	if(actividad.value=="" || actividad.value==required)
	{
		actividad.className="field_required";
		actividad.value=required;
		return false;
	}

	if(cif.value=="" || cif.value==required)
	{
		cif.className="field_required";
		cif.value=required;
		return false;
	}

	if(fecha.value=="" || fecha.value==required)
	{
		fecha.className="field_required";
		fecha.value=required;
		return false;
	}


	if(facturacion.value=="" || facturacion.value==required || facturacion.value=='Introduzca un valor num\xe9rico')
	{
		facturacion.className="field_required";
		facturacion.value=required;
		return false;
	}else{

		error = validarEntero(facturacion.value);
		if(error=='1'){
			facturacion.className="field_required";
			facturacion.value='Introduzca un valor num\xe9rico';
			return false;
		}
	}

	if(trabajadoresm.value=="" || trabajadoresm.value==required)
	{
		trabajadoresm.className="field_required";
		trabajadoresm.value=required;
		return false;
	}else{
		error = validarEntero(trabajadoresm.value);
		if(error=='1'){
			trabajadoresm.className="field_required";
			trabajadoresm.value='Introduzca un valor num\xe9rico';
			return false;
		}
	}

	if(trabajadoresh.value=="" || trabajadoresh.value==required)
	{
		trabajadoresh.className="field_required";
		trabajadoresh.value=required;
		return false;
	}else{
		error = validarEntero(trabajadoresh.value);
		if(error=='1'){
			trabajadoresh.className="field_required";
			trabajadoresh.value='Introduzca un valor num\xe9rico';
			return false;
		}
	}

	if(nombre.value=="" || nombre.value==required)
	{
		nombre.className="field_required";
		nombre.value=required;
		return false;
	}

	if(apellido.value=="" || apellido.value==required)
	{
		apellido.className="field_required";
		apellido.value=required;
		return false;
	}

	
	if(email.value=="" || email.value==required || email.value=="formato incorrecto")
	{
		email.className="field_required";
		email.value=required;
		return false;
	}
	else
	{
		error = validarEmail(email.value);
		
		if(error==1){
			email.className='field_required';
			email.value='formato incorrecto.'
			return false;
		}
	}

	if(clave.value=="")
	{
		clave.className="field_required";
		c1.innerHTML='entre 8 y 10 caracteres, no utilizar caracteres especiales';
		return false;
	}else{
	
		error = validarClave(clave.value);
		if(error==1){
			clave.className="field_required";
			c1.className="field_required";
			c1.innerHTML='entre 8 y 10 caracteres, no utilizar caracteres especiales';
			
			return false;
		}
	}

	
	if(clave2.value=="")
	{
		clave2.className="field_required";
		c2.innerHTML='entre 8 y 10 caracteres, no utilizar caracteres especiales';
		return false;
	}else{

		error = validarClave(clave2.value);
		if(error==1){
			clave2.className="field_required";
			c2.className="field_required";
			c2.innerHTML='entre 8 y 10 caracteres, no utilizar caracteres especiales';

			return false;
		}
	}

	
	if (clave.value != clave2.value) {
        alert('La clave y la confirmación no coinciden');
        return false
    }

	
	if(direccion.value=="" || direccion.value==required)
	{
		direccion.className="field_required";
		direccion.value=required;
		return false;
	}
	
	if(localidad.value=="" || localidad.value==required)
	{
		localidad.className="field_required";
		localidad.value=required;
		return false;
	}
	
	if(provincia.value=="" || provincia.value==required)
	{
		provincia.className="field_required";
		provincia.value=required;
		return false;
	}
	
	if(codigopostal.value=="" || codigopostal.value==required || codigopostal.value=='Introduzca un valor num\xe9rico' )
	{
		codigopostal.className="field_required";
		codigopostal.value=required;
		return false;
	}else{
		error = validarEntero(codigopostal.value);
		if(error=='1'){
			codigopostal.className="field_required";
			codigopostal.value='Introduzca un valor num\xe9rico';
			return false;
		}
	}

	if(telefono.value!="")
	{
		error = validarEntero(telefono.value);
		if(error==1)
		{
		
			telefono.className="field_required";
			telefono.value="Introduzca un valor num\xe9rico";
			return false;
		}
	}
	
	if(fax.value!="")
	{
		error = validarEntero(fax.value);
		if(error==1)
		{
		
			fax.className="field_required";
			fax.value="Introduzca un valor num\xe9rico";
			return false;
		}
	}
	
	
	if(entidad_presentadora.value=="" || entidad_presentadora.value==required)
	{
		entidad_presentadora.className="field_required";
		entidad_presentadora.value=required;
		return false;
	}

	if(categoria.value=="" || categoria.value==required)
	{
		categoria.className="field_required";
		categoria.value=required;
		return false;
	}


}







function validation2(){


	var clave1  = document.getElementById('clave').value;
	var clave2  = document.getElementById('clave2').value;

	var empresa = $('empresa_candidata');
	var actividad = $('actividad');
	var cif = $('cif');
	var fecha = $('fecha_empresa');
	var facturacion = $('facturacion');
	var trabajadoresm = $('trabajadoresm');
	var trabajadoresh = $('trabajadoresh');
	var nombre = $('nombre');
	var apellido = $('apellido');
	var email = $('email');
	var clave = $('clave');
	var clave2 = $('clave2');
	var clave1 = $('clave1');


	var direccion = $('direccion');
	var localidad = $('localidad');
	var provincia = $('provincia');
	var codigopostal = $('codigopostal');
	var genero = $('genero');
	var entidad_presentadora = $('entidad_presentadora');
	var categoria = $('id_cat');

	var telefono = $('telefono');
	var fax = $('fax');



	var c1 = $('c1');
	var c2 = $('c2');
	var c3 = $('c3');

	var required = 'campo obligatorio';



	if(empresa.value=="" || empresa.value==required)
	{
		empresa.className="field_required";
		empresa.value=required;
		return false;
	}


	if(actividad.value=="" || actividad.value==required)
	{
		actividad.className="field_required";
		actividad.value=required;
		return false;
	}

	if(cif.value=="" || cif.value==required)
	{
		cif.className="field_required";
		cif.value=required;
		return false;
	}

	if(fecha.value=="" || fecha.value==required)
	{
		fecha.className="field_required";
		fecha.value=required;
		return false;
	}


	if(facturacion.value=="" || facturacion.value==required || facturacion.value=='Introduzca un valor num\xe9rico')
	{
		facturacion.className="field_required";
		facturacion.value=required;
		return false;
	}else{

		error = validarEntero(facturacion.value);
		if(error=='1'){
			facturacion.className="field_required";
			facturacion.value='Introduzca un valor num\xe9rico';
			return false;
		}
	}

	if(trabajadoresm.value=="" || trabajadoresm.value==required)
	{
		trabajadoresm.className="field_required";
		trabajadoresm.value=required;
		return false;
	}else{
		error = validarEntero(trabajadoresm.value);
		if(error=='1'){
			trabajadoresm.className="field_required";
			trabajadoresm.value='Introduzca un valor num\xe9rico';
			return false;
		}
	}

	if(trabajadoresh.value=="" || trabajadoresh.value==required)
	{
		trabajadoresh.className="field_required";
		trabajadoresh.value=required;
		return false;
	}else{
		error = validarEntero(trabajadoresh.value);
		if(error=='1'){
			trabajadoresh.className="field_required";
			trabajadoresh.value='Introduzca un valor num\xe9rico';
			return false;
		}
	}
	if(nombre.value=="" || nombre.value==required)
	{
		nombre.className="field_required";
		nombre.value=required;
		return false;
	}
	
	if(apellido.value=="" || apellido.value==required)
	{
		apellido.className="field_required";
		apellido.value=required;
		return false;
	}

	
	if(email.value=="" || email.value==required || email.value=="formato incorrecto")
	{
		email.className="field_required";
		email.value=required;
		return false;
	}
	else
	{
		error = validarEmail(email.value);
		
		if(error==1){
			email.className='field_required';
			email.value='formato incorrecto.'
			return false;
		}
	}


	
	if(direccion.value=="" || direccion.value==required)
	{
		direccion.className="field_required";
		direccion.value=required;
		return false;
	}
	
	if(localidad.value=="" || localidad.value==required)
	{
		localidad.className="field_required";
		localidad.value=required;
		return false;
	}
	
	if(provincia.value=="" || provincia.value==required)
	{
		provincia.className="field_required";
		provincia.value=required;
		return false;
	}
	
	if(codigopostal.value=="" || codigopostal.value==required || codigopostal.value=='Introduzca un valor num\xe9rico' )
	{
		codigopostal.className="field_required";
		codigopostal.value=required;
		return false;
	}else{
		error = validarEntero(codigopostal.value);
		if(error=='1'){
			codigopostal.className="field_required";
			codigopostal.value='Introduzca un valor num\xe9rico';
			return false;
		}
	}

	if(telefono.value!="")
	{
		error = validarEntero(telefono.value);
		if(error==1)
		{
		
			telefono.className="field_required";
			telefono.value="Introduzca un valor num\xe9rico";
			return false;
		}
	}
	
	if(fax.value!="")
	{
		error = validarEntero(fax.value);
		if(error==1)
		{
		
			fax.className="field_required";
			fax.value="Introduzca un valor num\xe9rico";
			return false;
		}
	}

	
	if(genero.value=="" || genero.value==required)
	{
		genero.className="field_required";
		genero.value=required;
		return false;
	}
	
	if(entidad_presentadora.value=="" || entidad_presentadora.value==required)
	{
		entidad_presentadora.className="field_required";
		entidad_presentadora.value=required;
		return false;
	}

	if(categoria.value=="" || categoria.value==required)
	{
		categoria.className="field_required";
		categoria.value=required;
		return false;
	}


}
	

