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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors = '',args = MM_validateForm.arguments;
  for (i = 0; i < (args.length - 2); i += 3) { 
		test = args[i + 2]; 
		val = MM_findObj(args[i]);
    if (val) { 
			nm = val.name; 
			switch (nm) {
				case "nombre": nm = "Campo \'Su nombre\'"; break;
				case "email": nm = "Campo \'Su e-mail\'"; break;
				case "asunto": nm = "Campo \'Asunto\'"; break;
				case "mensaje": nm = "Campo \'Mensaje\'"; break;
			}
			if ((val = val.value) != "") {
	      if (test.indexOf('isEmail') != -1) { 
					p = val.indexOf('@');
	        if (p < 1 || p == (val.length - 1)) errors += '- ' + nm + ' debe ser una dirección válida de e-mail.\n';
				}
				else if (test != 'R') { 
					num = parseFloat(val);
	        if (isNaN(val)) errors += '- ' + nm + ' must contain a number.\n';
					if (test.indexOf('inRange') != -1) { 
						p = test.indexOf(':');
	          min = test.substring(8,p); 
						max = test.substring(p + 1);
	          if (num < min || max < num) errors += '- ' + nm + ' must contain a number between ' + min + ' and ' + max + '.\n';
					}
				}
			}
			else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; 
		}
  }
	if (errors) alert('ERROR EN DATOS DEL FORMULARIO:\n' + errors);
  document.MM_returnValue = (errors == '');
}

/*
function clientes() {
  ruta = "http://localhost/emparanza/";
//  ruta = "http://www.emparanza.cl/";
	espacio = 10;
//	ancho = screen.width - espacio;
	ancho = 800;
  alto = screen.height - espacio;
	izquierda = espacio / 2;
	arriba = espacio / 2;
  opciones = "width=" + ancho + ",height=" + alto + ",titlebar=0,rezisable=0,toolbar=0,left=" + izquierda + ",top=" + arriba + "";
  doc = window.open("", "concurso", opciones);
  doc.document.open();
  doc.document.write('<HTML>\n<HEAD>\n<TITLE>Laboratorio Clínico Veterinario Dr. Emparanza :: Sección Clientes</TITLE>\n');
  doc.document.write('</HEAD>\n<FRAMESET cols="100%,*"" FRAMEBORDER="NO" BORDER="0" FRAMESPACING="0">\n<FRAME SRC="clientes/index.php" NAME="index" SCROLLING="NO"></FRAMESET>\n</HEAD>\n</HTML>');
	doc.document.close();
}
*/

function destaca1(obj, posicionX, posicionY) {
	obj.style.backgroundColor = '#FFDEAD';
	obj.style.backgroundImage = 'url(img/pic2.gif)';
	obj.style.backgroundRepeat = 'no-repeat';
	obj.style.textDecoration = 'underline';
	obj.style.color = '#0000FF';
	obj.style.backgroundPosition = posicionX + 'px ' + posicionY + 'px';
}

function destaca2(obj) {
	obj.style.backgroundColor='#FFFFFF';
	obj.style.backgroundImage='';
	obj.style.textDecoration = 'none';
	obj.style.color = '#000000';
}

function verResultado(cid, rid) {
	// cid = id del cliente
	// rid = id del resultado
//  ruta = "http://localhost/emparanza/";
//  ruta = "http://www.emparanza.cl/";
	ruta = "./";
	espacio = 10;
//	ancho = screen.width - espacio;
	ancho = screen.availWidth;
  alto = screen.availHeight;
	izquierda = 0; //espacio / 2;
	arriba = 0; //espacio / 2;
  opciones = "width=" + ancho + ",height=" + alto + ",titlebar=0,rezisable=0,toolbar=0,left=" + izquierda + ",top=" + arriba + "";
  doc = window.open("", "win_resultado", opciones);
  doc.document.open();
  doc.document.write('<HTML>\n<HEAD>\n<TITLE>Laboratorio Clínico Veterinario Dr. Emparanza :: Sección Clientes</TITLE>\n');
  doc.document.write('</HEAD>\n<FRAMESET cols="100%,*"" FRAMEBORDER="NO" BORDER="0" FRAMESPACING="0">\n<FRAME SRC="clientes_ver.php?cid=' + cid + '&amp;rid=' + rid + '" NAME="frame_resultado" SCROLLING="NO"></FRAMESET>\n</HEAD>\n</HTML>');
	doc.document.close();
	
}
function MostrarPVI(URL) {
	var PVI = window.open(URL,'PVI','scrollbars=yes,resizable=yes,fullscreen=YES');
	if (PVI) {
		PVI.moveTo(0,0);
		PVI.resizeTo(screen.availWidth,screen.availHeight);
		PVI.focus();
	}
	else {
		alert('Deshabilite el bloqueador de pop-up de su navegador');
	}
}

function cambiarGaleria(objeto) {
	if (objeto.selectedIndex == 0) location.href = "javascript:void(0)";
	else  {
		location.href = "index.php?pag=galeria&cat=" + objeto.options[objeto.selectedIndex].value;
		objeto.selectedIndex = 0;
	}
}

function crearInstancia() {
	XMLHttp = false;
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		var versiones = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		for (var i = 0; i < versiones.length; i++) {
			try {
				XMLHttp = new ActiveXObject(versiones[i]);
				if (XMLHttp) {
					return XMLHttp;
					break;
				}
			} catch (e) {};
		}
	}
}

function enviarEmail() {
	var nombre = document.getElementById("nombreEmail").value;
	var email = document.getElementById("emailEmail").value;
	var asunto = document.getElementById("asuntoEmail").value;
	var mensaje = document.getElementById("mensajeEmail").value;
	
	XMLHttp = crearInstancia();
	if (XMLHttp) {
		url = "contacto2.php?nombre=" + nombre + "&email=" + email + "&asunto=" + asunto + "&mensaje=" + mensaje;
		XMLHttp.open("POST", url, true);
		XMLHttp.onreadystatechange = cambiaEstado;
		XMLHttp.send(null);
	}
	else {
		alert("Sin instancia");
	}
}

function cambiaEstado() {
	var respuesta;
	if (XMLHttp.readyState == 4) {
		if (XMLHttp.responseText == '1') {
			respuesta = "Email OK";
		}
		else if (XMLHttp.responseText == '2') {
			respuesta = "Faltan datos";
		}
		else {
			respuesta = "Errores";
		}
		document.getElementById("respuesta").innerHTML = respuesta;
		document.getElementById("respuesta").display = "inline";
	}
}