function multi_select(id, all) {
	var target = document.getElementById("selected_"+id);
	var source = document.getElementById("avail_"+id);	
	
	var tpos = target.options.length;
	
	
	for(i=0;i<source.options.length;) {
		if(source.options[i].selected || all) {
			target.options[tpos] = new Option(source.options[i].text,source.options[i].value);
			target.options[tpos].selected = true;
			
			tpos++;
		    
			source.options[i] = null;
			i=0;
		} else {
			i++;
		}
	}
	updateMultiSelectHidden(id);
}

function updateMultiSelectHidden(id) {

	var target = document.getElementById("selected_"+id);
	var hidden = document.getElementById(id);
	
	hidden.value = "";
	for(i=0;i<target.options.length;i++) {
		hidden.value = hidden.value + "," +target.options[i].value;
	}

}

function multi_unselect(id, all) {
	var source = document.getElementById("selected_"+id);
	var target = document.getElementById("avail_"+id);	
	
	var tpos = target.options.length;
	
	for(i=0;i<source.options.length;) {
		if(source.options[i].selected || all) {
			target.options[tpos++] = new Option(source.options[i].text,source.options[i].value);
			source.options[i] = null;
			i=0;
		} else {
			i++;
		}
	}
	updateMultiSelectHidden(id);
}


function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

// MOUSE COORDINATES START HERE
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousedown = getMouseXY;

var xPos = 0
var yPos = 0

function getMouseXY(e) {

  	if (IE) { // grab the x-y pos.s if browser is IE
		xPos = event.clientX + document.body.scrollLeft
		yPos = event.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
    	xPos = e.pageX
    	yPos = e.pageY
  	}  

  	if (xPos < 0){xPos = 0}
  	if (yPos < 0){yPos = 0}  

    //document.getElementById('x').innerHTML = 'X='+xPos+', long = '+long;
    //document.getElementById('y').innerHTML = 'Y='+yPos+' lat = '+lat;

}
// MOUSE COORDINATES END HERE


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


