// Este script encuatra objetos por su ID
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;
}

// Este script valida la info de un formulario
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+='- '+nm+' debe contener una dirección de e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+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 (num<min || max<num) errors+='- '+nm+' debe contener un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; }
  } if (errors) alert('Han ocurrido los siguientes errores:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// Este script abre un popup
function MM_popup(theURL,winName,features,ancho,alto) { 
   var left = Math.floor( (screen.width-ancho) / 2);
   var top = Math.floor( (screen.height-alto) / 2);
   var parametros = features + ',top=' + top + ',left=' + left + ',width=' + ancho + ',height=' + alto;
   window.open(theURL,winName,parametros);
}
// Fin del script

// Este script maneja los cuadros random del top
var ic = 5; // Number of alternative images 
var xoxo = new Array(ic); // Array to hold filenames 
var datos = new Array(ic); // Array to hold filenames 
xoxo[0] = "cuadro_1"; datos[0] = "Kandisky - Composición 7"; 
xoxo[1] = "cuadro_2"; datos[1] = "Picasso - L'Aubade (1965)";
xoxo[2] = "cuadro_3"; datos[2] = "Georges Braque - Viaduct"; 
xoxo[3] = "cuadro_4"; datos[3] = "Kasimir Malevich - Snowstorm"; 
xoxo[4] = "cuadro_5"; datos[4] = "Kurt  Schwitters - Nobleldy"; 

function pickRandom(range) { 
	if (Math.random) 
		return Math.round(Math.random() * (range-1)); 
	else { 
		var now = new Date(); 
		return (now.getTime() / 1000) % range;
	}
}
// Write out an IMG tag, using a randomly-chosen image name. 
var choice = pickRandom(ic); // --> 
// Fin del script


// Este script maneja los menues y submenues colapsables
function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("menues").getElementsByTagName("DIV");
		if(el.style.display == "none"){
			for (var i=0; i<ar.length; i++){
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
// document.onselectstart = new Function("return false"); // esta función anula la posibilidad de seleccionar el texto en explorer
// Fin del script

// Este script maneja el buscador
var win=null;
function MyWindow(mypage,myname,w,h,scroll,pos){
	var rndURL = (1000*Math.random());
	if(pos=="random"){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	win=window.open(mypage+'&rndURL='+rndURL,myname,settings);
	if(win.focus){
		win.focus();
	}
}

function DoSearch(){
var mbool = "AND";
var mcase = "Insensitive";
if(!document.cssearch.terms.value){
 alert("Error. Por favor ingrese una palabra antes de comenzar la búsqueda.");
 return false;
 }
else{
  var URL = "/cgi-bin/csSearchPro/csSearchPro.cgi?command=query&terms="+escape(document.cssearch.terms.value)+"&mbool="+mbool+"&mcase="+mcase;
   if("checked"){
      window.location=URL;
      }
    else{
      MyWindow(URL,'query',600,400,'yes','center');
      }
  return false;
  }
}
// Fin del script

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

// Este script carga un object de Windows Media Player evitando la protección de Microsoft
function embedAudioVideo(pelicula,ancho,alto) {
	document.write('<OBJECT ');
	document.write('	classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"');
	document.write('    codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"');
	document.write('	TYPE="application/x-oleobject" width="'+ancho+'" height="'+alto+'" align="top"');
	document.write('	standby="Cargando componentes Microsoft Windows Media Player..." ID="MediaPlayer" VIEWASTEXT>');
	document.write('        <PARAM NAME="FileName" VALUE="'+pelicula+'">');
	document.write('        <PARAM NAME="AnimationatStart" VALUE="false">');
	document.write('        <PARAM NAME="TransparentatStart" VALUE="false">');
	document.write('        <PARAM NAME="AutoStart" VALUE="true">');
	document.write('        <PARAM NAME="ShowControls" VALUE="true">');
	document.write('        <PARAM NAME="Autosize" VALUE="false">');
	document.write('        <PARAM NAME="ShowStatusBar" VALUE="true">');
	document.write('        <embed	SRC="'+pelicula+'" width="'+ancho+'" height="'+alto+'" AutoStart=1 align="top" TYPE="application/x-mplayer2" ');
	document.write('		pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&"');
	document.write('        ShowControls=1 Autosize=0 ShowStatusBar=1></embed>');
	document.write('</OBJECT>');
}
