<!--

var startposx;  // mouse x start position
var startposy;  // mouse y start position
var obj_id;  // reference id for the object / cell currently being resized
var obj_id_number;  // returned value of: obj_id.split( "div_resize_" );
var div_size;  // size of the cell  currently being resized
var obj_to_resize;

var mouse_down = false;



startposx = 0;
startposy = 0;

/**
 * object that gives the property of start position 
 * and sorting direction of the SQL query.
 */
function jsgrid_object() 
{
	this.start_pos = 0;
	this.sort_column = "";
	this.sort_direction = "desc";	
	this.toggle_sort_direction = function() {
		if( this.sort_direction == "asc" )
			this.sort_direction = "desc";
		else
			this.sort_direction = "asc";
	
	} // end function toggle_sort_direction()
	
  this.update_column_width = function(width) {
  	this.active_column_width = width;
  }
  


} // end function jsgrid_object()

/*
 * this function is a bug fix for internet explorer 
 * note: internet explorer currently doesnt support
 * javascript getElementsByName()
 * url source: http://code.dreamincode.net/snippet293.htm
 */
function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}


//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
  
} // end function Browser()

var browser = new Browser();

function jsgrid_onmousedown(event, id) {

  var x, y;
  
  obj_id = id;
  obj_id_number = obj_id.split( "div_resize_" );
  obj_id_number = ( obj_id_number[1] -1 );
  
  mouse_down = true;

  // Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  
  startposx = x; // mouse x start position
  startposy = y; // mouse y start position
  
  obj_name_to_resize = "col_" + obj_id_number;
  
  if (browser.isIE) {
	  
    obj_to_resize =  getElementsByName_iefix( "div", obj_name_to_resize);
  
    js_grid.update_column_width( parseInt(obj_to_resize[0].style.width) ); // set the width of the current selected cell

	document.attachEvent("onmousemove", js_start_resize );
    document.attachEvent("onmouseup",  js_stop_resize );
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
   
    obj_to_resize = document.getElementsByName(obj_name_to_resize);  
	js_grid.update_column_width( parseInt(obj_to_resize[0].style.width) ); // set the width of the current selected cell
	
    document.addEventListener("mousemove", js_start_resize,   true);
    document.addEventListener("mouseup",  js_stop_resize, true);
    event.preventDefault();
  }
  
} // end function jsgrid_onmousedown()

function js_start_resize(event) {
	

	
  var x, y; // x and y mouse position
  div_size = 0;
  //obj_id_number = obj_id.split( "div_resize_" );
  //obj_id_number = ( obj_id_number[1] -1 );
  

  // Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
 

  distance = Math.abs( startposx - x ); // computes the distance of the current mouse x position from the mouse start x position

  // dynamically resize columns...
  for( counter = 0; counter < obj_to_resize.length; counter++ ) {
	 
	  if( ( js_grid.active_column_width - distance ) < 20 ) { // limit the minimum size of cel to 20 pixels (19 actually) 
	  	div_size = 21;
		break;
	  }
		
	  if( x <= startposx )
	  	div_size = (js_grid.active_column_width - distance);
	  else
	    div_size = (js_grid.active_column_width + distance);
	    
	  obj_to_resize[ counter ].style.width = div_size + "px"; 
	  
  } // end for( counter = 0; counter < obj_to_resize.length; counter++ )

	


	
  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();

} // end function js_start_resize()

function js_stop_resize(event) { // Stop capturing mousemove and mouseup events.
	
	js_grid.active_column_width = div_size;
	mouse_down = false;


  if (browser.isIE) {
    document.detachEvent("onmousemove", js_start_resize );
    document.detachEvent("onmouseup",  js_stop_resize );
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", js_start_resize,   true);
    document.removeEventListener("mouseup",  js_stop_resize, true);
  }
  
} // end function js_stop_resize()



/*  start flexgride code */
//global variables used to track status
var curWidth=0
var curPos=0
var newPos=0
var mouseStatus='up'
var curCol=''

//this function gets the original div height

function setPos(e){
		// set some value for the columns in case they don't have
			//document.getElementById(curCol).style.width="100px";
    //for handling events in ie vs. w3c
    curevent = (typeof event == 'undefined' ? e:event);
    //sets mouse flag as down
    mouseStatus = 'down';
    //gets position of click
    curPos = curevent.clientX;
    //accepts height of the div
    tempWidth = document.getElementById(curCol).style.width;
    //these lines split the width value from the 'px' units
    widthArray = tempWidth.split('px');
    curWidth = parseInt(widthArray[0]);

}

//this changes the height of the div while the mouse button is depressed

function getPos(e){
				//document.getElementById('flexCol_1').style.width = 100+'px';
				//document.getElementById('flexCol_2').style.width = 100+'px';
    if(mouseStatus=='down'){


        curevent = (typeof event == 'undefined' ? e:event);
        //get new mouse position
        newPos = curevent.clientX;
        //calculate movement in pixels
        var pxMove=parseInt(newPos-curPos);
        //determine new width
        var newWidth = parseInt(curWidth+pxMove);
        //conditional to set minimum width to 5
        newWidth = (newWidth < 10 ? 10:newWidth);
        //set the new width of the div
        document.getElementById(curCol).style.width = newWidth+'px';

    }

}
/* end flexgrid code */

