﻿function SelecionaTodosChecks(spanChk,tipoCheck){
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;
   for(i=0;i<elm.length;i++)
    if(elm[i].type=="checkbox" && elm[i].name.indexOf(tipoCheck)!=-1)
     {
       if(elm[i].checked!=xState)
         elm[i].checked = xState;
     }
 }

//CALENDÁRIO
function OpenCalendar(idname, postBack)
{   
	Page='../../../Paginas/Calendario/Calendario/Calendario.aspx?formname=' + document.forms[0].name+"&id="+idname+"&selected=0&postBack="+postBack;	
	popUp = window.open(Page, 'popupcal', 'width=200,height=220,left=250,top=250,status=yes');	
	popUp.focus();
	return false;
}

function OpenCalendarB(idname, idname1,  postBack)
{    
	Page='../../../Paginas/Calendario/Calendario/Calendario.aspx?formname=' + document.forms[0].name+"&id="+idname+"&selected=0&postBack=true";	
	popUp = window.open(Page, 'popupcal', 'width=200,height=220,left=250,top=250,status=yes');	
	popUp.focus();
}

function CallPrint(strid)
{
    var prtContent = document.getElementById(strid);
    
    var WinPrint = window.open('','','letf=0,top=0,width=0,height=0,toolbar=0,scrollbars=0,status=0');
    
    //document.writeln(opener.document.getElementById(strid).outerHTML);

    WinPrint.document.write(prtContent.innerHTML);
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();
    prtContent.innerHTML=strOldOne;
    return false;
}


//FUNCIONÁRIO
function PesqFunc(IdCtrl, CodCtrl, NomeCtrl, IdForn, CodForn, NomeForn,CampoEvento)
{
    var theform = document.forms[document.forms[0].name];
    
    if(CodCtrl != ''){
        theform.elements[CodCtrl].readOnly = false;
        theform.elements[CodCtrl].value    = CodForn;
        theform.elements[CodCtrl].readOnly = true;
    }//if
    if(NomeCtrl != ''){
        //Tira o readOnly somente para atribuir
        theform.elements[NomeCtrl].readOnly = false;
        theform.elements[NomeCtrl].value = NomeForn;
        theform.elements[NomeCtrl].readOnly = true;
    }//if
    if(IdCtrl != ''){        
        theform.elements[IdCtrl].value = IdForn;                            
    }
    if(CampoEvento != '')
	{
	    setTimeout('__doPostBack(\''+ CampoEvento +'\',\'\')', 0);
	}//if
    
        
}

function SetDate(formName, id, newDate, postBack)
{    
	eval('var theform = document.' + formName + ';');	
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');	
}
function ValY(){
	vReturn = "";
	if (document.body && document.body.scrollTop) 
		vReturn = document.body.scrollTop; 
	else if (window.scrollY) vReturn = window.scrollY; 
	return vReturn;
}
//FIM CALENDÁRIO


//FORNECEDOR
function DefinirFornecedor(IdCtrl, CodCtrl, NomeCtrl, IdForn, CodForn, NomeForn,CampoEvento)
{
    var theform = document.forms[document.forms[0].name];
    
    if(CodCtrl != ''){
        theform.elements[CodCtrl].readOnly = false;
        theform.elements[CodCtrl].value    = CodForn;
        theform.elements[CodCtrl].readOnly = true;
    }//if
    if(NomeCtrl != ''){
        //Tira o readOnly somente para atribuir
        theform.elements[NomeCtrl].readOnly = false;
        theform.elements[NomeCtrl].value = NomeForn;
        theform.elements[NomeCtrl].readOnly = true;
    }//if
    if(IdCtrl != ''){        
        theform.elements[IdCtrl].value = IdForn;                            
    }
    if(CampoEvento != '')
	{
	    setTimeout('__doPostBack(\''+ CampoEvento +'\',\'\')', 0);
	}//if
    
        
}
function LimpaCampoPesquisa(IdCtrl, CodCtrl, NomeCtrl, CampoEvento){
    var theform = document.forms[document.forms[0].name];
    
    if(CodCtrl != ''){
        theform.elements[CodCtrl].readOnly = false;
        theform.elements[CodCtrl].value    = '';
        theform.elements[CodCtrl].readOnly = true;
    }//if
    if(NomeCtrl != ''){
        //Tira o readOnly somente para atribuir
        theform.elements[NomeCtrl].readOnly = false;
        theform.elements[NomeCtrl].value = '';
        theform.elements[NomeCtrl].readOnly = true;
    }//if
    if(IdCtrl != ''){        
        theform.elements[IdCtrl].value = '';                            
    }
    
    if(CampoEvento != '')
	{
	    setTimeout('__doPostBack(\''+ CampoEvento +'\',\'\')', 0);
	}//if
}
//FIM FORNECEDOR

function VoltaCombo(){
	if(document.forms.length>0){
		for(x=1;x<document.forms[0].elements.length;x++){ 		  		
        	if(document.forms[0].elements[x].type =='select-one' || document.forms[0].elements[x].type =='select-multiple'){						
            	document.forms[0].elements[x].style.visibility = 'visible';    			
        	}
  		}
	}
}

function EscondeCombo(){
	if(document.forms.length>0){
		for(x=1;x<document.forms[0].elements.length;x++){ 		  		
        	if(document.forms[0].elements[x].type =='select-one' || document.forms[0].elements[x].type =='select-multiple'){						
            	document.forms[0].elements[x].style.visibility = 'hidden';    			
        	}
  		}
	}
}

function validadisp(ddldispensa, txtnota, txtfalta, txtac, ddlconceito, ddldificuldade, txtdificuldade, vtiponota) {
      if (ddldispensa.options[ddldispensa.selectedIndex].value == '') {
            txtnota.disabled  = false;
            txtfalta.disabled = false;
            txtac.disabled = false;
            ddlconceito.disabled = false;
            txtdificuldade.disabled = false;
            ddldificuldade.disabled = false;
            if (vtiponota == 'T')
            {
                txtnota.disabled  = false;
                ddlconceito.disabled = false;
            }
            else
            {
                if (vtiponota == 'A')
                {
                    txtnota.disabled  = true;
                    ddlconceito.disabled = false;
                }
                else
                {
                    txtnota.disabled  = false;
                    ddlconceito.disabled = true;
                }
            }
      }
      else
      {
            txtnota.disabled  = true;
            ddlconceito.disabled = true;
            txtac.disabled = true;
            txtfalta.disabled = true;
            ddlconceito.disabled = true;
            txtdificuldade.disabled = true;
            ddldificuldade.disabled = true;
      }      
}
