/*************************************
 *
 * Funciones prototipo para objetos
 *
 *************************************/

//Constantes:
var SITEADDRESS = location.host;
var IMGDIR = "/lookfeel/images/";

// Array

// bool ArrayIsInto(mixed value);

function ArrayIsInto(value)
{
	for (var i=0;i<this.length;i++)
	{
		if (this[i] === value)
		{
			return true;
		}
	}
	return false;
}

Array.prototype.isInto = ArrayIsInto;


// void ArrayAddRange(mixed value);

function ArrayAddRange(value)
{
	for (var i=0; i<value.length; i++)
	{
		this[this.length] = value[i];
	}
}

Array.prototype.AddRange = ArrayAddRange;

//bool IsNullOrEmpty(string value);

function $SE(value)
{
	return (value === "" || value === null || value.length <= 0);
}

function StringIsMail()
{
	return this.match(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/i);
}

String.prototype.IsMail = StringIsMail;

//Str = Class.create();
//Str.prototype.IsNullOrEmpty = StringIsNullOrEmpty;

function $CT(elem, cls, tag)
{
	if (elem = $(elem))
	{
		elems = $A(elem.getElementsByTagName(tag));

		returnelems = new Array();
		j = 0;
		for (i=0;i<elems.length; i++)
		{
			if ( elems[i].className.indexOf(cls) >=0 )
			{
				returnelems[j++] = elems[i];
			}
		}
		return returnelems;
	}
}
function $C(elem, cls)
{
	if (elem = $(elem))
	{
		elems = $A(elem.getElementsByTagName("*"));

		returnelems = new Array();
		j = 0;
		for (i=0;i<elems.length; i++)
		{
			if ( elems[i].className.indexOf(cls) >=0 )
			{
				returnelems[j++] = elems[i];
			}
		}
		return returnelems;
	}
}

/*************************************
 *
 * Objetos propios
 *
 *************************************/




/*Elemento fade, se encarga de manejar fade-ins y fade-outs */
/**
 * Elemento Fade
 * @author Ezequiel Rabinovich erabinovich@gmail.com
 */
Fade = Class.create();
Fade.prototype =
{
	/**
	 * Constructor
	 * @param {String, HTMLElement} element Elemento html que va a hacer el fade
	 */
	initialize: function (element)
	{
		this.elem = $(element);
		this.current;
	},
	/**
	 * Realiza el Fade según corresponda.
	 */
	Fade: function ()
	{
		if (this.OpacityStart < this.OpacityEnd)
		{
			this.current += this.OpacityJump;
		}
		else
		{
			this.current -= this.OpacityJump;
		}
		if ((this.OpacityStart > this.OpacityEnd && this.current <= this.OpacityEnd) ||
			(this.OpacityStart < this.OpacityEnd && this.current >= this.OpacityEnd))
		{
				this.current = this.OpacityEnd;
				this.Set(this.current);
		}
		else
		{
			this.Set(this.current);
			this.FadeNext();
		}
	},
	/**
	 * Comienza un cambio de opacidad
	 * @param {Integer} OpacityStart Valor de la opacidad inicial del objeto (entre 0-100)
	 * @param {Integer} OpacityEnd Valor de la opacidad que tendrá el objeto al terminar el efecto (entre 0-100)
	 * @param {Integer} TimeOut Valor del tiempo que se esperará entre cada cambio de opacidad (en milisegundos)
	 * @param {Integer} OpacityJump La cantidad de niveles de opacidad que seagregarán o restarán por vez.
	 */
	Start: function (OpacityStart, OpacityEnd, TimeOut, OpacityJump)
	{
		this.Set(OpacityStart);
		this.elem.style.display = "block";
		this.OpacityStart = OpacityStart;
		this.OpacityEnd = OpacityEnd;
		this.TimeOut = TimeOut;
		this.OpacityJump = OpacityJump;
		this.current = OpacityStart;
		this.FadeNext();
	},
	/**
	 * Realiza el siguiente cambio de opacidad.
	 */
	FadeNext: function ()
	{
		setTimeout(this.Fade.bind(this), this.TimeOut);
	},
	/**
	 * Setea la opacidad en el valor especificado.
	 * @param {Integer} Opacity Valor de la opacidad (entre 0-100)
	 */
	Set: function(nOp)
	{
		this.elem.style.opacity = nOp/100;
		this.elem.style.filter = "alpha(opacity=" + (nOp) + ")";
		if (nOp == 0)
		{
			this.elem.style.display = "none";
		}
	},
	/**
	 * Obtiene el valor actual de la opacidad
	 * @return {Integer} Valir de la opacidad actual (0-100)
	 */
	Get: function ()
	{
		if (isIE())
		{
			return this.elem.filters.item('alpha').opacity;
		}
		else
		{
			return this.elem.style.opacity*10;
		}
	}
}


/**
 * Elemento html, sirve para funciones basicas como mostrar u ocultar
 * @author Ezequiel Rabinovich erabinovich@gmail.com
 */
BasicUtilsClass = Class.create();
BasicUtilsClass.prototype =
{
	/**
	 * Constructor
	 */
	initialize: function ()
	{
		this.FadeElement = null;
		this.FadeTimeOut = null;
	},
	/**
	 * Muestra un elemento oculto
	 * @param {String, Object} ElementName Nombre o referencia al elemento
	 */
	Show: function (ElementName, DisplayType)
	{
		try
		{
			if (DisplayType != null)
			{
				$(ElementName).style.display = "block";
			}
			else
			{
				$(ElementName).style.display = "";
			}

		}
		catch (e)
		{
			;
		}
	},
	/**
	 * Oculta un elemento oculto
	 * @param {String, Object} ElementName Nombre o referencia al elemento
	 */
	Hide: function (ElementName)
	{
		if ($(ElementName) != null)
		{
			try
			{
				$(ElementName).style.display = "none";
	
			}
			catch (e)
			{
				;
			}
		}
	},
	/**
	 * Hace aparecer un elemento oculto
	 * @param {String, Object} ElementName Nombre o referencia al elemento
	 */
	FadeIn: function (ElementName)
	{
		Elem = new Fade(ElementName);
		Elem.Start(0, 100, 1, 5);
	},
	/**
	 * Hace desparecer un elemento oculto
	 * @param {String, Object} ElementName Nombre o referencia al elemento
	 */
	FadeOut: function (ElementName)
	{
		Elem = new Fade(ElementName);
		Elem.Start(100, 0, 1, 5);
	},
	/**
	 * Muestra u oculta las barras de scroll
	 * @param {Boolean} Show Define si se muestran o no las scrollbars
	 */
	ShowScrollbars: function (Show)
	{
		if (Show)
		{
			$("documentRoot").style.overflow = "auto";
		}
		else
		{
			$("documentRoot").style.overflow = "hidden";
		}
	},
	SwitchDiv: function (DivId)
	{
		//if (DivId.lastIndexOf(
	},
	FlashElem : "",
	FlashCount : 0,
	Flash: function (elem)
	{
		this.FlashCount = 0;
		this.FlashElem = $(elem);
		this.StartFlash();
	},
	StartFlash: function()
	{
		if ((this.FlashCount % 2) != 0)
		{
			this.FlashElem.style.visibility = "hidden";
		}
		else
		{
			this.FlashElem.style.visibility = "";
		}
		if (this.FlashCount++ < 8)
		{
			setTimeout(this.StartFlash.bind(this), 100);
		}
	},
	GetParentElement : function(elem)
	{
		if (elem.parentNode)
			return elem.parentNode;
		else
			return elem.parentElement;
	}
}

var BasicUtils = new BasicUtilsClass();

EventUtilClass = Class.create();

EventUtilClass.prototype =
{
	initialize : function()
	{
		;
	},
	addEventHandler : function (oTarget, sEventType, fnHandler)
	{
		oTarget = $(oTarget);
		if (oTarget.addEventListener)
		{ //for DOM-compliant browsers
			oTarget.addEventListener(sEventType, fnHandler, false);
		}
		else if (oTarget.attachEvent)
		{ //for IE
			oTarget.attachEvent("on" + sEventType, fnHandler);
		}
		else
		{ //for all others
			oTarget["on" + sEventType] = fnHandler;
		}
	},
	removeEventHandler : function (oTarget, sEventType, fnHandler)
	{
		if ($(oTarget))
			oTarget = $(oTarget);
		if (oTarget.removeEventListener)
		{ //for DOM-compliant browsers
			oTarget.removeEventListener(sEventType, fnHandler, false);
		}
		else if (oTarget.detachEvent)
		{ //for IE
			oTarget.detachEvent("on" + sEventType, fnHandler);
		}
		else
		{ //for all others
			oTarget["on" + sEventType] = null;
		}
	},
	formatEvent : function (oEvent)
	{
		if (isIE && isWin)
		{
			oEvent.charCode = (oEvent.type == "keypress") ? oEvent.keyCode : 0;
			oEvent.eventPhase = 2;
			oEvent.isChar = (oEvent.charCode > 0);
			oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
			oEvent.pageY = oEvent.clientY + document.body.scrollTop;
			oEvent.preventDefault = function ()
			{
				this.returnValue = false;
			};

			if (oEvent.type == "mouseout")
			{
				oEvent.relatedTarget = oEvent.toElement;
			}
			else if (oEvent.type == "mouseover")
			{
				oEvent.relatedTarget = oEvent.fromElement;
			}

			oEvent.stopPropagation = function () {
				this.cancelBubble = true;
			};

			oEvent.target = oEvent.srcElement;
			oEvent.time = (new Date).getTime();
		}
		return oEvent;
	},
	getEvent : function()
	{
		if (window.event)
		{
			return this.formatEvent(window.event);
		}
		else
		{
			return EventUtil.getEvent.caller.arguments[0];
		}
	},
	getElement : function(evt)
	{
		if (evt.srcElement)
		{
			return evt.srcElement;
		}
		else
		{
			return evt.target;
		}
	},
	addEventHandlerToArray : function(ElemenentsArray, eventName, eventHandler)
	{
		if (typeof ElemenentsArray == 'object')
		{
			for (i=0;i<ElemenentsArray.length;i++)
			{
				this.addEventHandler(ElemenentsArray[i], eventName, eventHandler);
			}
		}
	}

}

// Funciones Sitebar
SitebarClass = Class.create();
SitebarClass.prototype =
{
	initialize : function ()
	{
		var expandElements = null;

		//expandElements = $CT("Sitebar", "openbar", "span");
		expandElements = $CT("Sitebar", "openbar", "div");
		EventUtil.addEventHandlerToArray(expandElements, "click", this.ExpConClicked.bind(this));

		//expandElements = $CT("Sitebar", "closedbar", "span");
		expandElements = $CT("Sitebar", "closedbar", "div");
		EventUtil.addEventHandlerToArray(expandElements, "click", this.ExpConClicked.bind(this));
	},
	ExpConClicked : function (evt)
	{
		if (
			EventUtil.getElement(evt).className == "Expand" ||
			EventUtil.getElement(evt).className == "Collapse" ||
			EventUtil.getElement(evt).className == "text"
			)
		{
			this.ExpandContract(BasicUtils.GetParentElement(BasicUtils.GetParentElement(EventUtil.getElement(evt))));
		}
		else
		{

			this.ExpandContract(BasicUtils.GetParentElement(EventUtil.getElement(evt)));
		}
	},
	ExpandContract : function (item)
	{
		//content = $CT(item, "content", "span");
		content = $CT(item, "content", "div");
		//titlespan = $CT(item, "openbar", "span");
		titlespan = $CT(item, "openbar", "div");
		//text = $CT(item, "closedbar", "span");
		text = $CT(item, "closedbar", "div");
		if (text[0].style.display == "block")
		{
			text[0].style.display = "";
			content[0].style.display = "";
			titlespan[0].style.display = "";
		}
		else
		{
			text[0].style.display = "block";
			content[0].style.display = "none";
			titlespan[0].style.display = "none";

		}
	}
}



///OUTSTANDING
OutstandingArrowsClass = Class.create();
OutstandingArrowsClass.prototype =
{
	initialize: function (arrowPrev, arrowNext, Cart, Outstanding)
	{
		if ((this.prev = $(arrowPrev))
		 	&&
		 	(this.next = $(arrowNext))
		 	&&
		 	(this.cart = $(Cart))
		 	&&
		 	(this.outstanding = Outstanding)
		)
		{
			//Agregar eventos de las flechas
			EventUtil.addEventHandler(this.next, "mouseover", this.EffectOver.bindAsEventListener(this));
			EventUtil.addEventHandler(this.prev, "mouseover", this.EffectOver.bindAsEventListener(this));
			EventUtil.addEventHandler(this.cart, "mouseover", this.EffectOver.bindAsEventListener(this));
			EventUtil.addEventHandler(this.next, "mouseout", this.EffectOut.bindAsEventListener(this));
			EventUtil.addEventHandler(this.prev, "mouseout", this.EffectOut.bindAsEventListener(this));
			EventUtil.addEventHandler(this.cart, "mouseout", this.EffectOut.bindAsEventListener(this));
			EventUtil.addEventHandler(this.next, "click", this.Clicked.bindAsEventListener(this));
			EventUtil.addEventHandler(this.prev, "click", this.Clicked.bindAsEventListener(this));
			EventUtil.addEventHandler(this.cart, "click", this.Clicked.bindAsEventListener(this));
		}
		else
		{
			//throw("Error en los destacados.");
		}
	},
	EffectOver: function ()
	{
		element = EventUtil.getElement(EventUtil.getEvent());
		if (element.id.indexOf("addToCart") > 0)
		{
			element.src = "/lookfeel/images/outstanding_cartButtonHover.gif";
		}
		else if (element.id.indexOf("next")>0)
		{
			element.src = "/lookfeel/images/arrow_nextHover.gif";
		}
		else
		{
			element.src = "/lookfeel/images/arrow_backHover.gif";
		}
	},
	EffectOut: function ()
	{
		element = EventUtil.getElement(EventUtil.getEvent());
		if (element.id.indexOf("addToCart") > 0)
		{

			element.src = "/lookfeel/images/outstanding_cartButton.gif";
		}
		else if (element.id.indexOf("next") > 0)
		{
			element.src = "/lookfeel/images/arrow_next.gif";
		}
		else
		{
			element.src = "/lookfeel/images/arrow_back.gif";
		}
	},
	Clicked: function ()
	{
		element = EventUtil.getElement(EventUtil.getEvent());
		if (element.id.indexOf("addToCart") > 0)
		{
			this.outstanding.Cart();
		}
		else if (element.id.indexOf("next") > 0)
		{
			this.outstanding.Next();
			this.outstanding.RestartCycle();
		}
		else
		{
			this.outstanding.Prev();
			this.outstanding.RestartCycle();
		}
	}

}

OutstandingClass = Class.create();
OutstandingClass.prototype =
{
	initialize: function ()
	{
		if (sitebar = $("Sitebar"))
		{
			var outstanding;
			if (outstanding = $CT(sitebar, "Outstanding_main", "table"))
			{
				this.outstanding = $A(outstanding);
				this.position = 0;
				this.max = this.outstanding.length-1;
				this.LoadCurrentCode();
				this.StartCycle();
			}
			else
			{
				//throw("No se encuentran los destacados");
			}
		}
		else
		{
			//throw("No se encuentra la Sitebar");
		}
	},
	Next: function()
	{
		if (this.position < this.max )
			this.position++;
		else
			this.position = 0;
		this.Display();
	},
	Prev: function()
	{
		if (this.position > 0 )
			this.position--;
		else
			this.position = this.max;
		this.Display();
	},
	Cart: function()
	{
		addToCart(this.bookcode);
	},
	Display: function()
	{
		for (var i=0; i < this.max+1; i++)
		{
			if (this.outstanding[i].style.display == "" || this.outstanding[i].style.display == "block")
			{
				BasicUtils.Hide(this.outstanding[i]);
				if (isIE6() || isIE7())
					BasicUtils.Show(this.outstanding[this.position]);
				else
					BasicUtils.FadeIn(this.outstanding[this.position]);
			}
		}
		this.LoadCurrentCode();
	},
	LoadCurrentCode: function()
	{
		if (Elems = $CT(this.outstanding[this.position], "Outstanding_code", "span")) {
			this.bookcode = Elems[0].innerHTML;
		}
	},
	StartCycle: function()
	{
		clearTimeout(this.timeout);
		this.timeout = setTimeout(this.CycleNext.bind(this), 5000);
	},
	CycleNext: function()
	{
		this.Next();
		clearTimeout(this.timeout);
		this.timeout = setTimeout(this.CycleNext.bind(this), 5000);
	},
	RestartCycle: function()
	{
		clearTimeout(this.timeout);
		this.timeout = setTimeout(this.CycleNext.bind(this), 10000);
	}
}

CssClass = Class.create();
CssClass.prototype =
{
	initialize : function(){},
	GetRuleFromStyleSheet : function (styleSheet)
	{
		if (styleSheet.cssRules)
		{
			rules = styleSheet.cssRules;
		}
		else
		{
			rules = styleSheet.rules;
		}
		return rules;
	},
	GetCssRules : function (selector)
	{
		ss = document.styleSheets;
		for (i=0;i<ss.length;i++)
		{
			rules = GetRuleFromStyleSheet(ss[i]);
			for (j=0;j<rules.length;j++)
			{
				if (rules[j].selectorText.toLowerCase() == selector.toLowerCase())
				{
					return rules[j].style;
				}
			}
		}
		return false;
	}
}

FixerClass = Class.create();
FixerClass.prototype =
{
	MinScreenSize : 810,
	BuscadorStandardInputSizes : new Array(),
	BuscadorAdvancedInputSizes  : new Array(),
	initialize : function()
	{
		EventUtil.addEventHandler(window, "resize", this.FixScreenSize.bind(this));
		this.mainTable = $C(document, "template_mainTable")[0];
		this.BuscadorStandardInputSizes[0] = "90px";
		this.BuscadorStandardInputSizes[1] = "118px";
		this.BuscadorAdvancedInputSizes[0] = "90px";
		this.BuscadorAdvancedInputSizes[1] = "160px";
		this.FixScreenSize();
		if (isIE6())
		{
			this.FixMouseOver();
		}
	},
	CheckScreenSize : function()
	{
		return (document.body.clientWidth <= this.MinScreenSize)
	},
	FixScreenSize : function()
	{
		var inputs = $C(document, "windowResize");
		var status;
		var newSize;
		if (this.CheckScreenSize())
		{
			status = 0;
		}
		else
		{
			status = 1;
		}
		for (var i=0;i < inputs.length; i++)
		{
			if (inputs[i].className.indexOf("Advanced")>=0)
				newSize = this.BuscadorAdvancedInputSizes[status];

			else if (inputs[i].className.indexOf("buscador_Input")>=0)
				newSize = this.BuscadorStandardInputSizes[status];
			else
				alert(inputs[i].className);

			inputs[i].style.width = newSize;
		}
	},
	FixMouseOver: function()
	{
		if ($("layoutMenu_MainDiv"))
		{
			var elems = $("layoutMenu_MainDiv").getElementsByTagName("span");
			for (var i=0; i<elems.length; i++)
			{
				EventUtil.addEventHandler(elems[i], "mouseover", this.IE6MouseOver.bindAsEventListener(this));
				EventUtil.addEventHandler(elems[i], "mouseout", this.IE6MouseOut.bindAsEventListener(this));
			}
		}
	},
	IE6MouseOver: function(event)
	{
		var elem = EventUtil.getElement(event);
		
		elem.style.backgroundPosition = "-29px 0px";
		elem.style.backgroundRepeat = "no-repeat";
		elem.style.width = "87px";
		if (elem.parentNode.className == "register")
		{
			elem.style.width = "110px";
		}
	},
	IE6MouseOut: function(event)
	{
		var elem = event.srcElement;
		elem.style.backgroundPosition = "0px 0px";
		elem.style.backgroundRepeat = "no-repeat";
		elem.style.width = "29px";
	}
}

DoctrineClass = Class.create();
DoctrineClass.prototype =
{
	initialize: function(doctrinaCode)
	{
		this.Code = doctrinaCode;
	},
	Open: function()
	{
		OtherResources('/frames.php?what=/files/articles/'+this.Code+'.pdf');
	}
}

//Sistema de Login

LoginResultClass = Class.create();
LoginResultClass.prototype =
{
	initialize: function(){
		;
	},
	ajaxUpdate: function(ajaxResponse)
	{
		var oElem = ajaxResponse.getElementsByTagName("user")[0];
		if (oElem.getAttribute("logged") == 1)
		{
			alert(location.href);
			location.reload();
		}
		else
		{
			DisplayOption("loginFail");
		}
	}
}

LoginResultFromCartClass = Class.create();
LoginResultFromCartClass.prototype =
{
	initialize: function(){
		;
	},
	ajaxUpdate: function(ajaxResponse)
	{
		var oElem = ajaxResponse.getElementsByTagName("user")[0];
		if (oElem.getAttribute("logged") == 1)
		{
			ReloadAllOpeners(window);
			window.opener.openOrderWindow();
			window.close();
		}
		else
		{
			BasicUtils.Show($("displayLoginFailedDiv"));
			BasicUtils.Flash($("displayLoginFailedDiv"));
			$("passid").value = "";
		}
	}
}

LoginResultFromDoctrineClass = Class.create();
LoginResultFromDoctrineClass.prototype =
{
	initialize: function(DoctrineCode){
		this.DoctrineCode = DoctrineCode;
	},
	ajaxUpdate: function(ajaxResponse)
	{
		var oElem = ajaxResponse.getElementsByTagName("user")[0];
		if (oElem.getAttribute("logged") == 1)
		{
			ReloadAllOpeners(window);
			if (this.DoctrineCode != null)
			{
				var Doc = new DoctrineClass(this.DoctrineCode);
				Doc.Open();
			}
			window.close();
		}
		else
		{
			BasicUtils.Show($("displayLoginFailedDiv"));
			BasicUtils.Flash($("displayLoginFailedDiv"));
			$("passid").value = "";
		}
	}
}

var EventUtil = new EventUtilClass();

QueryStringClass = Class.create();
QueryStringClass.prototype =
{
	initialize: function (QueryString)
	{
		this.QueryString = QueryString;
	},
	Break: function()
	{
		this.ValuePairs = this.QueryString.split("&");
		for (var i=0; i < this.ValuePairs.length; i++)
		{
			this.ValuePairs[i] = this.ValuePairs[i].split("=");
		}
	},
	Join: function()
	{
		for (var i = 0; i < this.ValuePairs.length; i++)
		{
			this.ValuePairs[i] = this.ValuePairs[i].join("=");
		}
		this.QueryString = this.ValuePairs.join("&");
	},
	Set: function (Variable, Value)
	{
		this.Break();
		for (var i = 0; i < this.ValuePairs.length; i++)
		{
			if (this.ValuePairs[i][0] == Variable)
			{
				this.ValuePairs[i][1] = Value;
			}
		}
		this.Join();
	},
	Get: function (Variable)
	{
		this.Break();
		for (var i = 0; i < this.ValuePairs.length; i++)
		{
			if (this.ValuePairs[i][0] == Variable)
			{
				return this.ValuePairs[i][1];
			}
		}
	}
}



var OutstandingArrows;
var Outstanding;
var Sitebar;
var Fixer;
var Css;
var Doctrine = null;
var UserObj;
EventUtil.addEventHandler(window, "load", Main);

function Main()
{
	Css = new CssClass();
	Fixer = new FixerClass();
	Sitebar = new SitebarClass();
	Outstanding = new OutstandingClass();
	OutstandingArrows = new  OutstandingArrowsClass("Outstanding_prev", "Outstanding_next", "Outstanding_addToCart", Outstanding);

	window.status = "Editorial Astrea de Alfredo y Ricardo Depalma SRL";

	HideLoader();
	
	if(window.location.toString().indexOf("/LoggedInFromArticle") >= 0 && UserIsLogged)
	{
		if (window.opener)
		{
			window.opener.location.href = "http://"+SITEADDRESS+"/doctrine/open/"+ArticleCode;
		}
		window.close();
	}
	else if(window.location.toString().indexOf("/LoggedInFromCart") >= 0 && UserIsLogged)
	{
		if (window.opener)
		{
			ReloadAllOpeners(window.opener);
			window.opener.location.href = "http://"+SITEADDRESS+"/cart.php?NextStep=true";;
		}
		window.close();
	}
	else if(window.location.toString().indexOf("/LoggedInFromUnknownPage") >= 0 && UserIsLogged)
	{
		ReloadAllOpeners(window);
		window.close();
	}
	else if (window.location.toString().indexOf("/cart") >= 0 && NextStep)
	{
		if (openOrderWindow())
		{
			window.close();
		}
	}
	else if (window.location.toString().indexOf("/doctrine/open/") >= 0)
	{
		if (OpenArticle != null)
			OtherResources("http://"+SITEADDRESS+'/frames.php?what=/files/articles/'+OpenArticle+'.pdf');
	}
	else if(window.location.toString().indexOf("/doctrine") >= 0 || ( window.location.toString().indexOf("/doctrina") >= 0 && window.location.toString().indexOf("/doctrina0") != 0 ) || window.location.toString().indexOf("/marcos_doctrina.htm") >= 0)
	{
    if (!(window.location.toString().indexOf("/doctrine/doctrina") >= 0))
    {
  		BasicUtils.Hide("secondaryColumn");
  		BasicUtils.Hide("doctrine_ShowThemesColumn");
    }
  }
	
	FixResolutionOnSearch();
}
function isIE6()
{
	return !(window.XMLHttpRequest);
}

function isIE7()
{
	return (window.XMLHttpRequest) && (document.all);
}

/*Abrir ventana centrada*/
function openCenteredWindow(Url, Name, Width, Height, Scroll, Resizable)
{
	var TopDif = screen.height/2 - Height/2;
	var LeftDif = screen.width/2 - Width/2;
	var scrollbars = Scroll ? "" : "=0";
	var resizable = Resizable ? "" : "=0";

	return window.open(Url, Name, "location=0, status=0, scrollbars"+scrollbars+", resizable"+resizable+", width="+Width+", height="+Height+", left=" + LeftDif + ", top=" + TopDif);
}


function GetLabelFor(Elem)
{
	var labels = document.body.getElementsByTagName("label");
	for (var i = 0; i < labels.length; i++)
	{
		if (labels.item(i).htmlFor == Elem.id)
		{
			return labels.item(i);
		}
	}
	return null;
}

function isIE()
{
	return (navigator.userAgent.indexOf("MSIE") > -1);
}

function isWin()
{
	return (navigator.platform == "Win32") || (navigator.platform == "Windows");
}

/*Funcion Global Alert*/

function GlobalAlert(what)
{
	switch(what)
	{
		case "underConstruction":

			alert ("La página se encuentra en construcción. Disculpe los inconvenientes.");
		break;

		case "unavailable":

			alert ("Esta opción se encuentra deshabilitada momentáneamente.");
		break;
	}
}

/*Funcion Mostrar/Ocultar el Menu*/
var prevshowHideMenuSelection = false;
function showHideMenu()
{
	if (arguments[0] == "hideOnly")
	{
		if ($("secondaryColumn").style.display === "" || $("secondaryColumn").style.display == "table-cell")
		{
			prevshowHideMenuSelection = true;
			BasicUtils.Hide("secondaryColumn");
			//$("arrowClose").src = IMGDIR + "arrowOpen.gif";
		}
	}
	else if (arguments[0] == "showOnly")
	{
		if ($("secondaryColumn").style.display == "none" /*&& prevshowHideMenuSelection == true*/)
		{
			$("secondaryColumn").style.display = "";
			//$("arrowClose").src = IMGDIR + "arrowClose.gif";
		}
	}
	else
	{
		if ($("secondaryColumn").style.display == "none")
		{
			$("secondaryColumn").style.display = "";
			$("arrowClose").src = IMGDIR + "arrowClose.gif";
			prevshowHideMenuSelection = false;
		}
		else
		{
			BasicUtils.Hide("secondaryColumn");
			$("arrowClose").src = IMGDIR + "arrowOpen.gif";
			prevshowHideMenuSelection = false;
		}
	}
}


/*Function Display Login*/

function DisplayOption(what)
{
	switch(what)
	{
		case "login":

			if(window.location.toString().indexOf("/doctrine") >= 0)
			{
				BasicUtils.Hide("doctrine_ThemesColumn");
				BasicUtils.Hide("doctrine_ShowSiteBarColumn");
				BasicUtils.Show("doctrine_ShowThemesColumn");
			}

			BasicUtils.FadeIn("userLogin");
			$("passid").value = "";
			BasicUtils.Hide("loginFail");
			BasicUtils.Hide("passRecovery");
			showHideMenu("showOnly");
			break;

		case "loginFail":
			BasicUtils.Hide("userLogin");
			BasicUtils.Show("loginFail", "block");
			BasicUtils.Hide("passRecovery");
			break;

		case "passRecovery":
			BasicUtils.Hide("userLogin");
			BasicUtils.Hide("loginFail");
			BasicUtils.Show("passRecovery", "block");
			break;

		case "cancel":
			BasicUtils.Hide("userLogin");
			BasicUtils.Hide("loginFail");
			//location.href = "/index.php";
			break;

		case "doctrine_showSitebar":
			showHideMenu("showOnly");
			BasicUtils.Hide("doctrine_ThemesColumn");
			BasicUtils.Hide("doctrine_ShowSiteBarColumn");
			BasicUtils.Show("doctrine_ShowThemesColumn");
			break;

		case "doctrine_showThemebar":
			showHideMenu("hideOnly");
			BasicUtils.Show("doctrine_ThemesColumn");
			BasicUtils.Show("doctrine_ShowSiteBarColumn");
			BasicUtils.Hide("doctrine_ShowThemesColumn");
			break;
	}
}

/**
 *
 * @access public
 * @return void
 **/
function RegisterShowHelp(what)
{
	switch(what.toLowerCase())
	{
		case "step1":

			openCenteredWindow("/registerhelp.php?what="+what, "RegisterHelpWindow", 600, 400, true, false);
		break;
	}
}



var CartWindow;

function CloseUserWindows()
{
	CartWindow = window.open("/cart.php", "CartWindow");

	if(CartWindow && !CartWindow.closed)
		CartWindow.close();
}
function userLogout()
{
	if(confirm("¿Terminar sesión en Mi Astrea?"))
	{
		SetLoaderText("Logout");
		CloseUserWindows();
		location.href="/logout.php";
	}
}

/*Funcion Cambiar el color del Texto en el Menu*/

function changeMenuColorOn(what)
{
	$(what).style.color = "#0F64D2";
}

function changeMenuColorOff(what)
{
	$(what).style.color = "#3F485D";
}

/*Function Expandir InfoLinks Div*/

function ExpandContract(what)
{
	var otherDivs = what.parentNode.parentNode.getElementsByTagName("div");
	for(var i = 0; i < otherDivs.length; i++)
	{
		if(otherDivs.item(i).className == "expandCollapse")
		{
			var j = 0;

			if(otherDivs.item(i).style.display == "none")
			{
				otherDivs.item(i).style.display = "block";
				var descriptionSpan = what.parentNode.getElementsByTagName("span");

				for(j = 0; j < descriptionSpan.length; j++)
				{
					if(descriptionSpan.item(j).className == "descriptionSpan")
						descriptionSpan.item(j).style.display = "none";
				}
			}
			else
			{
				otherDivs.item(i).style.display = "none";
				descriptionSpan = what.parentNode.getElementsByTagName("span");

				for(j = 0; j < descriptionSpan.length; j++)
				{
					if(descriptionSpan.item(j).className == "descriptionSpan")
						descriptionSpan.item(j).style.display = "block";
				}

			}

			if(what.tagName == "IMG")
			{
				switch(otherDivs.item(i).style.display)
				{
					case "none":
						what.src = IMGDIR + "expandMas.gif";
						break;
					case "block":
						what.src = IMGDIR + "expandMenos.gif";
						break;
				}
			}
			return;
		}
	}
}

/*Cookies de formato*/

/*
var DefaultOptions = "option=1|1|1|1";

function LoadCookies()
{
	var cookies = document.cookie;
	var cookiesArray = cookies.split(";");
	var LayOutOptions = "";
	for ( var i = 0; i < cookiesArray.length; i++)
	{
		if (cookiesArray[i].substr(1,6) == "option")
		{
			LayOutOptions = cookiesArray[i];
		}
	}
	if (LayOutOptions == "")
	{
		LayOutOptions = DefaultOptions;
	}
	LayOutOptions = LayOutOptions.substr(8, LayOutOptions.length-8);
	LayOutArray = LayOutOptions.split("|");
*/
	/*Sidebar*/
/*	if ($("secondaryColumn") != null)
	{
		if (LayOutArray[0] == 1)
		{
			showHideMenu("showOnly");
		}
		else
		{
			showHideMenu("hideOnly");
		}
	}

}

function ChangeCookies(index, value)
{
	var cookies = document.cookie;
	var cookiesArray = cookies.split(";");
	var LayOutOptions;
	for ( var i = 0; i < cookiesArray.length; i++)
	{
		if (cookiesArray[i].substr(1,6) == "option")
		{
			LayOutOptions = cookiesArray[i];
		}
	}
	if (LayOutOptions == "" || LayOutOptions == null)
	{
		LayOutOptions = DefaultOptions;
	}
	LayOutOptions = LayOutOptions.substr(8, LayOutOptions.length-8);
	LayOutArray = LayOutOptions.split("|");

	LayOutArray[index] = value;
	LayOutOptions = "option=";
	LayOutOptions += LayOutArray.join("|");

	document.cookie = LayOutOptions;
}
*/

/*Function Mostrar Div de Agenda*/

function showAgendaDiv()
{
	if ($("userAgenda").style.display == "none")
	{
		BasicUtils.Show("userAgenda");
		$("flechaAgenda").src = IMGDIR + "flecha_cerrar.gif";
	}
	else
	{
		BasicUtils.Hide("userAgenda");
		$("flechaAgenda").src = IMGDIR + "flecha_abrir.gif";
	}
}



/*Function Change Text Size*/

var fsize = 11;

function ChangeTextSize(sizechange)
{
	switch(sizechange)
	{
		case "Bigger":
			if (fsize != 48)
			{
				fsize += 2;
			}
			break;
		case "Smaller":
			if (fsize != 11)
			{
				fsize -= 2;
			}
			break;
	}

	$("asd").style.fontSize = fsize + "px";

}

/*Function Add Page To Favorites*/

function addBookmarkForBrowser()
{
	if(isIE())
	{
		if (document.all)
		{
			window.external.AddFavorite("http://"+SITEADDRESS, "Editorial Astrea SRL");
		}
	}
	else
	{
		alert("Presione las teclas Ctrl + D para añadir a favoritos.");
	}
}

/*Function Set Home Page*/
function setHomePage()
{
	if(isIE())
	{
		document.body.style.behavior="url(#default#homepage)";
		document.body.setHomePage("http://"+SITEADDRESS);
	}
	else
	{
		alert("Opción sólo disponible para Internet Explorer.");
	}
}

/*Function Show or Hide a Table*/
function showHideDivNewApp(whatDiv, whatTbl)
{
	var i;
	var divs;
	var tables;

	divs = $("novedadesDiv").getElementsByTagName("div");
	for (i=0; i<divs.length; i++)
	{
		divs.item(i).className = "tabsStyle_DivUnselected";
	}
	$(whatDiv).className = "tabsStyle_DivSelected";

	tables = $("novedadesTbls").getElementsByTagName("table");

	for (i=0; i<tables.length; i++)
	{
		tables.item(i).style.display = "none";
	}
}
function showHideAboutUs(what)
{
	switch(what)
	{
		case "aboutus":

		if ($("aboutusDiv").style.display == "none")
		{
			BasicUtils.Show("aboutusDiv");
			BasicUtils.Hide("organizationDiv");
			$("aboutus").className = "tabsStyle_DivSelected";
			$("organization").className = "tabsStyle_DivUnselected";
			//showHideMenu("showOnly");
		}
		break;

		case "organization":

		if ($("organizationDiv").style.display == "none")
		{
			BasicUtils.Show("organizationDiv");
			BasicUtils.Hide("aboutusDiv");
			$("aboutus").className = "tabsStyle_DivUnselected";
			$("organization").className = "tabsStyle_DivSelected";
			//showHideMenu("showOnly");
		}
		break;
	}
}
function showHideDiv(what)
{
	switch(what)
	{

		case "Estandar":

		if ($("divSearchEstandar").style.display == "none")
		{
			BasicUtils.Show("divSearchEstandar");
			$("DivEstandar").className = "tabsStyle_DivSelected";
			$("DivAvanzado").className = "tabsStyle_DivUnselected";
			$("DivAutores").className = "tabsStyle_DivUnselected";
			//$("DivIndice").className = "tabsStyle_DivUnselected";
			BasicUtils.Hide("divSearchAdvanced");
			BasicUtils.Hide("divSearchAuthor");
			BasicUtils.Show("divSearchIncludeResultTitle");
			BasicUtils.Show("divSearchIncludeResultContent");
			BasicUtils.Show("divSearchFormButtons");
			//BasicUtils.Hide("divSearchIndex");
			$("searchType").value = "standard";
			showHideMenu("showOnly");
		}
		break;

		case "Advanced":

		if ($("divSearchAdvanced").style.display == "none")
		{
			BasicUtils.Show("divSearchAdvanced");
			$("DivEstandar").className = "tabsStyle_DivUnselected";
			$("DivAvanzado").className = "tabsStyle_DivSelected";
			$("DivAutores").className = "tabsStyle_DivUnselected";
			//$("DivIndice").className = "tabsStyle_DivUnselected";
			BasicUtils.Hide("divSearchEstandar");
			BasicUtils.Hide("divSearchAuthor");
			BasicUtils.Show("divSearchIncludeResultTitle");
			BasicUtils.Show("divSearchIncludeResultContent");
			BasicUtils.Show("divSearchFormButtons");
			//BasicUtils.Hide("divSearchIndex");
			$("searchType").value = "advanced";
			showHideMenu("showOnly");
		}
		break;

		case "Authors":

		if ($("divSearchAuthor").style.display == "none")
		{
			BasicUtils.Show("divSearchAuthor");
			$("DivEstandar").className = "tabsStyle_DivUnselected";
			$("DivAvanzado").className = "tabsStyle_DivUnselected";
			$("DivAutores").className = "tabsStyle_DivSelected";
			//$("DivIndice").className = "tabsStyle_DivUnselected";
			BasicUtils.Hide("divSearchEstandar");
			BasicUtils.Hide("divSearchAdvanced");
			BasicUtils.Hide("divSearchIncludeResultTitle");
			BasicUtils.Hide("divSearchIncludeResultContent");
			BasicUtils.Hide("divSearchFormButtons");
			//BasicUtils.Hide("divSearchIndex");
			$("searchType").value = "authors";
			showHideMenu("showOnly");
		}
		break;

		case "DoctrineStandar":

		if ($("divDoctrineStandar").style.display == "none")
		{
			BasicUtils.Show("divDoctrineStandar");
			BasicUtils.Hide("divDoctrineThemes");
			$("divThemes").className = "tabsStyle_DivUnselected";
			$("divStandar").className = "tabsStyle_DivSelected";
			showHideMenu("showOnly");
		}
		break;

		case "DoctrineThemes":

		if ($("divDoctrineThemes").style.display == "none")
		{
			BasicUtils.Show("divDoctrineThemes");
			BasicUtils.Hide("divDoctrineStandar");
			BasicUtils.Show("doctrine_ThemesColumn");
			BasicUtils.Hide("secondaryColumn");
			$("divStandar").className = "tabsStyle_DivUnselected";
			$("divThemes").className = "tabsStyle_DivSelected";
		}
		break;

		/*case "Index":

		if ($("divSearchIndex").style.display == "none")
		{
			BasicUtils.Show("divSearchIndex");
			$("DivEstandar").className = "tabsStyle_DivUnselected";
			$("DivAvanzado").className = "tabsStyle_DivUnselected";
			$("DivAutores").className = "tabsStyle_DivUnselected";
			$("DivIndice").className = "tabsStyle_DivSelected";
			BasicUtils.Hide("divSearchEstandar");
			BasicUtils.Hide("divSearchAdvanced");
			BasicUtils.Hide("divSearchIncludeResultTitle");
			BasicUtils.Hide("divSearchIncludeResultContent");
			BasicUtils.Hide("divSearchFormButtons");
			BasicUtils.Hide("divSearchAuthor");
			$("searchType").value = "index";
			showHideMenu("showOnly");
		}
		break;*/
	}
}

/*Funcion Mostrar/Ocultar Articulos de doctrina*/

function ShowHideDoctrine(what)
{
	if($(what).style.display == "none")
	{
		BasicUtils.Show(what);
	}
	else
	{
		BasicUtils.Hide(what);
	}
}

/*Terminos y condiciones*/

function termsAccepted()
{
	if($("register_AcceptButton").disabled)
	{
		$("register_AcceptButton").className = "globalInputButton";
		$("register_AcceptButton").disabled = false;
		BasicUtils.Hide("step5_reminderDiv");
	}
	else
	{
		$("register_AcceptButton").className = "register_AcceptButtonOff";
		$("register_AcceptButton").disabled = true;
		BasicUtils.Show("step5_reminderDiv");
	}
}

function checkBorndateCase(what)
{
	switch(what)
	{
		case "Day":

			if ($("day").value >= 30)
			{
				$("month_option_Febrero").disabled = true;
			}
			else
			{
				$("month_option_Febrero").disabled = false;
			}
		break;

		case "Month":

			if ($("month").value == "Febrero")
			{
				$("day_option_30").disabled = true;
				$("day_option_31").disabled = true;
			}
			else
			{
				$("day_option_30").disabled = false;
				$("day_option_31").disabled = false;
			}
		break;
	}
}
/**
 *
 * @access public
 * @return void
 **/
function checkPurchaseCase(what)
{
	switch(what)
	{
		case "tarjetas":
			$("creditcards_option_Seleccione").disabled = true;
		break;

		case "month":
			$("CCmonth_option_Mes").disabled = true;
		break;

		case "year":
			$("CCyear_option_Año").disabled = true;
		break;
	}
}

function checkAvailability()
{
	if($("username").value.length < 3)
	{
		alert("El nombre de usuario debe tener al menos tres caracteres.");
	}
	else
	{
		var username = $("username").value;
		var firstname = $("firstname").value;
		var lastname = $("lastname").value;
		var email = $("email").value;
		var phone = $("phone").value;
		var fax = $("fax").value;
		var documenttype = $("documenttype").value;
		var documentnumber = $("documentnumber").value;
		var day = $("day").value;
		var month = $("month").value;
		var year = $("year").value;
		var address = $("address").value;
		var city = $("city").value;
		var zipcode = $("zipcode").value;
		var country = $("country").value;

		if(country == "Argentina")
		{
			var state = $("stateAR").value;
		}
		else
		{
			var state = $("stateOther").value;
		}

		var job = $("job").value;
		var gender = $("gender").value;

		if(country == "Brasil")
		{
			var brasilcuit = $("brasilcuit").value;
		}

		var infoother = $("infoother").value;

		window.location="/registerdata.php?username="+username+"&firstname="+firstname+"&lastname="+lastname
		+"&email="+email+"&phone="+phone+"&fax="+fax+"&documenttype="+documenttype+"&documentnumber="+documentnumber
		+"&day="+day+"&month="+month+"&year="+year+"&address="+address+"&city="+city+"&zipcode="+zipcode
		+"&country="+country+"&state="+state+"&gender="+gender+"&brasilcuit="+brasilcuit+"&job="+job+"&infoother="+infoother;
	}
}

function AdditionalInfoSelectAll()
{
	inputs = $("register_aditionalInfoMain").getElementsByTagName("input");

	if(inputs.item(i).checked = false)
	{
		for (i=0; i<inputs.length; i++)
		{
			inputs.item(i).checked = true;
		}
	}
	else
	{
		inputs.item(i).checked = false;
	}
}
/*Function Change Pass*/
function changePass()
{
	if($("oldPassword").value.length < 6)
	{
		alert("La contraseña actual debe contener al menos tres caracteres.");
	}
	else if((document.RegisterForm.newPassword.value.length < 6) || (document.RegisterForm.newPassword.value.length >14) || (document.RegisterForm.newPassword.value != document.RegisterForm.newPassword2.value) || (document.RegisterForm.newPassword.value === ""))
	{
		alert("La contraseña nueva es incorrecta. Compruebe que los datos ingresados sean correctos y vuelva a intentarlo. Si el problema persiste póngase en contacto con el administrador.");
	}
	else
	{
		openCenteredWindow("/changepassconfirmation.php", "PassConfirm", 400, 200, false, false);
	}
}

/* Funcion para controlar que el campo del mail no esta vacio en Recuperar Contraseña*/
function checkRecoveryPassMailEntry()
{
	
}

/* Funcion para recuperar contraseña */
function PasswordRecovery(email)
{
	email = $("user_passRecoveryMailInput").value;
	
	if($SE(email))
	{
		alert("Ingrese una dirección de mail válida");
		return false;
	}
	else
		openCenteredWindow("https://"+SITEADDRESS+"/passwordrecovery.php?email="+email, "PassConfirm", 400, 200, false, false);
}

/*Function Tell a Friend*/

function popUp_tell_A_Friend()
{
	openCenteredWindow("/tafmail.php", "TafWindow", 400, 380, true, true);
}
function addPlugin()
{
	openCenteredWindow("/plugin.php", "PluginWindow", 600, 550, true, true);
}
function openUserMessages(what)
{
	openCenteredWindow("/usermail.php", "UserMailWindow", 800, 600, false, false);
}

/*Function Cart*/
function cartDisplay()
{
	openCenteredWindow("/cart.php", "CartWindow", 800, 400, true, true);
}
function addToCart(code)
{
	var CartWindow;

	CartWindow = openCenteredWindow("/cart.php?code="+code, "CartWindow", 800, 400, true, true);
	if(CartWindow)
	{
		CartWindow.focus();
	}
}
function cartSessionRequired()
{
	alert("Debe iniciar su sesión para continuar con la compra");
}


function showOldPurchases()
{
	openCenteredWindow("/oldpurchases.php?iscase='oldpurchases'", "OldPurchasesWindow", 790, 400, true, true);
}

function showShippingStatus()
{
	openCenteredWindow("/shippingstatus.php", "ShippingStatusWindow", 800, 600, true, true);
}

function showFaxOrder(orderid)
{
	var orderid = orderid;
	openCenteredWindow("https://"+SITEADDRESS+"/faxorder.php?orderid="+orderid, "FaxOrderWindow", 800, 600, true, true);
}

function OpenLoginWindow(from, articleCode)
{
	if(from)
	{
		switch(from)
		{
			case "fromCart":
				openCenteredWindow("https://"+SITEADDRESS+"/login.php?whatCase="+whatCase, "LoginWindow", 300, 250, true, false);
				break;

			case "doctrine":
				openCenteredWindow("https://"+SITEADDRESS+"/login.php?from="+from+"&articleCode="+articleCode, "LoginWindow", 300, 250, true, false);
				break;
		}
	}
	else
		openCenteredWindow("https://"+SITEADDRESS+"/login.php", "LoginWindow", 300, 250, false, false);
}

function OpenUserDataRecoveryWindow()
{
	openCenteredWindow("https://"+SITEADDRESS+"/userdatarecovery.php", "UserDataRecoveryWindow", 300, 150, false, false);
}

function OpenFDLMap()
{
	openCenteredWindow("http://"+SITEADDRESS+"/fdlmap.php", "FDLMap", 740, 1133, false, false);
}

function OpenFDLPage()
{
	window.open("http://www.el-libro.org.ar");
}

function OpenAdobePage()
{
	window.open("http://get.adobe.com/es/reader/");
}

/*Function Reservation*/
function makeReservation(code)
{
	openCenteredWindow("/reservation.php?code="+code, "ReservWindow", 800, 400, true, true);
}

function OpenVacationWindow()
{
	openCenteredWindow("/popupvacation.php", "PopoupVacation", 400, 300, true, true);
}

/*Function change CartImage and Add to cart*/
function addToCartImage(what)
{
	switch(what)
	{
		case "Hover":

			$("boton_addtocart").src = IMGDIR + "boton_addtocartHover.gif";
			break;

		case "Out":

			$("boton_addtocart").src = IMGDIR + "boton_addtocart.gif";
			break;
	}
}

function userData(what, isFromPurchase)
{
	switch(what.toLowerCase())
	{
		case "userregistration":

			openCenteredWindow("https://"+SITEADDRESS+"/registerdata.php", "UserRegwindow", 800, 600, true, true);
		break;

		case "modifypersonaldata":

			if(isFromPurchase == "fromPurchase")
			{
				openCenteredWindow("https://"+SITEADDRESS+"/modifypersonaldata.php?purchaseCase=purchaseCase", "UserModifywindow", 800, 600, true, true);
			}
			else
			{
				openCenteredWindow("https://"+SITEADDRESS+"/modifypersonaldata.php", "UserModifywindow", 800, 600, true, true);
			}
		break;

		case "modifycompanydata":

			if(isFromPurchase == "fromPurchase")
			{
				openCenteredWindow("https://"+SITEADDRESS+"/modifycompanydata.php?purchaseCase=purchaseCase", "UserModifywindow", 800, 600, true, true);
			}
			else
			{
				openCenteredWindow("https://"+SITEADDRESS+"/modifycompanydata.php", "UserModifywindow", 800, 600, true, true);
			}
		break;

		case "changepassword":

			openCenteredWindow("https://"+SITEADDRESS+"/changepass.php", "changePassWindow", 400, 280, false, false);
		break;
	}

}

/*Function Other Resources*/

function OtherResources(what)
{
	var newWindow;

	newWindow = openCenteredWindow(what, "newWindow", 800, 600, true, true);
	newWindow.focus();
}

/*Function Check Invalid Fields*/

function samePass()
{
	if ((document.RegisterForm.password.value.length < 6) || (document.RegisterForm.password.value.length >14) || (document.RegisterForm.password.value != document.RegisterForm.password2.value) || (document.RegisterForm.password.value === ""))
	{
		$("passwordsCheck").src = IMGDIR + "checkFail.gif";
		$("passwordsCheck").title = "Las contraseñas no coinciden";
		$("passwordsCheck").alt = "Las contraseñas no coinciden";
	}
	else
	{
		$("passwordsCheck").src = IMGDIR + "checkOk.gif";
		$("passwordsCheck").title = "Las contraseñas coinciden correctamente";
		$("passwordsCheck").alt = "Las contraseñas coinciden correctamente";
	}
}

function changePassAllowed()
{
	if ((document.RegisterForm.newPassword.value.length < 6) || (document.RegisterForm.newPassword.value.length >14) || (document.RegisterForm.newPassword.value != document.RegisterForm.newPassword2.value) || ($SE(document.RegisterForm.newPassword.value)))
	{
		$("passwordsCheck").src = IMGDIR + "checkFail.gif";
		$("passwordsCheck").title = "Las contraseñas no coinciden";
		$("passwordsCheck").alt = "Las contraseñas no coinciden";
		$("miastrea_ChangePassButton").className = "register_AcceptButtonOff";
		$("miastrea_ChangePassButton").disabled = true;
	}
	else
	{
		$("passwordsCheck").src = IMGDIR + "checkOk.gif";
		$("passwordsCheck").title = "Las contraseñas coinciden correctamente";
		$("passwordsCheck").alt = "Las contraseñas coinciden correctamente";
		$("miastrea_ChangePassButton").className = "globalInputButton";
		$("miastrea_ChangePassButton").disabled = false;
	}
}

function check_ChangePass_entry()
{
	var inputs = $("changePass_FormDiv").getElementsByTagName("input");
	var labels = $("changePass_FormDiv").getElementsByTagName("label");

	for(var i=0;i<inputs.length;i++)
	{
		if(inputs[i].value.length < 1)
		{
			alert("El campo \""+labels[i].innerHTML+"\" es obligatorio");
			return false;
		}
	}
	if($("newpassword").value.length < 6)
	{
		alert("La nueva contraseña no puede ser menor a 6 dígitos");
		return false;
	}
	else if($("newpassword").value != $("newpassword2").value)
	{
		alert("Las contraseñas no coinciden");
		return false;
	}
	else if($("newpassword").value == $("oldpassword").value)
	{
		alert("Debe ingresar una contraseña diferente de la anterior");
		return false;
	}
}

function check_RegisterData_entry()
{
	if ($("username").value.length < 3)
	{
		alert("El nombre de usuario debe contener al menos tres caracteres.");
		return false;
	}
	else if ($("password").value.length < 6 || $("password").value.length > 14 || $("password").value != $("password2").value)
	{
		alert("La contraseña es incorrecta. Compruebe que ambas sean idénticas y que contengan al menos seis caracteres");
		return false;
	}

	if($("country").value == "Argentina")
		state = "stateAR";
	else
		state = "stateOther";

	if($("country").value == "Brasil" && $("brasilcuit").value.length < 3)
	{
		alert("Debe ingresar un número de CNPJ/CPF");
		return false;
	}

	var inputs = new Array();
	var labelsArray;
	var i;

	inputs.AddRange($("register_Step2_Div").getElementsByTagName("input"));
	inputs.AddRange($("register_Step2_Div").getElementsByTagName("select"));

	labelsArray = ["firstname", "lastname", "email", "phone", "documenttype", "documentnumber", "day", "month", "year", "address", "city", "zipcode", "country", state];

	for(i=0;i<inputs.length;i++)
	{
		if(inputs[i].tagName == "INPUT" && inputs[i].value.length < 3 && labelsArray.isInto(inputs[i].id))
		{
			alert("El campo \""+GetLabelFor(inputs[i]).innerHTML+"\" es obligatorio");
			return false;
		}
		else if(inputs[i].selectedIndex === 0 && labelsArray.isInto(inputs[i].id))
		{
			alert("El campo \""+GetLabelFor(inputs[i]).innerHTML+"\" es obligatorio");
			return false;
		}
	}
	return true;
}

function check_ModifyPersonalData_entry()
{
	var inputs = new Array();
	var labels;
	var labelsArray;
	var i;

	inputs.AddRange($("miastrea_Step2_Div").getElementsByTagName("input"));
	inputs.AddRange($("miastrea_Step2_Div").getElementsByTagName("select"));

	if($("country").value == "AR")
	{
		state = "stateAR";
	}
	else
	{
		state = "stateOther";
	}

	if($("country").value == "BR" && $("brasilcuit").value.length < 3)
	{
		alert("Debe ingresar un número de CNPJ/CPF");
		return false;
	}

	labelsArray = ["firstname", "lastname", "email", "phone", "documenttype", "documentnumber", "day", "month", "year", "address", "city", "zipcode", "country", state];

	for(i=0; i<inputs.length; i++)
	{
		if(inputs[i].tagName == "INPUT" && inputs[i].value.length < 3 && labelsArray.isInto(inputs[i].id))
		{
			alert("El campo \""+GetLabelFor(inputs[i]).innerHTML+"\" es obligatorio");
			return false;
		}
		else if(inputs[i].selectedIndex === 0 && labelsArray.isInto(inputs[i].id))
		{
			alert("El campo \""+GetLabelFor(inputs[i]).innerHTML+"\" es obligatorio");
			return false;
		}
	}
	return true;
}

function check_ModifyCompanyData_entry()
{
	var inputs = new Array();
	var labels;
	var labelsArray;
	var i;

	inputs.AddRange($("miastrea_Step3_Div").getElementsByTagName("input"));
	inputs.AddRange($("miastrea_Step3_Div").getElementsByTagName("select"));

	//labels = $("ModifyDataForm").getElementsByTagName("label");

	if($("country2").value == "Argentina")
	{
		state2 = "stateAR2";
	}
	else
	{
		state2 = "stateOther2";
	}

	labelsArray = ["companyname", ivacondition, "cuit", "phone2", "address2", "city2", "zipcode2", "country2", state2];

	for(i=0; i<inputs.length; i++)
	{
		if(inputs[i].tagName == "INPUT" && inputs[i].value.length < 3 && labelsArray.isInto(inputs[i].id))
		{
			alert("El campo \""+GetLabelFor(inputs[i]).innerHTML+"\" es obligatorio");
			return false;
		}
		else if(inputs[i].tagName == "SELECT" && inputs[i].selectedIndex === 0 && labelsArray.isInto(inputs[i].id))
		{
			alert("El campo \""+GetLabelFor(inputs[i]).innerHTML+"\" es obligatorio");
			return false;
		}
	}
	return true;
}


function purchase_check_step1()
{
	if($("purchase_shippingChoiceMain").style.display == "block")
	{
		if(!$("purchase_radioCA").checked && !$("purchase_radioFX").checked)
		{
			alert("Seleccione una empresa de correo para el envío de su pedido.");
			return false;
		}
	}
	if(!$("purchase_radioCC").checked && !$("purchase_radioCR").checked && !$("purchase_radioFax").checked && !$("purchase_radioPhone").checked)
	{
		alert("Debe seleccionar un modo de pago");
		return false;
	}
	else
	{
		if($("purchase_radioCC").checked)
		{
			var i;
			var labels;
			var inputs = new Array();
			var labelsArray;

			labels = $("purchase_CCMain").getElementsByTagName("label");
			inputs.AddRange($("purchase_CCMain").getElementsByTagName("input"));
			inputs.AddRange($("purchase_CCMain").getElementsByTagName("select"));

			labelsArray = ["creditcards", "CCnumber", "CCmonth", "CCyear", "CCsecuritycode"];

			for(i=0; i<inputs.length; i++)
			{
				if(inputs[i].tagName == "INPUT" && inputs[i].value.length < 1 && labelsArray.isInto(inputs[i].id))
				{
					alert("El campo \""+GetLabelFor(inputs[i]).innerHTML+"\" es obligatorio");
					return false;
				}
				else if(inputs[i].selectedIndex === 0 && labelsArray.isInto(inputs[i].id))
				{
					alert("El campo \""+GetLabelFor(inputs[i]).innerHTML+"\" es obligatorio");
					return false;
				}
			}
		}
		return true;
	}
}


function PopUpComplete(fromWhat, articleCode)
{
	switch(fromWhat)
	{
		case "fromCart":
			ReloadAllOpeners(window);
			openOrderWindow();
			window.opener.close();
			window.close();
		break;

		case "fromDoctrine":
			ReloadAllOpeners(window);
			SwitchToOtherResources("http://"+SITEADDRESS+'/frames.php?what=/files/articles/'+articleCode+'.pdf');

		break;

		case "fromPurchase":
			ReloadAllOpeners(window);
			window.close();
		break;

		default:
			window.close();
		break;
	}
}

function SwitchToOtherResources(what)
{
	window.location.href = what;
	ResizeAndCenter(800, 600);
	BasicUtils.ShowScrollbars(true);
}
function ReloadMain()
{
	alert("ASD");
	window.opener.reload();
}

function ReloadAllOpeners(win)
{
	if (win.opener)
	{
		try 
		{
			win.opener.ReloadWindow();
			ReloadAllOpeners(win.opener);
		}
		catch (ex)
		{
			;
		}
	}
}

function ReloadWindow()
{
	location.reload(true);
}

function CheckInputsLength(FormToCheck, RequiredLength, OnlyOne)
{
	var i;
	FormToCheck = $(FormToCheck);
	var Inputs = Form.getInputs(FormToCheck, "text");

	for (i=0;i<Inputs.length;i++)
	{
		if (OnlyOne)
		{
			if (Inputs[i].type == "text" && Inputs[i].value.length >= RequiredLength)
			{
				return true;
			}
		}
		else
		{
			if (Inputs[i].type == "text" && Inputs[i].value.length < RequiredLength)
			{
				return false;
			}
		}
	}
	return !OnlyOne;
}

function check_reserve_entry()
{
	var inputs = document.getElementById("formReserve").getElementsByTagName("input");
	
	for(var i=0;i<inputs.length;i++)
	{
		if($F(inputs[i]).length < 3)
		{
			alert("Debe completar todos los campos antes de continuar");
			return false;
		}
	}
	if($F("email") != $F("email2"))
	{
		alert("Las direcciones de mail deben ser iguales");
		return false;
	}
	if (!$F("email").IsMail())
	{
		alert("La dirección de email ingresada es incorrecta");
		return false;
	}
	return true;
}

function check_correct_entry()
{
	var selects;
	var i;

	if ($("searchType").value == "standard")
	{
		if ( !CheckInputsLength("formSearch", 3, true) )
		{
			alert("Debe ingresar al menos tres caracteres en alguno de los campos");
			return false;
		}
		else
		{
			ShowLoader();
		}
	}
	else if ($("searchType").value == "advanced")
	{
		var datacheck = new Array(
							$("chkbox_titulo").checked,
							$("chkbox_temas_principales").checked, 
							$("chkbox_preliminares").checked,
							$("chkbox_subtitulo1").checked,
							$("chkbox_resumenes").checked,
							$("chkbox_indice").checked,
							$("chkbox_coleccion").checked,
							$("chkbox_comentarios").checked,
							$("chkbox_todas").checked
								);
		
		if ($("palabras_claves").value.length < 3)
		{
			alert("Debe ingresar al menos tres caracteres en \"Palabras claves\"");
			return false;
		}
		else if (!CheckArrayForTrue(datacheck))
		{
			alert("Debe seleccionar algún campo en donde realizar la búsqueda.");
			return false;
		}
		ShowLoader();
	}
	else if ($("searchType").value == "doctrine")
	{
		if ( !CheckInputsLength("formDoctrineSearch", 3, true) )
		{
			alert("Debe ingresar al menos tres caracteres en alguno de los campos");
			return false;
		}
		else
		{
			ShowLoader();
		}
	}
}

function CheckArrayForTrue(vararray)
{
	for (var i=0;i<vararray.length;i++)
	{
		if (vararray[i])
			return true;
	}
	return false;
}

/*Funcion Check del TAF*/

function check_Taf_correct_entry()
{
	if (!CheckInputsLength("tafForm", 3, true))
	{
		alert("Debe ingresar al menos tres caracteres en los campos requeridos");
		return false;
	}
	else
	{
		return true;
	}

}

/*Ex login_check_correct_entry*/

function DoLogin()
{
	if ($SE($("userid").value))
	{
		alert("Debe ingresar un nombre de usuario válido.");
	}
	else if ($SE($("passid").value))
	{
		alert("Debe ingresar una contraseña válida.");
	}
	else
	{
		LogUser = new LoginClass();
		LogUser.Login($F("userid"), $F("passid"), $("userRemindMe").checked ? "yes" : "no");
	}
}

function loginCheckEntry(whatCase, articleCode)
{
	if ($SE($("userid").value))
	{
		alert("Debe ingresar un nombre de usuario válido.");
		return false;
	}
	else if ($SE($("passid").value))
	{
		alert("Debe ingresar una contraseña válida.");
		return false;
	}
	else
	{
		Login = new LoginClass();
		switch(whatCase)
		{
			case "fromCart":
				Login.LoginFromCart($F("userid"), $F("passid"), $("userRemindMe").checked ? "yes" : "no");
				break;
			case "fromDoctrine":
				Login.LoginFromDoctrine($F("userid"), $F("passid"), $("userRemindMe").checked ? "yes" : "no", articleCode);
				break;
			default:
				window.close();
				break;
		}
	}
}


function ChangeBindingRel(to, from, fromName, RimageDiv, EimageDiv)
{
	$('bookBinding'+from).innerHTML = fromName;
	$('priceContainer'+from).style.display = "inline";

	if ($("cover_"+RimageDiv))
	{
		if($("cover_"+RimageDiv).style.display == "none")
		{
			BasicUtils.Show("cover_"+RimageDiv);
			BasicUtils.Hide("cover_"+EimageDiv);
		}
		else
		{
			BasicUtils.Hide("cover_"+RimageDiv);
			BasicUtils.Show("cover_"+EimageDiv);
		}
	}
	BasicUtils.Hide('priceContainer'+to);
	if (fromName == 'R&uacute;stica' || fromName == "Rústica")
	{
		$('bookBinding'+to).innerHTML = "<a href=\"/book/"+to+"\" onclick=\"javascript:ChangeBindingRel('"+from+"', '"+to+"', 'Encuadernada', '"+RimageDiv+"', '"+EimageDiv+"'); return false;\">Encuadernada</a>";
	}
	else
	{
		$('bookBinding'+to).innerHTML = "<a href=\"/book/"+to+"\" onclick=\"javascript:ChangeBindingRel('"+from+"', '"+to+"', 'R&uacute;stica', '"+RimageDiv+"', '"+EimageDiv+"'); return false;\">R&uacute;stica</a>";
	}
}

function CartSelectAll(what)
{
	switch(what)
	{
		case "check":
			var items = document.getElementsByTagName("input");
			for (var i=0; i<items.length;i++)
			{
				if(items[i].type == "checkbox")
				{
					items[i].checked = true;
				}
			}
		break;

		case "uncheck":
			var items = document.getElementsByTagName("input");
			for (var i=0; i<items.length;i++)
			{
				if(items[i].type == "checkbox")
					items[i].checked = false;
			}
		break;
	}
}

function SearchSelectAll(evt)
{
	var elem;
	elem = EventUtil.getElement(evt);
	
	var i;

	var checkBoxes = new Array(
		'chkbox_titulo',
		'chkbox_temas_principales',
		'chkbox_preliminares',
		'chkbox_subtitulo1',
		'chkbox_resumenes',
		'chkbox_indice',
		'chkbox_coleccion',
		'chkbox_comentarios',
		'chkbox_todas'
	)
	
	if (elem.id == 'chkbox_todas')
	{

		for (i = 0; i < checkBoxes.length; i++)
		{
			if(!checkBoxes[i]!='chkbox_todas')
			{
				$(checkBoxes[i]).checked = $('chkbox_todas').checked;
			}
		}
	}
	else if (checkBoxes.isInto(elem.id))
	{
		if ( $('chkbox_todas').checked && !$(elem.id).checked )
		{
			$('chkbox_todas').checked = false;
		}

		var check = true;
		for (i = 0; i < checkBoxes.length; i++)
		{
			if(!$(checkBoxes[i]).checked && checkBoxes[i]!='chkbox_todas')
			{
				check = false;
			}
		}
		if (check)
		{
			$('chkbox_todas').checked = true;
		}

	}

}

/*Abrir currículum*/
function openResume(cv, author)
{
	openCenteredWindow("/viewresume.php?resume="+cv+"&author="+author, "Resume", 640, 480, true, true);
}

/*Abrir la ventana con la orden de compra*/
function openOrderWindow()
{
	return openCenteredWindow("https://"+SITEADDRESS+"/order.php", "OrderWindow", 800, 600, true, true);
}

/*Terminos y Condiciones*/

function TermsAndCondition()
{
	openCenteredWindow("/termsconditions.php", "TCwindow", 800, 400, true, false);
}

/*FAQ*/
function faq()
{
	openCenteredWindow("/faq.php", "FAQwindow", 800, 400, true, false);
}

/*Libro de quejas y sugerencias*/
function complainsBook()
{
	openCenteredWindow("/complainsbook.php", "ComplainsBookwindow", 800, 600, true, true);
}

function check_complainform()
{
	if($SE($("name").value) || $SE($("email").value) || $SE($("complain").value))
	{
		alert("Por favor, complete los campos requeridos");
		return false;
	}
	else if(!$F("email").IsMail())
	{
		alert("Por favor, ingrese una dirección de e-mail válida");
		return false;
	}
	else
	{
		return true;
	}
}



/*Envíos y forma de pago*/
function shipping()
{
	var TopDif = screen.height/2-200;
	var LeftDif = screen.width/2-400;

	Deliverwindow = window.open("/shiping.php", "Deliverwindow", "location=0, status=0, scrollbars, resizable, width=800, height=400, left=" + LeftDif + ", top=" + TopDif);
}

/* Venta de costos de envio */
function OpenShippingCosts()
{
	openCenteredWindow("/enviosalext.htm", "ShippingCosts", 800, 600, true, true);
}


/*Control de formularios: Envío de mail*/
function SendMail()
{
	var Name;
	var LastName;
	var SendTo;
	var Subject;
	var Company;
	var TextBody;

	if (document.formulario.asunto.value=="")
		{
			alert ("Por favor, complete todos los campos");
			return false;
		}
	if (document.formulario.nombre.value=="")
		{
			alert ("Por favor, complete todos los campos");
			return false;
		}
	if (document.formulario.apellido.value=="")
		{
			alert ("Por favor, complete todos los campos");
			return false;
		}
	if (document.formulario.empresa.value=="")
		{
			alert ("Por favor, complete todos los campos");
			return false;
		}
	if (document.formulario.cuerpo.value=="")
		{
			alert ("Por favor, complete todos los campos");
			return false;
		}

	switch (document.formulario.enviara.selectedIndex)
	{
		case 0:
			SendTo = "info@astrea.com.ar";
			break;
		case 1:
			SendTo = "ventas@astrea.com.ar";
			break;
		case 2:
			SendTo = "exterior@astrea.com.ar";
			break;
		case 3:
			SendTo = "administracion@astrea.com.ar";
			break;
		case 4:
			SendTo = "produccion@astrea.com.ar";
			break;
	}

	Subject = document.formulario.asunto.value;
	Name = document.formulario.nombre.value;
	LastName = document.formulario.apellido.value;
	Company = document.formulario.empresa.value;
	TextBody = document.formulario.cuerpo.value;

	var MailBody;
	MailBody =  "Nombre: " + Name + "%0A";
	MailBody += "Apellido: " + LastName + "%0A";
	MailBody += "Empresa: " + Company + "%0A";
	MailBody += "Mensaje: " + TextBody;
	location.href ="mailto:" + SendTo + "?subject=" + Subject + "&body="+ MailBody;
	return false;
}

/*Centro de Atención Online*/
function caoHelpButtons(what)
{
	switch(what)
	{
		case "OnlineHelp":

			alert("Esta opción se encuentra deshabilitada momentáneamente.");
		break;

		case "ContactUs":

			var TopDif = screen.height/2-210;
			var LeftDif = screen.width/2-200;

			openCenteredWindow("/contactuspopup.php", "ContactWindow", 400, 420, false, false);
		break;

		case "Email":

			location.href ="mailto:info@astrea.com.ar";
		break;
	}
}

/*Detección de la resolución de pantalla*/
function DetectScreenResolution()
{
	var TopDif = screen.height/2-250;
	var LeftDif = screen.width/2-250;

	testWind = window.open("/testWind.php", "testWind", "location=0, status=0, width=500, height=500, left=" + LeftDif + ", top=" + TopDif);
}
function FixResolutionOnSearch()
{
	var wWidth = screen.width;
	var i;

	if(wWidth == "800")
	{
		try
		{
			if ($("search_advancedOptionsDiv"))
				$("search_advancedOptionsDiv").className = "search_advancedOptionsDivRS1";
			if ($("search_incResultsOptionsDiv"))
				$("search_incResultsOptionsDiv").className = "search_incResultsOptionsDivRS1";
		}
		catch (ex)
		{

		}
	}
	else if(wWidth == "1024")
	{
		try
		{
			if($("search_advancedOptionsDiv"))
				$("search_advancedOptionsDiv").className = "search_advancedOptionsDivRS2";
			if($("search_incResultsOptionsDiv"))
				$("search_incResultsOptionsDiv").className = "search_incResultsOptionsDivRS2";
			if($("Sitebar"))
				$("Sitebar").style.width = "290px";

			sitebarimages = $C("Sitebar", "Collapse");

			for (i = 0; i < sitebarimages.length; i++)
				sitebarimages[i].style.left = "270px";

			sitebarimages = $C("Sitebar", "Expand");

			for (i = 0; i < sitebarimages.length; i++)
				sitebarimages[i].style.left = "270px";
		}
		catch (ex)
		{

		}
	}
	else
	{
		try
		{
			if($("search_advancedOptionsDiv"))
				$("search_advancedOptionsDiv").className = "search_advancedOptionsDivRS3";
			if($("search_incResultsOptionsDiv"))
				$("search_incResultsOptionsDiv").className = "search_incResultsOptionsDivRS3";
			if($("Sitebar"))
				$("Sitebar").style.width = "290px";

			sitebarimages = $C("Sitebar", "Collapse");

			for (i = 0; i < sitebarimages.length; i++)
				sitebarimages[i].style.left = "270px";

			sitebarimages = $C("Sitebar", "Expand");

			for (i = 0; i < sitebarimages.length; i++)
				sitebarimages[i].style.left = "270px";
		}
		catch (ex)
		{

		}
	}

}


/*Destacados*/
var changed = 0;
function outstandingNext(outCurrent, outLimit, timeout)
{

	if (!timeout)
		changed = 3;

	if(!changing)
	{
		if (outCurrent >= outLimit)
		{
			outNewDiv = 1;
			outOldDiv = outLimit;
		}
		else
		{
			outOldDiv = outCurrent;
			outNewDiv = outCurrent+1;
		}
		Change(outOldDiv, outNewDiv);
		AutoChangeCurrent = outNewDiv;
	}
}
function outstandingPrevious(outCurrent, outLimit, timeout)
{
	if (!timeout)
		changed = 3;

	if(!changing)
	{
		if (outCurrent <= 1)
		{
			outNewDiv = outLimit;
			outOldDiv = 1;
		}
		else
		{
			outOldDiv = outCurrent;
			outNewDiv = outCurrent-1;
		}
		Change(outOldDiv, outNewDiv);
		AutoChangeCurrent = outNewDiv;
	}
}
var AutoChangeCurrent;
var AutoChangeLimit;

function AutomaticChange()
{
	if (arguments[0] != null)
	{
		AutoChangeCurrent = arguments[0]
	}
	if (arguments[1] != null)
		AutoChangeLimit = arguments[1]

	if ( changed > 0)
	{
		--changed;
	}
	else
	{
		outstandingNext(AutoChangeCurrent, AutoChangeLimit, true);
	}
	setTimeout("AutomaticChange(null, null)", 5000);
}

var changei = 11;
var changei2 = 0;
var changing = false;
function Change(oldDiv, newDiv)
{
	CurrentOldDiv = "outstanding_"+oldDiv;
	CurrentNewDiv = "outstanding_"+newDiv;
	if (changei >= 0)
	{
		changei--;
		$(CurrentOldDiv).style.opacity = changei/10;
		setTimeout("Change("+oldDiv+", "+newDiv+")", 30);
		changing = true;
	}
	else
	{
		if (changei2 == 0)
		{
			BasicUtils.Hide(CurrentOldDiv);
			BasicUtils.Show(CurrentNewDiv);
			$(CurrentNewDiv).style.opacity = 0;
		}
		if (changei2 <= 10)
		{
			changei2++;
			$(CurrentNewDiv).style.opacity = changei2/10;
			setTimeout("Change("+oldDiv+", "+newDiv+")", 30);
		}
		else
		{
			changei = 11;
			changei2 = 0;
			changing = false;
		}
	}
}

/*Plugin Astrea*/
function pluginHandler(what)
{
	if (navigator.appName == "Netscape")
	{
		switch(what)
		{
			case "select":
				$("pluginTextArea").select();
			break;

			case "copy":
				var myRange;

				if (document.createRange)
				{
					myRange = document.createRange();
					mySelection = window.getSelection();
					mySelection.addRange(myRange);
				}
			break;
		}
	}
	else
	{
		switch(what)
		{
			case "select":
				$("pluginTextArea").select();
			break;

			case "copy":
				var code = $("pluginTextArea").value;
				clipboardData.setData("Text", code);
			break;
		}
	}
}

function HideLoader()
{
	if ($("documentRoot").style.overflow == "hidden")
		BasicUtils.ShowScrollbars(true);
	BasicUtils.Hide("loader");
	BasicUtils.Show("template_header");
	BasicUtils.Show("template_menu");
	BasicUtils.Show("template_content");
}

function ShowLoader()
{
	BasicUtils.ShowScrollbars(false);
	BasicUtils.Show("loader");
	BasicUtils.Hide("template_header");
	BasicUtils.Hide("template_menu");
	BasicUtils.Hide("template_content");

	return true;
}

/*Function Loader Text*/

function SetLoaderText(what)
{
	switch(what)
	{
		case "Search":
			$("loaderTextSpan").innerHTML="Realizando la búsqueda. Por favor aguarde unos instantes, gracias.";
			break;

		case "Register":

			$("loaderTextSpan").innerHTML="Verificando los datos ingresados. Por favor aguarde unos instantes.";
			break;
	}
}

function checkUserCompanyCountry()
{
	country = $("country2").value;

	if(country == "Argentina")
	{
		BasicUtils.Show("register_countryAR_Div2");
		BasicUtils.Hide("register_countryOTHER_Div2");
	}
	else
	{
		BasicUtils.Hide("register_countryAR_Div2");
		BasicUtils.Show("register_countryOTHER_Div2");
	}
}

function SendAdvisorMessage()
{
	var checkdata = new Array($F("name"), $F("lastname"), $F("email"), $F("message"));

	for(var i=0;i<checkdata.length;i++)
	{
		if($SE(checkdata[i]))
		{
			alert("Debe completar todos los campos solicitados");
			return false;
		}
	}
	
	openCenteredWindow("/advisorsender.php?name="+$F("name")+"&lastname="+ $F("lastname")+"&email="+$F("email")+"&message="+$F("message"), "AdvisorSender", 300, 200, true, false);
}

/**
 *
 * @access public
 * @return void
 **/
function checkUserPersonalCountry()
{
	country = $("country").value;

	if(country == "AR")
	{
		BasicUtils.Show("register_countryAR_Div");
		BasicUtils.Hide("register_countryOTHER_Div");
	}
	else
	{
		BasicUtils.Hide("register_countryAR_Div");
		BasicUtils.Show("register_countryOTHER_Div");
		$("stateOther").value = "";
	}

	if(country == "BR")
		BasicUtils.Show("brasilcuitDiv");
	else
		BasicUtils.Hide("brasilcuitDiv");
}

function checkUserCompanyState()
{
	country = $("country").value;

	if(country == "AR")
	{
		BasicUtils.Show("register_countryAR_Div");
		BasicUtils.Hide("register_countryOTHER_Div");
		$("cuit").value = null;
	}
	else
	{
		BasicUtils.Hide("register_countryAR_Div");
		BasicUtils.Show("register_countryOTHER_Div");
		$("stateOther").value = null;
	}
}

function checkPurchaseCountry()
{
	country = $("country2").value;

	if(country == "Brasil")
	{
		BasicUtils.Hide("purchase_ivaOnDiv");
		BasicUtils.Show("purchase_brasilIvaOnDiv");
	}
	else
	{
		BasicUtils.Hide("purchase_brasilIvaOnDiv");
		BasicUtils.Show("purchase_ivaOnDiv");
	}
}

function GetCookie(val)
{
	var cookies = document.cookie;
	cookies = cookies.split(";");
	for (var i = 0; i<cookies.length; i++)
	{
		cookies[i] = cookies[i].split("=");
		if (cookies[i][0] == val || cookies[i][0].replace(" ", "") == val)
		{
			return cookies[i][1];
		}
	}
}

function ChangeCartQuantity(code, quantity)
{
	window.location.href = "/cart.php?code="+code+"&quantity="+quantity;
}

function EndOrder()
{
	window.location.href = "/endorder.php";
}

function modifyPurchaseInputs(what)
{
	switch(what)
	{
		case "data1":
			inputs = $("purchase_UserData1").getElementsByTagName("input");

			for(var i=0;i<inputs.length;i++)
			{
				inputs[i].readOnly = false;
				inputs[i].className = "purchase_ModInputsOn";
			}
			BasicUtils.Hide("purchase_UserData1ModButton");
			BasicUtils.Show("purchase_UserData1AcceptModButtons");

			BasicUtils.Hide("purchase_ivaOffDiv");
			BasicUtils.Show("purchase_ivaOnDiv");
			BasicUtils.Hide("purchase_country1OffDiv");
			BasicUtils.Show("purchase_country1OnDiv");
		break;

		case "data2":
			inputs = $("purchase_UserData2").getElementsByTagName("input");

			for(var i=0;i<inputs.length;i++)
			{
				inputs[i].readOnly = false;
				inputs[i].className = "purchase_ModInputsOn";
			}
			BasicUtils.Hide("purchase_UserData2ModButton");
			BasicUtils.Show("purchase_UserData2AcceptModButtons");

			BasicUtils.Hide("purchase_dniOffDiv");
			BasicUtils.Show("purchase_dniOnDiv");
			BasicUtils.Hide("purchase_country2OffDiv");
			BasicUtils.Show("purchase_country2OnDiv");
		break;
	}
}

function modifyPurchaseCancel(what)
{
	switch(what)
	{
		case "data1":
			inputs = $("purchase_UserData1").getElementsByTagName("input");

			for(var i=0;i<inputs.length;i++)
			{
				inputs[i].readOnly = true;
				inputs[i].className = "purchase_ModInputsOff";
			}

			BasicUtils.Show("purchase_UserData1ModButton");
			BasicUtils.Hide("purchase_UserData1AcceptModButtons");

			BasicUtils.Show("purchase_ivaOffDiv");
			BasicUtils.Hide("purchase_ivaOnDiv");
			BasicUtils.Show("purchase_country1OffDiv");
			BasicUtils.Hide("purchase_country1OnDiv");
			break;

		case "data2":
			inputs = $("purchase_UserData2").getElementsByTagName("input");

			for(var i=0;i<inputs.length;i++)
			{
				inputs[i].readOnly = true;
				inputs[i].className = "purchase_ModInputsOff";
			}

			BasicUtils.Show("purchase_UserData2ModButton");
			BasicUtils.Hide("purchase_UserData2AcceptModButtons");

			BasicUtils.Show("purchase_dniOffDiv");
			BasicUtils.Hide("purchase_dniOnDiv");
			BasicUtils.Show("purchase_country2OffDiv");
			BasicUtils.Hide("purchase_country2OnDiv");
			break;
	}
}

function moneyChange(elem)
{
	var selected = elem.selectedIndex;
	var Selects = $CT(document.body, "moneySelect","select");
	var Spans = $CT(document.body, "moneyPrice", "span");

	for (var i=0; i<Selects.length; i++)
	{
		Selects[i].selectedIndex = selected;
		Spans[i].innerHTML = Selects[i].options[selected].value + " ";
	}
	document.cookie = "MONEY="+elem.options[selected].title + ";";
}

function GoTop()
{
	scrollTo(0,0);
}


function doctrineSearchByThemes(what)
{
	window.location.href = "/doctrine.php?themeId="+what;
}

function SearchChangeResultsPerPage(QueryString, newValue)
{
	var Query = new QueryStringClass(QueryString);
	Query.Set("rpp", newValue);
	var currentLoc = this.location.href;
	currentLoc = currentLoc.split("?");
	var newLoc = currentLoc[0] + "?" + Query.QueryString;
	this.location.href = newLoc;
}

function purchaseFormEmail()
{
	location.href = "mailto:info@astrea.com.ar?subject=Compra por email&body=Si conoce el titulo de la obra y el nombre del autor puede comprarla enviando este e-mail con los siguientes datos%3A<br><br><br>NOMBRE Y APELLIDO%3A<br>TELEFONO%3A<br>DIRECCION%3A<br>CODIGO POSTAL%3A<br>CIUDAD%3A<br>PROVINCIA%3A<br>PAIS%3A<br><br>Nosotros nos comunicaremos con usted para indicarle el precio y las formas de pago.";
}

function togglePainting(what, painting, limit)
{
	var nextpainting = parseInt(painting) + 1;
	var prevpainting = parseInt(painting) - 1;
	
	if (painting == "1" && what == "back") {
		document.getElementById("painting_"+painting).style.display = "none";
		document.getElementById("painting_9").style.display = "block";
	}
	if (painting == limit && what == "next") {
		document.getElementById("painting_"+painting).style.display = "none";
		document.getElementById("painting_1").style.display = "block";
	}
	if (what == "back" && painting != "1") {
		document.getElementById("painting_"+painting).style.display = "none";
		document.getElementById("painting_"+prevpainting).style.display = "block";
	}
	if (what == "next" && painting != "9") {
		document.getElementById("painting_"+painting).style.display = "none";
		document.getElementById("painting_"+nextpainting).style.display = "block";
	}
}

function openCFPage()
{
	window.open("http://cristinafreydier.com");
}