  // Copyrigth 2002 Peopleware (www.peopleware.lu)
  // All right reserved. Could not be used without a writted authorisation
  //
  // Author: Gilles Freart
  //
  function copySelectedOptions (src, tgt, msg) {
 	var i, j;
  	if(tgt.options.length < 30){
  	for (i=0; i<src.options.length;i++) {
  	  if (src.options[i].selected == true) {
   	    var value = src.options[i].value;
  	    var text  = src.options[i].text;
  	  
  	    for (j=0; j<tgt.options.length;j++) {
  	      if (tgt.options[j].value == value) {
  	        break;
  	      }
  	    }
  	  
  	    if (j == tgt.options.length) {
  	      tgt.options[j] = new Option (text, value, false, false);
  	    }
  	  }
  	}
  	}
  	else
  	window.alert(msg);
  }

  function removeSelectedOptions (tgt) {
  	var i,j, newOption = new Array ();

  	for (i=j=0; i<tgt.options.length;i++) {
  	  if (tgt.options[i].selected == false) {
  	    if (i != j) {
   	      tgt.options[j].text     = tgt.options[i].text;
 	      tgt.options[j].value    = tgt.options[i].value;
 	      tgt.options[j].selected = false;;
 	    }
 	    j++;
  	  }
  	}
  	tgt.options.length = j;
  }
  
  function selectAllOptions (tgt) {
  	for (i=0; i<tgt.options.length;i++) {
  	  tgt.options[i].selected = true;
    }
  }

// Currency Input Mask
 
var decEntryWasPress = false;
var decZeroPress = false;
function currencyFormat(fld, milSep, decSep, e) {
	
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = decPos = 0;
	var strCheck = '0123456789';
	var strDec = ',';
	var aux = aux2 = entVal = decVal = '';
	var parDec = false;
	var whichCode = (window.Event) ? e.which : e.keyCode;
		
	if (whichCode == 0) return true;
	if (whichCode == 8) return true; // Backspace
	if (whichCode == 13) return true;  // Enter
	
	key = String.fromCharCode(whichCode);  // Get key value from key code
	

	// If key Press equal . or , set decEntryWasPress to Thrue
	if (key == '.' || key == ','){
		decEntryWasPress = true;
		vr = false;
		len = fld.value.length;
		for (i = 0; i < len; i++) {
			if (fld.value.charAt(i) == ',') vr = true;
		}
		if (vr) 
			return false; // dec entry exist in string
		else 
			return true;     // put dec entry in string
	}

	// Not a valid Key do nothing
	if (strCheck.indexOf(key) == -1) return false;

	// Check if backspace delete the ',' from the string 
	//	if does not exist then considere integer entry ( set decEntryWasPress to false )
	vr = false;
	len = fld.value.length;
	for (i = 0; i < len; i++) {
  		if (fld.value.charAt(i) == ',') 
  			vr = true;
	}
	if (vr == false) 
		decEntryWasPress = false;

	// put ",00" if is the first key press 
//	if (fld.value.length == 0) {
//  		fld.value = key + ',00';
//  		return false;
//	}

	len = fld.value.length;
	aux = '';
	aux2 = '';

	if (key == '0' && decEntryWasPress) {
		decZeroPress = true;
		return false;
	}

	// Save Decimal Part
	parDec = false;
	for(i = 0; i <= len - 1; i++){
		if (strDec.indexOf(fld.value.charAt(i))!= -1 ){ 
			parDec = true;
  		} else {
			if (parDec) 
				decVal += fld.value.charAt(i);
    			else 
    				if (strCheck.indexOf(fld.value.charAt(i))!=-1) 
    					entVal += fld.value.charAt(i);
  		}
	}


	// if decVal = '00' reset decimal value
	if (decVal == '00') {
		decVal = '';
		parDec = false;
	}


	// remove non signifiant decimal digit
	if (decVal.charAt(1)== '0') 
		decVal = decVal.charAt(0);

	// Max two decimal entry
	if (decEntryWasPress && decVal.length > 1 ) 
		return false;

	fld.value = entVal;
	len = fld.value.length;

	// Push Numerical Entry in the FILO stack aux
	for(i = 0; i < len; i++){
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) 
			aux += fld.value.charAt(i);
	}
	len = aux.length;
	if (parDec || decEntryWasPress) 
		len -= 1;

	// Restore the Stack
	for (j = 0, i = len; i >= 0; i--) {
		if (j == 3) {
			aux2 += milSep;
			j = 0;
		}
		aux2 += aux.charAt(i);
		j++;
	}

	aux = '';
	len = aux2.length;
	for (i = len; i >= 0; i--) {
		aux += aux2.charAt(i);
	}

	aux2 = aux ;

	if (decZeroPress && decEntryWasPress) {
		aux = aux2 + ',0' + key;
		decZeroPress = false;
		fld.value = aux;
		return false;
	}

	if ((parDec || decEntryWasPress ) && decVal.length == 0) 
		key = key + '0';

	if (parDec || decEntryWasPress) {
		aux = aux2 + ',' + decVal + key;
	} else {
  		// aux = aux2 + key + ',00';
  		aux = aux2 + key;
  	}

	fld.value = aux;

	return false;
}
function currencyFormatSearchBox(fld, milSep, decSep, e, id) {
	
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = decPos = 0;
	var strCheck = '0123456789';
	var strDec = ',';
	var aux = aux2 = entVal = decVal = '';
	var parDec = false;
	var whichCode = (window.Event) ? e.which : e.keyCode;
		
	if (whichCode == 0) return true;
	if (whichCode == 8) return true; // Backspace
	if (whichCode == 13) return true;  // Enter
	
	key = String.fromCharCode(whichCode);  // Get key value from key code
	

	// If key Press equal . or , set decEntryWasPress to Thrue
	if (key == '.' || key == ','){
		decEntryWasPress = true;
		vr = false;
		len = fld.value.length;
		for (i = 0; i < len; i++) {
			if (fld.value.charAt(i) == ',') vr = true;
		}
		if (vr) 
			return false; // dec entry exist in string
		else 
			return true;     // put dec entry in string
	}

	// Not a valid Key do nothing
	if (strCheck.indexOf(key) == -1) return false;

	// Check if backspace delete the ',' from the string 
	//	if does not exist then considere integer entry ( set decEntryWasPress to false )
	vr = false;
	len = fld.value.length;
	for (i = 0; i < len; i++) {
  		if (fld.value.charAt(i) == ',') 
  			vr = true;
	}
	if (vr == false) 
		decEntryWasPress = false;

	// put ",00" if is the first key press 
//	if (fld.value.length == 0) {
//  		fld.value = key + ',00';
//  		return false;
//	}

	len = fld.value.length;
	aux = '';
	aux2 = '';

	if (key == '0' && decEntryWasPress) {
		decZeroPress = true;
		return false;
	}

	// Save Decimal Part
	parDec = false;
	for(i = 0; i <= len - 1; i++){
		if (strDec.indexOf(fld.value.charAt(i))!= -1 ){ 
			parDec = true;
  		} else {
			if (parDec) 
				decVal += fld.value.charAt(i);
    			else 
    				if (strCheck.indexOf(fld.value.charAt(i))!=-1) 
    					entVal += fld.value.charAt(i);
  		}
	}


	// if decVal = '00' reset decimal value
	if (decVal == '00') {
		decVal = '';
		parDec = false;
	}


	// remove non signifiant decimal digit
	if (decVal.charAt(1)== '0') 
		decVal = decVal.charAt(0);

	// Max two decimal entry
	if (decEntryWasPress && decVal.length > 1 ) 
		return false;

	fld.value = entVal;
	len = fld.value.length;

	// Push Numerical Entry in the FILO stack aux
	for(i = 0; i < len; i++){
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) 
			aux += fld.value.charAt(i);
	}
	len = aux.length;
	if (parDec || decEntryWasPress) 
		len -= 1;

	// Restore the Stack
	for (j = 0, i = len; i >= 0; i--) {
		if (j == 3) {
			aux2 += milSep;
			j = 0;
		}
		aux2 += aux.charAt(i);
		j++;
	}

	aux = '';
	len = aux2.length;
	for (i = len; i >= 0; i--) {
		aux += aux2.charAt(i);
	}

	aux2 = aux ;

	if (decZeroPress && decEntryWasPress) {
		aux = aux2 + ',0' + key;
		decZeroPress = false;
		fld.value = aux;
		return false;
	}

	if ((parDec || decEntryWasPress ) && decVal.length == 0) 
		key = key + '0';

	if (parDec || decEntryWasPress) {
		aux = aux2 + ',' + decVal + key;
	} else {
  		// aux = aux2 + key + ',00';
  		aux = aux2 + key;
  	}

	fld.value = aux;
	document.getElementById(id).value = fld.value;
	return false;
}

var TRange = null;
var dupeRange = null;
var TestRange = null;
var win = null;

var nom = navigator.appName.toLowerCase();
var agt = navigator.userAgent.toLowerCase();
var is_major   = parseInt(navigator.appVersion);
var is_minor   = parseFloat(navigator.appVersion);
var is_ie      = (agt.indexOf("msie") != -1);
var is_ie4up   = (is_ie && (is_major >= 4));
var is_not_moz = (agt.indexOf('netscape')!=-1)
var is_nav     = (nom.indexOf('netscape')!=-1);
var is_nav4    = (is_nav && (is_major == 4));
var is_mac     = (agt.indexOf("mac")!=-1);
var is_gecko   = (agt.indexOf('gecko') != -1);
var is_opera   = (agt.indexOf("opera") != -1);

var is_rev=0
if (is_gecko) {
	temp = agt.split("rv:")
	is_rev = parseFloat(temp[1])
}
var frametosearch = self;

function findInPage(value, whichframe) {
	
	if (is_ie4up && is_mac) return;
	if (is_gecko && (is_rev <1)) return;
	if (is_opera) return;
	if(value!='') {
		str = value;
		win = whichframe;
		var frameval=false;
		if(win!=self) {
			frameval=true;
			win = parent.frames[whichframe];
		}
	} else return;

	var strFound;
	if(is_nav4 && (is_minor < 5)) {
		strFound=win.find(str);
        }

	if (is_gecko && (is_rev >= 1)) {
		if(frameval!=false) win.focus();
		strFound=win.find(str, false, false, true, false, frameval, false);
	}

	if (is_ie4up) {
		if (TRange!=null) {
			TestRange=win.document.body.createTextRange();
			if (dupeRange.inRange(TestRange)) {
				TRange.collapse(false);
				strFound=TRange.findText(str);
				if (strFound) {
					win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop;
					TRange.select();
				}
			} else {
				TRange=win.document.body.createTextRange();
				TRange.collapse(false);
				strFound=TRange.findText(str);
				if (strFound) {
					win.document.body.scrollTop = TRange.offsetTop;
					TRange.select();
				}
			}
  		}
		if (TRange==null || strFound==0) {
			TRange=win.document.body.createTextRange();
			dupeRange = TRange.duplicate();
			strFound=TRange.findText(str);
			if (strFound) {
				win.document.body.scrollTop = TRange.offsetTop;
				TRange.select();
			}
		}
	}
}

