var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var ihs=0;
var ahs=-1;
var intervalo=0;
var retardo=0;
var ocupado=false;
var t_ihs=0;
var t_ahs=-1;
var t_intervalo=0;
var t_retardo=0;
var t_ocupado=false;
var selRow=0;
var selColor="#ddecfe";
var overColor="#ffffdd";
var outColor="#ffffff";

function homeslide(cant){
    if(ahs<0) ahs=cant;
    var delta=100;
    document.getElementById('slideimg_'+ihs).style.display="block";
    ocupado=true;
    intervalo=setInterval(function(){
        if(isIE){
            document.getElementById('slideimg_'+ihs).style.filter="alpha(opacity="+(100-delta)+")";
            document.getElementById('slideimg_'+ahs).style.filter="alpha(opacity="+delta+")";
        } else {
            document.getElementById('slideimg_'+ihs).style.opacity=(100-delta)/100;
            document.getElementById('slideimg_'+ahs).style.opacity=delta/100;
        }
        if(delta<=0){
            clearInterval(intervalo);
            document.getElementById('slideimg_'+ahs).style.display="none";
            document.getElementById('btnhs_'+ihs).style.opacity=1;
            document.getElementById('btnhs_'+ihs).style.filter="alpha(opacity=100)";
            document.getElementById('btnhs_'+ahs).style.opacity=0.5;
            document.getElementById('btnhs_'+ahs).style.filter="alpha(opacity=50)";
            ahs=ihs;
            if(ihs>=cant) ihs=0; else ihs++;
            ocupado=false;
            retardo=setTimeout(function(){ homeslide(cant); },10000);
        } else delta-=10;
    },30);
}

function textslide(cant){
    if(t_ahs<0) t_ahs=cant;
    var delta=100;
    document.getElementById('slidetext_'+t_ihs).style.display="block";
    t_ocupado=true;
    t_intervalo=setInterval(function(){
        if(isIE){
            document.getElementById('slidetext_'+t_ihs).style.filter="alpha(opacity="+(100-delta)+")";
            document.getElementById('slidetext_'+t_ahs).style.filter="alpha(opacity="+delta+")";
        } else {
            document.getElementById('slidetext_'+t_ihs).style.opacity=(100-delta)/100;
            document.getElementById('slidetext_'+t_ahs).style.opacity=delta/100;
        }
        if(delta<=0){
            clearInterval(t_intervalo);
            document.getElementById('slidetext_'+t_ahs).style.display="none";
            t_ahs=t_ihs;
            if(t_ihs>=cant) t_ihs=0; else t_ihs++;
            t_ocupado=false;
            t_retardo=setTimeout(function(){ textslide(cant); },10000);
        } else delta-=10;
    },30);
}

function subMenu(capa,acc){
    if(document.getElementById(capa)) document.getElementById(capa).style.display=(acc=="hide")?"none":"block";
}

function nextSlide(ne,cant){
    var temp=ahs;
    if(temp!=ne){
        if(!ocupado){
            clearTimeout(retardo);
            ihs=ne;
            homeslide(cant);
        }
    }
}

function ajax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function loadProductsCombo(v){
    peticion=ajax();
    peticion.open("GET", "../comboproducts.php?id="+v, true);
  	peticion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=Latin1');
	peticion.onreadystatechange=function(){
        if (peticion.readyState==4){
            if(document.getElementById('divproducts')) document.getElementById('divproducts').innerHTML = peticion.responseText;
        }
    }
    peticion.send(null);
}

function loadAjaxContent(dest,capa){
    peticion=ajax();
    peticion.open("GET", dest, true);
  	peticion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=Latin1');
	peticion.onreadystatechange=function(){
        if (peticion.readyState==4){
            if(document.getElementById(capa)) document.getElementById(capa).innerHTML = peticion.responseText;
        }
    }
    peticion.send(null);
}

function getVideo(src){
    var temp=src.split("~");
    if(document.getElementById('divCont')) document.getElementById('divCont').innerHTML=temp.join("\"");
}

function setSupportFromMenu(ide){
    document.frmsupportmenu.idcatsop.value=ide;
    document.frmsupportmenu.submit();
}

function setVideoFromMenu(ide){
    document.frmvideomenu.cid.value=ide;
    document.frmvideomenu.submit();
}

function setVideoId(ide){
    document.frmvideocat.cid.value=ide;
    document.frmvideocat.submit();
}

init=function(){
    if(document.getElementById('datagrid')){
    var ta=document.getElementById('datagrid');
    for(i=0;i<ta.rows.length;i++){
        if(i>0){
            var rch=function(t,n){ return function(){ 
                if(parent.document.frmcontrol){
                    parent.document.frmcontrol.cod.value=t.rows[n].cells[0].innerHTML; 
                    if(selRow!=0){ for(i=0;i<t.rows[selRow].cells.length;i++){ t.rows[selRow].cells[i].style.backgroundColor=outColor; } }
                    selRow=n;
                    for(i=0;i<t.rows[selRow].cells.length;i++){ t.rows[selRow].cells[i].style.backgroundColor=selColor; }                       
                    parent.document.getElementById('downbutton').style.backgroundPosition="10px 0px";
                }; }; }; ta.rows[i].onclick=rch(ta,i);
            var roh=function(t,n){ return function(){ 
                if(n!=selRow){ 
                    for(i=0;i<t.rows[n].cells.length;i++){ t.rows[n].cells[i].style.backgroundColor=overColor; }
                }; }; }; ta.rows[i].onmouseover=roh(ta,i);
            var ruh=function(t,n){ return function(){ 
                if(n!=selRow){ 
                    for(i=0;i<t.rows[n].cells.length;i++){ t.rows[n].cells[i].style.backgroundColor=outColor; }
                }; }; }; ta.rows[i].onmouseout=ruh(ta,i);
        }
    }
    }
}
