/*
  %%%%%%%%%%%%%%%%%%%%%%%%{ DEVELOPER NOTES }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%
  %%   Modified Date:    Monday 23 March 2009
  %%   Developer:        
  %%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  */
var s_tpl;
var count = 0;
var NEWLINE = '\n';
var TABBED = '\t';
var dbg = nlbr(1) + 'Debug mode: ' + nlbr(2);
var func;
var cb_boolean = false;
var r_val;
/**
 *
 * @param int * @return
 * @access public
 */
function nlbr(times){
  var str;
  for (i = 0; i < times; i++){
    str += NEWLINE;
  }
  return str;
}

function pageloading(){
/*
  var text = new Array();
  window.status = text[i]
  //complete
  //i = ceil(Math.random() * 100);
  setTimeout("pageloading", 21000)
  if (!(i >= 99)){
  text[i+0] = "Page loading...";
  text[i+1] = "Page loading.";
  text[i+2] = "Page loading..";
  text[i+3] = "Page loading....";
  i++;
} else {
  text[99] = "";
  window.status = '';
  i = 0;
}*/
}

/**
 *
 * @param int * @return
 * @access public
 */
function tabs(times){
  var str;
  for (i = 0; i < times; i++){
    str += TABBED;
  }
  return str;
}

/**
 *
 * @param int * @return
 * @access public
 */
function nbsp(times){
  var str;
  for (i = 0; i < times; i++){
    str += ' ';
  }
  return str;
}

/**
 *
 * @param string * @return
 * @access public
 */
function cb_f(f){
  func = f + nlbr(1);
  dbg = nlbr(1) + tabs(1) + 'Function: ' + func + nlbr(1);
}

/**
 *
 * @param boolean * @return
 * @access public
 */
function cb_debug(enable){
  func = 'cb_debug(boolean):void';
  cb_f(func);
  dbg += nlbr(1) + tabs(1) + 'Count: ' + count + nlbr(1);
  dbgwnd = document.getElementById('debug_wnd_wrapper');
  if (enable){
    dbgwnd.value = dbg;
  } else {
    dbgwnd.value = '';
  }
  return;
}

/**
 *
 * @param boolean * @return
 * @access public
 */
function show_debugger(){
  cb_debug(0);
}

function hide(elem){
  func = 'hide(dom:id):void';
  cb_f(func);
  
  var obj = document.getElementById(elem);
  var visible = (obj.style.display != 'none');
  if (visible){
    obj.style.display = 'none';
  }
}

function do_close(elem){
  func = 'do_close(dom:id):void';
  cb_f(func);
  hide(elem);
}

function show_block(elem){
  func = 'show_block(dom:id):void';
  cb_f(func);
  var obj = document.getElementById(elem);

  visible = (obj.style.display != 'none');
  //key = document.getElementById('x' + elem);
  if (visible){
    
  } else {
    obj.style.display = "block";
  }
}

function show_ihtml(elem, data){
  func = 'show_ihtml(dom:id, string):void';
  cb_f(func);
  //document.getElementById(elem).firstChild.nodeValue = data;
  document.getElementById(divEl).innerHTML = data;
}

function goto_url(url){
  func = 'goto_url(string):void';
  cb_f(func);
  window.location = url;
}

function clear_text(elem){
  func = 'clear_text(dom:id):void';
  cb_f(func);
  document.getElementById(elem).value = '';
}

function change_bgcolor(element, color)
{
  func = 'change_bgcolor(dom:element, string):void';
  cb_f(func);
  element.style.backgroundColor = color;
}

function change_style(element, style)
{
  func = 'change_style(dom:element, string):void';
  cb_f(func);
  element.className = style;
}

function set_border(element, style, thickness, color)
{
  func = 'set_border(dom:element, string, int, string):void';
  cb_f(func);
  element.style.border = style + ' ' + thickness + ' ' + color;
}

function unset_border(element)
{
  func = 'unset_border(dom:element):void';
  cb_f(func);
  element.style.border = '0';
}

function set_cursor(element, type)
{
  func = 'set_cursor(dom:element, string):void';
  cb_f(func);
  element.style.cursor = type;
}

function display(elem, data){
  func = 'display(string):void';
  cb_f(func);
  //document.getElementById(elem).firstChild.nodeValue = data;
  document.getElementById(elem).innerHTML = data;
}

function caution(data){
  func = 'caution(string):void';
  cb_f(func);
  if (data != '')
  alert(data);
}

function onstatus(data){
  func = 'onstatus(string):void';
  cb_f(func);
  window.status = data;
}

function query(data){
  func = 'query(string):void';
  cb_f(func);

  prompt(data);
}

function form_submit(objForm, type, url){
  objForm.method = type;
  objForm.action = url;
  objForm.submit();
}

function handle_key_up(e){
  code = get_key_up(e);

  //custom code
  switch(code){
    case 13:
	doLogin();
    break;
  }
}

function get_key_up(e){
  if(!e){
    e = window.event;
  }
  return (e.keyCode);
}

function refresh(){
  func = 'refresh():void';
  cb_f(func);
  
  //var s_url = unescape(window.location.pathname);
  var s_url = unescape(window.location.href);
  try { //1.0
    window.location.href = s_url;
    s_url = window.location.href;
  } catch (e){
    try { //1.1
      window.location.replace(s_url);
    } catch (ob){ //1.2
      window.location.reload(false);
    }
  }
}

function do_nothing(data){
  func = 'do_nothing(string):void';
  cb_f(func);
}

function do_toggle(elem){
  func = 'do_toggle(dom:id):void';
  cb_f(func);
  var obj = document.getElementById(elem);
  visible = (obj.style.display != 'none');
  //key = document.getElementById('x' + elem);
  if (visible){
    obj.style.display = "none";
  } else {
    obj.style.display = "block";
  }
}

function make_readonly(elem){
	document.getElementById(elem).readOnly = true;
}

function make_children_readonly(elem) {
	
	elem = document.getElementById(elem);
	current_elem = elem.firstChild;
	while(current_elem != null)
	{
		current_elem.readOnly = true;
		
		if(current_elem!=null && current_elem.type=="radio")
		{
			add_event(current_elem, "click", null_callback, false);
		}
		current_elem = current_elem.nextSibling;
	}
}

function null_callback(e) {
	e.preventDefault();
	e.stopPropagation();
	return false;
}

function add_event(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

function disable_right_click(event)
{
	// For mouse right click 
	if (event.button==2)
	{
		alert("Copy-Paste disabled!");
	}
}

function disable_ctrl_key(e)
{
	var code = (document.all) ? event.keyCode:e.which;
	var message = "Copy-Paste disabled!";
	// look for CTRL key press
	if (parseInt(code)==17)
	{
		alert(message);
		window.event.returnValue = false;
	}
}
