var GTabControl_tabSheets = new Array();
var GBrowser_name = navigator.appName;
var GBrowser_version = parseFloat(navigator.appVersion);
var GBrowser_IE = (GBrowser_name == 'Microsoft Internet Explorer');
 
function GMultiSelect_selecAll(name) {
  var options = document.getElementsByName(name);
  for(i = 0; i < options.length; i++) {
    if(options[i].disabled) {
      continue;
    }
    options[i].checked = true;
  }
  return true;
}
function GMultiSelect_selecAllOrNone(name) {
  var options = document.getElementsByName(name);
  var hotovo = false;

  for(i = 0; i < options.length; i++) {
    if(options[i].disabled) {
      continue;
    }
    if(!options[i].checked) {
      hotovo = true;
    }
    options[i].checked = true;
  }

 
  if(hotovo) {
    return true;
  }

  for(i = 0; i < options.length; i++) {
    if(options[i].disabled) {
      continue;
    }
    options[i].checked = false;
  }
  return true;  
}
function GMultiSelect_selecNone(name) {
  var options = document.getElementsByName(name);
  for(i = 0; i < options.length; i++) {
    if(options[i].disabled) {
      continue;
    }
    options[i].checked = false;
  }
  return true;   
}
function GMultiSelect_selecInverse(name) {
  var options = document.getElementsByName(name);
  for(i = 0; i < options.length; i++) {
    if(options[i].disabled) {
      continue;
    }
    options[i].checked = !options[i].checked;
  }
  return true;   
}
function GCustomSimpleLister_submitForm(form_name, method, action, type, confirm_question, target) {
  if(confirm_question) {
    if(!confirm(confirm_question)) {
      return false;
    }
  }
  var form = document.getElementById(form_name);

  form.action = action;
  form.method = method;
  form.target = target;

/*  if(action) {
    form.action = action;
  }
  if(method) {
    form.method = method;
  }
  if(target) {
    form.target = target;
  }*/
  
  if(type == 'link') {
    form.submit();
  }
  return true;
}
function GApplication_popup(url,target,width,height) {
  if(!height) {
    height = 500;
  }
  if(!width) {
    width = 620;
  }  
  if(!target) {
    target = 'popup';
  }
  url = String(url);
  var i = url.indexOf('#'); 
  if(i >-1 ) {
    var anchor = url.substring(i);
    url = url.substring(0,i);
  }
  if(url.indexOf('?') <0 ) {
    url += '?popup';
  } else {
    url += '&popup';  
  }
  if(anchor) {
    url += anchor;
  }
                                    
  var x = window.open (url,target,"scrollbars=1, scrollable=1, resizable=1, status=0,toolbar=0,width="+width+",height="+height);
  if(x) {
    x.focus();
  }
  return x;
}

function GApplication_hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function GApplication_addClass(ele,cls) {
	if (!GApplication_hasClass(ele,cls)) ele.className += " "+cls;
}

function GApplication_removeClass(ele,cls) {
	if (GApplication_hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function GTabControl_selectTabSheet(tabControlName,tabSheetName) {
  var tabControl = GTabControl_tabSheets[tabControlName];
  var tabSheet; 
  if(tabControl) {
    for(i = 0; i < tabControl.length; i++) {
      tabSheet = document.getElementById(tabControl[i]);
      tabSheet.style.display = "none"; 
      if(tabSheet) {            
        GApplication_removeClass(tabSheet, 'GSelected');
        GApplication_removeClass(document.getElementById(tabControl[i]+'_header'), 'GSelected');        
      }
    }
  }
  tabSheet = document.getElementById(tabSheetName);
  tabSheet.style.display = "block";
  GApplication_addClass(tabSheet, 'GSelected');
  GApplication_addClass(document.getElementById(tabSheetName+'_header'), 'GSelected');
  document.getElementById(tabControlName+'_selected').value = tabSheetName;   
  return true;  
}
function GApplication_basename(path, suffix) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
 
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function GCustomSimpleLister_openDetails(listerName,rowID,uri) {
  row = document.getElementById(listerName + '_row_' + rowID + '_details_row');
  cell = document.getElementById(listerName + '_row_' + rowID + '_details_cell');
  if((row == null) || (cell == null)) {
    return false;
  }

  if(cell.innerHTML == '&nbsp;') {
    cell.innerHTML = '<iframe frameborder="0" class="GRowDetailsFrame" src="'+uri+'" name="'+listerName+'_row_'+rowID+'_details_frame">frames not supported</iframe>';
    if (GBrowser_IE) {
      row.style.display = 'block';
    } else {
      row.style.display = 'table-row';
    }
  } else {
    row.style.display = 'none';
    cell.innerHTML = '&nbsp;';      
  } 
    
}