var DIR="";

if (location.href.indexOf('sublimemaster')>0) {DIR = "/estudioacostaylara";}

var imgs=DIR+"/artworks";

function abrirVentana(url, width, height, name) {
	if (name==null) {name='nueva_ventana';}
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}

	str += ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";

	objwin=window.open(url, name, str);
	objwin.focus();
}


function getObj(id) {if (document.getElementById) {return document.getElementById(id)}	else if (document.all) {return document.all[id]}	else {return document.all[id]}}

function rnd(max) {
	var x = Math.random() * max;
	x = x + 1;
	return parseInt(x);
}


//// EFECTOS VISUALES

function mOvr(src,clrOver) {
	if(clrOver=='') {clrOver = '#B9D7EA'};
	//if (!src.contains(event.fromElement)) { defaultColor = src.bgColor; src.bgColor = clrOver; }
	defaultColor = src.bgColor;
	src.bgColor = clrOver;
}

function mOut(src) {
	//if (!src.contains(event.toElement)) src.bgColor = defaultColor;
	src.bgColor = defaultColor;
}

/******** CAMBIO DE BACKROUND ********/
function change_background(obj,img) {obj.background=img;}

function hide_unhide(id_obj) {
	obj=getObj(id_obj);
	if (obj.style.visibility=="visible") {
		obj.style.visibility="hidden";
	} else {
		obj.style.visibility="visible";
	}
}

//******** MOUSEHOVERS ********
var pics = new Array("menu1","menu2","menu3","menu4","menu5","menu6","menu7","menu8","menu9","menu10","menu11");
var imgObjs = new Array(pics.length);
var imgObjs_on= new Array(pics.length);

//if (typeof imgs_lang=="undefined") {imgs_lang = "en/";}
if (typeof imgs_lang=="undefined") {imgs_lang = "";}

if (document.getElementById || document.all) {
	for (var i=0; i<pics.length; i++) {
		imgObjs[i] = new Image();
		imgObjs[i].src = DIR+"/artworks/"+imgs_lang+pics[i]+".gif";

		imgObjs_on[i] = new Image();
		imgObjs_on[i].src = DIR+"/artworks/"+imgs_lang+pics[i]+"-on.gif";

	}
}

function do_imagechange(objimg) {
	for (var i=0; i<pics.length; i++) {
		if (objimg.src.indexOf('-on') > 0) {
			if (objimg.src == imgObjs_on[i].src) {
				objimg.src = imgObjs[i].src;
				break;
			}
		} else {
			if (objimg.src == imgObjs[i].src) {
				objimg.src = imgObjs_on[i].src;
				break;
			}
		}
	}
}

function hide_unhide_tabla(t) {
	o=getObj(t);
	if (o==null) {return;}
    if (o.style.display=="none") {o.style.display="";} else {o.style.display="none";}
}

function validar_login(formulario, msg) {
	if (formulario.usuario.value == '' || formulario.clave.value == '') { alert(msg); formulario.usuario.focus(); return false; }
	return true;
}

function showLayer_Alert(msg) {

	obj_txt=getObj("texto_alert");
	if (obj_txt==null) {obj_txt=window.parent.document.getElementById("texto_alert");}
	obj_txt.innerHTML=msg;

	showAndCenter("layer_alert");

}

function hideLayer_Alert() {

	hideAndReset("layer_alert");

	obj_txt=getObj("texto_alert");
	if (obj_txt==null) {obj_txt=window.parent.document.getElementById("texto_alert");}
	obj_txt.innerHTML="";

}

function hideAndReset(id) {

	obj=getObj(id);
	if (obj==null) {obj=window.parent.document.getElementById(id);}
	obj.style.zIndex=-1;
	obj.style.visibility="hidden";
	obj.style.left=0;
	obj.style.top=0;

}
function showAndCenter(id) {

	obj=getObj(id);
	if (obj==null) {obj=window.parent.document.getElementById(id);}
	ancho_layer=obj.style.width;
	ancho_layer=ancho_layer.replace("px","");
	alto_layer=obj.style.height;
	alto_layer=alto_layer.replace("px","");

	var X = ((window.parent.document.body.scrollWidth-alto_layer)/2);
	var Y = ((window.parent.screen.availHeight-alto_layer)/2);

	obj.style.zIndex=1001;
	obj.style.visibility="visible";
	obj.style.left=(window.parent.document.body.scrollLeft+(X))-100;
	obj.style.top =(window.parent.document.body.scrollTop +(Y))-100;

}

function validar_olvidemiclave(form) {
	if (form.email.value.indexOf('@') < 0 || form.email.value.indexOf('.') < 0 || form.email.value.indexOf(',') > 0) { alert('Bad email address'); form.email.focus(); return false; }
	return true;
}

function hide_ampliacion() {
	var o=getObj("foto_ampliacion");
	o.src=imgs+"/blank.gif";
	ly=getObj("layer_ampliacion");
	ly.style.visibility="hidden";
	ly.style.width=0;
	ly=getObj("layer_cargando_ampliacion");
	ly.style.visibility="hidden";
}
function unhide_cargando() {
	ly=getObj("layer_cargando_ampliacion");
	ly.style.visibility="hidden";
}
function showfoto(f,d) {
	center_gal();
	ly=getObj("layer_ampliacion");
	ly.style.width=ancho_gal+4;
	ly.style.visibility="visible";
	ly=getObj("layer_cargando_ampliacion");
	ly.style.visibility="visible";
	i=getObj("foto_ampliacion");
	i.src=f;
	if (d!="") {
		d="<table bgcolor='#000000' width='100%' cellspacing='0' cellpadding='0' border='0' height='18'><tr><td width='3'></td><td><font class='verysmalltext'>"+d+"</font></td><td width='3'></td></tr></table>";
	}
	s=getObj("desc_foto");
	s.innerHTML=d;

}
function center_gal() {
	obj=getObj("layer_ampliacion");
	var X = ((document.body.scrollWidth-ancho_gal)/2);
	var Y = ((window.screen.availHeight-alto_gal)/2);
	obj.style.zIndex=255;
	obj.style.visibility="visible";
	obj.style.left=document.body.scrollLeft+(X);
	obj.style.top=document.body.scrollTop+(Y/2);
}

var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var flag = 0;
var msg = 'El material de esta página pertenece a Estudio Acosta y Lara';
var x,y,x1,y1,copyAttempt;

function init_prot()
{
return;
	if (!(document.getElementById || document.all || document.layers)) return;
	if (specialcase && document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = special;
	}
	for (i=0;i<document.images.length;i++)
	{
		document.images[i].onmousedown = checkIt;
		document.images[i].onmouseup = function() {return false};
		if (specialcase)
		{
			document.images[i].onmousemove = special;
			document.images[i].onclick = clearIt;
		}
	}
}

function checkIt(e)
{
	copyAttempt = 0;
	if (window.Event)
	{
		x = e.screenX;
		y = e.screenY;
		theButt = (e.which == 3);
	}
	else
	{
		x = window.event.clientX;
		y = window.event.clientY;
		theButt = (window.event.button == 2);
	}
	if (theButt)
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false; // NN4 only
	}
	if (specialcase) flag = 1;
	return false;
}

function special(e)
{
	theObj = '';
	if (window.Event)
	{
		x1 = e.screenX;
		y1 = e.screenY;
		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
	else
	{
		x1 = window.event.clientX;
		y1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
	var isLink = (theObj == 'A');
	if (flag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false;
	}
}

function clearIt()
{
	flag = 0;
	if (copyAttempt)
	{
		copyAttempt = 0;
		return false;
	}
}


function writeflash(o,m,w,h,p,oid) {
	ospan=getObj(o);
	if (ospan!=null) {
		if (oid!=null) {oid="id='"+oid+"'";}
		f="<object "+oid+" classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"'>";
		f+="<param name='movie' value='"+m+"'>";
		f+="<param name='quality' value='high'>";
		if (p!="") {f+="<param name=flashvars value='"+p+"'>";}
		f+="<param name='wmode' value='transparent'>";
		f+="<embed "+oid+" src='"+m+"' width='"+w+"' height='"+h+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent'";
		if (p!="") {f+=" flashvars='"+p+"'";}
		f+="></embed>";
		f+="</object>";
		ospan.innerHTML=f
	}
}

function hide_unhide_tabla(t) {
	tabla=getObj(t);
	if (tabla.style.display=="none") {tabla.style.display="";} else {tabla.style.display="none";}
}

String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,'');}

function check_buscar(form) {
	form.buscar.value=form.buscar.value.trim();
	var v=form.buscar.value;
	if (v=="" || v.length<3) {
		alert("Ingrese el texto a buscar por favor");
		form.buscar.focus();
		return false;
	}

	return true;
}
