var
  COLOR_BTN             ='#606060',
  COLOR_BTN_HOVER       ='#000000',
  COLOR_FONT_DISABLED   ='#909090',
  COLOR_ROW_HOVER       ='#F9F9F9';
var _aMenuActions = new Array(
  new Array(
    '../1pub/read.php?menu_code=1',
    '../1pub/read.php?menu_code=2',
    '../1pub/read.php?menu_code=3' ),
  new Array(
    '../1pub/read.php?menu_code=4',
    '../1pub/read.php?menu_code=5',
    '../1pub/read.php?menu_code=6' ),
  new Array(
    '../1pub/read.php?menu_code=7',
    '../1pub/read.php?menu_code=8',
    '../1pub/read.php?menu_code=9',
    '../1pub/read.php?menu_code=10' ),
  new Array(
    '../1pub/read.php?menu_code=11',
    '../1pub/faq.php' ),
  new Array(
    '../1pub/read.php?menu_code=12',
    '../1pub/read.php?menu_code=13',
    '../1pub/partners.php',
    '../1pub/forum.php' ),
  new Array(),
  new Array(
    '../2adm/questions.php',
    '../2adm/legal_entities.php',
    '../2adm/messages.php',
    '../2adm/users.php',
    '../2adm/stats.php',
    '../2adm/emails.php' ),
  new Array(
    '../2adm/cfg_list.php?name=countries',
    '../2adm/cfg_list2.php?name=regions',
    '../2adm/cfg_list2.php?name=counties',
    '../2adm/cfg_list.php?name=categories_le',
    '../2adm/cfg_list.php?name=domains',
    '../2adm/cfg_list.php?name=progs',
    '../2adm/cfg_site.php' ) );
var _aMenuEnabled = new Array(
  new Array( true, true, true ),
  new Array( true, true, true ),
  new Array( true, true, true, true ),
  new Array( true, true ),
  new Array( true, true, true, false ),
  new Array(),
  new Array( false, false, false, false, false, false ),
  new Array( false, false, false, false, false, false, false ) );
var _bCmbOnChange=false, _sLineOldColor;



function checkDate( inStr )
{
  var d = '', m = '', y = '', i = 0;
  while( i < inStr.length && ( inStr.charAt( i ) == ' ' || isNaN( inStr.charAt( i ) ) ) ) i++;
  while( i < inStr.length && inStr.charAt( i ) != ' ' && !isNaN( inStr.charAt( i ) ) ) { d += inStr.charAt( i ); i++; }
  while( i < inStr.length && ( inStr.charAt( i ) == ' ' || isNaN( inStr.charAt( i ) ) ) ) i++;
  while( i < inStr.length && inStr.charAt( i ) != ' ' && !isNaN( inStr.charAt( i ) ) ) { m += inStr.charAt( i ); i++; }
  while( i < inStr.length && ( inStr.charAt( i ) == ' ' || isNaN( inStr.charAt( i ) ) ) ) i++;
  while( i < inStr.length && inStr.charAt( i ) != ' ' && !isNaN( inStr.charAt( i ) ) ) { y += inStr.charAt( i ); i++; }
  var nd = parseInt( d, 10 ); if( isNaN( nd ) ) return '';
  var nm = parseInt( m, 10 ); if( isNaN( nm ) ) return '';
  var ny = parseInt( y, 10 ); if( isNaN( ny ) ) return '';
  if( ny >= 0 && ny < 70 )
    ny += 2000;
  if( ny >= 70 && ny <= 99 )
    ny += 1900;
  if( ny < 1900 || ny > 2100 )
    return '';
  var daysInMonth = new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
  if( ( ny % 4 ) == 0 && ( ny % 400 ) != 0 )
    daysInMonth[1] = 29;
  if( nm <= 0 || nm > 12 )
    return '';
  if( nd <= 0 || nd > daysInMonth[nm - 1] )
    return '';
  d = String( nd );
  if( d.length == 1 ) d = '0' + d;
  m = String( nm );
  if( m.length == 1 ) m = '0' + m;
  y = String( ny );
  return d + '-' + m + '-' + y;
}

function checkTime( inStr )
{
  var h = '', m = '', i = 0;
  while( i < inStr.length && ( inStr.charAt( i ) == ' ' || isNaN( inStr.charAt( i ) ) ) ) i++;
  while( i < inStr.length && inStr.charAt( i ) != ' ' && !isNaN( inStr.charAt( i ) ) ) { h += inStr.charAt( i ); i++; }
  while( i < inStr.length && ( inStr.charAt( i ) == ' ' || isNaN( inStr.charAt( i ) ) ) ) i++;
  while( i < inStr.length && inStr.charAt( i ) != ' ' && !isNaN( inStr.charAt( i ) ) ) { m += inStr.charAt( i ); i++; }
  var nh = parseInt( h, 10 ); if( isNaN( nh ) ) return '';
  var nm = parseInt( m, 10 ); if( isNaN( nm ) ) return '';
  if( nh < 0 || nh > 23 )
    return '';
  if( nm < 0 || nm > 59 )
    return '';
  h = String( nh );
  if( h.length == 1 ) h = '0' + h;
  m = String( nm );
  if( m.length == 1 ) m = '0' + m;
  return h + ':' + m;
}

function checkNumber( inStr, beforeDecPoint, afterDecPoint, allowNegative, showThousandSep )
{
  var neg = false, bDec = '', dec = false, aDec = '', i = 0, fin = false;
  while( i < inStr.length && ! fin ) {
    while( i < inStr.length && ( inStr.charAt( i ) == ' ' || ( isNaN( inStr.charAt( i ) ) && ( ! allowNegative || inStr.charAt( i ) != '-' ) && inStr.charAt( i ) != _sDecimalSymbol ) ) ) i++;
    if( i < inStr.length ) {
      if( inStr.charAt( i ) == '-' ) { neg = true; i++; }
      else
        if( inStr.charAt( i ) == _sDecimalSymbol ) { dec = true; i++; if( afterDecPoint == 0 ) fin = true; }
        else
          while( i < inStr.length && ! fin && inStr.charAt( i ) != ' ' && ! isNaN( inStr.charAt( i ) ) ) {
            if( dec ) {
              if( aDec.length < afterDecPoint ) aDec += inStr.charAt( i );
              else fin = true;
            }
            else {
              if( bDec == '' || bDec == '0' ) bDec = inStr.charAt( i );
              else
                if( beforeDecPoint == 0 || bDec.length < beforeDecPoint ) bDec += inStr.charAt( i );
                else if( afterDecPoint == 0 ) fin = true;
            }
            i++;
          }
    }
  }
  var res = '';
  if( bDec.length > 0 || aDec.length > 0 ) {
    if( bDec == '' ) bDec = '0';
    if( showThousandSep ) {
      c = 0;
      for( i = bDec.length - 1; i >= 0; i-- )
      {
        if( c == 3 )
        {
          res = _sThousandSeparator + res;
          c = 0;
        }
        res = bDec.charAt( i ) + res;
        c++;
      }
    }
    else res = bDec;
    if( neg && ( bDec != '0' || ( aDec.length > 0 && parseInt( aDec, 10 ) != 0 ) ) ) res = '-' + res;
    if( afterDecPoint > 0 ) {
      res += _sDecimalSymbol + aDec;
      if( aDec.length < afterDecPoint ) for( var j = aDec.length; j < afterDecPoint; j++ ) res += '0';
    }
  }
  return res;
}

function formatNumber( iNumber, iNoOfDecimals, bShowThSep )
{
  var sRes = String( iNumber ), sBDec = "", sADec = "", i;
  if( sRes.length && ! isNaN( iNumber ) )
  {
    sRes = String( Number( iNumber ) );
    i = sRes.indexOf( "e" );
    if( i < 0 )
      i = sRes.indexOf( "E" );
    if( i >= 0 )
    {
      var bNeg, iExp, sBase;
      sBase = sRes.substr( 0, i );
      if( sRes.charAt( i + 1 ) == "-" )
      {
        iExp = parseInt( sRes.substr( i + 2 ), 10 );
        bNeg = true;
      }
      else
      {
        iExp = parseInt( sRes.substr( i + 1 ), 10 );
        bNeg = false;
      }
      if( iExp )
      {
        i = sBase.indexOf( "." );
        if( i >= 0 )
        {
          sBDec = sBase.substr( 0, i );
          sADec = sBase.substr( i + 1 );
        }
        else
        {
          sBDec = sBase;
          sADec = "";
        }
        if( bNeg )
        {
          bNeg = false;
          if( sBDec.charAt( 0 ) == "-" )
          {
            bNeg = true;
            sBDec = sBDec.substr( 1 );
          }
          if( sBDec.length > iExp )
          {
            sADec = sBDec.substr( sBDec.length - iExp ) + sADec;
            sBDec = sBDec.substr( 0, sBDec.length - iExp );
          }
          else
          {
            sADec = sBDec + sADec;
            for( i = 1; i <= iExp - sBDec.length; i++ )
              sADec = "0" + sADec;
            sBDec = "0";
          }
          if( bNeg )
            sBDec = "-" + sBDec;
        }
        else
        {
          if( sADec.length >= iExp )
          {
            sBDec = sBDec + sADec.substr( 0, iExp );
            sADec = sADec.substr( iExp );
          }
          else
          {
            sBDec = sBDec + sADec;
            for( i = 1; i <= iExp - sADec.length; i++ )
              sBDec = sBDec + "0";
            sADec = "";
          }
        }
        sRes = sBDec + "." + sADec;
      }
      else
        sRes = sBase;
    }
    i = sRes.indexOf( "." );
    if( i >= 0 )
    {
      sBDec = sRes.substr( 0, i );
      sADec = sRes.substr( i + 1, iNoOfDecimals );
      if( sRes.charAt( i + iNoOfDecimals + 1 ) >= 5 )
      {
        var sTmp = "", bOF = true, iChr;
        for( i = sADec.length - 1; i >= 0; i-- )
        {
          if( bOF )
          {
            iChr = parseInt( sADec.charAt( i ), 10 );
            if( iChr < 9 )
            {
              iChr++;
              bOF = false;
            }
            else
              iChr = 0;
            sTmp = iChr + sTmp;
          }
          else
            sTmp = sADec.charAt( i ) + sTmp;
        }
        sADec = sTmp;
        if( bOF )
        {
          sTmp = "";
          for( i = sBDec.length - 1; i >= 0; i-- )
          {
            if( bOF )
            {
              if( sBDec.charAt( i ) == "-" )
              {
                sTmp = "-1" + sTmp;
                bOF = false;
              }
              else
              {
                iChr = parseInt( sBDec.charAt( i ), 10 );
                if( iChr < 9 )
                {
                  iChr++;
                  bOF = false;
                }
                else
                  iChr = 0;
                sTmp = iChr + sTmp;
              }
            }
            else
              sTmp = sBDec.charAt( i ) + sTmp;
          }
          if( bOF )
            sTmp = "1" + sTmp;
          sBDec = sTmp;
        }
      }
    }
    else
    {
      sBDec = sRes;
      sADec = "";
    }
    sRes = "";
    if( bShowThSep ) {
      var c = 0;
      for( i = sBDec.length - 1; i >= 0; i-- )
      {
        if( c >= 3 && sBDec.charAt( i ) != "-" )
        {
          sRes = _sThousandSeparator + sRes;
          c = 0;
        }
        sRes = sBDec.charAt( i ) + sRes;
        c++;
      }
    }
    else
      sRes = sBDec;
    if( iNoOfDecimals )
    {
      sRes += _sDecimalSymbol + sADec;
      if( sADec.length < iNoOfDecimals ) for( i = sADec.length; i < iNoOfDecimals; i++ ) sRes += "0";
    }
  }
  else
    sRes = "";
  return sRes;
}

function getNumber( inStr )
{
  var res='';
  for(var i=0; i < inStr.length; i++)
    if(inStr.charAt(i)!=_sThousandSeparator) {
      if(inStr.charAt(i)==_sDecimalSymbol) res+='.';
      else res+=inStr.charAt(i);
    }
  if( res.length )
    return Number(res);
  else
    return '';
}

function trim( inStr ) {
  var b=0, e=inStr.length-1, left=true;
  for(var i=0; i<inStr.length; i++) {
    if(inStr.charAt(i)==' ') { if(left) b++; }
    else { left = false; e=i; }
  }
  return inStr.substr(b,e-b+1);
}

function escapeFull( sString )
{
  sString = escape( sString );
  var sRet = "";
  for( var i = 0; i < sString.length; i++ )
  {
    switch( sString.charAt( i ) )
    { // these are the characters that are not escaped by the JavaScript escape() function
      case '*': sRet += "%2A"; break;
      case '+': sRet += "%2B"; break;
      case '-': sRet += "%2D"; break;
      case '.': sRet += "%2E"; break;
      case '/': sRet += "%2F"; break;
      case '@': sRet += "%40"; break;
      case '_': sRet += "%5F"; break;
      default: sRet += sString.charAt( i );
    }
  }
  return sRet;
}

function addDays( inStr, n ) {
var tmp=new Date(inStr.substr(6,4),inStr.substr(3,2)-1,inStr.substr(0,2)), res="", d, m, y;
tmp=new Date(tmp.getTime()+n*24*3600*1000);
d=String(tmp.getDate());
m=String(tmp.getMonth()+1);
y=tmp.getYear(); y+=(y<1000?1900:0); y=String(y);
if(d.length==1) res+="0"+d; else res+=d;
res+="-";
if(m.length==1) res+="0"+m; else res+=m;
res+="-"+y;
return res;
}

function addMonths( inStr, n ) {
var y=Number(inStr.substr(6,4)), m=Number(inStr.substr(3,2)), res=inStr.substr(0,3), s=(n<0?-1:1);
n*=s;y+=s*Math.floor(n/12);n%=12;m+=s*n;
if(m>12) {y++;m-=12;}
else if(m<1) {y--;m+=12;}
m=String(m);y=String(y);
if(m.length==1) res+="0"+m; else res+=m;
res+="-"+y;
return res;
}



function btnOn( oBtn ) {
oBtn.style.backgroundColor=COLOR_BTN_HOVER;
oBtn.style.borderColor=COLOR_BTN_HOVER;
}

function btnOff( oBtn ) {
oBtn.style.backgroundColor=COLOR_BTN;
oBtn.style.borderColor=COLOR_BTN;
}

function rowOn( oRow ) {
_sLineOldColor=oRow.style.backgroundColor;
oRow.style.backgroundColor=COLOR_ROW_HOVER;
}

function rowOff( oRow ) {
oRow.style.backgroundColor=_sLineOldColor;
}

function cmbOff() {
for(var f=0; f<document.forms.length; f++) {
  for(var i=0; i<document.forms[f].elements.length; i++) {
    if(document.forms[f].elements[i].type.substr(0,6)=='select')
      document.forms[f].elements[i].style.visibility='hidden';
  }
} }

function cmbOn() {
for(var f=0; f<document.forms.length; f++) {
  for(var i=0; i<document.forms[f].elements.length; i++) {
    if(document.forms[f].elements[i].type.substr(0,6)=='select')
      document.forms[f].elements[i].style.visibility='visible';
  }
} }


function expandMenu( iMenuIdx )
{
  var i;
  for( i = 0; i < _aMenuHeadings.length; i++ )
  {
    if( _aMenuHeadings[i].length > 0 )
      document.getElementById( "_idMenu"+( i + 1 ) ).style.display = ( i == iMenuIdx - 1 ? "block" : "none" );
  }
}

function printMenu( iPart, sColor1, sColor2, sColor3, bUser )
{
  var i, j, p = 1;
  document.write( '<TABLE>' );
  for( i = 0; i < _aMenuHeadings.length; i++ )
  {
    if( _aMenuHeadings[i].length > 0 )
    {
      if( p == iPart )
      {
        document.write( '<TR><TD class="p0"><IMG src="../img/space.gif" alt="" width=1 height=1></TD></TR>'+
                        '<TR><TD class="menuHeading" style="background-color: #'+sColor1+';" onClick="expandMenu( '+( i + 1 )+' );">'+_aMenuHeadings[i]+'</TD></TR>'+
                        '<TR><TD class="p0"><TABLE id="_idMenu'+( i + 1 )+'" style="background-color: #'+sColor2+'; border-width: 1; border-style: solid; border-color: #'+sColor1+';'+( i == 0 ? '' : ' display: none;' )+'">' );
        for( j = 0; j < _aMenuOptions[i].length; j++ )
        {
          if( _aMenuEnabled[i][j] )
            document.write( '<TR><TD style="padding: 2px 3px 2px 10px;"><IMG style="background-color: #'+sColor3+'; border-width: 1; border-style: solid; border-color: #'+sColor1+';" src="../img/space.gif" alt="" width=8 height=8></TD><TD style="width: 100%; padding: 1px 9px 1px 2px;"><A class="menu" target="main" href="'+_aMenuActions[i][j]+'">'+_aMenuOptions[i][j]+'</A></TD></TR>' );
          else
            document.write( '<TR><TD style="padding: 1px 2px 1px 9px;"><IMG src="../img/ico_no.gif" alt="" width=12 height=12></TD><TD style="color: '+COLOR_FONT_DISABLED+'; width: 100%; padding: 1px 9px 1px 2px;" onClick="'+( bUser ? 'alert( \''+_sMenuNoAccess+'\' );' : 'window.main.location.href=\'../gen/login.php\';' )+'">'+_aMenuOptions[i][j]+'</TD></TR>' );
        }
        document.write( '</TABLE></TD></TR>' );
      }
    }
    else
    {
      p++;
    }
  }
  document.write( '</TABLE>' );
}


function printCombo( sName, aList, bNull, sSel, iSelType ) {
var r='', f=false;
if(bNull) r+='<option'+(sSel==""?' selected':'')+' value=""></option>';
for(i=0; i<aList[0].length; i++) {
  r+='<option';
  if((iSelType==1 && aList[0][i]==sSel) || (iSelType==2 && aList[2][i]==sSel) || (iSelType==3 && i+1==Number(sSel))) {
    r+=' selected'; f=true; }
  r+=' value="'+aList[0][i]+'">'+aList[1][i]+'</option>';
}
if(!f && sSel!="" && iSelType==1) r+='<option selected value="'+sSel+'">['+_sCmbUnknownVal+']</option>';
document.write('<SELECT name="'+sName+'" onChange="if(_bCmbOnChange) cmbChanged(this);">'+r+'</SELECT>');
}


function printComboEmpty( sName, aList, bNull, sSel, iSelType ) {
var r='', f=false, sVal, sText;
if(bNull) r+='<option'+(sSel==""?' selected':'')+' value=""></option>';
document.write('<SELECT name="'+sName+'" onChange="if(_bCmbOnChange) cmbChanged(this);">'+r+'</SELECT>');
for(i=0; i<aList[0].length; i++) {
  if((iSelType==1 && aList[0][i]==sSel) || (iSelType==2 && aList[2][i]==sSel) || (iSelType==3 && i+1==Number(sSel))) {
    sVal=aList[0][i]; sText=aList[1][i]; f=true; }
}
if(!f && sSel!="" && iSelType==1) { sVal=sSel; sText='['+_sCmbUnknownVal+']'; f=true; }
if(f) {
  document.forms[0].elements[sName].options[document.forms[0].elements[sName].length] = new Option( sText, sVal, true, true );
  document.forms[0].elements[sName].selectedIndex = 1;
}
}


function cmbSet( oCmb, sValue )
{
  var si = -1;
  for( var i = 0; i < oCmb.length && si < 0; i++ )
    if( oCmb.options[i].value == sValue )
      si = i;
  if( si >= 0 )
  {
    for( var i = 0; i < oCmb.length; i++ )
      oCmb.options[i].selected = ( i == si );
    oCmb.selectedIndex = si;
  }
}

/*
function wsfClear( iForm, sName ) {
document.forms[iForm].elements[sName].value='';
document.forms[iForm].elements[sName+'Description'].value='';
if(document.forms[iForm].elements[sName].onchange!=undefined)
  document.forms[iForm].elements[sName].onchange();
}

function wsfSelect( iForm, sName, sURL, sParameters ) {
w=window.open(sURL+'?_wsfForm='+iForm+'&_wsfName='+sName+( sParameters=='' ? '' : '&'+eval(sParameters) ),'wsfSelect','left='+Math.round(40*Math.random())+',top='+Math.round(20*Math.random())+',width=760,height=580,scrollbars=yes,resizable=yes,status=yes');
w.focus();
}

function wsfSet( iForm, sName, sId, sDescription ) {
opener.document.forms[iForm].elements[sName].value=sId;
opener.document.forms[iForm].elements[sName+'Description'].value=sDescription;
if(opener.document.forms[iForm].elements[sName].onchange!=undefined)
  opener.document.forms[iForm].elements[sName].onchange();
opener.focus();
window.close();
}
*/

function goPage( oForm, iPage )
{
  if( iPage > 0 )
    oForm._page.value = iPage;
  oForm.submit();
  return false;
}


