function openHelpWindow(id,w,h)
{
  win = window.open( '/parkers/popup_help.php#'+id, 'Help', 'width='+w+',height='+h+',left=0,top=100,screenX=0,screenY=100,scrollbars=yes' );
}
function openHelpWindowAlt(id,w,h)
{
  win = window.open( '/sellers/popup_help.php#'+id, 'Help', 'width='+w+',height='+h+',left=0,top=100,screenX=0,screenY=100,scrollbars=yes' );
}
function openWindow(page,w,h,opt)
{
  win = window.open( page, '', 'width='+w+',height='+h+',left=0,top=100,screenX=0,screenY=100'+opt );
}


var newwindow = '';

function openTplBrowser( skinfield )
{
  // fetch current selected skin id
  var skin_id = document.getElementById( skinfield ).options[document.getElementById( skinfield ).selectedIndex].value;

  // set url
  var url = '/parkers/_tplbrowser.php?skinidtype='+ skinfield +'&skin_id='+ skin_id;

  if( ! newwindow.closed && newwindow.location )
  {
    newwindow.location.href = url;
  }
  else
  {
    var w = 500;
    var h = 400;

    LeftPosition = (screen.width)  ? (screen.width-w)/2 : 0;
    TopPosition  = (screen.height) ? (screen.height-h)/2 : 0;

    newwindow=window.open( url, 'name', 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',status=yes,scrollbars=yes,resizable=yes' );

    if( ! newwindow.opener ) newwindow.opener = self;
  }

  if( window.focus ) { newwindow.focus() }

  return false;
}



var newwindow = '';

function openTplEditor( skinfield )
{
  // fetch current selected skin id
  var skin_id = document.getElementById( skinfield ).options[document.getElementById( skinfield ).selectedIndex].value;

  // set url
  var url = '/parkers/_tpleditor.php?id='+ skin_id +'&field='+ skinfield;

  if( ! newwindow.closed && newwindow.location )
  {
    newwindow.location.href = url;
  }
  else
  {
    var w = screen.width;
    var h = screen.height;

    var LeftPosition = 0; //(screen.width)  ? (screen.width-w)/2 : 0;
    var TopPosition  = 0; //(screen.height) ? (screen.height-h)/2 : 0;

    newwindow=window.open( url, 'name', 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',status=yes,scrollbars=yes,resizable=yes' );
    //newwindow=window.open( url, 'name', 'status=yes,scrollbars=yes,resizable=yes,fullscreen=yes' );

    if( ! newwindow.opener ) newwindow.opener = self;
  }

  if( window.focus ) { newwindow.focus() }

  return false;
}


function toggleChecks()
{
  // fetch all checkboxes
  var checks = document.getElementsByTagName( 'INPUT' );

  for( var i=0; i<checks.length; i++ )
  {
    // check this checkbox is of right type, if yes toggle check value
    var str = checks.item(i).id;

    if( str.match( "cList" ) && checks[i].getAttribute('type') == 'checkbox' )
    {
      if( document.getElementById( checks.item(i).id ).checked == true )
      {
        document.getElementById( checks.item(i).id ).checked = false;
      }
      else
      {
        document.getElementById( checks.item(i).id ).checked = true;
      }
    }
  }
}

var privs_checked_last = 'cleared'; // cleared or checked

function checkAllNone()
{
    // fetch all checkboxes
    var checks = document.getElementsByTagName( 'INPUT' );

    for( var i=0; i<checks.length; i++ )
    {
        var str = checks.item(i).id;

        if( str.match( "cList" ) && checks[i].getAttribute('type') == 'checkbox' )
        {
            if( privs_checked_last == 'cleared' )
            {
                document.getElementById( checks.item(i).id ).checked = true;
            }
            else
            {
                document.getElementById( checks.item(i).id ).checked = false;
            }
        }
    }
    
    if( privs_checked_last == 'cleared' )
    {
        privs_checked_last = 'checked';
    }
    else
    {
        privs_checked_last = 'cleared';
    }
}



function toggleRadio( targetGroup )
{
  // fetch all radio buttons
  var form_fields = document.getElementsByTagName( 'INPUT' );

  for( var i=0; i<form_fields.length; i++ )
  {
    // check this form field is of right type, if yes toggle check value
    var str = form_fields.item(i).id;

    if( str.match( targetGroup ) && form_fields[i].getAttribute('type') == 'radio' )
    {
      document.getElementById( form_fields.item(i).id ).checked = true;
    }
  }
}




// insertScriptCode
function insertScriptCode()
{
  // to be called on page load, should insert all required code into the DOM, JS browsers wont see

  // display:none in the page, will be ignored by non js browser

  // tabs are the controllers so they are inserted, if not Jscript, page will be quite long!


  // need to fetch all child nodes like below
  // but for each addEvent Handler, onclick =''
  // ACTUALLY - just insert whole bar as JSCRIPT
}


// showFormSection
function showFormSection( showme, styleme )
{
  // hide all form containers, then set selected to visible
  var divs = document.getElementsByTagName( 'div' );

  for( var i=0; i < divs.length; i++ )
  {
    var str = divs.item(i).id;

    if( str.match( "jForm" ) )
    {
      document.getElementById( divs.item(i).id ).style.display = 'none';
    }
  }

  document.getElementById( showme ).style.display = 'block';

  // reset all tab styles, then set selected style to highlighted
  var child_nodes = document.getElementById( 'jTabs' ).childNodes;

  for( var i=0; i<child_nodes.length; i++ )
  {
    if( child_nodes[i].nodeType == 1 && child_nodes[i].nodeName == 'DIV' )
    {
      //child_nodes[i].setAttribute( "class", "jTabOff" );
      //child_nodes[i].setAttribute( "className", "jTabOff" );

      /* IE disregards setAttribute "class", rather than set both for mozilla + IE, use below  */

      child_nodes[i].className= "jTabOff";
    }
  }

  document.getElementById( styleme ).className= "jTabOn";
}


function show_payment_block( block )
{
  // fetch all tr elements - turn to hidden if not class prefixed with target
  var trs = document.getElementsByTagName( 'tr' );

  for( var i=0; i < trs.length; i++ )
  {
    var str = trs.item(i).id;

    if( str.match( "paymentblock_" ) )
    {
      document.getElementById( trs.item(i).id ).style.display = 'none';
    }
  }


  // determine block id and turn on
  if( block > 0 && block < 5 )
  {
    // when dealing with tr hiding, table-row is the display property
    // by setting to blank, the browser can default to its default tr visibility property, ie block, ffox table-row
    document.getElementById( 'paymentblock_'+block ).style.display = '';
  }
}



function toggle_row( row )
{
  // fetch row
  var the_row = document.getElementById( row );

  if( the_row.style.display == 'none' )
  {
    the_row.style.display = '';
  }
  else
  {
    the_row.style.display = 'none';
  }
}

function toggle_multi_rows( row )
{
  // fetch rows
  var trs = document.getElementsByTagName( 'tr' );

  for( var i=0; i < trs.length; i++ )
  {
    var str = trs.item(i).id;

    /* if( str == row ) */
    if( str.match( row ) )
    {
      the_row = document.getElementById( trs.item(i).id );

      if( the_row.style.display == 'none' )
      {
        the_row.style.display = '';
      }
      else
      {
        the_row.style.display = 'none';
      }
    }
  }
}




function show_fraud_filter( block )
{
  // fetch all td elements - turn to hidden if not class prefixed with target
  var tds = document.getElementsByTagName( 'td' );

  for( var i=0; i < tds.length; i++ )
  {
    var str = tds.item(i).id;

    if( str.match( "levelFilter_" ) )
    {
      document.getElementById( tds.item(i).id ).style.display = 'none';
    }
  }


  // determine block id and turn on
  if( block > 0 && block < 5 )
  {
    document.getElementById( 'levelFilter_'+block ).style.display = '';
  }
}