


function mouse_down(evt){

    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
        if ((evt.button && evt.button == 2) || (evt.which && evt.which == 3)) {
            rightButton = true;
        }
        if (rightButton) {
            // process right-click here
            //return false;
        } else {
	pos_down_x = getMouseX(evt);
	pos_down_y = getMouseY(evt);
	mouse_down_flag = true ;
	jpeg_return_check = true;
	document.onmousemove = realtime_wlww ;
	document.getElementById('wl_ww_value').innerHTML = 'WL/WW ' + wl + ':' + ww;
	if (evt.preventDefault) {
    evt.preventDefault();
    }
        }
    }
}



function realtime_wlww(evt){

	if((mouse_down_flag == true) && (jpeg_return_check == true)){
	
   var d1 = new Date().getTime();
   var d2 = new Date().getTime();
   while( d2 < d1+1000*realtime_ratio ){    //T•b‘Ò‚Â
       d2=new Date().getTime();
   }
   jpeg_return_check = false ;
   
	evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
        if ((evt.button && evt.button == 2) || (evt.which && evt.which == 3)) {
            rightButton = true;
        }
        if (rightButton) {
            // process right-click here
            //return false;
        } else {
	pos_up_x = getMouseX(evt);
	pos_up_y = getMouseY(evt);
	sub_x = (pos_down_x - pos_up_x) * mouse_move_ratio ;
	sub_y = (pos_down_y - pos_up_y) * mouse_move_ratio ;

	change_x = wl - sub_x ;
	change_y = ww - sub_y ;
	
	
	
	change_x = Math.floor(change_x);
	change_y = Math.floor(change_y);

	if(change_y <= 1){
	change_y = 1;
	}
	
		document.wlww.wl.value = change_x;
		document.wlww.ww.value = change_y;
	
	document.getElementById('wl_ww_value').innerHTML = 'WL/WW ' + change_x + ':' + change_y;
	
	var realtime_power = 1;
	do_convert(dicom_path,change_x,change_y,negate_check,rotate_check,realtime_power);
	
	pos_down_x = pos_up_x;
	pos_down_y = pos_up_y;
	
        }
	}
	 rightButton = false;
	 
	 }else{
	 return false;
	 }
	
}

function mouse_up(evt){

    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
        if ((evt.button && evt.button == 2) || (evt.which && evt.which == 3)) {
            rightButton = true;
        }
        if (rightButton) {
            // process right-click here
            //return false;
        } else {
	pos_up_x = getMouseX(evt);
	pos_up_y = getMouseY(evt);
	sub_x = (pos_down_x - pos_up_x) * mouse_move_ratio ;
	sub_y = (pos_down_y - pos_up_y) * mouse_move_ratio ;
	change_x = wl - sub_x ;
	change_y = ww - sub_y ;
	
	
	change_x = Math.floor(change_x);
	change_y = Math.floor(change_y);

	
	if(change_y <= 1){
	change_y = 1;
	}
	
		document.wlww.wl.value = change_x;
		document.wlww.ww.value = change_y;
		
		document.getElementById('wl_ww_value').innerHTML = 'WL/WW ' + change_x + ':' + change_y;
		
		mouse_down_flag = false ;
		document.onmousemove = null ;
		
	var realtime_power = 1;
	do_convert(dicom_path,change_x,change_y,negate_check,rotate_check,realtime_power)
        }
	}
	 rightButton = false;
	
}
