
//--------------------------------
//********************************
//******** Class label***********
//********************************
//--------------------------------


//********************************
//********* Constructors *********
//********************************
function label()
{
   this.m_font = 0;//chiffre de la font
   this.m_text;
   this.m_line_color = new color(0,0,0,255);    
   this.m_back_color = new color(255,255,255,255); 
}

function owk_label_create(layer_group, i_region, i_visible, i_text)
{
   if(layer_group!=null)
   {
      this.set_parent(layer_group);
   }

   this.ancestor_create(i_region,i_visible, false, false);

   if(layer_group!=null)
   {
      layer_group.push_back_layer(this);
   }

   this.set_text(i_text);   
}

function owk_label_on_mouse_button_down()
{
   
}

function owk_label_on_mouse_button_up()
{

}

function owk_label_on_mouse_button_up()
{

}

function owk_label_on_mouse_move()
{

}

function owk_label_draw()
{

}

function owk_label_text()
{
   return this.m_text;
}

function owk_label_set_text(i_text)
{
   this.m_text = i_text;
   this.m_div.innerHTML = this.m_text;
}

function owk_label_line_color()
{
   return this.m_line_color;   
}

function owk_label_set_line_color(i_color)
{
   this.m_line_color = i_color;
   this.m_div.style.color = this.m_line_color.rgb_to_hex();
}

function owk_label_back_color()
{
   return this.m_back_color;
}

function owk_label_set_back_color(i_back_color)
{
   this.m_back_color = i_back_color;
   this.m_div.style.background=this.m_back_color.rgb_to_hex();
}

function owk_label_font()
{
   return this.m_font;
}

function owk_label_set_font(i_font)
{
   this.m_font = i_font;
   
   if(i_font == 0)
   {
      this.m_div.style.fontSize = 18;
      this.m_div.style.fontFamily = 'arial';
      this.m_div.style.fontWeight = 'bold';
   }
   else if(i_font == 1)
   {
      this.m_div.style.fontSize = 12;
      this.m_div.style.fontFamily = 'arial';
      this.m_div.style.fontWeight = 'bold';
   }
   else if(i_font == 2)
   {

   }
   else if(i_font == 3)
   {

   }
   else if(i_font == 4)
   {

   }
   else if(i_font == 5)
   {

   }
   else if(i_font == 6)
   {

   }
   else if(i_font == 7)
   {

   }
   else if(i_font == 8)
   {

   }
   else if(i_font == 9)
   {

   }
   else if(i_font == 10)
   {

   }
   else if(i_font == 11)
   {

   }
   else if(i_font == 12)
   {

   }
   else if(i_font == 13)
   {

   }
   else if(i_font == 14)
   {

   }
   else if(i_font == 15)
   {

   }
   else if(i_font == 16)
   {

   }
   else if(i_font == 17)
   {

   }
   else if(i_font == 18)
   {

   }
   else if(i_font == 19)
   {

   }
   else if(i_font == 20)
   {

   }
   else if(i_font == 21)
   {

   }
   else if(i_font == 22)
   {
      this.m_div.style.fontSize = 12;
      this.fontFamily = 'verdana';
      this.fontWeight = 'normal';
   }
   else if(i_font == 23)
   {
      this.m_div.style.fontSize = 12;
      this.fontFamily = 'verdana';
      this.fontWeight = 'bold';
   }
   else if(i_font == 24)
   {  
      this.m_div.style.fontSize = 13;
      this.fontFamily = 'verdana';
      this.fontWeight = 'normal';
   }
   else if(i_font == 25)
   {
      this.m_div.style.fontSize = 13;
      this.fontFamily = 'verdana';
      this.fontWeight = 'bold';
   }
   else if(i_font == 26)
   {
      this.m_div.style.fontSize = 14;
      this.fontFamily = 'verdana';
      this.fontWeight = 'normal';
   }
   else if(i_font == 27)
   {
      this.m_div.style.fontSize = 14;
      this.fontFamily = 'verdana';
      this.fontWeight = 'bold';
   }
   else if(i_font == 28)
   {
      this.m_div.style.fontSize = 16;
      this.fontFamily = 'verdana';
      this.fontWeight = 'normal';
   }
   else if(i_font == 29)
   {
      this.m_div.style.fontSize = 16;
      this.fontFamily = 'verdana';
      this.fontWeight = 'bold';
   }
   else if(i_font == 30)
   {
      this.m_div.style.fontSize = 17;
      this.fontFamily = 'verdana';
      this.fontWeight = 'normal';
   }
   else if(i_font == 31)
   {  
      this.m_div.style.fontSize = 17;
      this.fontFamily = 'verdana';
      this.fontWeight = 'bold';
   }
   else if(i_font == 32)
   {
      this.m_div.style.fontSize = 18;
      this.fontFamily = 'verdana';
      this.fontWeight = 'normal';
   }
   else if(i_font == 33)
   {
      this.m_div.style.fontSize = 18;
      this.fontFamily = 'verdana';
      this.fontWeight = 'bold';
   }
   else if(i_font == 34)
   {

   }
   else if(i_font == 35)
   {

   }
}

label.prototype = new layer;
label.prototype.create = owk_label_create;
label.prototype.ancestor_create = owk_layer_create;
label.prototype.on_mouse_button_down = owk_label_on_mouse_button_down;
label.prototype.on_mouse_button_up = owk_label_on_mouse_button_up;
label.prototype.on_mouse_move = owk_label_on_mouse_move;
label.prototype.draw = owk_label_draw;
label.prototype.text = owk_label_text;
label.prototype.set_text = owk_label_set_text;
label.prototype.line_color = owk_label_line_color;
label.prototype.set_line_color= owk_label_set_line_color;
label.prototype.back_color = owk_label_back_color;
label.prototype.set_back_color = owk_label_set_back_color;
label.prototype.font = owk_label_font;
label.prototype.set_font = owk_label_set_font;

//--------------------------------
//********************************
//******** Class button***********
//********************************
//--------------------------------


//********************************
//********* Constructors *********
//********************************
function button()
{
  
}

function owk_button_create(i_parent,i_region,i_visible,i_title)
{
   this.set_parent(i_parent)
   this.ancestor_create(i_region,i_visible,false,false);  
   i_parent.push_back_layer(this);

   this.m_press_layer = new layer();
   this.m_unpress_layer = new layer();

   var layer_rect = new rectangle(0, 0, this.m_region.size.width-1, this.m_region.size.height-1);

   this.m_press_layer.set_parent(this);
   this.m_unpress_layer.set_parent(this);
   this.m_unpress_layer.create(layer_rect, true, false, false);   
   this.m_press_layer.create(layer_rect, false, false, false);
     
   this.m_title = i_title;
   
   this.m_div_text = document.createElement("div");
   this.m_div_text.style.display = 'none';
   this.m_div_text.style.width = this.m_region.size.width-1;
   this.m_div_text.style.position = 'absolute';   
   this.m_div.appendChild(this.m_div_text);
}

function owk_button_press_layer()
{
  return this.m_press_layer;
}

function owk_button_unpress_layer()
{
   return this.m_unpress_layer;
}

function owk_button_pressed()
{
   return this.m_pressed;
}

function owk_button_set_pressed(i_pressed)
{
   this.m_pressed = i_pressed;
   
   if(i_pressed == true)
   {
      this.m_press_layer.set_visible(true);
      this.m_unpress_layer.set_visible(false);      
   }
   else 
   {
      this.m_press_layer.set_visible(false);
      this.m_unpress_layer.set_visible(true);      
   }
}

function owk_button_on_draw(i_pressed)
{
     
}

function owk_button_on_mouse_move(i_mouse)
{
   this.ancestor_on_mouse_move(i_mouse);
   return true;
}
 
function owk_button_on_mouse_button_down(i_mouse) {
    
   this.ancestor_on_mouse_button_down(i_mouse);
   i_mouse.capture(this); // active the mouse capture

   this.set_pressed(true);
  // draw();
   // convert region to surface coordinate for invalidate
   //invalidate();

   return true;
}  

function owk_button_on_mouse_button_up(i_mouse)
{  
   this.ancestor_on_mouse_button_up(i_mouse);
 
   i_mouse.release_capture(); // active the mouse capture

   this.set_pressed(false);

   // convert region to surface coordinate for invalidate
   // draw();
//   invalidate();

   var mouse_position = new point(); 
   mouse_position.copy(i_mouse.position());

   if (this.has_parent())
   {
       this.parent().global_to_local_point(mouse_position);
   }

   if (this.region().is_point_inside(mouse_position))
   {
      this.on_pressed();
      this.on_hit();
   }

   return true;
}  

function owk_button_on_pressed()
{
   
}

function owk_button_title()
{
   return this.m_title;
}

function owk_button_set_title(i_value)
{
   try
   {
      this.m_title = i_value;

      if(i_value!="")
      {
         this.m_div_text.style.textAlign = 'center';
         this.m_div_text.style.paddingTop = '3px';

         this.m_div_text.innerHTML = i_value;
         //this.m_div_text.style.zIndex = 99;
         this.m_div_text.style.display = '';
      }
      else
      {
         this.m_div_text.style.display = 'none';
      }
   }
   catch(e){}
}

function owk_button_load_patterns(i_url, i_repeat_middle, i_is_horizontal, i_is_vertical)
{
   this.m_background_decorator_unpress_layer = new pattern_decorator(); 
   this.m_background_decorator_unpress_layer.create(this.m_unpress_layer);
   
   var mybutton = this;
   this.m_unpress_layer.on_loaded = mybutton.on_loaded;
   
   this.m_background_decorator_press_layer = new pattern_decorator(); 
   this.m_background_decorator_press_layer.create(this.m_press_layer);
   
   if(i_is_horizontal && i_is_vertical)
   {
      this.m_background_decorator_press_layer.load(i_url + "pressed/",i_repeat_middle);
      this.m_background_decorator_unpress_layer.load(i_url + "unpress/",i_repeat_middle);
   }
   else if(i_is_horizontal)
   {
      this.m_background_decorator_press_layer.load_hori(i_url + "pressed/",i_repeat_middle);
      this.m_background_decorator_unpress_layer.load_hori(i_url + "unpress/",i_repeat_middle);
   }
   else if(i_is_vertical)
   {
      this.m_background_decorator_press_layer.load_vert(i_url + "pressed/",i_repeat_middle);
      this.m_background_decorator_unpress_layer.load_vert(i_url + "unpress/",i_repeat_middle);
   }
   else
   {
      this.m_background_decorator_press_layer.load_image(i_url + "/pressed.png");
      this.m_background_decorator_unpress_layer.load_image(i_url + "/unpress.png");
   }
}

function owk_button_on_loaded()
{
   this.parent().m_div_text.style.display = '';
   this.parent().m_div_text.style.top = (this.m_region.height() / 2 )-10;
}
	
function owk_button_set_font_color(i_color)
{
   this.m_font_color = i_color;
   this.m_div_text.style.color = '#' + i_color.rgb_to_hex();
}

function owk_button_on_hit()
{

}

button.prototype = new layer;
button.prototype.load_patterns = owk_button_load_patterns;
button.prototype.create = owk_button_create;
button.prototype.ancestor_create = owk_layer_create;
button.prototype.ancestor_destroy = owk_layer_destroy;
button.prototype.press_layer = owk_button_press_layer;
button.prototype.unpress_layer = owk_button_unpress_layer;
button.prototype.on_mouse_move = owk_button_on_mouse_move;
button.prototype.ancestor_on_mouse_move = owk_layer_on_mouse_move;
button.prototype.on_mouse_button_down = owk_button_on_mouse_button_down;
button.prototype.ancestor_on_mouse_button_down = owk_layer_on_mouse_button_down;
button.prototype.on_mouse_button_up = owk_button_on_mouse_button_up;
button.prototype.ancestor_on_mouse_button_up = owk_layer_on_mouse_button_up;
button.prototype.pressed = owk_button_pressed;
button.prototype.set_pressed = owk_button_set_pressed;
button.prototype.on_draw = owk_button_on_draw;
button.prototype.on_pressed = owk_button_on_pressed;
button.prototype.title = owk_button_title;
button.prototype.set_title = owk_button_set_title;
button.prototype.on_loaded = owk_button_on_loaded;
button.prototype.font_color = owk_button_set_font_color;
button.prototype.on_hit = owk_button_on_hit;

function popup_item()
{
 
}

function owk_popup_item_create(i_region, i_visible, i_resizable, i_dragable)
{
   this.m_sel_layer = new layer();
   this.m_unsel_layer = new layer()
   this.ancestor_create(i_region, i_visible, i_resizable, i_dragable);
   //opacity(100.0f);
   this.m_font_color = new color(255, 255, 255, 255);
   //padding.ltrb(3, 13, 0, 0);
   //this.font_color().set_rgba(255, 255, 255, 255);

   var layer_rect = new rectangle(0, 0, this.region().size.width-1, this.region().size.height-1);
   var layer_rect2 = new rectangle(0, 0, this.region().size.width-1, this.region().size.height-1);
   this.m_sel_layer.set_parent(this);
   this.m_unsel_layer.set_parent(this); 
   this.sel_layer().create(layer_rect, true, false, false);
   this.unsel_layer().create(layer_rect2, true, false, false);  
}

function owk_popup_item_on_mouse_move(i_mouse)
{
   //this.ancestor_on_mouse_move(i_mouse);
   return true;
}

function owk_popup_item_on_mouse_button_down(i_mouse)
{
   //this.ancestor_on_mouse_button_down(i_mouse);
   return true;
}

function owk_popup_item_on_mouse_button_up(i_mouse)
{
   //this.ancestor_on_mouse_button_up(i_mouse);
   return true;
}

function owk_popup_item_draw()
{

}

function owk_popup_item_on_draw()
{

}

function owk_popup_item_stamp_text()
{
  /* if (title().size() > 0)
   {
      // draw the button text
      cgcontext cgc;
      color font_background; font_background.rgba(0, 0, 0, 0);
      cg_begin_context(&i_layer_ref, &cgc);
      cg_context_set_line_color(&cgc, font_color());
      cg_context_set_fill_color(&cgc, font_background); 

      point text_origin;   
      text_origin.xy(border.left + padding.left, border.top + padding.top);
      
      cg_context_draw_text(&cgc, text_origin, title().c_str(), fontidx_verdana12_bold);

      cg_end_context(&i_layer_ref, &cgc);
   }*/
}

function owk_popup_item_set_stamp_text()
{

}

function owk_popup_item_font_color()
{
   return this.m_font_color;
}

function owk_popup_item_set_font_color(i_color)
{
   this.m_font_color = i_color;
}

function owk_popup_item_unsel_layer()
{
   return this.m_unsel_layer;
}

function owk_popup_item_sel_layer()
{
   return this.m_sel_layer;
}


popup_item.prototype = new layer;
popup_item.prototype.create = owk_popup_item_create;
popup_item.prototype.ancestor_create = owk_layer_create;
popup_item.prototype.sel_layer = owk_popup_item_sel_layer;
popup_item.prototype.unsel_layer = owk_popup_item_unsel_layer;
popup_item.prototype.on_mouse_move = owk_popup_item_on_mouse_move;
popup_item.prototype.on_mouse_button_down = owk_popup_item_on_mouse_button_down;
popup_item.prototype.on_mouse_button_up = owk_popup_item_on_mouse_button_up;
popup_item.prototype.ancestor_on_mouse_move = owk_layer_on_mouse_move;
popup_item.prototype.ancestor_on_mouse_button_down = owk_layer_on_mouse_button_down;
popup_item.prototype.ancestor_on_mouse_button_up = owk_layer_on_mouse_button_up;
popup_item.prototype.draw = owk_popup_item_draw;
popup_item.prototype.on_draw = owk_popup_item_on_draw;
popup_item.prototype.stamp_text = owk_popup_item_stamp_text;
popup_item.prototype.set_stamp_text = owk_popup_item_set_stamp_text;
popup_item.prototype.font_color = owk_popup_item_font_color;
popup_item.prototype.set_font_color = owk_popup_item_set_font_color;


//--------------------------------
//********************************
//******** Class radio box *******
//********************************
//--------------------------------

//********************************
//********* Constructors *********
//********************************
function radio_box()
{

}

function owk_radio_box_load_patterns(i_url)
{
   this.sel_layer().load_image(i_url + "checked.png");
   this.unsel_layer().load_image(i_url + "uncheck.png");
   this.sel_layer().m_div.style.display='none';
}

function owk_radio_box_on_change_selecting()
{
   if(this.select() && this.sel_layer().m_div.style.display != '')
   {
      this.sel_layer().m_div.style.display='';
      this.unsel_layer().m_div.style.display='none';
   }
   else if(this.select() == false && this.sel_layer().m_div.style.display != 'none')
   {
      this.sel_layer().m_div.style.display='none';
      this.unsel_layer().m_div.style.display='';
   }
}

radio_box.prototype = new popup_item;
radio_box.prototype.load_patterns = owk_radio_box_load_patterns;
radio_box.prototype.on_change_selecting = owk_radio_box_on_change_selecting;


//--------------------------------
//********************************
//******** Class popup_button ****
//********************************
//--------------------------------

//********************************
//********* Constructors *********
//********************************
function popup_button()
{
   this.m_popup_layer = new popup_list();
}

function owk_popup_button_popup_layer()
{
   return m_popup_layer;
}


function owk_popup_button_draw()
{

}

function owk_popup_button_on_mouse_button_down()
{
   taken = this.ancestor_on_mouse_button_down(i_mouse);

   this.popup_layer().set_is_popup(true);
   this.popup_layer().set_visible(true);
   
   var pt = new point();    
   
   if (this.has_parent())
   {
      this.pt.xy(parent().region().left() + this.region().left(), this.parent().region().top() + this.region().bottom());

      if (this.popup_layer().has_parent())
      {
         this.popup_layer().parent().bring_to_front(this.popup_layer());
      }
   }
   else
   {
      pt.xy(this.region().left(), this.region().bottom()); 
   }

   this.popup_layer().region().origin.xy(pt.x, pt.y);

   this.popup_layer().set_region(this.popup_layer().region());

   return taken;
}

function owk_popup_button_on_select_item()
{

}

popup_button.prototype = new button;
popup_button.prototype.popup_layer = owk_popup_button_popup_layer;
popup_button.prototype.on_select_item = owk_popup_button_on_select_item;
popup_button.prototype.on_mouse_button_down = owk_popup_button_on_mouse_button_down;
popup_button.prototype.ancestor_on_mouse_button_down = owk_button_on_mouse_button_down;

//--------------------------------
//********************************
//******** Class check_box ********
//********************************
//--------------------------------


//********************************
//********* Constructors *********
//********************************
function check_box()
{
  
}


function owk_check_box_create(i_parent, i_region, i_visible, i_title, i_is_check)
{
   this.set_parent(i_parent);
   this.ancestor_create(i_region, i_visible, false, false);  
   i_parent.push_back_layer(this);

   this.m_check_layer = new layer();
   this.m_uncheck_layer = new layer();
   
   var layer_rect = new rectangle(0, 0, i_region.size.width-1, i_region.size.height-1);
   var layer_rect2 = new rectangle(0, 0, i_region.size.width-1, i_region.size.height-1);

   this.m_check_layer.set_parent(this);
   this.m_uncheck_layer.set_parent(this);
      
   this.m_check_layer.set_parent(this);
   this.m_uncheck_layer.set_parent(this);

   if(i_is_check==true)
   {      
      this.m_uncheck_layer.create(layer_rect, false, false, false);   
      this.m_check_layer.create(layer_rect2, true, false, false);
   }
   else
   {
      this.m_check_layer.create(layer_rect, false, false, false);   
      this.m_uncheck_layer.create(layer_rect2, true, false, false);
   }

   this.m_title = i_title;
   
   this.m_div_text = document.createElement("div");
   this.m_div_text.style.display = 'none';
   this.m_div_text.style.position = 'absolute';   
   this.m_div.appendChild(this.m_div_text);
   
   this.m_check_layer.m_div.style.cursor='hand';
   this.m_uncheck_layer.m_div.style.cursor='hand';
   this.m_div_text.style.cursor='hand';  

   this.m_checked = false;
   this.set_checked(i_is_check);
}

function owk_check_box_check_layer()
{
  return this.m_check_layer;
}

function owk_check_box_uncheck_layer()
{
   return this.m_uncheck_layer;
}

function owk_check_box_checked()
{
   return this.m_checked;
}

function owk_check_box_set_checked(i_checked)
{
   this.m_checked = i_checked;
   
   if(i_checked == true)
   {
      this.m_check_layer.set_visible(true);
      this.m_uncheck_layer.set_visible(false);
   }
   else 
   {
      this.m_check_layer.set_visible(false);
      this.m_uncheck_layer.set_visible(true);
   }

   this.on_hit();
}

function owk_check_box_on_draw(i_pressed)
{
     
}

function owk_check_box_on_mouse_button_down(i_mouse)
{  

   this.ancestor_on_mouse_button_down(i_mouse);
   i_mouse.capture(this); // active the mouse capture

   this.set_checked(!this.checked());

   return true;
}  

function owk_check_box_on_mouse_button_up(i_mouse)
{  
   this.ancestor_on_mouse_button_up(i_mouse);
 
   i_mouse.release_capture(); // active the mouse capture

   var mouse_position = new point();
   mouse_position.copy(i_mouse.position());
   if (this.has_parent())
   {
       this.parent().global_to_local_coordinates(mouse_position);
   }

   if (!this.region().is_point_inside(mouse_position))
   { 
      this.set_checked(!checked()); 
   }
   else
   {
      this.on_hit();
   }

   return true;

}  

function owk_check_box_on_checked()
{
   
}

function owk_check_box_load_patterns(i_url)
{   
   this.m_background_decorator_check_layer = new pattern_decorator(); 
   this.m_background_decorator_uncheck_layer = new pattern_decorator(); 

   this.m_background_decorator_check_layer.create(this.m_check_layer);
   this.m_background_decorator_uncheck_layer.create(this.m_uncheck_layer);

   this.m_uncheck_layer.m_div.zIndex=9999;
   this.m_check_layer.m_div.zIndex=9999;

   var mycheck_box = this;
   this.m_check_layer.on_loaded =  mycheck_box.on_loaded;   

   this.m_background_decorator_check_layer.load_image(i_url + "checked.png");
   this.m_background_decorator_uncheck_layer.load_image(i_url + "uncheck.png");
}


function owk_check_box_set_title(i_title)
{
   this.m_title = i_title;
   this.m_div_text.innerHTML = "<table height='100%' align='left' border='0' style='color:#ff0000' cellspacing='0' cellpadding='0'><tbody><tr><td valign='middle'>" + i_title + "</td></tr></tbody></table>";
}

function owk_check_box_on_loaded(i_width,i_height)
{
   this.parent().m_div_text.style.left = i_width + 4;
   this.parent().m_div_text.style.display = '';
}
	
function owk_check_box_on_hit()
{

}

check_box.prototype = new layer;
check_box.prototype.load_patterns = owk_check_box_load_patterns;
check_box.prototype.create = owk_check_box_create;
check_box.prototype.ancestor_create = owk_layer_create;
check_box.prototype.ancestor_destroy = owk_layer_destroy;
check_box.prototype.check_layer = owk_check_box_check_layer;
check_box.prototype.uncheck_layer = owk_check_box_uncheck_layer;
check_box.prototype.on_mouse_button_down = owk_check_box_on_mouse_button_down;
check_box.prototype.on_mouse_button_up = owk_check_box_on_mouse_button_up;
check_box.prototype.ancestor_on_mouse_button_down = owk_layer_on_mouse_button_down;
check_box.prototype.ancestor_on_mouse_button_up = owk_layer_on_mouse_button_up;
check_box.prototype.checked = owk_check_box_checked;
check_box.prototype.set_checked = owk_check_box_set_checked;
check_box.prototype.on_draw = owk_check_box_on_draw;
check_box.prototype.on_checked = owk_check_box_on_checked;
check_box.prototype.set_title = owk_check_box_set_title;
check_box.prototype.on_loaded = owk_check_box_on_loaded;
check_box.prototype.on_hit= owk_check_box_on_hit;

function scrollbar()
{

}

function owk_scrollbar_create(i_region, i_visible, i_resizable, i_dragable)
{
   this.m_scroll_layer_decorator = new pattern_decorator(); 
   this.m_bar_layer_decorator = new pattern_decorator(); 

   this.ancestor_create(i_region, i_visible, i_resizable, i_dragable);

   this.m_is_over = false;
   this.m_pressed = false;

   this.m_scroll_layer = new layer();
   this.m_scroll_layer.set_parent(this);
   this.m_scroll_layer.create(new rectangle(0, 0, this.region().size.width-1, this.region().size.height-1), true, true ,true);

   this.m_bar_layer = new layer();
   this.m_bar_layer.set_parent(this);
   
   if(this.is_horizontal())
   {
      this.m_bar_layer.create(new rectangle(50, 0, 55, this.region().size.height-1), true, true ,true);  
   }
   else
   {
      this.m_bar_layer.create(new rectangle(0, 50, this.region().size.width-1, 50), true, true ,true);
   }
       
   this.minx_bar = 0;
   this.maxx_bar = 0;
   this.set_page_size(10);
   this.set_pressed(false); 
}

function owk_scrollbar_destroy()
{
   this.scroll_layer().destroy();
   this.bar_layer().destroy();
   this.ancestor_destroy(); 
}

function owk_scrollbar_load_patterns(i_url, i_repeat_middle, i_is_horizontal, i_is_vertical)
{  
   this.m_scroll_layer_decorator.create(this.m_scroll_layer);
   this.m_bar_layer_decorator.create(this.m_bar_layer);

   var myscrollbar = this;
   this.m_scroll_layer.on_loaded = function(){myscrollbar.on_loaded();};	

   this.m_page_size = 1;
   this.m_pick_bar_origin_x = 0;
   this.m_pick_bar_origin_y = 0;

   var bar_string = i_url  ;

   if (i_is_horizontal && i_is_vertical)
   {      
      this.m_scroll_layer_decorator.load(i_url, i_repeat_middle);
      this.m_bar_layer_decorator.load(bar_string, i_repeat_middle);
   }
   else if (i_is_vertical)
   {
      this.m_scroll_layer_decorator.load_vert(i_url, i_repeat_middle);
      this.m_bar_layer_decorator.load_vert(bar_string, i_repeat_middle);
   }
   else if (i_is_horizontal)
   {
      this.m_scroll_layer_decorator.load_hori(i_url, i_repeat_middle);
      this.m_bar_layer_decorator.load_hori(bar_string, i_repeat_middle);
   }
}

function owk_scrollbar_on_loaded()
{
   if (this.is_horizontal())
   {     
      this.maxx_bar = this.region().size.width - this.bar_layer().region().size.width - this.scroll_layer_decorator().right_size().width;
      this.minx_bar = this.scroll_layer_decorator().left_size().width;     
      this.bar_layer().region().origin.x = this.minx_bar;
      this.bar_layer().set_region(this.bar_layer().region());
   }
   else
   {
      this.maxx_bar = this.region().size.height - this.bar_layer().region().size.height - this.scroll_layer_decorator().bottom_size().height;
      this.minx_bar = this.scroll_layer_decorator().top_size().height;
      this.bar_layer().region().origin.y = this.minx_bar;
      this.bar_layer().set_region(this.bar_layer().region());
   }
}

function owk_scrollbar_on_draging_bar()
{

}

function owk_scrollbar_on_hit()
{

}

function owk_scrollbar_page_size()
{
   return this.m_page_size;
}

function owk_scrollbar_set_page_size(i_value)
{
   this.m_page_size = i_value;
}

function owk_scrollbar_draw(i_value)
{
  
}

function owk_scrollbar_on_draw(i_surface, i_region)
{
  
}

function owk_scrollbar_is_horizontal()
{  
   return (this.region().size.width > this.region().size.height);
}

function owk_scrollbar_pressed()
{
   return this.m_pressed;
}  

function owk_scrollbar_set_pressed(i_value)
{
   this.m_pressed = i_value
}

function owk_scrollbar_bar_layer_decorator()
{   
   return this.m_bar_layer_decorator;
}

function owk_scrollbar_scroll_layer_decorator()
{
   return this.m_scroll_layer_decorator;   
}

function owk_scrollbar_on_mouse_move(i_mouse)
{
   if (this.pressed())
   {
      var mouse_position = new point(i_mouse.position().x, i_mouse.position().y);
   
      if(this.m_have_parent == true)
      {
         this.global_to_local_point(mouse_position);
      }   
      
      if (this.is_horizontal())
      {  
         this.bar_layer().region().origin.x = Math.max(Math.min(mouse_position.x - this.distancebetweendivandmouseleft, this.maxx_bar), this.minx_bar); 
      }
      else
      {
         this.bar_layer().region().origin.y = Math.max(Math.min(mouse_position.y - this.distancebetweendivandmousetop, this.maxx_bar), this.minx_bar); 
      }
      this.bar_layer().set_region(this.bar_layer().region());
      this.on_draging_bar();
      
   }

   return true;
}

function owk_scrollbar_on_mouse_button_down(i_mouse)
{
   i_mouse.capture(this);
   this.ancestor_on_mouse_button_down(i_mouse);
   
   // convert mouse pos to local
   var mouse_position = new point(i_mouse.position().x, i_mouse.position().y);
   this.global_to_local_point(mouse_position);

   this.m_pick_bar_origin_x = this.bar_layer().region().origin.x;
   this.m_pick_bar_origin_y = this.bar_layer().region().origin.y;
   
   
   if (this.bar_layer().region().is_point_inside(mouse_position))
   {      
      this.distancebetweendivandmouseleft = mouse_position.x - this.bar_layer().m_region.origin.x;
      this.distancebetweendivandmousetop = mouse_position.y - this.bar_layer().m_region.origin.y; 
      this.set_pressed(true);
   }
   else if (this.region().is_point_inside(mouse_position))
   {
      if (this.is_horizontal())
      {
         if (mouse_position.x < this.minx_bar)
         {
            this.bar_layer().region().origin.x = Math.max(Math.min(this.m_pick_bar_origin_x - 1, this.maxx_bar), this.minx_bar); 
         }            
         else if (mouse_position.x > this.maxx_bar + this.bar_layer().region().size.width)
         {
            this.bar_layer().region().origin.x = Math.max(Math.min(this.m_pick_bar_origin_x + 1, this.maxx_bar), this.minx_bar); 
         }
         else if (mouse_position.x < this.bar_layer().region().origin.x)
         {
            this.bar_layer().region().origin.x = Math.max(Math.min(this.m_pick_bar_origin_x - this.page_size(), this.maxx_bar), this.minx_bar); 
         }
         else if (mouse_position.x > this.bar_layer().region().origin.x + this.bar_layer().region().size.width)
         {
            this.bar_layer().region().origin.x = Math.max(Math.min(this.m_pick_bar_origin_x + this.page_size(), this.maxx_bar), this.minx_bar); 
         }
      }
      else
      {
         if (mouse_position.y < this.minx_bar)
         {
            this.bar_layer().region().origin.y = Math.max(Math.min(this.m_pick_bar_origin_y - 1, this.maxx_bar), this.minx_bar); 
         }
         else if (mouse_position.y > this.maxx_bar + this.bar_layer().region().size.height)
         {
            this.bar_layer().region().origin.y = Math.max(Math.min(this.m_pick_bar_origin_y + 1, this.maxx_bar), this.minx_bar); 
         }
         else if (mouse_position.y < this.bar_layer().region().origin.y)
         {
            this.bar_layer().region().origin.y = Math.max(Math.min(this.m_pick_bar_origin_y - this.page_size(), this.maxx_bar), this.minx_bar); 
         }
         else if (mouse_position.y > this.bar_layer().region().origin.y + this.bar_layer().region().size.height)
         {
            this.bar_layer().region().origin.y = Math.max(Math.min(this.m_pick_bar_origin_y + this.page_size(), this.maxx_bar), this.minx_bar);
         }
      }

      this.bar_layer().set_region(this.bar_layer().region());
   }       
      
   // convert region to surface coordinate for invalidate
  // invalidate();
   return true;
}

function owk_scrollbar_on_mouse_button_up(i_mouse) {

   var mouse_position = new point(i_mouse.position().x, i_mouse.position().y);
   this.global_to_local_point(mouse_position);
   
   if (this.region().is_point_inside(mouse_position))
   { 
       this.ancestor_on_mouse_button_up(i_mouse);
       this.set_pressed(false);
       i_mouse.release_capture();
       this.on_hit();
   }
   
   return false;   
}

function owk_scrollbar_on_mouse_move_enter(i_mouse)
{
   this.m_is_over = true;  
   return true;
}

function owk_scrollbar_on_mouse_move_leave(i_mouse)
{
   this.m_is_over = false;  
   return true;
}

function owk_scrollbar_scroll_layer()
{
   return this.m_scroll_layer;     
}

function owk_scrollbar_bar_layer()
{
   return this.m_bar_layer;  
}

scrollbar.prototype = new layer;
scrollbar.prototype.create = owk_scrollbar_create;
scrollbar.prototype.ancestor_create = owk_layer_create;
scrollbar.prototype.destroy = owk_scrollbar_destroy;
scrollbar.prototype.ancestor_destroy = owk_layer_destroy;
scrollbar.prototype.load_patterns = owk_scrollbar_load_patterns;
scrollbar.prototype.on_draging_bar = owk_scrollbar_on_draging_bar;
scrollbar.prototype.on_hit = owk_scrollbar_on_hit;
scrollbar.prototype.page_size = owk_scrollbar_page_size;
scrollbar.prototype.set_page_size = owk_scrollbar_set_page_size;
scrollbar.prototype.draw = owk_scrollbar_draw;
scrollbar.prototype.on_draw = owk_scrollbar_on_draw;
scrollbar.prototype.is_horizontal = owk_scrollbar_is_horizontal;
scrollbar.prototype.pressed = owk_scrollbar_pressed;
scrollbar.prototype.set_pressed = owk_scrollbar_set_pressed;
scrollbar.prototype.bar_layer_decorator = owk_scrollbar_bar_layer_decorator;
scrollbar.prototype.scroll_layer_decorator = owk_scrollbar_scroll_layer_decorator; 
scrollbar.prototype.bar_layer = owk_scrollbar_bar_layer;
scrollbar.prototype.scroll_layer = owk_scrollbar_scroll_layer; 
scrollbar.prototype.on_loaded = owk_scrollbar_on_loaded; 
scrollbar.prototype.on_mouse_move = owk_scrollbar_on_mouse_move;
scrollbar.prototype.on_mouse_button_down = owk_scrollbar_on_mouse_button_down;
scrollbar.prototype.on_mouse_button_up = owk_scrollbar_on_mouse_button_up;
scrollbar.prototype.on_mouse_move_enter = owk_scrollbar_on_mouse_move_enter;
scrollbar.prototype.on_mouse_move_leave = owk_scrollbar_on_mouse_move_leave; 
scrollbar.prototype.ancestor_on_mouse_move = owk_layer_on_mouse_move;
scrollbar.prototype.ancestor_on_mouse_button_down = owk_layer_on_mouse_button_down;
scrollbar.prototype.ancestor_on_mouse_button_up = owk_layer_on_mouse_button_up;

function slider()
{
   this.m_range_value = new range_value(0,0,0);
   this.bar_layer_is_loaded = false;
   this.scroll_layer_is_loaded = false;
}

function owk_slider_on_mouse_button_down(i_mouse) {
   //vérifier si on est la bonne zone
   i_mouse.capture(this);
   this.ancestor_on_mouse_button_down(i_mouse);
  
   var changevalue = false;

   // convert mouse pos to local
   var mouse_position = new point(i_mouse.position().x, i_mouse.position().y);
   this.global_to_local_point(mouse_position);

   if (this.region().is_point_inside(mouse_position)) {
      
      this.m_pick_bar_origin_x = this.bar_layer().region().origin.x;
      this.m_pick_bar_origin_y = this.bar_layer().region().origin.y;
            
      if (this.bar_layer().region().is_point_inside(mouse_position))
      {      
         this.distancebetweendivandmouseleft = mouse_position.x - this.bar_layer().m_region.origin.x;
         this.distancebetweendivandmousetop = mouse_position.y - this.bar_layer().m_region.origin.y; 
         this.set_pressed(true);
      }
      else 
      {      
         if (this.is_horizontal())
         {
            if (mouse_position.x < this.minx_bar)
            {
               this.bar_layer().region().origin.x = Math.max(Math.min(this.bar_layer().region().origin.x - 1, this.maxx_bar), this.minx_bar); 
               changevalue = true;           
            }
            else if (mouse_position.x > this.maxx_bar)
            {
               this.bar_layer().region().origin.x = Math.max(Math.min(this.bar_layer().region().origin.x + 1, this.maxx_bar), this.minx_bar); 
               changevalue = true;
            }
            else 
            {
               this.bar_layer().region().origin.x = Math.max(Math.min(mouse_position.x - (this.bar_layer().size.width / 2), this.maxx_bar), this.minx_bar); 
               changevalue = true;
            }
         }
         else
         {
            if (mouse_position.y < this.minx_bar)
            {
               this.bar_layer().region().origin.y = Math.max(Math.min(this.bar_layer().region().origin.y*1 - this.m_page_size, this.maxx_bar), this.minx_bar); 
               changevalue = true;
            }
            else if (mouse_position.y > this.maxx_bar)
            {
               this.bar_layer().region().origin.y = Math.max(Math.min(this.bar_layer().region().origin.y*1 + this.m_page_size, this.maxx_bar), this.minx_bar); 
               changevalue = true;
            }         
            else
            { 
               this.bar_layer().region().origin.y = Math.max(Math.min(mouse_position.y - (this.bar_layer().region().size.height / 2), this.maxx_bar), this.minx_bar); 
               changevalue = true;
            }
         }      

         this.bar_layer().set_region(this.bar_layer().region());

         if(changevalue == true)
         {
            if (this.is_horizontal())
            {   
               this.m_range_value.convert_to(this.bar_layer().region().origin.x, this.minx_bar,  this.maxx_bar);
            }
            else
            {      
               this.m_range_value.convert_to(this.bar_layer().region().origin.y, this.minx_bar,  this.maxx_bar);
            }   
            this.on_draging_bar();
         }         
      }       

      return true;      
   }
   else {
     
      return false;
   }
}

function owk_slider_load_patterns(i_url, i_repeat_middle, i_is_horizontal, i_is_vertical)
{  
   this.m_scroll_layer_decorator.create(this.m_scroll_layer);

   var myslidebar = this;
   this.m_scroll_layer.on_loaded = function(){myslidebar.on_loaded();};	
   this.m_bar_layer.on_loaded = myslidebar.on_loaded_bar;	

   var bar_string = i_url + "bar.png";   
   var bar_width = 10;
   var bar_height = 10;
   
   if (i_is_horizontal && i_is_vertical)
   {      
      this.m_scroll_layer_decorator.load(i_url, i_repeat_middle);      
   }
   else if (i_is_vertical)
   {
      this.m_scroll_layer_decorator.load_vert(i_url, i_repeat_middle);   
        
   }
   else if (i_is_horizontal)
   {
      this.m_scroll_layer_decorator.load_hori(i_url, i_repeat_middle);
   }
   
   var xmlDoc = null;

   if (window.ActiveXObject) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url + "info.xml");
   }
   else if (window.XMLHttpRequest) {
       var xmlDoc2 = new window.XMLHttpRequest();
       xmlDoc2.open("GET", i_url + "info.xml", false);
       xmlDoc2.send("");
       xmlDoc = xmlDoc2.responseXML;
   }
   else if (ActiveXObject("Microsoft.XMLDOM")) {
       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.load(i_url + "info.xml");
   }

   if(xmlDoc!=null)
   {          
      var x=xmlDoc.getElementsByTagName("bar");
      bar_width = x[0].getElementsByTagName("width")[0].childNodes[0].nodeValue;
      bar_height = x[0].getElementsByTagName("height")[0].childNodes[0].nodeValue;

      this.m_bar_layer.region().set_top(0);
      this.m_bar_layer.region().set_left(0);
      this.m_bar_layer.region().set_right(bar_width);
      this.m_bar_layer.region().set_bottom(bar_height);

      this.bar_layer().set_region(this.bar_layer().region());   
      this.m_bar_layer.load_image(bar_string);   
   }
      
   if (this.is_horizontal())
   {     
      this.maxx_bar = this.region().size.width - this.bar_layer().region().size.width - this.scroll_layer_decorator().right_size().width;
      this.minx_bar = this.scroll_layer_decorator().left_size().width;     
      this.bar_layer().region().origin.x = this.minx_bar;
      this.bar_layer().set_region(this.bar_layer().region());
   }
   else
   {
      this.maxx_bar = this.region().size.height - this.bar_layer().region().size.height - this.scroll_layer_decorator().bottom_size().height;
      this.minx_bar = this.scroll_layer_decorator().top_size().height;
      this.bar_layer().region().origin.y = this.minx_bar;
      this.bar_layer().set_region(this.bar_layer().region());     
   }

   this.on_loaded();
}


function owk_slider_on_loaded_bar(i_width,i_height)
{ 
   /*this.bar_layer_is_loaded = true;
   this.region().size.width = i_width;
   this.region().size.height = i_height;  
   this.set_region(this.region()); */
}

function owk_slider_on_loaded()
{
   if (this.is_horizontal())
   {     
      this.maxx_bar = this.region().size.width - this.bar_layer().region().size.width - this.scroll_layer_decorator().right_size().width;
      this.minx_bar = this.scroll_layer_decorator().left_size().width;     
      this.bar_layer().region().origin.x = this.minx_bar;
      this.bar_layer().set_region(this.bar_layer().region());
   }
   else
   {
      this.maxx_bar = this.region().size.height - this.bar_layer().region().size.height - this.scroll_layer_decorator().bottom_size().height;
      this.minx_bar = this.scroll_layer_decorator().top_size().height;
    
      this.bar_layer().region().origin.y = this.minx_bar;
      this.bar_layer().set_region(this.bar_layer().region());
   }
}

function owk_slider_all_image_loaded()
{
   
}

function owk_slider_range_value()
{
   return this.m_range_value;
}

function owk_slider_invalidate()
{
    var slider_value = Math.floor(this.m_range_value.convert_from(this.minx_bar, this.maxx_bar));
   
   if(this.is_horizontal())
   {         
      slider_value = slider_value + this.m_scroll_layer_decorator.left_size().width + this.bar_layer().region().size.width/2;
      this.bar_layer().region().origin.x = slider_value;
      this.bar_layer().set_region(this.bar_layer().region());
   }
   else
   {
       //slider_value = slider_value + this.m_scroll_layer_decorator.top_size().height + this.bar_layer().region().size.height/2;
       slider_value = slider_value + 20;
      this.bar_layer().region().origin.y = slider_value;
      this.bar_layer().set_region(this.bar_layer().region());
   }
}

function owk_slider_on_mouse_move(i_mouse) {
   
   this.ancestor_on_mouse_move(i_mouse);
   
   if (this.is_horizontal()) {       
      this.m_range_value.convert_to(this.bar_layer().region().origin.x, this.minx_bar,  this.maxx_bar);
   }
   else {
       this.m_range_value.convert_to(this.bar_layer().region().origin.y, this.minx_bar, this.maxx_bar);             
   }


   return true;
}

function owk_slider_set_increment_size(i_value)
{
   this.m_page_size = Math.round((this.maxx_bar - this.minx_bar)/(this.m_range_value.max- this.m_range_value.min) * i_value);

}


function owk_slider_on_mouse_button_up(i_mouse) {

    var mouse_position = new point(i_mouse.position().x, i_mouse.position().y);
    this.global_to_local_point(mouse_position);

    if (this.region().is_point_inside(mouse_position)) {
       
        //this.ancestor_on_mouse_button_up(i_mouse);
        this.set_pressed(false);
        i_mouse.release_capture();
        
        if (this.is_horizontal()) 
        {
            this.m_range_value.convert_to(this.bar_layer().region().origin.x, this.minx_bar, this.maxx_bar);
        }
        else {

            var range_min_max = (this.m_range_value.max * 1 - this.m_range_value.min * 1);
            var range_min_max_bar = (this.maxx_bar * 1 - this.minx_bar * 1);
            var range = range_min_max_bar/range_min_max ;

            var div_range = ((this.bar_layer().region().origin.y - this.minx_bar) / range_min_max_bar);
            //alert(range_min_max + " range_min_max");
            //alert(range_min_max_bar + " range_min_max_bar");
           // alert(this.bar_layer().region().origin.y + " this.bar_layer().region().origin.y");
           // alert(div_range + " div_range");
           // alert("(this.bar_layer().region().origin.y / range)" + (this.bar_layer().region().origin.y / range));
            //var div_range_div = (this.m_range_value.min * 1 / div_range);
           // var div_range_div_plus = (this.m_range_value.min * 1 + div_range * 1);
            this.m_range_value.val = div_range * range_min_max;
           // alert("m_range_value test " + this.m_range_value.val + " range_min_max" + range_min_max + " div_range_div_plus" + div_range_div_plus + " div_range_div" + div_range_div + "this.m_range_value.min" + this.m_range_value.min);
          //  this.m_range_value.convert_to(this.bar_layer().region().origin.y, this.minx_bar, this.maxx_bar);
        }

      //  alert("apres " + this.bar_layer().region().origin.y + " minx_bar " + this.minx_bar + " this " + this.maxx_bar + " m_range_value.val" + this.m_range_value.val + " m_range_value.val" + m_range_value.val + " m_range_value.max" + this.m_range_value.max + " m_range_value.min" + this.m_range_value.min);
        
        this.on_hit();
      
    }

    return false;
}

slider.prototype = new scrollbar;
slider.prototype.on_mouse_button_down = owk_slider_on_mouse_button_down;
slider.prototype.on_mouse_move = owk_slider_on_mouse_move;
slider.prototype.on_mouse_button_up = owk_slider_on_mouse_button_up;
slider.prototype.ancestor_on_mouse_move = owk_scrollbar_on_mouse_move;
slider.prototype.load_patterns = owk_slider_load_patterns;
slider.prototype.on_loaded = owk_slider_on_loaded;
slider.prototype.on_loaded_bar = owk_slider_on_loaded_bar;
slider.prototype.range_value = owk_slider_range_value;
slider.prototype.invalidate = owk_slider_invalidate;
slider.prototype.all_image_loaded = owk_slider_all_image_loaded;
slider.prototype.set_increment_size = owk_slider_set_increment_size;


function text_box(i_region,i_visible,i_resizable,i_dragable)
{   
   this.font = 18;
   this.font_color = new color(0,0,0,255);
   this.back_color = new color(255,255,255,255);
   this.text = "";
   this.title = "";
   this.m_numeric = false;
   this.m_in_floats = false;   
}

function owk_text_box_create(i_parent,i_region,i_visible,i_text)
{
   this.set_parent(i_parent);
   this.ancestor_create(i_region,i_visible,false,false);  
   this.m_context = document.createElement('input');
   this.m_context.setAttribute("type",  "text");
   this.m_context.style.width = i_region.size.width;
   this.m_context.style.border = 0;
   this.m_context.value = i_text;
   this.text = i_text;
   this.m_context.style.height = i_region.size.height;
   this.m_div.appendChild(this.m_context);

   var mytextbox = this;

   this.m_context.onmousedown = function(){if(mytextbox.m_context.value == mytextbox.title){mytextbox.m_context.value = "";}}
   this.m_context.onfocus = function(){mytextbox.on_focus(); if(mytextbox.m_context.value == mytextbox.title){mytextbox.m_context.value = "";}}
   this.m_context.onblur = function(){mytextbox.on_lost_focus();  if(mytextbox.m_context.value == ""){mytextbox.m_context.value = mytextbox.title;}}

   this.m_context.onkeyup =  function (){mytextbox.text = mytextbox.m_context.value;mytextbox.on_change();}
	this.m_context.onkeypress =  function numbersonly(e)
   {
      var unicode;
      if(isIE())
      { 
         var unicode =  event.keyCode;
      }
      else
      {
         var unicode = e.charCode ? e.charCode : e.keyCode;
      }
      
      var return_value = false;

      //Marche pas avec le .
      if(mytextbox.m_numeric==true)
      {
         if(unicode == 46 && mytextbox.m_in_floats == true)
         {
            try
            {              
               //Valide if the have a point
               for(var i=1;i<=mytextbox.m_context.value.length;i++)
               {
                  if("." == mytextbox.m_context.value.substring(i,1))  
                  {   
                     return_value =  false;
                     break;
                  }         
               }             
            }
            catch(e){alert(e.Message);}
            
         }         
         //if the key isn't the backspace key (which we should allow)
         else if( unicode != 8 )
         {             
            //if not a number
            if( unicode < 48 || unicode > 57 )
            {
               //disable key press
               return_value = false;
            }
            else
            {
               // enable keypress
               return_value = true;
            }
         }
         else
         {
            // enable keypress
            return_value = true;
         }
      }
      else
      {
         return_value = true;
      }

      mytextbox.text = mytextbox.m_context.value;

      if(unicode == 27)
      {
         mytextbox.on_cancel();
      }
      else if(unicode == 13)
      {           
         mytextbox.on_submit();
      } 
      
      return return_value;
   }
}

function owk_text_box_invalidate()
{
   if(this.text != this.m_context.value)
   {
      this.m_context.value = this.text;
      this.on_change();
   }
 
   if(this.m_context.style.color != this.font_color.to_hex())
   {
      this.m_context.style.color = this.font_color.to_hex();
   }

   if(this.m_context.style.backgroundColor != this.back_color.to_hex())
   {
      this.m_context.style.backgroundColor = this.back_color.to_hex();
   }

   if(this.m_context.value == "")
   {
       this.m_context.value = this.title;
   }

   if(this.font == 0)
   {

   }
   else if(this.font == 1)
   {

   }
   else if(this.font == 2)
   {

   }
   else if(this.font == 3)
   {

   }
   else if(this.font == 4)
   {

   }
   else if(this.font == 5)
   {

   }
   else if(this.font == 6)
   {

   }
   else if(this.font == 7)
   {

   }
   else if(this.font == 8)
   {

   }
   else if(this.font == 9)
   {

   }
   else if(this.font == 10)
   {

   }
   else if(this.font == 11)
   {

   }
   else if(this.font == 12)
   {

   }
   else if(this.font == 13)
   {

   }
   else if(this.font == 14)
   {

   }
   else if(this.font == 15)
   {

   }
   else if(this.font == 16)
   {
      this.m_context.style.fontSize = 8;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'normal';
   }
   else if(this.font == 17)
   {
      this.m_context.style.fontSize = 8;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'bold';
   }
   else if(this.font == 18)
   {
      this.m_context.style.fontSize = 10;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'normal';
   }
   else if(this.font == 19)
   {
      this.m_context.style.fontSize = 10;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'bold';
   }
   else if(this.font == 20)
   {
      this.m_context.style.fontSize = 11;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'normal';
   }
   else if(this.font == 21)
   {
      this.m_context.style.fontSize = 11;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'bold';
   }
   else if(this.font == 22)
   {
      this.m_context.style.fontSize = 12;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'normal';
   }
   else if(this.font == 23)
   {
      this.m_context.style.fontSize = 12;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'bold';
   }
   else if(this.font == 24)
   {  
      this.m_context.style.fontSize = 13;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'normal';
   }
   else if(this.font == 25)
   {
      this.m_context.style.fontSize = 13;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'bold';
   }
   else if(this.font == 26)
   {
      this.m_context.style.fontSize = 14;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'normal';
   }
   else if(this.font == 27)
   {
      this.m_context.style.fontSize = 14;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'bold';
   }
   else if(this.font == 28)
   {
      this.m_context.style.fontSize = 16;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'normal';
   }
   else if(this.font == 29)
   {
      this.m_context.style.fontSize = 16;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'bold';
   }
   else if(this.font == 30)
   {
      this.m_context.style.fontSize = 17;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'normal';
   }
   else if(this.font == 31)
   {  
      this.m_context.style.fontSize = 17;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'bold';
   }
   else if(this.font == 32)
   {
      this.m_context.style.fontSize = 18;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'normal';
   }
   else if(this.font == 33)
   {
      this.m_context.style.fontSize = 18;
      this.m_context.style.fontFamily = 'verdana';
      this.m_context.style.fontWeight = 'bold';
   }
   else if(this.font == 34)
   {

   }
   else if(this.font == 35)
   {

   }
}

function owk_text_box_is_numeric(i_numeric)
{
   return this.m_numeric;
}

function owk_text_box_set_is_numeric(i_numeric)
{
   this.m_numeric = i_numeric;
}

function owk_text_box_is_in_floats()
{
   return this.m_in_floats;
}

function owk_text_box_set_in_floats(i_in_floats)
{
   this.m_in_floats = i_in_floats;
}

function owk_text_box_load_patterns(i_url)
{

}

function owk_text_box_destroy()
{

}

function owk_text_box_on_cancel()
{

}

function owk_text_box_on_change()
{

}

function owk_text_box_on_submit()
{

}

function owk_text_box_set_font(i_value)
{
   this.m_font = i_value;
}

function owk_text_box_on_focus()
{

}

function owk_text_box_on_lost_focus()
{

}

function owk_text_box_get_text()
{
   return this.m_context.value;
}

text_box.prototype = new layer_group;
text_box.prototype.create = owk_text_box_create;
text_box.prototype.ancestor_create = owk_layer_create;
text_box.prototype.load_patterns = owk_text_box_load_patterns;
text_box.prototype.destroy = owk_text_box_destroy
text_box.prototype.is_numeric = owk_text_box_is_numeric;
text_box.prototype.set_is_numeric = owk_text_box_set_is_numeric;
text_box.prototype.is_in_floats = owk_text_box_is_in_floats;
text_box.prototype.set_in_floats = owk_text_box_set_in_floats;
text_box.prototype.invalidate = owk_text_box_invalidate;
text_box.prototype.on_cancel = owk_text_box_on_cancel;
text_box.prototype.on_change = owk_text_box_on_change;
text_box.prototype.on_submit = owk_text_box_on_submit;
text_box.prototype.on_focus = owk_text_box_on_focus;
text_box.prototype.on_lost_focus = owk_text_box_on_lost_focus;
text_box.prototype.set_font = owk_text_box_set_font;
text_box.prototype.get_text = owk_text_box_get_text;

function text_scroll()
{
   
}

function owk_text_scroll_create(i_parent, i_region, i_visible)
{
   this.set_parent(i_parent);
   this.ancestor_create(i_region, i_visible, false, false);
   i_parent.push_back_layer(this);
}

function owk_text_scroll_set_HTML(i_value)
{     
   this.m_text.m_div.innerHTML = i_value;
  /* this.m_vertical_slider.range_value().val_min_max(0,0,this.m_text.m_div.scrollHeight*1); 
   this.m_vertical_slider.set_increment_size(this.m_region.size.height/16);      
   this.m_vertical_slider.invalidate();    */
}

function owk_text_scroll_set_url(i_url)
{    
   var mytext_scroll = this;
   var XmlObj = null;

	if(window.XMLHttpRequest){XmlObj=new XMLHttpRequest();}
	else if(window.ActiveXObject){XmlObj = new ActiveXObject("Microsoft.XMLHTTP");}
	else{return;}		

	XmlObj.open("POST", i_url);			
	XmlObj.onreadystatechange  = function() 
	{				
		if(XmlObj.readyState == 4)
		{
			try
			{	
				mytext_scroll.set_HTML(XmlObj.responseText);           				
			}
			catch(e){}   		
		}				
	}
	XmlObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var data = "champ=" + escape("");
	XmlObj.send(data);	
   
   this.m_iframe = document.createElement("iframe");
   this.m_iframe.style.position='absolute';
   this.m_iframe.style.top=5;
   this.m_iframe.style.left=5;
   this.m_iframe.frameborder = '0';
   this.m_iframe.src=i_url;
   this.m_iframe.scrolling = 'yes';
   this.m_iframe.setAttribute('width',this.region().size.width-10);
   this.m_iframe.setAttribute('height',this.region().size.height-10);
   this.m_iframe.style.backgroundColor = 'transparent';
   this.m_iframe.allowTransparency="true";
   this.m_div.appendChild(this.m_iframe);
   //this.m_vertical_slider.range_value().val_min_max(0,0,0); 
   //this.m_vertical_slider.set_increment_size(this.m_region.size.height/16);      
   //this.m_vertical_slider.invalidate();    
}

function owk_text_scroll_vertical_slider()
{
  // return this.m_vertical_slider;
}

function owk_text_scroll_load_patterns(i_url, i_repeat_middle)
{
   this.m_background_decorator = new pattern_decorator(); 
   this.m_background_decorator.create(this);
   this.m_background_decorator.load(i_url,i_repeat_middle);
   /**
   this.m_vertical_slider = new slider();  
   this.m_vertical_slider.set_parent(this);
   this.m_vertical_slider.create(new rectangle(0, 0, this.m_region.size.height-100, this.m_region.size.height-2), true,false,false);
   this.m_vertical_slider.range_value().val_min_max(0,0,100);   
*/
   
  // this.push_back_layer(this.m_vertical_slider);
/*
   var my_text_scroll = this;
   this.m_vertical_slider.on_draging_bar = function(){my_text_scroll.on_draging_bar();};
   this.m_vertical_slider.on_hit = function(){my_text_scroll.on_draging_bar();};
   this.m_vertical_slider.load_patterns(i_url + "vertical_slider/",i_repeat_middle,false,true);    
   this.m_vertical_slider.region().origin.x= this.region().size.width - this.m_vertical_slider.m_bar_layer.region().size.width;
   this.m_vertical_slider.set_region(this.m_vertical_slider.region());
*/
  /* this.m_text = new layer();  
   this.m_text.set_parent(this);
   this.m_text.create(new rectangle(0, 0, this.m_region.size.width-this.m_vertical_slider.m_bar_layer.region().size.width, this.m_region.size.height-2), true,false,false);
*/
   //this.m_text.m_div.style.overflow = 'auto';
   
}

function owk_text_scroll_on_draging_bar()
{  
 /* 
    //alert(Math.abs(Math.round(this.m_vertical_slider.range_value().value())));
   if(this.m_vertical_slider.range_value().max==0)
   {
      this.m_vertical_slider.range_value().val_min_max(0,0,this.iframedoc.body.scrollHeight);   
      alert(this.iframedoc.body.scrollHeight s23123 + " this.iframedoc.body.scrollHeight" );   
      this.m_iframe.style.height = this.iframedoc.body.scrollHeight;
   
   }


  // alert((Math.abs(Math.round(this.m_vertical_slider.range_value().value()))));

   this.m_iframe.style.top = (Math.abs(Math.round(this.m_vertical_slider.range_value().value())));

   //this.iframedoc.body.scrollTop = (Math.abs(Math.round(this.m_vertical_slider.range_value().value())));*/
  // this.m_text.m_div.scrollTop = Math.round(this.m_vertical_slider.range_value().value());
}

function owk_text_scroll_invalidate()
{

}

function owk_text_scroll_hide_scroll()
{ 
   this.m_iframe.scrolling = 'no';
}

function owk_text_scroll_show_scroll()
{  
   this.m_iframe.scrolling = 'yes';
}


text_scroll.prototype = new layer_group;
text_scroll.prototype.hide_scroll = owk_text_scroll_hide_scroll;
text_scroll.prototype.show_scroll = owk_text_scroll_show_scroll;
text_scroll.prototype.create = owk_text_scroll_create;
text_scroll.prototype.ancestor_create = owk_layer_create;
text_scroll.prototype.load_patterns = owk_text_scroll_load_patterns;
text_scroll.prototype.set_HTML = owk_text_scroll_set_HTML;
text_scroll.prototype.set_url = owk_text_scroll_set_url;
text_scroll.prototype.vertical_slider = owk_text_scroll_vertical_slider;
text_scroll.prototype.on_draging_bar = owk_text_scroll_on_draging_bar;
text_scroll.prototype.invalidate = owk_text_scroll_invalidate;

