// JavaScript Document
function RTrim(VALUE){
    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";
    
    
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;


	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){}


		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
    }
   	return strTemp;
}

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);


	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;


	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){}


		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return "";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);


    	if(TRIM_VALUE == ""){
    		return "";
    	}
    	else{
    		return TRIM_VALUE;
    	}
    }

//
function deplace(a,p,s){
	var w = window.open('produit_modif.php?action=' + a + '&produit=' + p + '&secteur=' + s,'modificationProduit','width=700,height=300,resizable=yes,status=yes,scrolling=yes,scrollbars=yes');
	w.focus();
}

function deplaceSession(obj){
    var etat = 0;
    if (obj.checked){
        etat = 1;
    }
    parent.deplacement.location.href = 'frame-deplacement.php?&etat=' + etat + '&produit='+ obj.value
    
}
function deplacerProduits(){
	 var cnt = 1;
	 /*
	var objs = document.getElementsByName("deplaceIDS[]");
	for (var i = 0; i < objs.length; i++){
		if (objs[i].checked == true){
			cnt++;
		}
	}
	*/
	if (cnt > 0 ){
		document.fdeplace.submit();
//		return true;
	}
	else {
		return false;
	}
	//var w = window.open('produit_modif.php?action=' + a + '&produit=' + p + '&secteur=' + s,'modificationProduit','width=700,height=300,status=yes');
	//w.focus();
}

function verifOf(){
    var f = document.fadmin;
    if (Trim(f.of.value) == ''){
        alert('Merci de renseigner le n° d\'OF');
        return false;
    }
    else {
        return true;
    }
}
function tous(){
	 var cnt = 0;
	var objs = document.getElementsByName("deplaceIDS[]");
	for (var i = 0; i < objs.length; i++){
		if (objs[i].checked == true){
			cnt++;
		}
	}

}
function keySort(dropdownlist,caseSensitive) {
  // check the keypressBuffer attribute is defined on the dropdownlist 
  var undefined; 
  if (dropdownlist.keypressBuffer == undefined) { 
    dropdownlist.keypressBuffer = ''; 
  } 
  // get the key that was pressed 
  var key = String.fromCharCode(window.event.keyCode); 
  dropdownlist.keypressBuffer += key;
  if (!caseSensitive) {
    // convert buffer to lowercase
    dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
  }
  // find if it is the start of any of the options 
  var optionsLength = dropdownlist.options.length; 
  for (var n=0; n < optionsLength; n++) { 
    var optionText = dropdownlist.options[n].text; 
    if (!caseSensitive) {
      optionText = optionText.toLowerCase();
    }
    if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) { 
      dropdownlist.selectedIndex = n; 
      return false; // cancel the default behavior since 
                    // we have selected our own value 
    } 
  } 
  // reset initial key to be inline with default behavior 
  dropdownlist.keypressBuffer = key; 
  return true; // give default behavior 
} 
