IE = (navigator.appVersion).indexOf("MSIE") != -1; 
NS = (navigator.appName).indexOf("Netscape") != -1; 

// js form validation stuff
var confirmMsg  = '¿Realmente desea ';


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];}
}

function on(td,color,estado)
{
	td.style.cursor='hand';
	td.style.background=color;
	td.title=estado ;
	window.status=estado ;
}


function off(td,color,estado)
{
	td.style.cursor='default';
	td.style.background=color;
	window.status=estado ;
}

function BuscarArtistas(form) {
if (form.nombre.value.length<3 && form.nombre.value.length>0){ alert ("Debes rellenar el campo 'nombre'. Puede ser una parte del nombre, mínimo 3 caracteres"); return ; }
if (form.nombre.value == "sin especificar nombre"  & form.categoria.value == "0" ){ alert ("Debes indicar al menos un criterio de búsqueda 'nombre' o 'categoría'"); return ; }
	{ form.submit();
    }
}

function TrabajaConNos(form,id_div,url_get) {
	if (form.nombre.value == ""){ alert ("Debes rellenar el campo 'nombre'."); return ; }
	if (form.email.value == ""  ||  form.email.value.indexOf('@', 0) == -1){ alert ("Debes rellenar el campo 'e-mail' con una dirección de correo electrónico válida"); return ; }
	if (form.privacidad.checked != true){ alert ("Debes leer y aceptar nuestra 'política de privacidad'."); return ; }

  	{ 
		//form.submit();
		var url_post="nombre="+form.nombre.value+"&email="+form.email.value;
		gen_item(id_div,url_get,url_post);
    }
}
	function TrabajaConNosClave(form,id_div,url_get,redirect_parm) {
if (form.email.value == ""  ||  form.email.value.indexOf('@', 0) == -1){ alert ("Debes rellenar el campo 'e-mail' con la dirección de correo que tenemos almacenada"); return ; }
if (form.clave.value == ""){ alert ("Debes rellenar el campo 'clave' con el código que te hemos enviado por e-mail."); return ; }

  	{ //form.submit();
		var url_post="email="+form.email.value+"&password="+form.clave.value;
		/*if (redirect_parm==0)
			gen_item(id_div,url_get,url_post);
		else if (redirect_parm==1)
			gen_item_redirect(id_div,url_get,url_post);*/
		
		makePOSTRequest(id_div,'inc/gen_ajax.php'+url_get, url_post);
    }
}
function TrabajaConNosClaveOlvidada(form,id_div,url_get) {
if (form.email.value == ""  ||  form.email.value.indexOf('@', 0) == -1){ alert ("Debes rellenar el campo 'e-mail' con la dirección de correo que tenemos almacenada"); return ; }

  	{
		//form.submit();
		var url_post="email="+form.email.value;
		gen_item(id_div,url_get,url_post);
    }
}
function form_contacto_artista(form,id_div,url_get,redirect_parm) {
	
	if (form.nombre.value == "" ){ alert ("Debes rellenar el campo 'nombre de contacto'"); 	return ; }
	if (form.artista.value == ""){ alert ("Debes rellenar el campo 'nombre artístico'"); return ; }
  	{ //form.submit();
		var url_post="nombre="+escape(form.nombre.value)+"&email="+escape(form.email.value)+"&direccion="+escape(form.direccion.value)+"&ciudad="+escape(form.ciudad.value)+"&provincia="+escape(form.provincia.value)+"&pais="+escape(form.pais.value)+"&tel="+escape(form.tel.value)+"&fax="+escape(form.fax.value)+"&comentarios="+escape(form.comentarios.value)+"&artista="+escape(form.artista.value)+"&descrip="+escape(form.descrip.value)+"&categoria="+escape(form.categoria.value);
		//alert (url_post);
		/*if (redirect_parm==0)
			gen_item(id_div,url_get,url_post);
		else if (redirect_parm==1)
			gen_item_redirect(id_div,url_get,url_post);*/
		
		makePOSTRequest(id_div,'inc/gen_ajax.php'+url_get, url_post);
		
		//alert ();
    }
}
/*function guardarForm (id_div,url_get)
{
	makePOSTRequest(id_div,'inc/gen_ajax.php'+url_get, url_post);
	form_contacto_artista(this.form,'foto','?form=8')
}*/

function detalle(wintype){
picture=window.open(wintype,"picture","toolbar=0,directories=0,status=0,scrollbars=1,menubar=0,width=400,height=470,top=10,left=75"); 
  picture.window.focus();
}

function not(wintype){
self.location.href=wintype; 
}

function BorrarNombreArtistas()
{
	if (document.buscar.nombre.value == "sin especificar nombre")
		document.buscar.nombre.value = "";
}

function Fecha()
{
	date = new Date();
	var day_of_week_number = date.getDay();
	var day_of_month = date.getDate();
	var month_number = date.getMonth();
	var year = date.getYear();
	if (year<200) year+=1900;
	var day_of_week = '';
	var month = '' 

	var message = '';

	if(month_number == 0){month = 'enero';}
	if(month_number == 1){month = 'febrero';}
	if(month_number == 2){month = 'marzo';}
	if(month_number == 3){month = 'abril';}
	if(month_number == 4){month = 'mayo';}
	if(month_number == 5){month = 'junio';}
	if(month_number == 6){month = 'julio';}
	if(month_number == 7){month = 'agosto';}
	if(month_number == 8){month = 'septiembre';}
	if(month_number == 9){month = 'octubre';}
	if(month_number == 10){month = 'noviembre';}
	if(month_number == 11){month ='diciembre';}
	
	if(day_of_week_number == 0){day_of_week = 'Domingo';}
	if(day_of_week_number == 1){day_of_week = 'Lunes';}
	if(day_of_week_number == 2){day_of_week = 'Martes';}
	if(day_of_week_number == 3){day_of_week = 'Miercoles';}
	if(day_of_week_number == 4){day_of_week = 'Jueves';}
	if(day_of_week_number == 5){day_of_week = 'Viernes';}
	if(day_of_week_number == 6){day_of_week = 'Sábado';} 

	var date_to_show=day_of_week+', '+day_of_month+' de '+month+' de '+year;
	document.write(date_to_show);
}

function redirect_page(url)
{
	alert ("emtraaa");
	window.location=url;
}
function abrir_img(wintype){
picture=window.open(wintype,"picture","toolbar=no,directories=no,status=no,scrollbars=1,menubar=no,width=590,height=450,top=20,left=50"); 
  picture.window.focus();
}
function borrar_img(form,images) {
	var all_images=images.split(",");
	var borrar=0;
	for(var i=0; i<all_images.length; i++)
	{
		if (eval('form.img_delete'+all_images[i]).checked==true)
		{
			borrar=1;
			break;
		}
	}
	
	if (borrar == 1)
	{
		if (window.confirm('¿Estas seguro de querer borrar todas las imágenes seleccionadas?'))
		  { 
		  	form.borrar_imagen.value=1;
			form.submit();
			//alert (images);
			}
	}
	else
	{
		alert ("Debe seleccionar al menos una imagen para borrar");	
	}
}
function back_reg_form()
{
	window.location='index.php?mc=8';
}
function borrarlista(form)
{
	form.nombre.value='';	
	form.email.value='';	
	form.direccion.value='';	
	form.ciudad.value='';	
	form.provincia.value='';	
	form.pais.value='';	
	form.tel.value='';	
	form.fax.value='';	
	form.comentarios.value='';	
	form.artista.value='';	
	form.descrip.value='';	
	form.categoria.value=0;	
}
function validaFoto(form)
{
	if (form.file.value=='')
	{
		alert ("Debe rellenar el campo 'imagen'");
		return false;
	}
	else
	{
		var exten=form.file.value.substring((form.file.value.length-3),form.file.value.length);
		exten=exten.toLowerCase();
		
		if (exten=='jpg' || exten=='gif' || exten=='png')
			return true;
		else
		{
			alert ("El tipo de archivo no es válido");
			return false;
		}
		
	}
}
function sendMail(idartista,form,idDiv)
{	
	if (form.published.checked==false)
	{
		if (confirm ("¿Esta seguro de desactivar a este artista de la base de datos?"))
			form.published.checked==false;
		else
			form.published.checked==true;		
	}
	else
	{
		if (confirm("¿Esta seguro de activar al artista seleccionado? Se enviará un mail al artista."))
		{
			form.published.checked=true;
			var url_get="?cod="+idartista+"&form=9";
			makePOSTRequest(idDiv,'../../../inc/gen_ajax.php'+url_get, '');						
		}
		else
		{
			form.published.checked=false;
		}
	}
}
function checkContact(form,url_get,idDiv) {
if (form.nombre.value == ""){ alert ("Debes rellenar el campo 'nombre'."); return ; }
if (form.email.value == ""  ||  form.email.value.indexOf('@', 0) == -1){ alert ("Debes rellenar el campo 'e-mail' con una dirección de correo electrónico válida"); return ; }
if (form.comentarios.value == ""){ alert ("Debes rellenar el campo 'comentario'."); return ; }

  { //form.enviar.submit();

	var url_post="nombre="+form.nombre.value+"&email="+form.email.value+"&artista="+form.artista.value+"&comentarios="+form.comentarios.value+"&aux=1";
	
  	makePOSTRequest(idDiv,'inc/gen_ajax.php'+url_get, url_post);						
    }
}

function changeimage(newimage)
{
	var imagen=MM_findObj('imageartist');
	var imagen2= new Image;	
	if(imagen)
	{
		imagen.src='images/cargando2.gif';
		imagen2.onload=function()
		{
				imagen.src=imagen2.src;
		}
			imagen2.src='files/'+newimage;
	}
}

function loadimages_pre()
{
	var imagen=MM_findObj('preimages');
	var vector;
	if(imagen)
	{
		if(imagen.value!='')
			vector=imagen.value.split(';');
			for(var i=0;i<vector.length;i++)
			{	
					eval('var image'+i+'= new Image;');
					eval('image'+i+'.src=\''+vector[i]+'\';');
			}
	}
}