
function setDisable( type ){

	if( type == 1 ){
	
		document.getElementById("image_str").disabled = "disabled";
		document.getElementById("title_str").disabled = false;
		document.getElementById("message_str").disabled = false;
		document.getElementById("author_str").disabled = false;
	
	}else{
	
		document.getElementById("title_str").disabled = "disabled";
		document.getElementById("message_str").disabled = "disabled";
		document.getElementById("author_str").disabled = "disabled";
		document.getElementById("image_str").disabled = false;
	
	}

}

function deleteFavorite( code ){
	if(confirm("Você deseja confirmar esta ação?"))			
		trator_removeFavorite( code );
}


function showImage( src ){

	document.getElementById('bigImage').src = src;

}

function getKey( e , index , page ){
	
	var pagina = index.toString() + page.toString();
	
	var tecla=(window.event)?event.keyCode:e.which;
	
	if( tecla == 13 ){

		document.location.href = pagina;		
	
	}

}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}

function eNum(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

/**
	* Confirma a exclusão de determinado objeto
	* @Event OnSubmit
	* @since 04/10/2006
	* @author Jonathan Pereira <jonathan@5clicks.com.br>
	* @access public
	*/

function createConfirm( codType , cod ){
		
		switch (codType) {
			case 0:
				type = "um usuário";
				destiny = "index.php?session=listUsers"
				break
			case 1:
				arr = cod.split( "|" );cod = arr[0];
				type = "um item";
				destiny = "index.php?session="+arr[1]
				break
			case 2:
				type = "uma maquina";
				destiny = "index.php?session=listMachines"
				break
			case 3:
				type = "uma proposta";
				destiny = "index.php?session=listProposals"
				break	
			case 4:
				type = "uma serie";
				destiny = "index.php?session=listSeries"
				break	
			case 5:
				type = "um pedido";
				destiny = "index.php?session=listBuys"
				break	
			case 6:
				type = "uma máquina";
				destiny = "index.php?session=listStolenMachines"
				break	
			case 7:
				type = "uma newsletter";
				destiny = "index.php?session=listNewsLetters"
				break	
			case 9:
				type = "um e-mail";
				destiny = "index.php?session=listMailing"
				break	
			case 10:
				type = "um banner";
				destiny = "index.php?session=listBanners"
				break	
			case 11:
				type = "um usuário do sistema";
				destiny = "index.php?session=listUsersSystem"
				break					
		}
		
		if( confirm( "Você está prestes a excluir "+type+". Deseja confirmar esta ação?" ) ){
		
			location.href= destiny+"&drop=1&code="+cod ;
		
		}
		
	}	
		
	var lastObject;

	function changeColor() {
		if ( this.type == "text" || this.type == "textarea" || this.type == "password" || this.type == "file" || this.type == "select" ) {
			this.style.borderColor = '#999';			
			if ( ( lastObject.name != undefined ) && ( lastObject.name != this.name ) ) {
				lastObject.style.borderColor = '#D9D9D9';
			}
			lastObject = this;
		}
	}
	
	function callElementsInForm() {
		if ( document.forms.length != 0 )
			lastObject = document.forms[ 0 ].elements[ 0 ];
		f = document.forms;
		
		for ( var i = 0; i < f.length; i++ ) {
			for ( var j = 0; j < f[ i ].elements.length; j++ ) {
				f[ i ].elements[ j ].onfocus = changeColor;
			}
		}
	}
	
	function enableButton(id){
		
		obj = document.getElementById(id);
		
		obj.disabled = !(obj.disabled);
		
	}
	
	/**
	* Mascara para Data
	* @Event OnKeyUp
	* @since 06/10/2006
	* @access public
	*/

	function mask(str,textbox,loc,delim){
		
		var locs = loc.split(',');

		for (var i = 0; i <= locs.length; i++){
			for (var k = 0; k <= str.length; k++){
				if (k == locs[i]){
					if (str.substring(k, k+1) != delim){
						if (event.keyCode != 8)
						str = str.substring(0,k) + delim + str.substring(k,str.length);
					}
				}
			}
		}
		
		document.getElementById(textbox.name).value = str;
	
	}
	
	/**
	* Controle de produtos alterados
	* @since 06/10/2006
	* @access public
	*/
	
	function addCheckBoxChanged( code ){

		exist = 0;
		
		arrCheckBox = document.getElementById("checkBoxChanged").value.split(",");
		
		for( x = 0 ; x < arrCheckBox.length ; x++ ){
			
			if( arrCheckBox[x] == code )
				exist = 1;
				
		}
		
		if( exist == 0 )
			document.getElementById("checkBoxChanged").value += code + ",";
		else{
		
			teste = "";
			
			arrCheckBox = document.getElementById("checkBoxChanged").value.split(",");
			
			for( x = 0 ; x < arrCheckBox.length - 1 ; x++ ){
				
				if( arrCheckBox[x] != code )
					teste += arrCheckBox[x] + ",";
					
			}
			
			document.getElementById("checkBoxChanged").value = teste;
		
		}
			

	}
	
	/**
	* Verifica se todos produtos selecionados estão com seus valores
	* @Event OnKeyUp
	* @since 06/10/2006
	* @access public
	*/
	
	function verifyProductsPrices(){
	
		error = 0;
		
		if( required('',document.offer,0) == true ){
	
		arrCheckBox = document.getElementById("checkBoxChanged").value.split(",");
		
		if( arrCheckBox.length > 1 ){
		
			for( x = 0 ; x < arrCheckBox.length - 1 ; x++ ){
				
				if( document.getElementById("priceProduct_"+arrCheckBox[x]).value == "" ){
					error = 1;
					x = arrCheckBox.length;
				}
			
			}
			
			if( error == 0 ){
			
				document.offer.submit();
				
			}else{
			
				alert("Coloque o valor de todos produtos selecionados para a oferta.");
				
			}
		
		}else{
		
			alert("Selecione ao menos um produto para inserir na oferta.");
			
		}
		
		}
		
	}
	
	
function limitTextarea( txtArea , limit )
{

    limite = limit;
    myTextArea = txtArea;
    myTextField = document.getElementById('cont_aux');

    if (myTextArea.value.length > limite) {
        myTextArea.value = myTextArea.value.substr(0, (myTextArea.value.length - 1));
    } else {
        myTextField.value=(limite - myTextArea.value.length);
    }
}

<!-- This script and many more are available free online at -->

<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Original:  Fred P -->

<!-- Begin

// Compare two options within a list by VALUES

function compareOptionValues(a, b) 

{ 

  // Radix 10: for numeric values

  // Radix 36: for alphanumeric values

  var sA = parseInt( a.value, 36 );  

  var sB = parseInt( b.value, 36 );  

  return sA - sB;

}



// Compare two options within a list by TEXT

function compareOptionText(a, b) 

{ 

  // Radix 10: for numeric values

  // Radix 36: for alphanumeric values

  var sA = parseInt( a.text, 36 );  

  var sB = parseInt( b.text, 36 );  

  return sA - sB;

}



// Dual list move function

function moveDualList( srcList, destList, moveAll ) 

{
  // Do nothing if nothing is selected

  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )

  {

    return;

  }



  newDestList = new Array( destList.options.length );



  var len = 0;



  for( len = 0; len < destList.options.length; len++ ) 

  {

    if ( destList.options[ len ] != null )

    {

      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );

    }

  }



  for( var i = 0; i < srcList.options.length; i++ ) 

  { 

    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )

    {

       // Statements to perform if option is selected



       // Incorporate into new list

       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );

       len++;

    }

  }



  // Sort out the new destination list

  newDestList.sort( compareOptionValues );   // BY VALUES

  //newDestList.sort( compareOptionText );   // BY TEXT



  // Populate the destination with the items from the new array

  for ( var j = 0; j < newDestList.length; j++ ) 

  {

    if ( newDestList[ j ] != null )

    {

      destList.options[ j ] = newDestList[ j ];

    }

  }



  // Erase source list selected elements

  for( var i = srcList.options.length - 1; i >= 0; i-- ) 

  { 

    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )

    {

       // Erase Source

       //srcList.options[i].value = "";

       //srcList.options[i].text  = "";

       srcList.options[i]       = null;

    }

  }



} // End of moveDualList()

//  End -->


function getSelectedMails( ){
	
	obj = document.getElementById("selectedMails");
	nameSelected = "e-mail";

	arrValues = "";

	for(var i=0;i<obj.options.length;i++){
		if(obj.options[i]){
			arrValues += "," + obj.options[i].value;
		}
	}
	
	if( arrValues == "" ){
		alert("Selecione ao menos um e-mail para enviar a newsletter.");
	}else{
		arrValues = arrValues.substr(1,arrValues.strlen)+",";
		document.getElementById("arrSelecteds").value = arrValues;
		document.newsLetter.submit();
	}
	
}

/**
* Gera um confirm para alteração de status
* @Event onClick
* @since 06/10/2006
* @access public
*/

function setStatusVehicle( action , codeMachine , admin ){

	if( confirm("Você deseja confirmar esta ação?") ){
		
		if( admin == 1 )
			location.href="index.php?session=listMachines&action="+action+"&codeMachine="+codeMachine;
		else
			location.href="listMachinesUsers.php?action="+action+"&codeMachine="+codeMachine;
	
	}
	
}