// JavaScript Document
// Code for the form select between cartas, catalog or ambos.

function changeTheForm(choice){
	var oHidden = document.getElementById('smodeTag');
	
	switch(choice){
		case "0":
			oHidden.innerHTML='<input type="hidden" name="smode" value="form-modify" /><input type="hidden" name="relation" value="" />';
			break;
		case "1":
			oHidden.innerHTML='<input type="hidden" name="smode" value="form-modify" /><input type="hidden" name="relation" value="relCarta" />';
			break;
		case "2":
			oHidden.innerHTML='<input type="hidden" name="smode" value="form-modify" /><input type="hidden" name="relation" value="relCatalog" />';
			break;
		default:
			oHidden.innerHTML='';
			break;
	}
	
	document.getElementById('frmBusqueda').submit();
}


/* Show/Hide Searchform variables*/
bMainOnOff=true;
bSubOnOff=true;
oFrmSub=document.getElementById('frmSearchAdvanceHide');
sSearchValue="";

 sAutor="";
 sText="";
 sDestinatario="";
 sOrigen="";
 sDestino="";
 sAno="";
 sTitulo="";
 sMateria="";
 sEpigraph="";

/* Show/Hide MainSearchform*/
function formShowHide(){
    var oFrmMain=document.getElementById('frmSearchHide');
    var oImg=document.getElementById('btnShowHide');
    if(!bMainOnOff){
            oFrmMain.style.display="none";
            oImg.src="icons/rb/down.png";
            bMainOnOff=true;
    }else{
        if(bSubOnOff){
             
            oFrmMain.style.display="block";
            oImg.src="icons/rb/up.png";
            bMainOnOff=false;
       }else{
            if(!bSubOnOff){
                document.getElementById('frmSearchAdvanceHide').style.display="none";
                bSubOnOff=true;
            }
              oFrmMain.style.display="none";
              oImg.src="icons/rb/up.png";
              bMainOnOff=true;
          }
    }
}

/* Show/Hide SubSearchform */
function formAdvancedShowHide(){
    if(!bSubOnOff){
            document.getElementById('frmSearchAdvanceHide').style.display="none";
            bSubOnOff=true;
            formShowHide();
    }else{
        document.getElementById('frmSearchAdvanceHide').style.display="block";
        bSubOnOff=false;
        formShowHide();
        }
}


/* Change search meta combobox elementen */

function changeSearchSelect(sValue){
// oTxtSearch=document.getElementById("txtSearch");
var oText=document.getElementById("txtText");
var oAutor=document.getElementById("txtAutor");
var oDestinatario=document.getElementById("txtDestinatario");
var oOrigen=document.getElementById("txtOrigen");
var oDestino=document.getElementById("txtDestino");
var oAno=document.getElementById("txtAno");
var oTitulo=document.getElementById("txtTitulo");
var oMateria=document.getElementById("txtMateria");
var oEpigraph=document.getElementById("txtEpigraph");
 

 //window.alert(sValue);
 
        switch(sValue){
            case "text":
                showHideControls(oText, oAutor, oDestinatario, oOrigen, oDestino, oAno, oTitulo, oMateria, oEpigraph);
                break;
            case "autor":
                showHideControls(oAutor, oText, oDestinatario, oOrigen, oDestino, oAno, oTitulo, oMateria, oEpigraph);
                break;
            case "destinatario":
                showHideControls(oDestinatario, oText, oAutor, oOrigen, oDestino, oAno, oTitulo, oMateria, oEpigraph);
                break;
            case "origen":
                showHideControls(oOrigen, oText, oAutor, oDestinatario, oDestino, oAno, oTitulo, oMateria, oEpigraph);
                break;
             case "destino":
                showHideControls(oDestino, oText, oAutor, oDestinatario, oOrigen, oAno, oTitulo, oMateria, oEpigraph);
                break;               
            case "ano":
                showHideControls(oAno, oText, oAutor, oDestinatario, oOrigen, oDestino, oTitulo, oMateria, oEpigraph);
                break;
            case "titulo":
                showHideControls(oTitulo, oText, oAutor, oDestinatario, oOrigen, oDestino, oAno, oMateria, oEpigraph);
                break;                
            case "materia":
                showHideControls(oMateria, oText, oAutor, oDestinatario, oOrigen, oDestino, oAno, oTitulo, oEpigraph);
                break;        
            case "epigraph":
                showHideControls(oEpigraph, oText, oAutor, oDestinatario, oOrigen, oDestino, oAno, oTitulo, oMateria);
                break;
             default:
                break;               
        }
 
 
       /*  sSearchValue=sValue; 
        var oTxtSearch=document.getElementById("txtSearch");
        oTxtSearch.innerHTML="";
        oTxtSearch.innerHTML='<input type="text" name="' + sValue  + '" value="' + sValue + '" id="txtSearchWord" />';
        document.getElementById("txtSearchWord").value="";*/
}

/* Change sort */
function changeSortSelect(sID){
    oCbo=document.getElementById("cboSort");
    i = 0 
    while (oCbo[i]!= null) 
    { 
        if(sID == oCbo[i].value){ 
        oCbo.selectedIndex = i; 
        } 
        i++ 
    }
    sortSubmit();
}

function sortSubmit(){
    document.frmSort.submit();
}


show = false;

function titleShowHide(td){
    var parent=td;
    //alert(parent.firstChild.nodeName);
if(parent.firstChild.nodeName.toLowerCase() =='span'){ /**/
   
        snippet=parent.firstChild;
        fullTitle=parent.firstChild.nextSibling;
        if(!show){
            snippet.style.display="none";
            fullTitle.style.display="block";
            parent.style.backgroundColor="#EFEFEF";
            show=true;
        }else{
            snippet.style.display="block";
            fullTitle.style.display="none";
            parent.style.backgroundColor="#FFFFFF";
            show=false;
           } 
    }else if(parent.firstChild.nodeName.toLowerCase() =='a' && parent.firstChild.nextSibling.nodeName.toLowerCase() =='span'){
        snippet=parent.firstChild.nextSibling;
        fullTitle=parent.firstChild.nextSibling.nextSibling;
        if(!show){
            snippet.style.display="none";
            fullTitle.style.display="block";
            parent.style.backgroundColor="#EFEFEF";
            show=true;
        }else{
            snippet.style.display="block";
            fullTitle.style.display="none";
            parent.style.backgroundColor="#FFFFFF";
            show=false;
           }      
    }
}

/*
function titleShowHide(title){
    snippet=title;
    fullTitle=snippet.nextSibling;
    if(snippet.style.display=="none"){
        snippet.style.display="block";
        fullTitle.style.display="none";   
    }else{
        snippet.style.display="none";
        fullTitle.style.display="block";
       }
}

f(snippet.style.display!="none"){
             snippet.style.display="none";
            fullTitle.style.display="block";  
        }else{
            snippet.style.display="block";
            fullTitle.style.display="none";
           } */

/*Show tooltip with full titulo */
/*
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
hoogte=document.getElementById('tooltip').style.height;
d.style.left = 50 + "px";
d.style.top = (cY - 20 - hoogte) + "px";
}

function hideTooltip(d) {
if(d.length < 1) { return; }
dd=document.getElementById(d);
dd.style.display = "none";
dd.innerHTML="";
}

function showTooltip(t,d) {
if(d.length < 1) { return; }
dd = document.getElementById(d);
AssignPosition(dd);
     titulo = t;
     text = document.createTextNode( ""+ titulo);
    dd.appendChild(text);
    dd.style.display = "block";
}
*/

/*   
 function setPos(elem){		
     
  posleft=document.body.scrollLeft+window.event.clientX - 20 ;
     postop=window.event.clientY;
     
     elem.style.top = postop - elem.style.height + 'px';
     elem.style.left = '20px';*/
     
     
    /* x = (window.Event) ? e.pageX : event.clientX;
     y = (window.Event) ? e.pageY : event.clientY;

     elem.style.top =  y - document.documentElement.scrollTop+'px';
     elem.style.left =document.documentElement.scrollLeft +  '20px';*/
    
/*    var posleft = mouseY(window.Event);
    var postop = mouseX(window.Event);
     elem.style.top = postop + 'px';
     elem.style.left = posleft + 'px';*/
     
   /* var bWidth = parseInt(elem.offsetWidth);
    var bHeight = parseInt(elem.offsetHeight);
    var bPosX = parseInt(woord.offsetTop);
    var bPosY = parseInt(woord.offsetLeft);
    

    			
    if (bPosX - bHeight < 0){
	bPosX = bPosX + parseInt(woord.offsetHeight);
    }
    else{
	bPosX -= bHeight;
    }

    if (bPosY + bWidth > parseInt(document.getElementById('Container').offsetWidth)){
	bPosY = (bPosY + bWidth) - parseInt(document.getElementById('Container').offsetWidth);
    }
			
    elem.style.top = bPosX + 'px';
    elem.style.left = bPosY + 'px';	
}
*/

function  getFRM(obj){
	//alert(obj.parentNode.nodeName);
	if(obj.parentNode.nodeName.toLowerCase() == 'form'){
		return obj.parentNode;
	}else{
		return getFRM(obj.parentNode);	
	}
}

function directToList(btn){
	var frm = getFRM(btn);
	//alert(frm.id);
	var oSmode = frm.firstChild;
	//alert(oSmode.id);
	var smode = '<input type="hidden" name="smode" value="search-' + btn.parentNode.firstChild.name + '"/>';
	//alert(smode);
	oSmode.innerHTML = smode;
	frm.submit();
}

function showHideControls(oShow, oHide1, oHide2, oHide3, oHide4, oHide5, oHide6, oHide7, oHide8){
                oShow.style.display="inline";
                oHide1.style.display="none";
                oHide2.style.display="none";
                oHide3.style.display="none";
                oHide4.style.display="none";
                oHide5.style.display="none";
                oHide6.style.display="none";
                oHide7.style.display="none";
                oHide8.style.display="none";
}

function hideCombobox(){
       document.getElementById("cmbSelect").innerHTML="";
}

function setSelectCbo(relation){
     
     oFrm=document.getElementById('frmSearchAdvanceHide');
     //changeSortSelect("autor");
     switch(relation){
         case "relCarta":
             sAutor=oFrm.autor.value;
             sText=oFrm.text.value;
             sDestinatario=oFrm.destinatario.value;
             sOrigen=oFrm.origen.value;
             sDestino=oFrm.destino.value;
             sAno=oFrm.ano.value;
             break;
         case "relCatalog":
             sAutor=oFrm.autor.value;
             sText=oFrm.text.value;
             sAno=oFrm.ano.value;
             sTitulo=oFrm.titulo.value;
             sMateria=oFrm.materia.value;
             sEpigraph=oFrm.epigraph.value;
             break;
         case "relTodos":
             sAutor=oFrm.autor.value;
             sText=oFrm.text.value;
             sAno=oFrm.ano.value;
             break;
        default:
             break;
     }
     
     //window.alert("autor: " + sAutor);
    
    changeSearchSelect(document.getElementById('selecto').value);
}

function setRangeMode(){
    document.getElementById("setRange").innerHTML='<input type="hidden" name="coverage" value="range" />';
}
