onload=eventLoader

var upH = 9;
var upW = 5;
var downH = 9;
var downW = 5;
var dragH = 26;
var dragW = 17;
var scrollH = 204;
var speed = 4;
var tocando = 0;
var tocando1 = 0;
var tocando2 = 0;

var objActual;
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

var mouseY;
var mouseX;

var clickUp = false;
var clickDown = false;
var clickDrag = false;
var clickAbove = false;
var clickBelow = false;

var timer = setTimeout("",500);
var upL;
var upT;
var downL;
var downT;
var dragL;
var dragT;
var rulerL;
var rulerT;
var contentT;
var contentH;
var contentClipH;
var scrollLength;
var startY;
var content;

function down(e){
	if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
	getMouse(e);
	startY = (mouseY - dragT);
	startY1 = (mouseY - dragT1);
	startY2 = (mouseY - dragT2);
	if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
		clickUp = true;
		return scrollUp();
	}	
	else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
		clickDown = true;
		return scrollDown();
	}
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
		clickDrag = true;
		return false;
	}
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
		if(mouseY < dragT){
			clickAbove = true;
			clickUp = true;
			return scrollUp();
		}
		else{
			clickBelow = true;
			clickDown = true;
			return scrollDown();
		}
	}
// 2 SCROLL 
	else if(mouseX >= upL1 && (mouseX <= (upL1 + upW1)) && mouseY >= upT1 && (mouseY <= (upT1 + upH1))){
		clickUp1 = true;
		return scrollUp1();
	}
	else if(mouseX >= downL1 && (mouseX <= (downL1 + downW1)) && mouseY >= downT1 && (mouseY <= (downT1 + downH1))){
		clickDown1 = true;
		return scrollDown1();
	}
	else if(mouseX >= dragL1 && (mouseX <= (dragL1 + dragW1)) && mouseY >= dragT1 && (mouseY <= (dragT1 + dragH1))){
		clickDrag1 = true;
		return false;
	}
	else if(mouseX >= dragL1 && (mouseX <= (dragL1 + dragW1)) && mouseY >= rulerT1 && (mouseY <= (rulerT1 + scrollH1))){
		if(mouseY < dragT1){
			clickAbove1 = true;
			clickUp1 = true;
			return scrollUp1();
		}
		else{
			clickBelow1 = true;
			clickDown1 = true;
			return scrollDown1();
		}
	}
// 3 SCROLL
	else if(mouseX >= upL2 && (mouseX <= (upL2 + upW2)) && mouseY >= upT2 && (mouseY <= (upT2 + upH2))){
		clickUp2 = true;
		return scrollUp2();
	}
	else if(mouseX >= downL2 && (mouseX <= (downL2 + downW2)) && mouseY >= downT2 && (mouseY <= (downT2 + downH2))){
		clickDown2 = true;
		return scrollDown2();
	}
	else if(mouseX >= dragL2 && (mouseX <= (dragL2 + dragW2)) && mouseY >= dragT2 && (mouseY <= (dragT2 + dragH2))){
		clickDrag2 = true;
		return false;
	}
	else if(mouseX >= dragL2 && (mouseX <= (dragL2 + dragW2)) && mouseY >= rulerT2 && (mouseY <= (rulerT2 + scrollH2))){
		if(mouseY < dragT2){
			clickAbove2 = true;
			clickUp2 = true;
			return scrollUp2();
		}
		else{
			clickBelow2 = true;
			clickDown2 = true;
			return scrollDown2();
		}
	}
	else{
		return true;
	}
}

function move(e){
//Parte del div que se mueve
	if (window.ss) {
            var x=(nav)?  e.pageX  :  event.x+document.body.scrollLeft; 
            var y=(nav)?  e.pageY  :  event.y+document.body.scrollTop; 
            skn.left=x+Xoffset; 
            skn.top=y+Yoffset; 
	}
//FINParte del div que se mueve
	getContent();
	getContent1();
	getContent2();
	if(clickDrag && contentH > contentClipH){
		getMouse(e);
		dragT = (mouseY - startY);
		
		if(dragT < (rulerT))
			dragT = rulerT;		
		if(dragT > (rulerT + scrollH - dragH))
			dragT = (rulerT + scrollH - dragH);
		
		contentT = ((dragT - rulerT)*(1/scrollLength));
		contentT=contentT*(-1);
		moveTo();
		
		if(ie4)
			return false;
	}
	else if( clickDrag1 && contentH1 > contentClipH1){
			getMouse(e);
			dragT1 = (mouseY - startY1);
		
			if(dragT1 < (rulerT1))
				dragT1 = rulerT1;		
			if(dragT1 > (rulerT1 + scrollH1 - dragH1))
				dragT1 = (rulerT1 + scrollH1 - dragH1);
		
			contentT1 = ((dragT1- rulerT1)*(1/scrollLength1));
			contentT1=contentT1*(-1);	
	
			moveTo1();
		
			// So ie-pc doesn't select gifs
			if(ie4)
				return false;
	}
	else if (clickDrag2 && contentH2 > contentClipH2){
			getMouse(e);
			dragT2 = (mouseY - startY2);
		
			if(dragT2 < (rulerT2))
				dragT2 = rulerT2;		
			if(dragT2 > (rulerT2 + scrollH2 - dragH2))
				dragT2 = (rulerT2 + scrollH2 - dragH2);
		
			contentT2 = ((dragT2- rulerT2)*(1/scrollLength2));
			contentT2=contentT2*(-1);	
	
			moveTo2();
		
			// So ie-pc doesn't select gifs
			if(ie4)
				return false;
	}
}

function up(){
	clearTimeout(timer);
	clearTimeout(timer1);
	clearTimeout(timer2);

	if (tocando!=1){
	clickUp = false;
	clickDown = false;
	}
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;

	if (tocando1!=1){	
	clickUp1 = false;
	clickDown1 = false;
	}
	clickDrag1 = false;
	clickAbove1 = false;
	clickBelow1 = false;

	if (tocando2!=1){	
	clickUp2 = false;
	clickDown2 = false;
	}
	clickDrag2 = false;
	clickAbove2 = false;
	clickBelow2 = false;
	return true;
}

function getT(){
	if(ie4)
		contentT = document.all.content1.style.pixelTop;
	else if(nn4)
		contentT = document.contentClip.document.content1.top;
	else if(dom)
		contentT = parseInt(document.getElementById("content1").style.top);
}

function getMouse(e){
	if(ie4){
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
		//if (escEnviar){
		//	if ((mouseX>585)&&(mouseX<670)&&(mouseY>345)&&(mouseY<362)) enviar();
		//}
	}
	else if(nn4 || dom){
		mouseY = e.pageY;
		mouseX = e.pageX;
		if (escEnviar) {
		if (nn4) {if ((mouseX>571)&&(mouseX<665)&&(mouseY>337)&&(mouseY<355)) enviar();}
		if (dom) {if ((mouseX>571)&&(mouseX<665)&&(mouseY>325)&&(mouseY<350)) enviar();}
		}
	}
}

function moveTo(){
	if(ie4){
		document.all.content1.style.top = contentT;
		document.all.ruler.style.top = dragT;
		document.all.drag.style.top = dragT;
	}
	else if(nn4){
		document.contentClip.document.content1.top = contentT;
		document.ruler.top = dragT;
		document.drag.top = dragT;
	}
	else if(dom){
		document.getElementById("content1").style.top = contentT + "px";
		document.getElementById("drag").style.top = dragT + "px";
		document.getElementById("ruler").style.top = dragT + "px";
	}
}

function scrollUp(){
	getT();
	if(clickAbove){
		if(dragT <= (mouseY-(dragH/2)))
			return up();
	}
	
	if(clickUp){
		if(contentT < 0){
			dragT = dragT - (speed*scrollLength);
			
			if(dragT < (rulerT))
				dragT = rulerT;
				
			contentT = contentT + speed;
			if(contentT > 0)
				contentT = 0;
			
			moveTo();
			timer = setTimeout("scrollUp()",25);
		}
	}
	return false;
}

function scrollDown(){
	getContent();
	getT();
	
	if(clickBelow){
		if(dragT >= (mouseY-(dragH/2)))
			return up();
	}
	if(clickDown){
		if(contentT > -(contentH - contentClipH)){			
			dragT = dragT + (speed*scrollLength);
			if(dragT > (rulerT + scrollH - dragH))
				dragT = (rulerT + scrollH - dragH);
			contentT = contentT - speed;
			if(contentT < -(contentH - contentClipH))
				contentT = -(contentH - contentClipH);
			moveTo();
			timer = setTimeout("scrollDown()",25);
		}
	}
	return false;
}

function reloadPage(){
	location.reload();
}

function getContent(){
	if (ie4){
		contentH = parseInt(document.all.content1.scrollHeight);
		contentClipH = parseInt(document.all.contentClip.style.height);
		contenedorAltura = parseInt(document.all.contentClip.style.height);
	}
	else if (nn4){
		contentH = document.contentClip.document.content1.clip.bottom;
		contentClipH = document.contentClip.clip.bottom;
		contenedorAltura = document.contentClip.clip.bottom;
	}
	else if(dom){
		contentH = parseInt(document.getElementById("content1").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
		contenedorAltura = parseInt(document.getElementById("contentClip").offsetHeight);
	}
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));

}

function eventLoader(){
	if(ie4){
		upL = document.all.up.style.pixelLeft;
		upT = document.all.up.style.pixelTop;		
		downL = document.all.down.style.pixelLeft;
		downT = document.all.down.style.pixelTop;
		dragL = document.all.drag.style.pixelLeft;
		dragT = document.all.drag.style.pixelTop;		
		rulerT = document.all.ruler.style.pixelTop;

	}
	else if(nn4){
		document.up.top=document.up.top-5;
		document.up1.top=document.up1.top-5;
		document.up2.top=document.up2.top-5;
		document.down.top=document.down.top-5;
		document.down1.top=document.down1.top-5;
		document.down2.top=document.down2.top-5;
		document.drag.top=document.drag.top-5;
		document.drag1.top=document.drag1.top-5;
		document.drag2.top=document.drag2.top-5;
		document.ruler.top=document.ruler.top-5;
		document.ruler1.top=document.ruler1.top-5;
		document.ruler2.top=document.ruler2.top-5;
		document.fondo.top=document.fondo.top-5;
		document.fondo1.top=document.fondo1.top-5;
		document.fondo2.top=document.fondo2.top-5;
		document.contentClip.top=document.contentClip.top-5;

		document.up.left=document.up.left-2;
		document.up1.left=document.up1.left-5;
		document.up2.left=document.up2.left-5;
		document.down.left=document.down.left-2;
		document.down1.left=document.down1.left-5;
		document.down2.left=document.down2.left-5;
		document.drag.left=document.drag.left-2;
		document.drag1.left=document.drag1.left-5;
		document.drag2.left=document.drag2.left-5;
		document.ruler.left=document.ruler.left-2;
		document.ruler1.left=document.ruler1.left-5;
		document.ruler2.left=document.ruler2.left-5;
		document.fondo.left=document.fondo.left-2;
		document.fondo1.left=document.fondo1.left-5;
		document.fondo2.left=document.fondo2.left-5;
		document.contentClip.document.content2.left=document.contentClip.document.content2.left-3;
		document.contentClip.top=document.contentClip.top-2;
		
		upL = document.up.left;
		upT = document.up.top;		
		downL = document.down.left;
		downT = document.down.top;		
		dragL = document.drag.left;
		dragT = document.drag.top;		
		rulerT = document.ruler.top;
		

	}
	else if(dom){
		document.getElementById("up").style.top=(parseInt(document.getElementById("up").style.top)-10)+ "px";
		document.getElementById("up1").style.top=(parseInt(document.getElementById("up1").style.top)-10)+ "px";
		document.getElementById("up2").style.top=(parseInt(document.getElementById("up2").style.top)-10)+ "px";
		document.getElementById("down").style.top=(parseInt(document.getElementById("down").style.top)-10)+ "px";
		document.getElementById("down1").style.top=(parseInt(document.getElementById("down1").style.top)-10)+ "px";
		document.getElementById("down2").style.top=(parseInt(document.getElementById("down2").style.top)-10)+ "px";
		document.getElementById("drag").style.top=(parseInt(document.getElementById("drag").style.top)-10)+ "px";
		document.getElementById("drag1").style.top=(parseInt(document.getElementById("drag1").style.top)-10)+ "px";
		document.getElementById("drag2").style.top=(parseInt(document.getElementById("drag2").style.top)-10)+ "px";
		document.getElementById("ruler").style.top=(parseInt(document.getElementById("ruler").style.top)-10)+ "px";
		document.getElementById("ruler1").style.top=(parseInt(document.getElementById("ruler1").style.top)-10)+ "px";
		document.getElementById("ruler2").style.top=(parseInt(document.getElementById("ruler2").style.top)-10)+ "px";
		document.getElementById("fondo").style.top=(parseInt(document.getElementById("fondo").style.top)-10)+ "px";
		document.getElementById("fondo1").style.top=(parseInt(document.getElementById("fondo1").style.top)-10)+ "px";
		document.getElementById("fondo2").style.top=(parseInt(document.getElementById("fondo2").style.top)-10)+ "px";
		
		document.getElementById("up").style.left=(parseInt(document.getElementById("up").style.left)-2)+ "px";
		document.getElementById("up1").style.left=(parseInt(document.getElementById("up1").style.left)-2)+ "px";
		document.getElementById("up2").style.left=(parseInt(document.getElementById("up2").style.left)-2)+ "px";
		document.getElementById("down").style.left=(parseInt(document.getElementById("down").style.left)-2)+ "px";
		document.getElementById("down1").style.left=(parseInt(document.getElementById("down1").style.left)-2)+ "px";
		document.getElementById("down2").style.left=(parseInt(document.getElementById("down2").style.left)-2)+ "px";
		document.getElementById("drag").style.left=(parseInt(document.getElementById("drag").style.left)-2)+ "px";
		document.getElementById("drag1").style.left=(parseInt(document.getElementById("drag1").style.left)-2)+ "px";
		document.getElementById("drag2").style.left=(parseInt(document.getElementById("drag2").style.left)-2)+ "px";
		document.getElementById("ruler").style.left=(parseInt(document.getElementById("ruler").style.left)-2)+ "px";
		document.getElementById("ruler1").style.left=(parseInt(document.getElementById("ruler1").style.left)-2)+ "px";
		document.getElementById("ruler2").style.left=(parseInt(document.getElementById("ruler2").style.left)-2)+ "px";
		document.getElementById("fondo").style.left=(parseInt(document.getElementById("fondo").style.left)-2)+ "px";
		document.getElementById("fondo1").style.left=(parseInt(document.getElementById("fondo1").style.left)-2)+ "px";
		document.getElementById("fondo2").style.left=(parseInt(document.getElementById("fondo2").style.left)-2)+ "px";

		document.getElementById("contentClip").style.top=(parseInt(document.getElementById("contentClip").style.top)-10)+ "px";
		
		upL = parseInt(document.getElementById("up").style.left);
		upT = parseInt(document.getElementById("up").style.top);
		downL = parseInt(document.getElementById("down").style.left);
		downT = parseInt(document.getElementById("down").style.top);
		dragL = parseInt(document.getElementById("drag").style.left);
		dragT = parseInt(document.getElementById("drag").style.top);
		rulerT = parseInt(document.getElementById("ruler").style.top);
		document.getElementById("content1").style.top = 0 + "px";
		document.getElementById("content2").style.top = 0 + "px";
	}
	getContent();

	eventLoader1();

	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;

	escribirCategorias();
	
	esconder1();
	esconder2();
	esconder3();
}

function esconder1() {
	var prof,proCont;
	if (nn4) {
		prof = parseInt(findObj("content1").clip.bottom);
		profCont = parseInt(findObj("contentClip").clip.bottom);
		if (profCont >= prof){ 
			document.up.visibility="hide";
			document.down.visibility="hide";
			document.drag.visibility="hide";
			document.ruler.visibility="hide";
			document.fondo.visibility="hide";
			}
		else   { 
			document.up.visibility="show";
			document.down.visibility="show";
			document.drag.visibility="show";
			document.ruler.visibility="show";
			document.fondo.visibility="show"; 
			}
	}
	if (ie4) {		
		prof = parseInt(findObj("content1").style.height);
		profCont = parseInt(findObj("contentClip").style.height);
		if (profCont >= prof){
			document.all.up.style.visibility="hidden";
			document.all.down.style.visibility="hidden";
			document.all.drag.style.visibility="hidden";
			document.all.ruler.style.visibility="hidden";
			document.all.fondo.style.visibility="hidden";}
		else 	{			
			document.all.up.style.visibility="visible";
			document.all.down.style.visibility="visible";
			document.all.drag.style.visibility="visible";
			document.all.ruler.style.visibility="visible";
			document.all.fondo.style.visibility="visible";
			}
	}
        if (dom) {
                prof = parseInt(document.getElementById("content1").offsetHeight);
                profCont = parseInt(document.getElementById("contentClip").offsetHeight);
                if (profCont >= prof){
                        document.getElementById("up").style.visibility="hidden";
                        document.getElementById("down").style.visibility="hidden";
                        document.getElementById("drag").style.visibility="hidden";
                        document.getElementById("ruler").style.visibility="hidden";
                        document.getElementById("fondo").style.visibility="hidden";
                        }
                else    {
                        document.getElementById("up").style.visibility="visible";
                        document.getElementById("down").style.visibility="visible";
                        document.getElementById("drag").style.visibility="visible";
                        document.getElementById("ruler").style.visibility="visible";
                        document.getElementById("fondo").style.visibility="visible"; 
                        }
        }
}

function esconder2() {
	var prof,proCont;
	if (nn4) {
		prof = parseInt(findObj("content2").clip.bottom);
		profCont = parseInt(findObj("contentClip").clip.bottom);
		if (profCont >= prof){			
			document.up1.visibility="hide";
			document.down1.visibility="hide";
			document.drag1.visibility="hide";
			document.ruler1.visibility="hide";
			document.fondo1.visibility="hide";
			}
		else   { 
			document.up1.visibility="show";
			document.down1.visibility="show";
			document.drag1.visibility="show";
			document.ruler1.visibility="show";
			document.fondo1.visibility="show";
			}
	}
	else if (ie4) {		
		prof = parseInt(findObj("content2").style.height);
		profCont = parseInt(findObj("contentClip").style.height);
		if (profCont >= prof){			
			document.all.up1.style.visibility="hidden";
			document.all.down1.style.visibility="hidden";
			document.all.drag1.style.visibility="hidden";
			document.all.ruler1.style.visibility="hidden";
			document.all.fondo1.style.visibility="hidden";}
		else 	{			
			document.all.up1.style.visibility="visible";
			document.all.down1.style.visibility="visible";
			document.all.drag1.style.visibility="visible";
			document.all.ruler1.style.visibility="visible";
			document.all.fondo1.style.visibility="visible";
			}
	}
        if (dom) {
                prof = parseInt(document.getElementById("content2").offsetHeight);
                profCont = parseInt(document.getElementById("contentClip").offsetHeight);
                if (profCont >= prof){
                        document.getElementById("up1").style.visibility="hidden";
                        document.getElementById("down1").style.visibility="hidden";
                        document.getElementById("drag1").style.visibility="hidden";
                        document.getElementById("ruler1").style.visibility="hidden";
                        document.getElementById("fondo1").style.visibility="hidden";
                        }
                else    {
                        document.getElementById("up1").style.visibility="visible";
                        document.getElementById("down1").style.visibility="visible";
                        document.getElementById("drag1").style.visibility="visible";
                        document.getElementById("ruler1").style.visibility="visible";
                        document.getElementById("fondo1").style.visibility="visible"; 
                        }
        }
}

function esconder3() {
	var prof,proCont;
	if (nn4) {
		prof = parseInt(findObj("content3").clip.bottom);
		profCont = parseInt(findObj("divcontent3").clip.bottom);
		if (profCont >= prof){			
			document.up2.visibility="hide";
			document.down2.visibility="hide";
			document.drag2.visibility="hide";
			document.ruler2.visibility="hide";
			document.fondo2.visibility="hide";
			}
		else   { 
			document.up2.visibility="show";
			document.down2.visibility="show";
			document.drag2.visibility="show";
			document.ruler2.visibility="show";
			document.fondo2.visibility="show";
			}
	}
	else if (ie4) {		
		prof = parseInt(findObj("content3").style.height);
		profCont = parseInt(findObj("divcontent3").style.height);
		if (profCont >= prof){			
			document.all.up2.style.visibility="hidden";
			document.all.down2.style.visibility="hidden";
			document.all.drag2.style.visibility="hidden";
			document.all.ruler2.style.visibility="hidden";
			document.all.fondo2.style.visibility="hidden";}
		else 	{			
			document.all.up2.style.visibility="visible";
			document.all.down2.style.visibility="visible";
			document.all.drag2.style.visibility="visible";
			document.all.ruler2.style.visibility="visible";
			document.all.fondo2.style.visibility="visible";
			}
	}
        if (dom) {
                prof = parseInt(findObj("content3").offsetHeight);
                profCont = parseInt(findObj("divcontent3").offsetHeight);
                if (profCont >= prof){
                        document.getElementById("up2").style.visibility="hidden";
                        document.getElementById("down2").style.visibility="hidden";
                        document.getElementById("drag2").style.visibility="hidden";
                        document.getElementById("ruler2").style.visibility="hidden";
                        document.getElementById("fondo2").style.visibility="hidden";
                        }
                else    {
                        document.getElementById("up2").style.visibility="visible";
                        document.getElementById("down2").style.visibility="visible";
                        document.getElementById("drag2").style.visibility="visible";
                        document.getElementById("ruler2").style.visibility="visible";
                        document.getElementById("fondo2").style.visibility="visible"; 
                        }
        }
}

function layerWrite(id,text) {
        
	if (nn4) {
		//var lyr = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document;
		var lyr=findObj(id).document;
		lyr.open();
		lyr.write(text);
		lyr.close();
	}
	else if (dom) {
            if (id=="content2") {
                findObj(id).style.visibility="visible";
            }
            findObj(id).innerHTML = text;
        }
}

function swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function findObj(n, d) {  
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); 
  return x;
}


function escribirCategorias(){
	var i,j,z,texto="";
//Escribimos el formulario global
	texto="<form name=\"formTotal\" method=\"post\">\n";
//Primero los campos obligatorios de formato,canal e idioma
	if (obligatorias){
	if ((esSMS)&&(!esUsuario)){
   		texto=texto+"<input type=\"hidden\" name=\"canal\" value=\"0\">\n";
    		texto=texto+"<input type=\"hidden\" name=\"formato\" value=\"0\">\n";
    		texto=texto+"<input type=\"hidden\" name=\"idioma\"  value=\"0\">\n";
	}
	else {
	for (z=0;z<obligatorias.array.length;z++){
		if (obligatorias.array[z]==formato){
		   for (i=0;i<obligatorias.array[z].array.length;i++){
		     if (!esSMS){
			if (obligatorias.array[z].array[i].checked){
			texto=texto+"<input type=radio name='formato' value=\""+obligatorias.array[z].array[i].valor+"\" checked>"+obligatorias.array[z].array[i].texto+"\n";
			}
			else {
			texto=texto+"<input type=radio name='formato' value=\""+obligatorias.array[z].array[i].valor+"\">"+obligatorias.array[z].array[i].texto+"\n";
			}
		     }
		     else {texto=texto+"<input type=hidden name='formato' value=\""+obligatorias.array[z].array[i].valor+"\">"+obligatorias.array[z].array[i].texto+"\n";}
		   }
		}
		else if (obligatorias.array[z]==idioma){
		   for (i=0;i<obligatorias.array[z].array.length;i++){
			if (obligatorias.array[z].array[i].checked){
			texto=texto+"<input type=radio name='idioma' value=\""+obligatorias.array[z].array[i].valor+"\" checked>"+obligatorias.array[z].array[i].texto+"\n";
			}
			else {
			//if ((obligatorias.array[z].array[i].texto!="Ingl&eacute;s")&&(obligatorias.array[z].array[i].texto!="Ingelesa"))
			texto=texto+"<input type=radio name='idioma' value=\""+obligatorias.array[z].array[i].valor+"\">"+obligatorias.array[z].array[i].texto+"\n";
			}
		   }	
		}
		else if (obligatorias.array[z]==canal){
		   for (i=0;i<obligatorias.array[z].array.length;i++){
			if (obligatorias.array[z].array[i].checked){
			texto=texto+"<input type=radio name='canal' value=\""+obligatorias.array[z].array[i].valor+"\" checked>"+obligatorias.array[z].array[i].texto+"\n";
			}
			else {
			texto=texto+"<input type=radio name='canal' value=\""+obligatorias.array[z].array[i].valor+"\">"+obligatorias.array[z].array[i].texto+"\n";
			}
		   }			
		}
	}
	//favoritos-global
	if (esUsuario) {
		texto=texto+"<input type=checkbox name=\"favoritos\">\n";
	}
	}
	}
//Despues los  campos Parametrizables
	if (!nocategorias.flag){
	for (z=0;z<categorias.array.length;z++){
		for (i=0;i<categorias.array[z].array.length;i++){
			if (categorias.array[z].array[i].tipo=="lista"){
				texto=texto+"<select name=\""+categorias.array[z].array[i].name+"\">\n";
				for (j=0;j<categorias.array[z].array[i].array.length;j++){
					if (categorias.array[z].array[i].array[j].selected){
					texto=texto+"<option class=\""+categorias.array[z].array[i].name+"\" selected value=\""+categorias.array[z].array[i].array[j].valor+"\">"+categorias.array[z].array[i].array[j].texto+"\n";
					}
					else {
					texto=texto+"<option class=\""+categorias.array[z].array[i].name+"\" value=\""+categorias.array[z].array[i].array[j].valor+"\">"+categorias.array[z].array[i].array[j].texto+"\n";
					}
				}
				texto=texto+"</select>\n";
			}
			if (categorias.array[z].array[i].tipo=="checkbox"){
				if (categorias.array[z].array[i].checked){
				texto=texto+"<input type=checkbox checked name='"+categorias.array[z].array[i].name+"' value='"+categorias.array[z].array[i].valor+"'>"+categorias.array[z].array[i].texto+"\n";
				}
				else {
				texto=texto+"<input type=checkbox name='"+categorias.array[z].array[i].name+"' value='"+categorias.array[z].array[i].valor+"'>"+categorias.array[z].array[i].texto+"\n";
				}
			}
		}
	}
	}
//Por ultimo los ocultos
	if (ocultos){
	for (z=0;z<ocultos.array.length;z++){
		texto=texto+"<input type=\"hidden\" name=\""+ocultos.array[z].nombre+"\" value=\""+ocultos.array[z].valor+"\">\n";
	}
	}
	texto=texto+"</form>\n";
	layerWrite("form",texto);
//Fin escribir
//Escribimos en el layer visible de los campo obligatorios
	texto="<form name=\"formVisible\">\n";
	if ((esSMS)&&(!esUsuario)){
		texto=texto+"<table width=\"100%\"><tr><td valign=top><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+errors+"</font></b><br></td></tr></table>";
	}
	else {
	if (obligatorias){
	texto=texto+"<table width=\"180\">\n";
	for (z=0;z<obligatorias.array.length;z++){
		if (obligatorias.array[z]==formato){
		   texto=texto+"<tr><td valign=top>\n";
		   texto=texto+"<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+formato.nombre+"</font></b><br>\n";
		   for (i=0;i<obligatorias.array[z].array.length;i++){
		     if (!esSMS){
			if (obligatorias.array[z].array[i].checked){
			texto=texto+"&nbsp;<img alt='' src=\"images/"+obligatorias.array[z].array[i].imagen+"\" width=\"15\" height=\"15\"><input type=radio name='formato' value=\""+obligatorias.array[z].array[i].valor+"\" checked><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obligatorias.array[z].array[i].texto+"</font></b><br>\n";
			}
			else {
			texto=texto+"&nbsp;<img alt='' src=\"images/"+obligatorias.array[z].array[i].imagen+"\" width=\"15\" height=\"15\"><input type=radio name='formato' value=\""+obligatorias.array[z].array[i].valor+"\"><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obligatorias.array[z].array[i].texto+"</font></b><br>\n";
			}
		     }
		     else {texto=texto+"&nbsp;<img alt='' src=\"images/"+obligatorias.array[z].array[i].imagen+"\" width=\"15\" height=\"15\"><input type=hidden name='formato' value=\""+obligatorias.array[z].array[i].valor+"\"><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obligatorias.array[z].array[i].texto+"</font></b><br>\n";}
		   }
		   texto=texto+"</td>\n";
		}
		else if (obligatorias.array[z]==idioma){
		   texto=texto+"<td valign=top>\n";
		   texto=texto+"<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+idioma.nombre+"</font></b><br>\n";
		   for (i=0;i<obligatorias.array[z].array.length;i++){
			if (obligatorias.array[z].array[i].checked){
			texto=texto+"&nbsp;<img alt='' src=\"images/"+obligatorias.array[z].array[i].imagen+"\" width=\"15\" height=\"15\"><input type=radio name='idioma' value=\""+obligatorias.array[z].array[i].valor+"\" checked><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obligatorias.array[z].array[i].texto+"</font><b><br>\n";
			}
			else {
//			if ((obligatorias.array[z].array[i].texto!="Ingl&eacute;s")&&(obligatorias.array[z].array[i].texto!="Ingelesa"))
			texto=texto+"&nbsp;<img alt='' src=\"images/"+obligatorias.array[z].array[i].imagen+"\" width=\"15\" height=\"15\"><input type=radio name='idioma' value=\""+obligatorias.array[z].array[i].valor+"\"><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obligatorias.array[z].array[i].texto+"</font></b><br>\n";
//			else
//			texto=texto+"&nbsp;<img src=\"images/"+obligatorias.array[z].array[i].imagen+"\" width=\"15\" height=\"15\"><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>&nbsp;"+prox+"</font></b><br>\n";
			}
		   }	
		   texto=texto+"</td></tr>\n";
		}
		else if (obligatorias.array[z]==canal){
		   texto=texto+"<tr><td colspan=2>\n";
		   texto=texto+"<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+canal.nombre+"</font></b><br>\n";
		   for (i=0;i<obligatorias.array[z].array.length;i++){
			if (obligatorias.array[z].array[i].checked){
			texto=texto+"&nbsp;<img alt='' src=\"images/"+obligatorias.array[z].array[i].imagen+"\" width=\"15\" height=\"15\"><input type=radio name='canal' value=\""+obligatorias.array[z].array[i].valor+"\" checked><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obligatorias.array[z].array[i].texto+"</font></b><br>\n";
			}
			else {
			texto=texto+"&nbsp;<img alt='' src=\"images/"+obligatorias.array[z].array[i].imagen+"\" width=\"15\" height=\"15\"><input type=radio name='canal' value=\""+obligatorias.array[z].array[i].valor+"\"><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obligatorias.array[z].array[i].texto+"</font></b><br>\n";
			}
		   }
		   texto=texto+"</td></tr>\n";			
		}
	}
	//acaba el form
	if (esUsuario) {
		texto=texto+"<tr><td colspan=2><input type=checkbox name=\"favoritos\"><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>" + favor + "</font></b></td></tr>";
	}
	}
	//acaba el else
	texto=texto+"</table>\n";
	}
	texto=texto+"</form>\n";
	if (nocategorias.flag){
		layerWrite("content1","<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#FFFFFF'>"+titulo+"</font></b>");
		layerWrite("content2",texto);
		layerWrite("content3","<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+nocategorias.texto+"</font></b>");
	}
	else {
		layerWrite("content3",texto);
		objActual=categorias.array[0];
		escribirFormulario(categorias.array[0],0);
		texto="<table width=\"190\">\n";
		texto=texto+"<tr><td width=\"190\"><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'><b>"+camposp+"</b></font></td></tr>\n";
		for (i=0;i<categorias.array.length;i++){
			texto=texto+"<tr><td width=\"190\"><a href=\"#\" onClick=\"escribirFormulario("+categorias.array[i].name+","+i+");\"><img alt='' name=\"Image"+i+"\" border=\"0\" src=\"images/mas.gif\"><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+categorias.array[i].texto+"</font></b></a></td></tr>\n"
		}
		texto=texto+"</table>\n";
		titi="<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#FFFFFF'>"+titulo+"</font></b><br>"+texto;
		layerWrite("content1",titi);

	}
//Fin escribir
}

function escribirFormulario(obj,id){
	var form1,form2,i,j,texto="";
//Pasar del Formulario al Global
	form1=eval("findObj(\"form"+objActual.texto+"\")");
	form2=findObj("formTotal");
	if (form1){
		for (i=0;i<objActual.array.length;i++){
			if (objActual.array[i].tipo=="lista"){
				  //miro si he elegido ULTIMO
				  if (esdetipoCuatro(eval("form1."+objActual.array[i].name))){
					  if (eval("form1."+objActual.array[i].name+".options[form1."+objActual.array[i].name+".selectedIndex].value")=="@@@") {
						  valoresUltimo(form2,eval("form1."+objActual.array[i-1].name+".options.length"),eval("form1."+objActual.array[i-1].name+".selectedIndex"));
					  }
					  else {
						  valoresUltimoNO(form2);
					  }
				  }
			  eval("form2."+objActual.array[i].name+".selectedIndex=form1."+objActual.array[i].name+".selectedIndex");
			}
			if (objActual.array[i].tipo=="checkbox"){
			  eval("form2."+objActual.array[i].name+".checked=form1."+objActual.array[i].name+".checked");
			}
		}
	}
//Fin pasar
//Preparando el Layer de contenido 2
	if (ie4){findObj("content2").style.pixelTop=0;dragT1=162;}
	else if (nn4) {findObj("content2").top=0;dragT1=152;}
	else if(dom){findObj("content2").style.top = 0 + "px";dragT1=152;}
	contentT1=0;
	moveTo1();
	swapImgRestore();
	eval("swapImage('Image"+id+"','','images/menos.gif',1)");
//Preparado

	objActual=obj;
	
	texto=texto+"<form name=\"form"+obj.texto+"\"><table width='180'><tr><td>\n";
	texto=texto+"<center><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'><b>"+campos+" "+obj.texto+"</b></font></center><br>\n";
	if (obj.array[0].tipo=="checkbox"){
		texto=texto+"<a href='#' onClick=\"selectDeselect('form" + obj.texto + "',true);\"><img alt='' src='images/select.gif' border='0'><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>" + selecci + "</font></a><br><a href='#' onClick=\"selectDeselect('form" + obj.texto + "',false);\"><img alt='' src='images/deselect.gif' border='0'><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>" + desselecci  + "</font></a><br>\n";
	}
	for (i=0;i<obj.array.length;i++){
		if (obj.array[i].tipo=="lista"){
			texto=texto+"<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obj.array[i].texto+"&nbsp;</font></b>\n";
			texto=texto+"<select name=\""+obj.array[i].name+"\" class=\"letrapequena\">\n";
			for (j=0;j<obj.array[i].array.length;j++){
				texto=texto+"<option class=\""+obj.array[i].name+"\" value=\""+obj.array[i].array[j].valor+"\"><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obj.array[i].array[j].texto+"</font></b>\n";
			}
			texto=texto+"</select><br>\n";
		}
		if (obj.array[i].tipo=="checkbox"){
			texto=texto+"<input type=checkbox name='"+obj.array[i].name+"' value='"+obj.array[i].valor+"'><b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>"+obj.array[i].texto+"</font></b><br>\n";
		}
	}
	texto=texto+"</td></tr></table></form>\n";
	layerWrite("content2",texto);
	esconder2();

//Pasar del Global al Formulario
	form1=eval("findObj(\"form"+objActual.texto+"\")");
	form2=findObj("formTotal");
	if (form1){
		for (i=0;i<objActual.array.length;i++){
			if (objActual.array[i].tipo=="lista"){
			  eval("form1."+objActual.array[i].name+".selectedIndex=form2."+objActual.array[i].name+".selectedIndex");
			}
			if (objActual.array[i].tipo=="checkbox"){
			  eval("form1."+objActual.array[i].name+".checked=form2."+objActual.array[i].name+".checked");
			}
		}
	}
//Fin pasar
}

function enviar(){
	var form1,form2;

	form2=findObj("formTotal");
	if (!nocategorias.flag){
//Pasar de los Formularios ocultos al Global
	  form1=eval("findObj(\"form"+objActual.texto+"\")");
	  if (form1){
		for (i=0;i<objActual.array.length;i++){
			if (objActual.array[i].tipo=="lista"){
				  //miro si he elegido ULTIMO
				  if (esdetipoCuatro(eval("form1."+objActual.array[i].name))){
					  if (eval("form1."+objActual.array[i].name+".options[form1."+objActual.array[i].name+".selectedIndex].value")=="@@@") {
						  valoresUltimo(form2,eval("form1."+objActual.array[i-1].name+".options.length"),eval("form1."+objActual.array[i-1].name+".selectedIndex"));
					  }
					  else {
						  valoresUltimoNO(form2);
					  }
				  }
			  eval("form2."+objActual.array[i].name+".selectedIndex=form1."+objActual.array[i].name+".selectedIndex");
			}
			if (objActual.array[i].tipo=="checkbox"){
			  eval("form2."+objActual.array[i].name+".checked=form1."+objActual.array[i].name+".checked");
			}
		}
	   }
	}
//Fin pasar
//Pasar del Formulario visible al Global
	form1=findObj("formVisible");
	if (form2.idioma.value) {
		form2.idioma.checked=form1.idioma.checked;
		form2.idioma.value=form1.idioma.value;
	}
	else {
		for (i=0;i<form2.idioma.length;i++){
			form2.idioma[i].checked=form1.idioma[i].checked;
		}
	}
	
	if (form2.canal.value) 
	{
		form2.canal.checked=form1.canal.checked;
		form2.canal.value=form1.canal.value;
	}
	else {
		for (i=0;i<form2.canal.length;i++){
			form2.canal[i].checked=form1.canal[i].checked;
		}
	}
	
	if (!esSMS){
		if (form2.formato.value) {
			form2.formato.checked=form1.formato.checked;
			form2.formato.value=form1.formato.value;
		}
		else {
			for (i=0;i<form2.formato.length;i++){
				form2.formato[i].checked=form1.formato[i].checked;
			}
		}
	}
	if (esUsuario) {
		form2.favoritos.checked=form1.favoritos.checked;	
	}
	
	//comprobar que haya elegido algun campo parametrizable
	if ((esUsuario)&&(!esSMS)) {
			salir=false;
			for (var i=0;i<categorias.array.length;i++) {
				objatratar=categorias.array[i];
				pulsado=false;
				for (var j=0;j<objatratar.array.length;j++) {
						if ((objatratar.array[j].tipo==="checkbox")&&eval("form2."+objatratar.array[j].name+".checked")){
								pulsado=true;
						}
				}
				if ((!pulsado)&&(objatratar.array[0].tipo==="checkbox")){
						salir=true;
						alert(mensajefallo+" '"+objatratar.texto+"'");
				}
			}
			if (salir){
					return;
			}
	}
	
//Fin Pasar
//Mostrar layer "procesandose"
  c2=findObj("content2");
  ppp=findObj("procesandose");
  dow1=findObj("down1");
  dow2=findObj("fondo1");
  if (nn4) {
		  ppp.visibility = "show";
		  c2.visibility = "hide";
		  dow1.visibility = "hide";
		  dow2.visibility = "hide";
  }
  else {
		  ppp.style.visibility = "visible";
		  c2.style.visibility = "hidden";
		  dow1.style.visibility = "hidden";
		  dow2.style.visibility = "hidden";
  }
 //Fin Mostrar layer
	form2.submit();
}

function selectDeselect(formu,checked){
	form1=findObj(formu);
	for (var i=0;i<form1.elements.length;i++) {
		var e = form1.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox')) {
			e.checked = checked;
		}
	}
}

function valoresUltimo(formu,tamano,elegido) {
var valor;
	
	valor=(tamano-elegido)-1;
	if (valor==0) {valor=1;}
	formu.esultimo.value="1";
	formu.ultimon.value=valor;
}

function valoresUltimoNO(formu) {
	formu.esultimo.value="0";
	formu.ultimon.value="0";
}

function esdetipoCuatro(formu){
devolver=false;
	for (j=0;j<formu.options.length;j++) {
		if (formu.options[j].value=="@@@") {
			devolver=true;
		}
	}
	return devolver;
}
