//-----------------------------------------------------------------------------
// impAct AD CODE
function impA_rotate(list) {
  var i = list.length;
  while (--i) {
  var j = Math.floor(Math.random() * (i + 1));
  if (i == j) continue;
  var k = list[i]; list[i] = list[j]; list[j] = k;
  }
  for ( i = 0; i <= list.length; i++){ if ( list[i] == "" ) list.splice(i,1);}
  return list;
}
//-----------------------------------------------------------------------------
var ov_exec  = new Array();
var ov_start = 6;
function show_ov_push(v1,v2,v3){
  ov_exec[ov_exec.length] = new Array(v1,v2,v3);
}


function show_ov_pop_boot(){
  var mc = 0;
  for (var i = 0; i< ov_exec.length ; i++){
    mc += ov_exec[i][0];
  }
  var x = document.getElementById("search_q");
  if(x){
    if(x.value != ""){
      writeOv_js_xml_1_0(mc,x.value);
      return;
    }
  }
  if(location.pathname.indexOf("/article/tag/") != -1){
    var metas = document.getElementsByTagName("meta");
    for(var i = 0 ; i < metas.length ; i++ ){
      if (metas[i].name == "keywords"){
        writeOv_js_xml_1_0(mc,metas[i].content);
        return;
      }
    }
  }
  writeOv_js_flat_1_0(mc);
}


function show_ov_pop(){
  var ov_start = 6;
  for (var i = 0; i < ov_exec.length ; i++){
    var dub = 0;
    for (var k = 0; k < ov_exec.length ; k++){
      if(ov_exec[i][2] == ov_exec[k][2]){
        dub=1;
        break;
      }
    }
    if(dub > 0 && ov_exec[i][2] == "x100py180"){
      var idx = 0;
      for (var k = 0; k <= i ; k++){
        if(ov_exec[i][2] == ov_exec[k][2]){
          idx++;
        }
      }
      ov_exec[i][3] = idx;
    }else{
      ov_exec[i][3] = "";
    }
  }
  for (var i = 0; i < ov_exec.length ; i++){
    ShowOv2(ov_start , ov_exec[i][0] , ov_exec[i][1] , ov_exec[i][2] , ov_exec[i][3]);
    ov_start += (6 * ov_exec[i][0]);
  }
}

var zSr;
function ShowOv2(start_i , ad_count , add_id , css_class , idx){
  if(!zSr){
    return;
  }

  var t = Math.floor(Math.random() * 100000);
  var i = start_i;
  var isstyle1 = (add_id.match('style1') == 'style1');
  var isstyle2 = (add_id.match('style2') == 'style2');
  var ispickup = (add_id.match('pickup') == 'pickup');

  while (i < start_i + (6 * ad_count)) {
    var descr    = zSr[i++];   // listing description
    var unused1  = zSr[i++];   // (ignore)
    var clickURL = zSr[i++];   // listing link
    var title    = zSr[i++];   // listing title
    var sitehost = zSr[i++];   // advertiserfs domain name
    var unused2  = zSr[i++];   // (ignore)
    if (descr == undefined){
      break;
    }

    var d = document.createElement("div");
    var a = document.createElement("a");

    var paths = location.pathname.split("/");
    var path  = (paths.length > 1 ? paths[1] : "top");
    if (location.pathname.indexOf("search") == 0){
      path = "search";
    }
    var oreg  = new RegExp("^[a-z]+$");
    if (!path.match(oreg)){
      path = (paths.length > 2 ? paths[2] : "top");
    }
    if (path.indexOf('%') != -1){
      path = "local";
    }
    var area = "";
    if(add_id  == "overture_ads_breadth_pickup"){
      area = "right";
    }else if(css_class == "x300y300"){
      area = "right";
    }else if(css_class == "x100py180"){
      area = "100x180";
    }else if(css_class == "x468y60"){
      area = "468x60";
    }else if(ad_count == "1"){
      area = "line";
    }else{
      area = "center" + ad_count
    }
    if(idx != ""){
      area += "-" + idx;
    }

    d.setAttribute("class",css_class);
    a.href=clickURL;
    a.setAttribute("onclick","ov_click_count(location.href,'" + path + area + "','" + title + "');");

    if(isstyle1){
      d1 = document.createElement("div");
      d1.setAttribute("class","ov_title");

      var c1 = document.createElement("div");
      c1.innerHTML = title;
      c1.setAttribute("class","title");
      d1.appendChild(c1);

      var c2 = document.createElement("div");
      c2.innerHTML = descr;
      c2.setAttribute("class","ov_descr");
      d1.appendChild(c2);

      //var c3 = document.createElement("div");
      //c3.innerHTML = " " + sitehost;
      //c3.setAttribute("class","host");
      //d1.appendChild(c3);

      a.appendChild(d1);
    }else if(isstyle2){
      d1 = document.createElement("div");
      d1.setAttribute("class","ov_title");

      var c1 = document.createElement("div");
      c1.innerHTML = title;
      c1.setAttribute("class","title");
      d1.appendChild(c1);

      var c2 = document.createElement("div");
      c2.innerHTML = " " + sitehost;
      c2.setAttribute("class","host");
      d1.appendChild(c2);

      d2 = document.createElement("div");
      d2.innerHTML = descr;
      d2.setAttribute("class","ov_descr");

      a.appendChild(d1);
      a.appendChild(d2);
    }else if(ispickup){
      a.setAttribute("class","ad");

      d1 = document.createElement("div");
      d1.setAttribute("class","ov_title");

      var c1 = document.createElement("div");
      c1.innerHTML = title;
      c1.setAttribute("class","title");
      d1.appendChild(c1);

      var c2 = document.createElement("div");
      c2.innerHTML = " " + sitehost;
      c2.setAttribute("class","host");
      d1.appendChild(c2);

      d2 = document.createElement("div");
      d2.innerHTML = descr;
      d2.setAttribute("class","desc");

      a.appendChild(d1);
      a.appendChild(d2);
    }else{
      var d1 = document.createElement("div");
      d1.innerHTML = title;
      d1.setAttribute("class","ov_title");
      a.appendChild(d1);

      var d2 = document.createElement("div");
      d2.innerHTML = descr;
      d2.setAttribute("class","ov_descr");
      a.appendChild(d2);

      var d3 = document.createElement("div");
      d3.innerHTML = " " + sitehost;
      d3.setAttribute("class","ov_host");
      d2.appendChild(d3);
    }

    d.appendChild(a);
    document.getElementById(add_id).appendChild(d);
  }

  if(document.getElementById(add_id).hasChildNodes() && add_id.search('search') == -1){
    var d = document.createElement("div");
    d.setAttribute("align","right");
    d.setAttribute("class","interest_footer");
    //d.innerHTML = 'インタレストマッチ - <a href="http://ov.yahoo.co.jp/service/int/index.html?o=IM0028" target="_blank">広告掲載について</a>';
    d.innerHTML = '<a href="http://ov.yahoo.co.jp/service/int/index.html?o=IM0028" target="_blank">インタレストマッチ</a>';
    document.getElementById(add_id).appendChild(d);
  }

  if (navigator.userAgent.indexOf("MSIE")!=-1){
    document.getElementById(add_id).innerHTML += "";          //for IE
  }
}


function writeOv_js_flat_1_0(c){
  var paths = location.pathname.split("/");
  var path  = (paths.length > 2 ? paths[1] : "top");
  var oreg  = new RegExp("^[a-z]+$");
  if (!path.match(oreg)){
    path = (paths.length > 3 ? paths[2] : "top");
  }
  if (path.indexOf('%') != -1){
    path = "local";
  }
  path = encodeURIComponent(path);
  var config  = "20253284135";
  var source  = "ecnavi_jp_moneyzine_cat_ctxt";
  var ctxtUrl = encodeURIComponent(location.protocol + "//" + location.host + location.pathname);
  var ctxtids = Array("spo0200","hea0204","hea0400","edu0400","ent0300","fin0100","com0400","com0900","com1001","pro0105","pro1100","pro1200","aut0102","app0401","fin0101","fin0203","fin0205","pro0902");
  var ctxtid  = ctxtids[Math.floor( Math.random() * ctxtids.length )];
  var type    = "cm_yz_" + path + "_" + ctxtid;
  var gen     = "M";
  var age     = "35";
//document.write('<s' + 'cript type="text/javascript" language="javascript" src="http://cm.jp.overture.com/js_flat_1_0/?config=' + config + '&source=' + source + '&ctxtId=' + ctxtid + '&mkt=jp&type=' + type + '&maxCount=' + c + '&ctxtUrl=' + ctxtUrl + '&ctxtCat=default_finance"></s' + 'cript>');
//  document.write('<s' + 'cript type="text/javascript" language="javascript" src="http://im.ov.yahoo.co.jp/js_flat/?source=' + source + '&type=' + type + '&ctxtId=' + ctxtid + '&maxCount=' + c + '&outputCharEnc=utf8&ctxtUrl=' + ctxtUrl + '"></s' + 'cript>');
  document.write('<s' + 'cript type="text/javascript" language="javascript" src="http://im.ecnavi.ov.yahoo.co.jp/js_flat/?source=' + source + '&type=' + type + '&ctxtId=' + ctxtid + '&maxCount=' + c + '&gen=' + gen + '&age=' + age + '&outputCharEnc=utf8&ctxtUrl=' + ctxtUrl + '"></s' + 'cript>');
}
function writeOv_js_xml_1_0(c,q){
  document.write('<s' + 'cript type="text/javascript" language="javascript" src="/search/xml_overture?keywords=' + encodeURI(q) + '&maxcount=' + c + '&ua=' + escape(escape(navigator.userAgent)) + '"></s' + 'cript>');
}
//-----------------------------------------------------------------------------


var hs_exec  = new Array();
function show_hs_push(v1,v2,v3,v4){
  //count,id,class,ref
  hs_exec[hs_exec.length] = new Array(v1,v2,v3,v4);
}
function show_hs(){
  var paths = location.pathname.split("/");
  var path  = (paths.length > 1 ? paths[1] : "top");
  if (location.pathname.indexOf("search") == 0){
    path = "search";
  }
  var oreg  = new RegExp("^[a-z]+$");
  if (!path.match(oreg)){
    path = (paths.length > 2 ? paths[2] : "top");
  }
  if (path.indexOf('%') != -1){
    path = "local";
  }

  var ctxtids = Array("富裕層向け雑誌","富裕層 年収","投資信託 比較","投資信託 手数料","積立投信","投信 比較","投信 評判","BRICs 投信","不動産投資","株式投資入門","株主優待","デイトレーダー 入門","スプレッド","FX 比較","FX 初心者","FX スプレッド","FX セミナー","FX クリック365","FXロボ","日経225 自動売買","日経225 先物","信用取引 空売り","信用取引 株主優待","サブプライム","システムトレード","確定申告 控除","確定申告 書き方","確定申告 相談","確定申告 個人","中国株","インデックスファンド","コモディティファンド","ベトナムファンド","オフショアファンド","ホテルファンド","FXファンド","金取引","貴金属相場","外貨預金");
  for (var i = 0; i < hs_exec.length ; i++){
    var ref    = path + hs_exec[i][3];
    var addtxt = '<div class="' + hs_exec[i][2] + '">';
    for (var k = 0; k < hs_exec[i][0]; k++){
      var sindex  = Math.floor( Math.random() * ctxtids.length );
      var s       = ctxtids[sindex];
      var enc_s   = encodeURIComponent(s);
      ctxtids.splice(sindex,1);
      var css     = (k < hs_exec[i][0] -1 ? "keyword" : "keyword_last");
      addtxt +=
        '<div class="' + css + '"><a href="http://search.moneyzine.jp/sponsor/?Keywords=' + enc_s + '&ref=' + ref + '_' + enc_s + '" ' + 
        'onclick="ov_click_count(location.href,\'' + ref + '\',\'' + s + '\')"' + 
        'target="_blank">' + s + '</a></div>';
    }
    addtxt += "</div>";
    document.getElementById(hs_exec[i][1]).innerHTML = addtxt;
  }
}

