var isImageView=false

function favs(src){
	var f=document.getElementById(src);
	if(f)f.style.display=(f.style.display=="none")?"block":"none";
}
function goBack(num){
	window.setTimeout(function(){history.go(num)},1000)
}
function staron(on,src){
	src.className=(on)?src.className.replace("_light","") + "_light":src.className.replace("_light","");	
}
function showImages(){
	if(isImageView)return
	if(document.getElementsByClassName){
		var tgt=document.getElementsByClassName("article")
	}else{
		var tgt=document.getElementsByTagName("div")
		for(el in tgt){
			if(tgt[el] && tgt[el].className=="article"){
				var tgt=tgt[el];
			}
		}
	}
	var imgs
	var urls=new Array()
	
	if(tgt){
		tgt=tgt[0]
		imgs=tgt.getElementsByTagName("img")
	}else{
		return
	}

	for(el in imgs){
		if(imgs[el].parentNode && imgs[el].parentNode.className=="divimage")urls.push(imgs[el].src)
	}
	
	if(urls.length==0){
		alert('Oops, este artículo no tiene imagenes para visualizar')
		return
	}
	isImageView=true
	tgt.innerHTML=""
	var ret="<a href='javascript:resetImages()' style='color:blue'>Volver al artículo</a><br><br>"
	var cont=document.createElement("div")
	cont.style.textAlign="center"
	cont.innerHTML=ret
	for(el in urls){
		var ni=document.createElement("img")
		var sep=document.createElement("br")
		ni.src=urls[el]
		cont.appendChild(ni)
		cont.appendChild(sep)
	}
	cont.innerHTML+="<br>" + ret
	tgt.appendChild(cont)
	document.location="#top"
}

function resetImages(){
	document.location=document.location.href.replace("#top","")
}
	


// *****WIN functions //
var to=null;
var opac=0;
var isdrag=false;
var x,y,tx,ty;
var dobj;


function animate(){
	var animwin=document.getElementById("win")
	
	if(opac<100){
		animwin.style.filter="alpha(opacity="+opac+")"
		animwin.style.opacity="0."+opac
	}else{
		animwin.style.filter="alpha(opacity=100)"
		animwin.style.opacity="1"+opac
	}
	animwin.style.display="block"
	opac+=25
	if(to)window.clearTimeout(to) 
	
	if(opac<110){
		to=window.setTimeout(animate,50) 
	}else{
		window.clearTimeout(to)
		to=null
		opac=0 
	}
}



function selectmouse(e) 
{
	if(!e)e=window.event;
    var obj=(e.target)?e.target.id:e.srcElement.id
    if(obj!="winbar")return
    isdrag = true;
    dobj=document.getElementById("win")
    
    var fframe=document.getElementById("floatframe").style.display="none"
    dobj.style.filter="alpha(opacity=75)"
	dobj.style.opacity="0.75"
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = e.clientX
    y = e.clientY
	document.onmousemove=movemouse;
    return false;
}

function movemouse(e)
{
  if(!e)e=window.event;
  if (isdrag)
  {
   var nposx=tx + e.clientX - x
   var nposy=ty + e.clientY - y
   
   if(nposx<-10){
		nposx=-10	
   }
   if(nposy<-10){
		nposy=-10	
   }
    dobj.style.left = nposx
    dobj.style.top  = nposy
    return false;
  }
  return false
}

function dragging(){
	isdrag=false
	var fframe=document.getElementById("floatframe")
	fframe.style.display="block"
	if(dobj){
		dobj.style.filter="alpha(opacity=100)"
		dobj.style.opacity="1"
	}
}
function closeW()
{
	document.getElementById("win").style.display="none"
}

function makeWin(){
	
	if(document.getElementById("winbar")){
		document.getElementById("winbar").onmousedown=selectmouse;
		document.onmouseup=dragging//new Function("isdrag=false");	
	}
}

function openWin(url,w,h){
	window.open(url,"","width="+ w +",height="+h)
}

function productDetail(code, go){
	var fframe=document.getElementById("floatframe")
	var win =document.getElementById("win")

	if(go){
		win.style.top=50 + parseInt(document.body.scrollTop)
		animate()
		fframe.src=go + "?cod="+ code
	}else{
		win.style.display="none"
		fframe.src="about:blank"
		window.setTimeout(function(){productDetail(code,"/portalre/productdetail.php")},200)
	}
}