/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Ultimater, Mr J :: http://www.webdeveloper.com/forum/showthread.php?t=77389 */

function toggleMe(a, b){
  var e=document.getElementById(a);
  var f=document.getElementById(b);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
	f.src = "/imagenes/collapse.gif"
  } else {
    e.style.display="none"
	f.src = "/imagenes/expand.gif"
  }
  return true;
}

function Reset_Campos() {
document.form1.materia.selectedIndex = 0
document.form1.autor.selectedIndex = 0
document.form1.busqueda["titulo"].checked = "true"
document.form1.frase.value = ""
//document.form1.opt2[0].checked = "true"
//document.form1.descrip.value = "todos"
//document.form1.opt3[0].checked = "true"
//document.form1.fecha.selectedIndex = "todos"

}


// ############ FUNCIONES SCROLL ###########
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

// ######################################

function CambiaCookie(ckvalue) {
//alert (ckvalue);
if (ckvalue == true) {
document.location='ordencompra.asp?cookie=1';
} else { 
document.location='ordencompra.asp?cookie=0';
}
}

function fAgregaPedido(fCod) {
var fscroll = f_scrollTop();
//alert (fscroll);
document.location='catalogo.asp?agregar=' + fCod + '&regresa=1&scrollpos=' + fscroll;
}

function fAgregaPedidoDetalleLibro(fCod) {
var fscroll = f_scrollTop();
//alert (fscroll);
document.location='catalogo.asp?agregar=' + fCod + '&codigo=' + fCod;
}

function fAgregaPedidoNovedades(fCod) {
var fscroll = f_scrollTop();
//alert (fscroll);
document.location='novedades.asp?agregar=' + fCod + '&regresa=1&scrollpos=' + fscroll;
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- el campo '+nm+' debe contener una dirección valida de e-mail.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- el campo '+nm+' debe contener un número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- el campo '+nm+' debe contener un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- el campo '+nm+' debe ser llenado.\n'; }
  } if (errors) alert('Error de formulario:\n'+errors);
  document.MM_returnValue = (errors == '');
}
