/////Funciones. No editar
//Funciones carrito
var carritoCargado = false;
var producto = '';
var producto_xml = '';
var xmlRequest = '';                    
var xmlRequestCallback = '';             

	
function ajax_EnviarSolicitud (url, callback)
{
    xmlRequest         = null;
    xmlRequestCallback = null;
           
    xmlRequest = __ajax_CrearRequest ();       
    xmlRequestCallback = callback;
    xmlRequest.onreadystatechange = __ajax_onXmlReqReadyStateChange;
    
    xmlRequest.open ('GET', url, true);
    
    xmlRequest.send (null);
}

 
function __ajax_CrearRequest ()
{
    var req;
    
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest()
    }

    else if (window.ActiveXObject)
    {
        req = new ActiveXObject("Microsoft.XMLHTTP")
    }

    return req;
}



function __ajax_cargarXml (xmlstr)
{
    var xmldoc;
            
 
    if (window.ActiveXObject)
    {
        xmldoc = new ActiveXObject("Microsoft.XMLDOM");
        xmldoc.async  ="false";
        xmldoc.loadXML (xmlstr);
    }
    

    else
    {
        var parser = new DOMParser ();
        xmldoc = parser.parseFromString (xmlstr, "text/xml");
    }
    
    return xmldoc;
}


function __ajax_onXmlReqReadyStateChange ()
{
    var xmldoc;
            
    if (xmlRequest.readyState == 4)
    {
        if (xmlRequest.status == 200)
        {
            
            if (xmlRequestCallback != null)
            {
                xmldoc = __ajax_cargarXml (xmlRequest.responseText);
                
                xmlRequestCallback (xmldoc);
            }
        }
        else
        {
            alert ('Se ha producido un error');
        }                
    }
}

	
	
	
	
	function ProcesarCargaCarrito(){
		//AjustaCarrito ();
		window.marcoCarrito.adaptarMarcoCarrito();
		if((!carritoCargado) && (producto != '')) { 
			carritoCargado=true;
			ComprarArticulo(producto,producto_xml);  
		}
		else
		{
			carritoCargado=true;
		}  
	}
	
	function ComprarArticulo(prod,xml){
		if (carritoCargado) {
			//document.frames('marcoCarrito').AgregarArticulos(xml);
			window.marcoCarrito.AgregarArticulos(xml);
		}
		else  
		{
			producto = prod;
			producto_xml = xml;
		}
	}

function AjustaCarrito ()
{

	//try {
	if (document.getElementById('marcoCarrito')) {
		
		//var contItems = document.frames('marcoCarrito').getContador();
		//var contItems = window.frames['marcoCarrito'].contador;
		var contItems = window.marcoCarrito.contador;
		
	if (contItems>0)
		document.getElementById('marcoCarrito').style.height=238+14*contItems+"px";
	else
		document.getElementById('marcoCarrito').style.height=0;
	}
	//}
	//catch (ex)
	//{
	//}
}




//Otras

var menuwidth='165px' //default menu width
var menubgcolor='white'  //menu bgcolor
var disappeardelay=300  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?



var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu


//Función de arquitectura
function seleccionarEntradaMenu(operacion, parametro, idsel)
 {
  var txtOperacionMenu;
  var txtUrlMenu;
  
  if(operacion == "POPUP"){
   window.open(parametro);
  }else{
      
	  txtOperacionMenu = document.createElement('INPUT');
	  txtOperacionMenu.setAttribute("type", "hidden");
	  txtOperacionMenu.setAttribute("name", "txtOperacionMenu");
      txtOperacionMenu.value = operacion;
      document.forms[0].appendChild(txtOperacionMenu);  
      txtUrlMenu = document.createElement('input');
	  txtUrlMenu.setAttribute("type", "hidden");
	  txtUrlMenu.setAttribute("name", "txtUrlMenu");
      txtUrlMenu.value = parametro;
      document.forms[0].appendChild(txtUrlMenu);
	selItemMenu (idsel);

      document.forms[0].submit();
  }
 }

function selItemMenu (idsel)
{
	if ( document.getElementById('txtIDSelM3N')){
		document.getElementById('txtIDSelM3N').value = document.gItemM3N;
	}else{
		
      eM3N = document.createElement('input');
	  eM3N.setAttribute("type", "hidden");
	  eM3N.setAttribute("name", "txtIDSelM3N");
      eM3N.value = document.gItemM3N;
	  document.forms[0].appendChild(eM3N);
	}

  }

function selComentarios()
{
  document.gItemM3N="imenu3";
}



//------------------------------
//Funciones Ampliar Imagen
//------------------------------

var posXAmpliarImagen = 0;			//Posicion Left del div ampliado
var posYAmpliarImagen = 0;			//Posicion top del div ampliado
var hilo01AmpliarImagen;			//Thread para el seguimiento del raton mientras se mueve el mouse sobre la imagen
var mDivAmpliarImagen = 15;			//Margen de separacion entre el div y el cursor


function posXYAmpliarImagen(e){ // NS is passing (event), while IE is passing (null)
	if (!e){
		e = window.event;
 		// works on IE, but not NS (we rely on NS passing us the event)
	}
	
	if (e){
		var scrX, scrY;
		if (e.pageX || e.pageY){ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
			posXAmpliarImagen = e.pageX + mDivAmpliarImagen;
			posYAmpliarImagen = e.pageY + mDivAmpliarImagen;
		}else if (e.clientX || e.clientY){ // works on IE6,FF,Moz,Opera7
			posXAmpliarImagen = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft + mDivAmpliarImagen;
			posYAmpliarImagen = e.clientY + document.body.scrollTop + document.documentElement.scrollTop + mDivAmpliarImagen;
		}  
	}
}


function openDivAmpliarImagen(){
	clearTimeout(hilo01AmpliarImagen);
	
	if(document.all){
		bigImg.style.posLeft=posXAmpliarImagen;
		bigImg.style.posTop=posYAmpliarImagen;
		bigImg.style.visibility="visible"; 
	}

	if(document.getElementById&&!document.all){	//Firefox
		var x,y;
		x=posXAmpliarImagen+'px';
		y=posYAmpliarImagen+'px';
		document.getElementById('bigImg').style.left=x;
		document.getElementById('bigImg').style.top=y;
		document.getElementById('bigImg').style.visibility="visible";
	}
	
	hilo01AmpliarImagen=setTimeout("openDivAmpliarImagen()",30);
}

function closeDivAmpliarImagen(){
	clearTimeout(hilo01AmpliarImagen);
	
	if(document.all){
		bigImg.style.visibility="hidden"; 
	}

	if(document.getElementById&&!document.all){	//Firefox
		document.getElementById('bigImg').style.visibility="hidden";
	}
}

document.onmousemove = posXYAmpliarImagen;
//-----------------------------------
// Fin Funciones Ampliar Imagen
//-----------------------------------

//-----------------------------------
// Funciones Cookie Gestor de lectura
//-----------------------------------

function estilo (a)
{

}

function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 

function setActiveStyleSheet(title) {
  var i, a, main;

 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 ) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false; 
    }
  }


}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  if (title!=null) setActiveStyleSheet(title);
if (document.getElementById("divContainer") != null && document.getElementById("divContent")!=null && document.getElementById("divSlider")!=null) {
initScroll(new Bs_ScrollableDiv(), new Bs_Slider(),'divContainer','divContent','divSlider');  
}

if (document.getElementById("ieslider1")) start();
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  if (title!=null) createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

// Funciones MENU

stat=new Array();

var stat=new Array();
var strUrl=location.pathname;
var strLoc;

var strCookieMain = 'ItemMain';
var strCookieSubMain = 'ItemSubMain';

function getMenuId(){
	var fin=0;
	var strRet;
	
	var pagina = strUrl.split('/')[strUrl.split('/').length-1];
	
	
	
	if ( pagina == '' || pagina.toLowerCase() == 'default.aspx') 
	{
				
		fin=strUrl.indexOf('/',1);
		strRet=strUrl.substring(0,fin);
		strLoc=strRet;
						
				
	} else {
		
						
		if (Get_Cookie(strCookieMain)) strLoc = Get_Cookie(strCookieMain);	
		
		// AC CAU-2007-03506 25/10/07 INICIO
		else
		{	
			var root;
			
			root = '/' + strUrl.split ('/')[1];
						
			strLoc = root;		
		}
		// AC CAU-2007-03506 25/10/07 FIN
	}
	
	getSubMenuId();	
	
}

function getSubMenuId(){
	var fin=0;
	var strRet;
	
	var pagina = strUrl.split('/')[strUrl.split('/').length-1]
	
	
	if ( pagina == '' || pagina.toLowerCase() == 'default.aspx') {
		
	
		
		fin=strUrl.indexOf('/',strUrl.indexOf('/', 1)+1);
	
		if (fin!=-1) {
			strRet2=strUrl.substring(0,fin);
			strLoc2=strRet2;
	
			changeSecond (strLoc2);
		}
					
	} else {
		
		if (Get_Cookie(strCookieSubMain)) {
			
			strLoc2=Get_Cookie(strCookieSubMain);
			
			changeSecond (strLoc2);
		}
	}
	
	
	
}
function selectMain(id) {
	Set_Cookie(strCookieMain,id,'','/','','');
	Delete_Cookie(strCookieSubMain,'/','');
		//alert('changemain' + id);
}

function changeMain(id){
	objParent=document.getElementById(id);
	objDaughter=document.getElementById('m'+id);

	if (objParent) { 
		objParent.style.color = "#ff9933";
	}

	//alert('changemain' + id);

	if (document.getElementById('m'+id)){
		if (stat[id]!=1) {
			//select
			stat[id]=1;
			objDaughter.style.display='block';
			objParent.style.color = "#ff9933";
			
		} else {
			if(stat[id]==1){
			//unselect
				stat[id]=0;
				objDaughter.style.display='none';
				objParent.style.color = "#ffFFFF";
			}
		}
	}
}

function changeSubMain(id){
		Set_Cookie(strCookieSubMain,id,'','/','','');
}


function changeSecond (id){
	if (obj=document.getElementById(id) ) 
	obj.style.fontWeight="bold";
}

function activaItemMenu (id)
{
if (objParent=document.getElementById(id) ) {
objParent.style.color = "#E4008C";
document.gItemM3N=id;
}

}

// FIN Funciones MENU

// Funciones de gestion de cookies

 function Set_Cookie( name, value, expires, path, domain, secure ) 
{
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );

		/*
		if the expires variable is set, make the correct 
		expires time, the current script below will set 
		it for x number of days, to make it for hours, 
		delete * 24, for minutes, delete * 60 * 24
		*/
		if ( expires )	expires = expires * 1000 * 60 * 60 * 24;
		
		var expires_date = new Date( today.getTime() + (expires) );
		document.cookie = name + "=" + escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" + secure : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	
	var end = document.cookie.indexOf( ";", len );
	
	if ( end == -1 ) end = document.cookie.length;
	
	return unescape( document.cookie.substring( len, end ) );
}
	
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



// Funciones ticker de noticias home

function start(){
	if (document.all){
		ieslider1.style.top=sheight;
		iemarquee(ieslider1);
		maxH=iediv.offsetHeight;
		maxH = maxH/2;
	}else if (document.getElementById&&!document.all){ //FireFox
		document.getElementById('ieslider1').style.top=sheight + "px";
		ns6marquee(document.getElementById('ieslider1'));
		maxH=document.getElementById('ieslider1').offsetHeight;
		maxH = maxH/2;
	}

}

function iemarquee(whichdiv){
	iediv=eval(whichdiv)
	/*
	if (iediv.style.pixelTop>0&&iediv.style.pixelTop<=sspeed){	//Cuando el topDiv llega cerca del topMarco, iguala el topDiv al topMarco
		iediv.style.pixelTop=1
	}*/
	if (iediv.style.pixelTop>=maxH*-1){
		iediv.style.pixelTop-=sspeed
	}else{
		iediv.style.pixelTop=-5
	}
	setTimeout("iemarquee(iediv)",110)
}

function ns4marquee(whichlayer){
	ns4layer=eval(whichlayer)
	if (ns4layer.top>0&&ns4layer.top<=sspeed){
		ns4layer.top=0
	}
	if (ns4layer.top>=maxH*-1){
		ns4layer.top-=sspeed
	}else{
		ns4layer.top=-5
	}
	setTimeout("ns4marquee(ns4layer)",110)
}

function ns6marquee(whichdiv){
ns6div=eval(whichdiv)
	if (parseInt(ns6div.style.top)>0&&parseInt(ns6div.style.top)<=sspeed){
		ns6div.style.top=0+"px";
	}
	if (parseInt(ns6div.style.top)>=maxH*-1){
		ns6div.style.top=parseInt(ns6div.style.top)-sspeed+"px";
	}else{
		ns6div.style.top="-5px";
	}
	setTimeout("ns6marquee(ns6div)",110)

}

/* Scroll Agrupaciones */

function initScroll(scrollerObj, sliderObj, stringdivContainer, stringdivContent, stringdivSlider) {
	//scrollablediv 1 
	//scrollerObj = new Bs_ScrollableDiv();
	scrollerObj.init(stringdivContainer, stringdivContent);
	
	//sliderObj = new Bs_Slider();
	sliderObj.attachOnChange(Bs_ScrollableDiv_sliderChange);
	sliderObj.width          = 11;
	sliderObj.height         = 'auto';
	sliderObj.minVal         = 0;
	sliderObj.maxVal         = 100;
	sliderObj.valueInterval  = 0.1;
	sliderObj.arrowAmount    = 0.2;
	sliderObj.arrowMouseOver = true;
	sliderObj.valueDefault   = 0;
	sliderObj.direction      = 1;
	sliderObj.imgDir         = '/recursos/';
	sliderObj.setBackgroundImage('punteado.gif', 'repeat');
	sliderObj.setSliderIcon('deslizador.gif', 11, 10);
	sliderObj.setArrowIconLeft('scroll_up.gif', 11, 10);
	sliderObj.setArrowIconRight('scroll_dn.gif', 11, 10);
	sliderObj.useInputField = 0;
		
	scrollerObj.setSliderObject(sliderObj, stringdivSlider);
	if (document.getElementById(stringdivContainer).offsetHeight < document.getElementById(stringdivContent).offsetHeight)
		document.getElementById(stringdivSlider).style.visibility='visible'
	else
		document.getElementById(stringdivSlider).style.visibility='hidden'
		
}

function restauraValorControl (item, valor)
{
	var elemento = document.getElementById(item);
	switch (elemento.type)
	{
		case 'select-one':
			for(var j = 0 ; j < elemento.length ; ++j) {
				if(elemento[j].value == valor)
				{
					elemento[j].selected = true;
					break;
				}
			}
			break;
		case 'radio':
			var radio = document.getElementById(valor);
			radio.checked = true;
			break;
		case 'checkbox':
			var chk = document.getElementById(valor);
			chk.checked = true;
			break;
		default:
			elemento.value = valor;
	}	
}

function MostrarFichaDetalleArticulo(url)
{
 if (url != "")
 {
 	parent.document.location.href=url + "?volver=" + parent.document.location.href
 }
}


function incrustarFlashWeb(elFlash, imagenDefecto, ancho, alto)
{

  if (pluginlist.indexOf("Flash")!=-1 && true) {
    document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'  width='" + __tcm_anchoFlash + "'  height='" + __tcm_altoFlash + "' ><param name='movie' value='" + __tcm_elFlash + "'><param name='quality' value='high'><embed src='" + __tcm_elFlash + "' quality='high' width='" + __tcm_anchoFlash + "'  height='" + __tcm_altoFlash + "' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' ></embed></object>"); 
  } 
  else 
  { 
    document.write (__tcm_imagenPorDefecto); 
  }
}


function WebTag () {
	var Tag = '';
	
	Tag = window.document.forms[0].action.toString().toLowerCase();

	return (Tag);

}