

function includeJS(jsPath){
  var script = document.createElement("script");
  script.setAttribute("type", "text/javascript");
  script.setAttribute("src", jsPath);
  document.getElementsByTagName("head")[0].appendChild(script);
}

includeJS('/include/js/url.js');
includeJS('/js/config.js');

function Configuration() {
 this.Ip='';
 this.Server='';
 this.Copyright='';
 this.Language='';
 this.VName='';
 this.VPass='';
 this.VSite='';
 this.points='';
 this.goods_points_205='';
 this.point_error_message='';
}

function windowConfiguration() {
 this.url='';
 this.width='';
 this.height='';
}

function thumbnailConfiguration() {
 this.viewerNum='';
 this.blink='';
 this.blinkNum='';
 this.template='';
 this.colNum='';
 this.limit='';
}

User=function () {
  var show_icon = 'regular';
  var user_name;
  var user_id;
  var site_id;
  var user_type;
}

function login(goURL) {
    ext = '';
    if (!goURL) {
        goURL = window.location.search.substring(1);
        if (goURL == '') goURL = 'viewers';
    } else {
        offset = goURL.indexOf('.');
        if (offset!=-1) {
          goURL  = goURL.replace(/\?/g,"&params=");
          length = goURL.length;
          ext    = '&ext='+goURL.substring(offset+1,length);
          goURL  = goURL.substring(0,offset);
        }
    }
    goURL = 'http://'+configuration.Server+'/'+goURL;
    site_id = configuration.VSite;
    window.location = vctp_url + "/login?site_id="+site_id+"&goto="+goURL+ext;
}

function checkViewerLogin() {
  url = window.location.href;
  if(active_user.user_name == '') {
    var path = location.protocol + '//' + location.host + location.pathname;
    var query = window.location.search.substring(1);
    var site = '';
    if (configuration.VSite)
      site = '&site_id='+configuration.VSite;
      window.location = vctp_url + "/login?goto="+path+"&params="+query+site;
  }
}

function logout(redirect){
    var win = window.opener ? window.opener : window.dialogArguments, c;
    if (redirect!='' && configuration.Server!='') {
      logout_url = vctp_url+"/logout/vctp/"+configuration.Server;
    } else {
      logout_url = vctp_url+"/logout";
    }
    if(win != undefined){
       opener.window.location = logout_url;
       window.close();
    } else {
       window.location = logout_url;
    }
}

function setCookie(name, value, expires, path, cookie_domain, secure) {
  expires = (expires) ? expires.toGMTString() : '';
  path = (path) ? path : '/';
  cookie_domain = (cookie_domain) ? cookie_domain : domain;
  var curCookie = name + "=" + escape(value) +
  ((expires) ? "; expires=" + expires : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + cookie_domain : "") +
  ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function copyright() {
    copyright=new Date();
    update=copyright.getFullYear();
    document.write("Copyright &copy; 2002-"+ update + " " + configuration.Copyright + " All rights reserved.");    
}

function getCookie(cookieName){
  var search = cookieName + '=';
  if (document.cookie.length>0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1){
      offset += search.length;
      end     = document.cookie.indexOf(';',offset);
      if(end == -1)
        end = document.cookie.length;
      return unescape(document.cookie.substring(offset,end));
    }
  }
  return null;
}

function openMemo(contact) {
  if (contact==null || contact == 'undefined') {
    var obj = getElementFromName('contact_name');
    if (obj) {
        contact = getElementFromName('contact_name').value;
    } else {
        contact = '';
    }
  }
  if (contact!='') {
    openNewWindow('/contact/memo/' + contact,'contact'+contact,'width=675 height=400 scrollbars=yes');
  } else {
    openNewWindow('/contact/','contact','width=900,height=600,resizable=yes,scrollbars=yes');
  }
}

function openProfile(uname) {
    var width = 760;
    var height = 600;
    if ((isUser() || isVIP()) && typeof(v_profile)!='undefined' && v_profile.url!='') {
      var link = v_profile.url;
      width = v_profile.width;
      height = v_profile.height;
    } else {
      if (typeof(profile)=='undefined' || profile.url=='') { var link = 'profile.shtml'; }
      else { var link = profile.url; }
      width = profile.width;
      height = profile.height;
    }
  openNewWindow(link+'?'+uname, 'profile'+uname, 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width='+width+',height='+height); 
}

function showThumbnail(uname,type) {
    if (!type || (type!='live' && type!='flash' && type!='original' && type!='thumbs' && type!='thumb100s' && type!='vctp'))
        type = 'vctp';
    return image_url + '/WebArchive/'+uname+'/'+type+'/LinkedImage.jpg';
}

function writeGallery(pfname, colNum, width, height, divID) {
  if (width>120 && width<=160) { type = 'live'; }
  else if (width>160) { type = 'flash'; }
  else { type = 'vctp'; }
  var galleryData = ''; 
  var count = 1;
  for (var i=0; i<pfimage.length; i++) {
    if (count==1) { galleryData+= '<tr>'; } 
    galleryData+= '<td><a href="'+image_url+'/WebArchive/'+pfname+'/original/'+pfimage[i]+'" target="_blank"/>';
    galleryData+= '<img src="'+image_url+'/WebArchive/'+pfname+'/'+type+'/'+pfimage[i]+'" width="'+width+'" height="'+height+'" border="0"/>';
    galleryData+= '</a></td>';
    if (count==colNum) { galleryData+='</tr>'; count = 0;}
    ++count;
  }
  galleryData = '<table class="pfimage">'+galleryData+'</table>';
  var obj = getElementFromName(divID);
  if (obj) {
    obj.innerHTML= galleryData;
  } else {
    document.write(galleryData);
  }
}

function showRanking(count) {
  if (!count) count = 10;
    var rankingData = '';
    if (rankedPerformers) {
      rankingData+='<table width="170"><tr><td id="rankingTitle"></td></tr><tr><td id="rankingContents">';
      for (var i=0; i<count; i++) {
        var name = rankedPerformers[i];
        if (name.length > 10) {
            name = name.substring(0, 10);
            name += '...';
        }

        rankingData+='<div class="rk_thumb"><a href="javascript:openProfile(\''+rankedPerformers[i]+'\')"><img src="http://imageup.dxlive.com/WebArchive/'+rankedPerformers[i]+'/thumbs/LinkedImage.jpg" width="64" height="48" border="0"/></a></div>';
        rankingData+='<div class="rk_desc">'+(i+1)+'位<br><a href="javascript:openProfile(\''+rankedPerformers[i]+'\')">'+name+'</a><br><a href="javascript:openProfile(\''+rankedPerformers[i]+'\')">プロフィール</a></div>';
        rankingData+='<div class="rk_clear"></div>';
      }
      rankingData+='</td></tr></table>';
    }
    document.write(rankingData);  
}

function setChatMode(mode) {
    var xmlhttp = getXmlhttp();
    var url = "";
    url = "/member/setChatMode/" + mode;
    xmlhttp.open('POST', url, true);
    xmlhttp.onreadystatechange = function()
    {
      if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
      {
        res = xmlhttp.responseText;
      }
    }

    xmlhttp.send(null);
    setCookie('vm',mode);
    setTimeout("xmlHttpGet('/member/account', 'status');",1500);

}

function openPreview(uname) {
    var width = 760;
    var height = 600;
    if ((isUser() || isVIP()) && typeof(v_preview)!='undefined' && v_preview.url!='') {
      var link = v_preview.url;
      width = v_preview.width;
      height = v_preview.height;
    } else {
      if (typeof(preview)=='undefined' || preview.url=='') { var link = 'preview.shtml'; }
      else { var link = preview.url; }
      width = preview.width;
      height = preview.height;
    }
  openNewWindow(link+'?'+uname, 'preview'+uname, 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width='+width+',height='+height); 
}

function openViewersChat(performer, stype, configuration) {
  if ((isUser() || isVIP() || configuration.force_chat==1) && getSessionType(performer)>110) {
    if (stype!=115 && stype!=120) {
      var chatmode = getCookie('vm');
      if (chatmode=='ROM') {
        stype = 120;
      } else {
        stype = 115;
      }
    }
    if (configuration.VSite!='') {
      var vctp_param = "?vctp_site="+configuration.VSite;
      var mode_str = "";
      var points_str = configuration.points;

      vctp_param += '&promo_points='+points_str;
      vctp_param += '&show_add_points='+configuration.show_add_points+'&goods_points_205='+configuration.goods_points_205;
      vctp_param += '&copyright_arg='+configuration.Copyright; 
      if (configuration.point_error_message=='off') vctp_param += '&point_error_message=off';
      var w = window.open(vctp_url + '/chat/'+performer+'/'+stype+vctp_param, performer, 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=800,height=540');
    } else {
      var w = window.open(vctp_url + '/chat/'+performer+'/'+stype, performer, 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=800,height=540');
    }
    w.focus();
   } else {
     openProfile(performer);
   }
}

function openViewerHelp() {
    var search = getQueryVariable('vctp_site');
    if (search != '') {
        openNewWindow('/vctp/beginner/index.html', 'help', 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no');
    } else {
        openNewWindow('/member/howto_start.html#t2','help', 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no');
    }
}

function openPerformerHelp() {
    if (is910Performer()) {
        openNewWindow('/performer910/first_time_chat_login.html', 'help', 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no');
    } else {
        openNewWindow('/performer/hajimete2.html#1', 'help', 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no');
    }
}

function openViewerVchat (uid, stype) {
  if (stype != 115 && stype != 120)
     stype = 115;
  openNewWindow('/chat/'+uid+'/'+stype, 'Chat'+uid, 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=800,height=540');
}

function openPerformerVchat() {
  openNewWindow('/chat','vchat','resizable=yes,width=800,height=500');
}

function checkUncheckAll(theElement) {
  var theForm = theElement.form;
	var z = 0;
	for(z=0; z<theForm.length; z++){
  	if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
			theForm[z].checked = theElement.checked;
		}
  }
}

function showCoupon() {
  if (typeof(coupons)!='undefined') { 
    for (i=0; i<coupons.balance.length; ++i) {
      coupon = '<div class="user_name">'+coupons.balance[i].user_name+'</div>';
      coupon+= '<div class="balance">'+coupons.balance[i].points+'</div>';
      $("#coupon").append(coupon);
    }
  }
}

function xmlHttpGet(strURL, elementId) {
  var xmlhttp = false;
  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest(); //Mozilla/Safari
  } else if (window.ActiveXObject) { //IE
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  if(!xmlhttp) return;
	strURL += (strURL.indexOf('?')>0?'&t=':'?t=') + Math.random();  
    xmlhttp.open('GET', strURL, true);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      var obj = getElementFromName(elementId);
      if(obj) obj.innerHTML= xmlhttp.responseText;
			fixPNGImages(elementId);
    }
  }
  xmlhttp.send(null);
  return;
}

function xmlHttpPost(strURL, params, elementId) {
  var xmlhttp = false;
  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest(); //Mozilla/Safari
  } else if (window.ActiveXObject) { //IE
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  if(!xmlhttp) return;
        strURL += (strURL.indexOf('?')>0?'&_rand=':'?_rand') + Math.random();
  xmlhttp.open('POST', strURL, true);
  xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      var obj = getElementFromName(elementId);
      if(obj) obj.innerHTML= xmlhttp.responseText;
                        fixPNGImages(elementId);
    }
  }
  xmlhttp.send(params);
  return;
}

function getXmlhttp(){
  var xmlhttp;
    
  if(window.XMLHttpRequest) {
 		try {
			xmlhttp = new XMLHttpRequest();
  	} catch(e) {
			xmlhttp = false;
  	}
  } else if(window.ActiveXObject) {
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
       try {
       		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       } catch(e) {
       		xmlhttp = false;
       }
		}
  }
  return xmlhttp;
}

function getElementFromName(nm){
  // IE5+, Mozilla, Opera
  if(document.getElementById) return document.getElementById(nm);
  if(document.all) return eval('document.all.' + nm); // IE4
  if(document.layers){ // NN4
    var s='';
    for(var i=1; i<arguments.length; i++)
      s+='document.layers.'+arguments[i]+'.';
    return eval(s+'document.layers.'+nm);
  }
  return null;
}

function openNewWindow(theURL,winName,features) {
	var w = window.open(theURL,winName,features);
	//w.focus();
}

var userName = '';
var userId = '';
var userType = '';
var c = getCookie('NetiA');
if(c) {
	var arr = c.split(':');
	userName = arr[0];
}
c = getCookie('vauth');
if(c) {
  var arr = c.split(':');
  userName = arr[0];
  userId = arr[1];
  userType = arr[2];
  siteId = arr[3];
  nightFlag = arr[4];
}
function isVIP() {
	return (userType==206)?true:false;
}
function isUser() {
  return (userType==205 || userType==207 || userType==208 || userType==215 || userType==220)?true:false;
}
function isPerformer() {
	return (userType==210)?true:false;
}
function isRegularUser() {
        return (userType==205)?true:false;
}
function isFreeUser() {
        return (userType==207 || userType==208)?true:false;
}
function isAdmin() {
        return (userType==215 || userType==220)?true:false;
}
function is910Performer() {
	return (nightFlag==1)?true:false;
}


// ---------------------------------------------------------------------------------
// Function for web and flash
// ---------------------------------------------------------------------------------

function openSendMail(uname) {
  var site = '';
  if (configuration.VSite)
    site = '&site_id='+configuration.VSite;
  openNewWindow(vctp_url + '/mailbox/compose/?toidlist='+uname+site, 'mailbox' , '');
}

function openMailbox() {
  var site = '';
  if (configuration.VSite)
    site = '?site_id='+configuration.VSite;
  openNewWindow(vctp_url + '/mailbox/'+site, 'mailbox' , 'resizable=yes, toolbar=yes, scrollbars=yes, menubar=yes, width=800, height=600');
}


function closeCurrentWindow(sec) {
  //case: viewer's connection to flash server has closed via logout button
  //js call: closeCurrentWindow(.1)  (parameter is delay before closing window)
  if (sec == '' || sec == null)
  	sec = 0.1;
  window.setTimeout('window.close()',sec*100);
  
}

function setBan(channel) {
  //case: perf has kicked a viewer
  //js call: setBan(channel)  (parameter 'channel' is the performer ID)
}

function setBlock(uid, flag){
    var xmlhttp = getXmlhttp();
    var url = "";

    url = vctp_url + "/contact/setBlock/"+uid+"/"+flag+"/"+Math.random();
    xmlhttp.open('GET', url, true);
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
            res = xmlhttp.responseText;
            if(res == "success")
                alert("メール受信を拒否しました");
            else if(res == "no_user")
                alert("連絡先が見つかりません");
            else if(res == "already")
                alert("既に拒否されています");
            else
                alert("拒否できませんでした。");
        }
    }

    xmlhttp.send(null);
}

function addFavorite(uname){
    var width = 760;
    var height = 600;
    if (favorite.url==null || favorite.url == undefined) {
        var link = 'fav.shtml';
    } else {
        var link = favorite.url;
        width = favorite.width;
        height = favorite.height;
    }
    if (isUser()==false) {
      alert('こちらは正規会員様限定のサービスとなっております\n先にログインしてください');
      openNewWindow('/join.html','join',"toolbar=yes,scrollbars=yes,location=yes,menubar=yes,resizable=yes");
    } else if (isUser() && isFreeUser()) {
      alert('こちらは正規会員様限定のサービスとなっております\nポイントをご購入後からご使用になれます');
      openNewWindow('/viewers/join.html','join',"toolbar=yes,scrollbars=yes,location=yes,menubar=yes,resizable=yes");
    } else {
      var redir = 'http://' + configuration.Server + '/' + link;
      if (configuration.VSite)
        site = '&site_id='+configuration.VSite;
      
      if (uname == undefined) {
        openNewWindow(vctp_url+'/favorite/add/?redir='+redir+site, 'favorite', 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width='+width+',height='+height);
      } else {
        openNewWindow(vctp_url+'/favorite/add/'+uname+'?redir='+redir+site, 'favorite', 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width='+width+',height='+height);
      }
    }
}

function search(divID,page) {
    var params = '';
//    params = window.location.search.substring(1);
    if (page && page>0) params+='&page='+page;
    var sinputs = $('#searchForm :input');
    sinputs.each(function() {
      if (this.type=='text') {
        params+='&'+this.name+'='+this.value;
      } else if (this.type=='checkbox' || this.type=='radio') {
        if (this.checked) { params+='&'+this.name+'='+this.value; }
      } else {
        params+='&'+this.name+'='+this.value;
      }
    });
    if (params!='') {
      if (!divID) divID = 'thumbshere';
      if (thumbnail.viewerNum==1) params += '&view_count=1';
      if (thumbnail.blink==1)     params += '&blink=1';
      if (thumbnail.blinkNum==1)  params += '&blink_num=1';
      if (typeof(thumbnail)=='undefined') {
        setTimeout("vctpSearch('"+params+"','"+divID+"')", 1000);
        return false;
      } else {
        vctpSearch(params, divID);
      }
    }
}

function categoryFilter(cat,id) {
    var params = '';
    switch(cat){
        case 'online':
            break;
        case 'toy':
            params = '&category=3406';
            break;
        case 'mic':
            params = '&category=3401';
            break;
        case 'recommended':
            params = '&recommended=1';
            break;
        case 'new':
            params = '&active_days=30';
            break;
        case 'housewives':
            params = '&category=2003';
            break;
        case 'birthmonth':
            params = '&birth_month=1';
            break;
        case 'standby':
            params = '&session_type=110';
            break;
        case 'session':
            params = '&session_type=115,120,125,130';
            break;
        case 'hd':
            params = '&category=3407&hd_chat=1';
            break;
        case 'type_of_girl': 
        case 'language':
        case 'living_area':
        case 'occupation':
            if (id) 
              params = '&category='+id;
            break;
    }
    divID = 'thumbshere';
    params = 'online=1&gets_hits=0&order_by=random'+params+'&rand='+ Math.random();
    if (typeof(thumbnail)=='undefined') {
      setTimeout("vctpSearch('"+params+"','"+divID+"')", 1000);
      return false;
    } else {
      vctpSearch(params, divID);
    }
}

function vctpSearch(params, divID) {
    if (thumbnail.viewerNum==1) params += '&view_count=1';
    if (thumbnail.blink==1)     params += '&blink=1';
    if (thumbnail.blinkNum==1)  params += '&blink_num=1';
    xmlHttpGet('/search/?1=1&tpl=vctp_search_list&'+params, divID);
}

function setLoginNoticeFlag(uname,flag){
    var xmlhttp = getXmlhttp();
    var url = "";
    var method = 'loginOn';
    if (flag==false) {
        method = 'loginOff';
    }
    url = "/favorite/"+method+"/"+uname+"/"+Math.random();
    xmlhttp.open('GET', url, true);
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
            res = xmlhttp.responseText;
        }
    }
    xmlhttp.send(null);
}

function getSessionType(perf) {
  var session = 0;
  if (typeof(performers)!='undefined') {
    var performer = eval("performers.online."+perf);
    session = (performer)?performer.session:0;
  }
  return session;
}

function showSessionType(perf, custom_flag) {
    var performer = eval("performers.online."+perf);
    var session = (performer)?performer.session:0;
    var image_url = '';

    if (!custom_flag) {
        image_url = vctp_url + '/vctp';
    }
    if (session > 110){
        document.writeln('<img src="' +image_url+ '/img/icons/chat.gif">');
    } else if (session == 110){
        document.writeln('<img src="'+image_url+'/img/icons/session.gif">');
    } else {
        document.writeln('<img src="'+image_url+'/img/icons/offline.gif">');
    }

    return false;
}

function checkOnline(perf) {
  if (typeof(performers)!='undefined') {
    var new_var = "performers.online."+perf;
    var online = eval(new_var);
    if (online) {
        return online;
    } else {
        return perf;
    }
  }
  return perf;
}

function getOnlineCount() {
  if (typeof(performers)!='undefined') { document.write(performers.list.length); }
}

function getSessionCount() {
  if (typeof(performers)!='undefined') { document.write(performers.busy.length); }
}

function getFreeCount() {
  if (typeof(performers)!='undefined') { document.write(performers.free.length); }
}

function showCustomOnline(cat,divID) {
  col_num = (thumbnail.colNum>0)?thumbnail.colNum:5;
  count = 1;
  thumbs = '';
  if (!divID) divID='thumbshere';
  $(document).ready(function(){
    $.getJSON(vctp_url + "/json/online/"+cat+"?jsoncallback=?",
        function(data){
          $.each(data.items, function(){
            if (count==1 || count>col_num) thumbs += '<tr class="test">';
            thumbs += '<td>';
            thumbs += outputItem(this);
            thumbs += '</td>';
            if (count == col_num) {
              thumbs += '</tr>';
              count = 1;
            } else { ++count; }
          });
        $("#"+divID).empty();
        $("#"+divID).append(thumbs);
        });
  });
}

function setSearchKey() {
 skey = '';
 search_count = search_key.length;
 for (var k=0; k<search_count; ++k) {
  skey+='<div class="list" align="left">';
  if (search_key[k].type=='select') {
   skey+='<span class="menu">'+search_key[k].desc+'</span><select name="'+search_key[k].key+'">';
   val_count = search_key[k].value.length;
   for (var v=0; v<val_count; ++v) {
    skey+='<option value="'+search_key[k].value[v].id+'"';
    if (getQueryVariable(search_key[k].key)==search_key[k].value[v].id) { skey+=" selected"; }
    skey+='>'+search_key[k].value[v].val+'</option>';
   }
   skey+='</select>';
  } else if (search_key[k].type=='checkbox' || search_key[k].type=='radio') {
   val_count = search_key[k].value.length;
   skey+='<div id="'+search_key[k].key+'"><span class="menu">'+search_key[k].desc+'</span>';
   for (var v=0; v<val_count; ++v) {
    skey+='<line><input name="'+search_key[k].value[v].name+'" value="'+search_key[k].value[v].id+'"';
    if (getQueryVariable(search_key[k].value[v].name).indexOf(search_key[k].value[v].id)>-1) { skey+=" checked"; }
    skey+=' type="'+search_key[k].type+'">'+search_key[k].value[v].val+'</line>';
   }
   skey+='</div>';
  }
   skey+='</div>';
 }
 $("#searchkey").empty();
 $("#searchkey").append(skey);
}
////////////////////////////////////////

function page_reload(){

if(!opener.window.userId)   
   window.opener.location.reload();
      
// if(document.referrer != '' || document.referrer)
//   alert(document.referrer);
// else
//   alert(document.referrer+"no referrer"+userId);   

}

function fixPNGImages(areaID) {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (document.body.filters)) {
		var pngAreaObj=document.getElementById(areaID);
		var pnglist=pngAreaObj.getElementsByTagName("img");

		for(var i=0; i<pnglist.length; i++){
			var img = pnglist[i];
			var imgName = img.src.toUpperCase();
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
				var imgID = (img.id) ? "id='" + img.id + "' " : "";
				var imgClass = (img.className) ? "class='" + img.className + "' " : "";
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:inline-block;" + img.style.cssText;
				if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
					+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
					+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
					+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				i = i-1;
			}
		}
  }
}

function ajax_request(strURL, tpl) {
  var xmlhttp = false;
  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest(); //Mozilla/Safari
  } else if (window.ActiveXObject) { //IE
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  if(!xmlhttp) return;
        strURL += (strURL.indexOf('?')>0?'&_rand=':'?_rand') + Math.random();
  xmlhttp.open('GET', strURL, true);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
       flag = xmlhttp.responseText;
       if(flag=='1'){
          alert("追加されました");
          if(isVIP()){
            xmlHttpGet('/search/performer/favorite/vip/?tpl='+tpl, 'favoritehere');
          } else {
            xmlHttpGet('/search/performer/favorite/viewer/?tpl='+tpl, 'favoritehere');
          }
       }
       else if(flag=='3'){
          alert("削除されました");
          if(isVIP()){
            xmlHttpGet('/search/performer/favorite/vip/?tpl='+tpl, 'favoritehere');
          } else {
            xmlHttpGet('/search/performer/favorite/viewer/?tpl='+tpl, 'favoritehere');
          }
       }else if(flag=='3000'){
          alert('登録制限数を越えています');
       }
       else
          alert("エラーで追加できませんでした");
    }
  }
  xmlhttp.send(null);
  return;
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkAll(theElement) {

  var theForm = theElement.form;
  for(i=0; i<theForm.length;i++){
    if(theForm[i].type == 'checkbox' && theForm[i].name != 'checkall'){
      theForm[i].checked = theElement.checked;
    }
  }
}

function mailValidation(email) {
  if (!email.match(/.+\@.+\.+/)) {
    alert('メールアドレスを確認してください');
    return false;
  } else {
    return true;
  }
}

function openJoinPage(goodsId)
{
  purchase_url=join_url+"?goods_id=" + goodsId;
  if (userName!='') { purchase_url+='&username='+userName; }
  openNewWindow(purchase_url,'join',"toolbar=yes,scrollbars=yes,location=yes,menubar=yes,resizable=yes");
}

function buyPoints(points)
{
  var purchase_url = join_url;
  if (isFreeUser()) { utype = 'promo';
  } else if (isUser() || isVIP()) { utype = 'member';
  } else { utype = 'guest'; }
  goodsId = goods[utype][points];
  if (goodsId) {
    purchase_url+="?goods_id=" + goodsId;
    if (userName!='') { purchase_url+='&username='+userName; }
    openNewWindow(purchase_url,'join',"toolbar=yes,scrollbars=yes,location=yes,menubar=yes,resizable=yes");
  } else {
    alert('商品が存在しません'); return;
  }
}


function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  var res = new Array();
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      res.push(pair[1]);
    }
  }
  return res.toString(); 
}

function randomizeOrder(a, b) {
  return Math.random() - .5;
}

