function openWindowWithURL(url)
{
    h = window.open(url, 'new_window', 'menubar=no,toolbar=no,scrollbars=yes,resizable=yes,location=no,status=no,width=615,height=622,left=200,top=60');
}

function submit_form(form_id, onsubmit)
{
	var f = document.getElementById(form_id);
	if (onsubmit)
		f.onsubmit();
	else
		f.submit();
}

function submit_form_with_loader(form_id, onsubmit, loader)
{
    var l = document.getElementById(loader);
    l.style.display = 'block';

    submit_form(form_id, onsubmit);
}

function submit_form_with_loader_check(form_id, onsubmit, loader, to_check)
{
    var e = document.getElementById(to_check);
    if (e.value != '')
        submit_form_with_loader(form_id, onsubmit, loader);
}

function show_image_in_popup(img, title)
{
    var newWindow;

    newWindow = window.open('', 'nw', 'menubar=no, toolbar=no, location=no, scrollbars=no, resizable=yes, status=no, width=600, height=500, left=400, top=400');

    newWindow.document.write("<html><head><title>" + title + "</title></head><body><a href='javascript:window.close();'><img id='imagePreview'  border='0' alt='' src='" + img + "' / onLoad='window.resizeTo(this.width+30, this.height+70); e = ((screen.width - this.width + 30) / 2); f = ((screen.height - this.height + 70) / 2); window.moveTo(f, e);'></a></body></html>");

    newWindow.document.close();
}

function show_hide(id)
{
	var div = document.getElementById(id);
	if (div.style.display == 'block') {
		div.style.display = 'none';
	} else {
		div.style.display = 'block';
	}
}

function show_element(id)
{
    var div = document.getElementById(id);
    div.style.display = 'block';
}

function show_hide_delay(id, period)
{
	setTimeout("show_hide('" + id + "')", period);
}

function hide_delay(id, period)
{
	setTimeout("$('" + id + "').hide()", period);
}

function change_role_id()
{
  var e = document.getElementById('administrator_id');
  e.value = '';
  submit_form("access_level_form", false)
}

function check_all_cbs(section_id, state)
{
  var cbs = document.getElementsByTagName('input');

  if (state)
  {
    for(var i=0; i < cbs.length; i++)
    {
      if ((cbs[i].type == 'checkbox') && (cbs[i].id.match('subsections_' + section_id + '_')))
      {
        cbs[i].checked = true;
      }
    }
  }
}

function change_organization_kind(k)
{
  var k0 = document.getElementById('organization_kind_0');
  var k1 = document.getElementById('organization_kind_1');

  if (k == '1')
  {
    k0.style.display = 'none';
    k1.style.display = 'block';
  }
  else
  {
    k1.style.display = 'none';
    k0.style.display = 'block';
  }
}

function select_banner_type(banner_type)
{
  var upload = document.getElementById('upload_div');
  var section = document.getElementById('section_div');
  var subsection = document.getElementById('subsection_div');

  if ((banner_type == '1') || (banner_type == '2')) {
    upload.style.display = 'block';
    if ((banner_type == '1'))
      section.style.display = 'block';
    else
      section.style.display = 'none';
  } else {
    if (banner_type == '4'){
      upload.style.display = 'block';
    } else {
      upload.style.display = 'none';
      section.style.display = 'none';
    }
  }

  if (banner_type == '0')
    subsection.style.display = 'none';
  else
    subsection.style.display = 'block';
}