function _writeLog(host, ovSrc, ovCtxtUrl) {
  if (ovSrc != 'dena_jp_circle_cm_ctxt_kw')
    return;

  var url      = 'http:/'+'/'                        + host 
                 + '/imglog.gif?p=pc_cmhs01&src=' + ovSrc
                 + '&ovCtxtUrl='                  + ovCtxtUrl
                 + '&remote=1'
                 + '&x_UID=' + (new Date()).getTime()
                 ;

  var image = new Image();
  image.src = url;
  image = null;
}

function LoadCM2(
  ovHost,    ovConfig, ovSrc, 
  ovCtxtId,  ovTypeId, ovMaxCnt,
  ovCtxtUrl, ovSex,    ovAge)
{
  
  var url = 'http:/'+'/' + ovHost + '/'
           + '?outputCharEnc=shiftjis'

           + (ovSrc     ? '&source='     + ovSrc     : '')
           + (ovCtxtId  ? '&ctxtId='     + ovCtxtId  : '')
           + (ovTypeId  ? '&type='       + ovTypeId  : '')
           + (ovMaxCnt  ? '&maxCount='   + ovMaxCnt  : '')
           + (ovCtxtUrl ? '&ctxtUrl='    + ovCtxtUrl : '')
           + (ovSex     ? '&gen='        + ovSex     : '')
           + (ovAge     ? '&age='        + ovAge     : '')
           + '&uid=' + (new Date()).getTime()
           ;
  var headElem = document.getElementsByTagName('head')[0];
  var jsElem   = document.createElement('script');
  jsElem.setAttribute('id', 'jsElem');
  jsElem.setAttribute('src', url);

  headElem.appendChild(jsElem);
}

function ShowHSListings()
{
  if (OV_PC_flg)
  {
    var divElem = document.getElementById('OV_HS');
    divElem.style.display = 'inline';
  }
}

function ShowCM2Listings( avaHost, hspace, mbHost, ovSrc, ovCtxtUrl )
{
  jwait( 'zSr', function()
  {
    var i=6;
    
    _writeLog( mbHost, ovSrc, ovCtxtUrl );
    
    if ( i < zSr.length )
      OV_PC_flg = true; 
    else
      return ; 

    var divElem = document.getElementById('OV_CM2');
    divElem.style.display = 'inline';
    while (i < zSr.length)
    {
      var descr    = zSr[i++]; 
      var unused1  = zSr[i++]; 
      var clickURL = zSr[i++]; 
      var title    = zSr[i++]; 
      var sitehost = zSr[i++]; 
      var unused2  = zSr[i++]; 

      
      descr = _unEntitize( descr );
      title = _unEntitize( title );
      
      var pElem   = document.createElement('p');
      var aElem   = document.createElement('a');
      var br1Elem = document.createElement('br');
      var br2Elem = document.createElement('br');
      var txtElem = document.createElement('font');
      var spcElem = document.createElement('img');
      
      var titleNode = document.createTextNode(title);
      var descrNode = document.createTextNode(descr);

      aElem.setAttribute('class', 'title');
      aElem.setAttribute('target', '_new');

      if (ovSrc == 'dena_jp_circle_cm_ctxt_kw')
        aElem.setAttribute('href', './_out_im?url=' + encodeURIComponent(clickURL));
      else
        aElem.setAttribute('href', clickURL);
      aElem.appendChild(titleNode);

      txtElem.style.fontSize = 'smaller';
      txtElem.appendChild(descrNode);
      spcElem.setAttribute('src', 'http:/' + '/'+avaHost+'/i/dot.gif');
      spcElem.setAttribute('height', hspace);
      spcElem.setAttribute('width',  1);

      pElem.appendChild(aElem);
      pElem.appendChild(br1Elem);
      pElem.appendChild(txtElem);
      pElem.appendChild(br2Elem);
      pElem.appendChild(spcElem);
      
      divElem.appendChild(pElem);
    }
    
    zSr = null;
    var headElem = document.getElementsByTagName('head')[0];
    headElem.removeChild( document.getElementById('jsElem') );
  });
};

function ShowHrLine( hrColor, updown, size )
{
  var hrElem = document.createElement('hr');
  hrElem.setAttribute('size', size);
  hrElem.setAttribute('color', hrColor);
  
  var divHR;
  if (updown == 'down')
    divHR = document.getElementById('OV_HR_DOWN');
  else
    divHR = document.getElementById('OV_HR_UP');

  jwait( 'OV_PC_flg', function()
  {
    divHR.appendChild(hrElem);
    divHR.style.display = 'inline';
  });
}

function ShowHeadLine( text, txColor )
{
  
  var headImgElem = document.createElement('img');
  headImgElem.setAttribute('src', '/pc/emoji/D/F8F3.gif');
  headImgElem.setAttribute('class', 'emoji');

  var headTxt = document.createTextNode( text );
  var headTxtElem = document.createElement( 'font' );
  headTxtElem.setAttribute( 'color', txColor );
  headTxtElem.appendChild( headTxt );

  var divHeadLine = document.getElementById('OV_HEADLINE');
  jwait( 'OV_PC_flg', function()
  {
    divHeadLine.appendChild(headImgElem);
    divHeadLine.appendChild(headTxtElem);
    divHeadLine.style.display = 'inline';
  });
}

function jwait( val, func )
{
  var check = null;
  try
  {
    eval( "check = " + val );
  }
  catch(e){}
  
  if( check )
    func();
  else
  {
    var f = function(){jwait( val, func )};
    setTimeout( f, 100 );
  }
}


var entities = 
{
  '&quot;' : '"',
  '&amp;'  : '&',
  '&#39;'  : "'"
};


var regArray = [];
for (var i in entities)
  regArray[i] = new RegExp(i, 'g');

function _unEntitize( word )
{
  var result = word;
  for (var i in entities)
    result = result.replace(regArray[i], entities[i]);

  return( result );
}
