//<!-
// Function for Web
function openVideoPlayer(mediaID) {
  openNewWindow("/app/video/video_player.php?vid=" + mediaID,"","width=360,height=395,scrollbars=no,location=no,menubar=no,left=10,top=30");
}

function openVideoPlayerPromo(mediaID) {
  openNewWindow("/app/videoPromo/video_player.php?vid=" + mediaID,"","width=800,height=550,scrollbars=no,location=no,menubar=no,left=10,top=30");
}


function openViewerEditProfile() {
  openNewWindow('/app/member/profile.php', 'viewerEditProfile', 'location = yes, resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=850, height=685');
}
function setCookie (name, value){
  document.cookie = name + '=' + escape(value) + ";path=/;"
}

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 openWindow(url, name, width, height, wincfg) {
	if(!wincfg) wincfg = 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width='+width+',height='+height;
	var w = window.open(url,name,wincfg);
	w.focus();
}
*/

function openPreview(uid) {
  openNewWindow('/app/preview.php?uid='+uid, 'preview', 'resizable=no,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=700,height=400'); 
}

function openPreviewByName(uname) {
  openNewWindow('/app/preview.php?uname='+uname, 'preview', 'resizable=no,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=700,height=400'); 
}

function openBigPreview(uid) {
  openNewWindow('/app/preview.php?tpl=big&uid='+uid, 'preview', 'resizable=no,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=700,height=400'); 
}

function openVideoPlayer(mediaID) {
  openNewWindow("/app/video/video_player.php?vid=" + mediaID,"","width=360,height=395,scrollbars=no,location=no,menubar=no,left=10,top=30");
}

function openVideoHistory() {
	openNewWindow('/app/member/video_history.php','purchase_history','status=yes,scrollbars=yes,resizable=yes,width=800,height=600');
}

function openVideoList(pname) {
	openNewWindow('/app/video/video.php?uname='+pname, pname+'videoList', 'resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=685, height=685');
}

function openVideoListPromo(pname) {
        openNewWindow('/app/videoPromo/video.php?uname='+pname, pname+'videoList', 'resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=685, height=685');
}

function openViewerVchat (uid, stype) {
  openNewWindow('/app/member/chat.php?uid='+uid+'&stype='+stype, 'Chat'+uid, 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=820, height=640'); 
  // openNewWindow('/app/member/chat.php?uid='+uid+'&stype='+stype, '', 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=808,height=510');
}

function openViewerVchatEX (uid, stype) {
  openNewWindow('http://www.exshot.com/app/member/chat.php?uid='+uid+'&stype='+stype, 'Chat'+uid, 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no, width=820, height=640');
}

function openPerformerVchat() {
  openNewWindow('/app/performer/chat.php', 'Chat', 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=950,height=520'); 
}

function openFavorites() {
	openNewWindow('/app/contact/index.php?favorite_flag=1', 'contact', '');
}

function openContact(id) {
        openNewWindow('/app/contact/index.php?mode=edit&contact_id='+id,'edit','width=675 height=450 scrollbars=yes resizable=yes')
}

function openGravureImage(uname, uid, event) {
  openNewWindow('popup.html?uname=' + uname + '&uid=' + uid + '&event=' + event, 'gravure'+uname, 'resizable=yes, toolbar=no, scrollbars=no, personalbar=no, menubar=no, width=665, height=505');
}

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 getSessionType(user_name) {
	if(user_arr!=null) {
		var user = user_arr[user_name];
		if(user!=null) {
			return user.session_type;
		}
	}
	return 0;
}

function xmlHttpGet(strURL, elementId) {
  var xmlhttp = false;
     var objOnline = getElementFromName(elementId);
     if(objOnline) objOnline.innerHTML = '<br><br><br><div align="center"><img src="/img/loading.gif"></div>';

  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) {
      var obj = getElementFromName(elementId);
      if(obj) obj.innerHTML= xmlhttp.responseText;
			fixPNGImages(elementId);
    }
  }
  xmlhttp.send(null);
  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];
  nightwork = 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 isFreeUser() {
  return (userType==207 || userType==208)?true:false;
}

function isRegularUser() {
  return (userType==205)?true:false;
}

function isAdmin() {
	return (userType==215 || userType==220)?true:false;
}

function isPerformer() {
	return (userType==210)?true:false;
}

function isNightWork() {
     return (nightwork==1)?true:false;
}

// ---------------------------------------------------------------------------------
// Function for web and flash
// ---------------------------------------------------------------------------------
function openViewerPresent() {
  openNewWindow('/present.html', 'viewerpresent', 'location=yes, resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=1000, height=700');
}

function openPerformerPresent() {
  openNewWindow('/performer/present.html', 'performerpresent', 'location=yes, resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=1000, height=700');
}


function openVideoLibrary() {
  openNewWindow('/app/video/newsearch.php', 'videoLibrary', 'location=yes, resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=1000, height=700');
}

function openVideoHistory() {
  openNewWindow('/app/member/video_history.php', 'videoHistory' , 'location=yes, resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=850, height=700');
}

function openMileage() {
  openNewWindow('/app/member/mileage.php', 'memberMileage' , 'resizable=yes, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=580, height=300');
}

function openPerformerMileage(){
  openNewWindow('/app/performer/mileage.php', 'performerMileage' , 'resizable=yes, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=650, height=600');
}


function openMemberAccount() {
  openNewWindow('/app/member/account.php', 'memberMileage' , 'resizable=yes, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=580, height=300');
}

function openNotification() {
  openNewWindow('/app/contact/index.php?favorite_flag=1', 'Notification' , 'resizable=yes, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=700, height=500');
}

function openBBS() {
  //http://utility.exshot.com/cgi-bin/exvwrbbs/bbs.cgi
  openNewWindow('http://utility.exshot.com/cgi-bin/exvwrbbs/bbs.cgi', 'BBS', 'resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=850, height=700');
}

function openPerformerHelp() {
  //http://www.exshot.com/exshot/performer2/howto_vc_functions.jsp
  openNewWindow('/performer_share/howto_vc_functions.html', 'help' , '');
}

function openViewerHelp() {
  //http://www.exshot.com/exshot/share/howto_chat.jsp
  openNewWindow('/howto/chat.html', 'help' , '');
}

function openProfile(pname) {
  openNewWindow('/profile/' + pname + '.html', 'profile' + pname, 'resizable=yes, location=no, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=700, height=690');
}

function openProfileEX(pname) {
  openNewWindow('http://www.exshot.com/profile/' + pname + '.html', 'profile' + pname, 'resizable=yes, location=no, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=700, height=690');
}

function openPerformerProfile(pname) {
  openNewWindow('/profile/sm/' + pname + '.html', 'smallprofile' + pname, 'resizable=yes, location=no, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=700, height=690');
}


function openProfileCEX(pname) {
  openNewWindow('http://club.exshot.com/profile/sm/' + pname + '.html', 'profile' + pname, 'resizable=yes, location=no, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=700, height=690');
}


function openSendMail(uname) {
  // openSendMail(pname)
  openNewWindow('/app/mailbox/index.php?mode=compose&clubEX=1&toidlist=' + uname , 'mailbox' , '');
}

function openMailbox() {
  // openMailbox()
  openNewWindow('/app/mailbox/index.php', 'mailbox' , '');
}

function openViewerProfile(uname) {
  //openViewerProfile(uname)
  openNewWindow('/app/performer/member_profile.php?uname='+uname, 'viewerProfile', 'resizable=yes, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=700, height=690');
}

function openPerformerMemo(uid) {
  //openPerformerMemo(viewerName)
  openNewWindow('/app/contact/index.php?mode=edit&contact_id='+uid, 'contact', '');
}

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 openRegularJoin() {
  //case: point purchase has failed
  //openNewWindow('/exshot/'+pagetype+'/addpoint.jsp','AddPoints','menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes')
  openNewWindow('/join.html', 'join', '');
}

function openVIPJoin() {
  openNewWindow('/join.html', 'join', '');
}

function openNewJoin() {
  //openNewWindow('/new_join.html', 'newjoin', '');
  window.location = "/new_join.html";
}


////////////////////////////////////////

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);
                if (!pngAreaObj) return;
		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 writeFavoriteTitle(mode) {
  var str = '';
  str += '<ul>';

  str += '<li id="favorite01"><a href="javascript:;" onClick="openFavorites();return false;">お気に入りの女の子編集</a></li>';

  if (isUser()) {
    if (mode == 'no_expand') str += '<li id="favorite02"><a href="javascript:;" onClick="xmlHttpGet(\'/app/search.php?favorite=1&limit=16&tpl=favorite&get_hits=0\', \'favoriteArea\'); writeFavoriteTitle(\'expand\');">お気に入りの女の子>をすべてみる。</a></li>';
    if (mode == 'expand') str += '<li id="favorite02ON"><a href="javascript:;" onClick="xmlHttpGet(\'/app/search.php?favorite=1&limit=8&tpl=favorite&get_hits=0\', \'favoriteArea\'); writeFavoriteTitle(\'no_expand\');">お気に入りの女の子をすべてみる。</a></li>';
  } else if (isVIP()) {
    if (mode == 'no_expand') str += '<li id="favorite02"><a href="javascript:;" onClick="xmlHttpGet(\'/app/search.php?favorite=1&limit=40&tpl=favorite&get_hits=0\', \'favoriteArea\'); writeFavoriteTitle(\'expand\');">お気に入りの女の子>をすべてみる。</a></li>';
    if (mode == 'expand') str += '<li id="favorite02ON"><a href="javascript:;" onClick="xmlHttpGet(\'/app/search.php?favorite=1&limit=8&tpl=favorite&get_hits=0\', \'favoriteArea\'); writeFavoriteTitle(\'no_expand\');">お気に入りの女の子をすべてみる。</a></li>';
  }
  str += '</ul>';

  obj = getElementFromName("favoriteTab");
  if (obj) obj.innerHTML = str;
}

function writeRSSTitle(mode) {
  var str = '';
  str += '<ul>';
  str += '<li id="RSS01"><a href="/app/news.php">新着情報</a></li>';
  str += '<li id="RSS02"><a href="/exshot/news/news.xml" target="_blank">ＲＳＳフィード</a></li>';
  if (mode == 'no_expand') str += '<li id="RSS03"><a href="javascript:;" onClick="xmlHttpGet(\'/app/news.php?tpl=home&limit=10\', \'RSS\');writeRSSTitle(\'expand\');">お得な情報が満載！今すぐチェック！すべて見る >></a></li>';
  if (mode == 'expand') str += '<li id="RSS03ON"><a href="javascript:;" onClick="xmlHttpGet(\'/app/news.php?tpl=home&limit=5\', \'RSS\');writeRSSTitle(\'no_expand\');">お得な情報が満載！今すぐチェック！すべて見る >></a></li>';
  str += '</ul>';

	obj = getElementFromName('RSStitle');
  if(obj) obj.innerHTML = str;
}

function writeFlash( swf , width , height )
{
  var html = ""
 
  html+="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
  html+="        width   = " + width
  html+="        height  = " + height + ">"
  html+="<param  name    = movie value=" + swf + ">"
  html+="<param  name    = quality value=high>"
  html+="<param name='wmode' value=transparent>"
  html+="<embed  src     = " + swf + " "
  html+="        wmode=transparent"
  html+="        quality = high  "
  html+="        width   = "+ width
  html+="        height  = " + height
  html+="        type    = 'application/x-shockwave-flash' "
  html+="        pluginspage='http://www.macromedia.com/go/getflashplayer'>"
  html+="</embed>"
  html+="</object>"
  
  document.write(html)
}

function ajaxRequest(url, method, params){

    xmlhttp = getXmlhttp();
    var params  = params;
    url     = url;
    var method  = method;
    result  = "";

    if(method.toUpperCase() == 'GET'){
       url = url + '?' + params;
    }
    xmlhttp.open(method, url, true);

    if(method.toUpperCase() == 'POST'){
      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlhttp.setRequestHeader("Content-length", params.length);
      xmlhttp.setRequestHeader("Connection", "close");
    }
 
    xmlhttp.onreadystatechange = function(){
     if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
       result = xmlhttp.responseText;
     }
    }
   xmlhttp.send(params);
alert(result);
 return result;

}
 
function isPopupBlocker(){
  var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
  if(mine)
     var popUpsBlocked = false;
  else
     var popUpsBlocked = true;

  if(mine) mine.close();
  
  return (popUpsBlocked) ? true : false;
}

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  var isChrome = navigator.userAgent.indexOf("Chrome") != -1;
  return (isIE || isChrome ) ? document.getElementById(movieName) : document[movieName];
}

function pauseVideo(videoname) {
  getFlashMovie(videoname).pauseVideo();
}

function enlargevideo(videoname) {
  pauseVideo(videoname);
  if(userType)
    openVideoPlayer(videoname);
  else
    openVideoPlayerPromo(videoname);
}


function add_point_campaign_not_use() {
  if (campaign) {
    var xmlhttp = getXmlhttp();
    var url = "/app/free_points.php";
    xmlhttp.open('GET', url, true);
    xmlhttp.onreadystatechange = function(){
     if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
       res = xmlhttp.responseText;
       //alert(res);
       if(res == 1){
         agreewin=dhtmlmodal.open("agreebox", "iframe", page, title, "width=300px,height=200px,center=0,resize=1,scrolling=1,left=0,top=0,screenX=0,screenY=100'", "recal");
       }
     }
    }
   xmlhttp.send(null); 
  }
}

// JavaScript function to open secret message window when the performer is complete 2shot chat mode. This function is called from Flash.
// pfuser_id : Performer User_id.
function open_cexmsgsubmit(pfuser_id)	{
	window.open('/app/member/cexmsgsubmit.php?pid='+pfuser_id+'', 'cexmsg', 'width=480, height=400, menubar=no, toolbar=no, scrollbars=yes');
}

function check_browser_version(){
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  if (isIE) {
     var arVersion = navigator.appVersion.split("MSIE");
     var version = parseFloat(arVersion[1]);
     return version;
  }
  return 7;
}

function refresh_d2pbar(){
   var version = check_browser_version();
   if (version <= 6 ) return true;

   var url = "/d2ptb";
   var xmlhttp = getXmlhttp();
   xmlhttp.open('GET', url, true);
   xmlhttp.onreadystatechange = function() {
     if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         var str = xmlhttp.responseText;
         var obj = document.getElementById("d2toolbar");
         if(obj) obj.innerHTML= str;
  
          //var iFrameBody = document.getElementById("d2ptoolbar").contentWindow.document.body;
          //if (iFrameBody)  {
            //  iFrameBody.innerHTML = str;
            //  document.getElementById("d2ptoolbar").style.height = 23;
         // }
     }else{
       return;
     }
   }
  xmlhttp.send(null);
}

//-->

