//<!-
/*
var ccg_url = "http://www.dev.caribbeancomgirl.vc/";
var img_url = "http://imageup.dev.caribbeancomgirl.vc/WebArchive/";
var cha_url = "http://staging.chafile.vc/";
var d2p_url = "https://staging.d2pass.d2p/";
var join_url = "https://join.staging.dev901.d2p/cgi-bin/d2pjoin.fcgi";
var en_url = "http://en.dev.caribbeancomgirl.vc/";
*/
/* staging
var ccg_url = "http://www.staging.caribbeancomgirl.vc/";
var img_url = "http://imageup.staging.caribbeancomgirl.vc/WebArchive/";
var cha_url = "http://staging.chafile.vc/";
var d2p_url = "https://staging.d2pass.d2p/";
var join_url = "https://join.staging.dev901.d2p/cgi-bin/d2pjoin.fcgi";
var en_url = "http://en.staging.caribbeancomgirl.vc/";
*/
// prod
 var ccg_url = "http://www.caribbeancomgirl.com/";
 var img_url = "http://imageup.caribbeancomgirl.com/WebArchive/";
 var cha_url = "http://www.chafile.com/";
 var d2p_url = "http://www.d2pass.com/";
 var join_url = "https://www5.dtiserv3.com/cgi-bin/d2pjoin.fcgi";
 var en_url = "http://en.caribbeancomgirl.com/";

// D2Pass/sales tracking
source_page = 1; // "1" all the time
//if(typeof from_site_id =="undefined"){
  from_site_id = 20000597; // 20000597 : CCG
//}

//==== DX Faceoff
var DX_URL = "http://www.dxlive.com";

function openProfileDX(uname) {
  if(userType)
    openNewWindow(DX_URL+'/preview/'+uname+'?action=login&fromSite=1003332', 'preview'+uname, 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=800,height=950');
  else
    openNewWindow(DX_URL+'/preview/'+uname+'?fromSite=1003332', 'preview'+uname, 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=800,height=950');
}

function openViewersChatDX(performer, stype) {
  if(!stype){
    stype=115;
  }
  openNewWindow(DX_URL+ '/chat/'+performer+'/'+stype+'/1003332/', performer, 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=780,height=700');
}

function openViewersChatHDDX(performer, stype) {
  if(!stype){
    stype= 115;
  }
  openNewWindow(DX_URL+ '/chat/'+performer+'/'+stype+'/1003332/', performer, 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=910,height=540');
}

function openMailboxDX(uname){
  openNewWindow(DX_URL+ '/mailbox/compose?url=mailbox/compose&toidlist='+uname, 'mailbox', 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=910,height=540');
}

//==== END DX


// =====EX FACEOFF
var EX_URL = "http://www.exshot.com";
var EXURL  = "http://www.exshot.com";

function openViewerHDVchatEX (uid, stype) { //850*540
  openNewWindow(EX_URL+'/app/member/chat_new.php?hd=1&uid='+uid+'&stype='+stype+'&fromSite=1003332', 'HDChat'+uid, 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=910,height=540');
}

function openViewerVchatEX (uid, stype) {
  openNewWindow(EX_URL+'/app/member/chat_new.php?uid='+uid+'&stype='+stype+'&fromSite=1003332', 'Chat'+uid, 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,width=820,height=640');
}

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

function openPreviewEX(uname) {
  if(userType)
    openNewWindow(EX_URL+'/preview/'+uname+'.html?fromSite=1003332&fo=WlBsYn362L5a2l5s2k36JjV9GL5TW9x6I6fKIngjGkm', 'preview', 'resizable=yes, location=no, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=800, height=800');
  else
    openNewWindow(EX_URL+'/preview/'+uname+'.html?fromSite=1003332', 'preview', 'resizable=yes, location=no, toolbar=no, scrollbars=yes, personalbar=no, menubar=no, width=800, height=800');
}

// ===== END EX FACEOFF

function liveviewer() {
      livew = window.open('/livesession.html', 'livesession', 'resizable=no,toolbar=no,scrollbars=no,personalbar=no,menubar=no,location=no,status=no,width=568,height=273,top=0,left=0');
    //w.focus();
}

function closeLiveviewer(){
  if(livew){
    livew.close();
  }
}


// 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 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 flashURL(name){

  if(isVIP())
    window.location.href = '/vip/howto/chat#'+name;
  else if(isUser())
    window.location.href = '/viewers/howto/chat#'+name; 
  else
    window.location.href = '/guest/howto/chat#'+name;
}

function openPromo(name){
  var spec = 'resizable=yes,toolbar=yes,scrollbars=yes,personalbar=yes,menubar=yes,width=710,height=900';
  if(name=='' || name==null){
    if(isVIP())
      openNewWindow('/promo/cmpn/promo_vip', 'promo', spec);
    else if(isUser())
      openNewWindow('/promo/cmpn/promo_v', 'promo', spec);
    else
      openNewWindow('/promo/cmpn/promo', 'promo', spec);
  }else{
    openNewWindow('/promo/cmpn/'+name, 'promo', spec);
  }
}

function openCouponPage() {
  openNewWindow('/viewers/coupon/', 'coupon', 'resizable=yes,toolbar=yes,scrollbars=yes,personalbar=yes,menubar=yes,width=890,height=900');
}


function openProfile(uname) {
  openNewWindow('/profile/'+uname, 'profile'+uname, 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=855,height=605'); 
}

function openProfile2(uname) {
  openNewWindow('/profile/'+uname+/prv/, 'profile'+uname, 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=855,height=605');
}

function openPictureGallery(uname){
  openNewWindow('/profile/'+uname+'/gallery/','','resizable=no,scrollbars=yes,personalbar=no,menubar=no,width=850,height=600');
}


//  this is for clickable flash window 
function openViewersChat (uid, stype) {
  openNewWindow('/chat/member/'+uid+'/'+stype, 'Chat'+uid, 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=800,height=700'); 
}

//function openViewerVchat (uid, stype) {
//  openNewWindow('/chat/member/'+uid+'/'+stype, 'Chat'+uid, 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=800,height=700');
//}

//function openViewerVchat (uid, stype) {
  //openNewWindow('/chat/member/'+uid+'/'+stype, 'Chat'+uid, 'directories=no,status=no,location=no,resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=975,height=480');
//}

function openViewerVchat (uid, stype, fromSite) {
  if(fromSite)
    openNewWindow('/chat/member/'+uid+'/'+stype+'/'+fromSite, 'Chat'+uid, 'directories=no,status=no,location=no,resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=975,height=480');
  else
    openNewWindow('/chat/member/'+uid+'/'+stype, 'Chat'+uid, 'directories=no,status=no,location=no,resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=975,height=480');
}



function openPerformerVchat() {
  openNewWindow('/chat/performer/', 'Chat', 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=800,height=582'); 
}

function openPerformerHDVchat() {
  openNewWindow('/chat/performer/hd/', 'HDChat', 'resizable=yes,toolbar=no,scrollbars=yes,personalbar=no,menubar=no,width=1150,height=600');
}

function openFavorites() {
  openNewWindow('/favorite','mygirl','resizable=yes,scrollbars=yes, width=700');
}

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 && 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;
  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);
                                    if (elementId==='thumbshere' && !(strURL.match(/rank/))){
    var thumbshere = obj;
    var thumbnails=[];
    var thisChild=thumbshere.firstChild;
    while(thisChild){
	if (thisChild.nodeType===1) {
	    thumbnails[thumbnails.length]=thisChild;
	}
	thisChild=thisChild.nextSibling;
    }
    thumbnails.sort(function(){return Math.round(Math.random())-0.5});
    for (var i=0; i<thumbnails.length; i++) {
        thumbshere.appendChild(thumbnails[i]);
    }
				    }
				}
  }
  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 siteID = '';
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];
}
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 show_pf_online(pfname){

  var session_type = getSessionType(pfname);
  if(session_type > 0)
     return session_type;
  else
     return false;

}

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

function openAddPoint(){
  window.resizeTo(850,800);
  if(isVIP()){
      window.location = ccg_url+"vip/add_point_v/";
  }else if(isUser()){
      window.location = ccg_url+"viewers/add_point/";
  }else{
      window.location = ccg_url+"viewers/add_point/";
  }
}

function openAddPointEn(){
  openNewWindow( en_url+'viewers/add_point/', 'videoLibrary', 'location=yes, resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=1000, height=700');
}

function openVideoLibrary() {
  openNewWindow('/performer/video/', '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 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() {
  openNewWindow('http://bbs.caribbeancomgirl.com/cgi-bin/bbs2/bbs.cgi', 'BBS', 'resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=850, height=700');
}

function openCampaign(){
  openNewWindow('/performer/menuCmpn/1','Performer Campaign','resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=850, height=700');

}
function openViewerHelp() {  
  if(isVIP()){
    openNewWindow('/vip/howto/howto', 'help','');
  }else if(isUser()){
    openNewWindow('/viewers/howto/howto', 'help' , '');
  }else{
    openNewWindow('/guest/howto/howto','help','');
  }
 
}

function openPerformerHelp() {
  openNewWindow('/performer/menu/?p=2c', 'help', 'resizable=yes, toolbar=yes, scrollbars=yes, personalbar=yes, menubar=yes, width=950, height=700');
}

function openSendMail(uname) {
  // openSendMail(pname)
  openNewWindow('/mailbox/compose/?to='+uname , 'mailbox' , '');
}

function openMailbox() {
  // openMailbox()
  openNewWindow('/mailbox/', 'mailbox' , 'resizable=yes, toolbar=yes, scrollbars=yes, menubar=yes, width=800, height=600');
}

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=500');
}

function openPerformerMemo(uid) {
  //openPerformerMemo(viewerName)
  if(!uid) {
    openNewWindow('/performer/memo/', '', 'resizable=yes, toolbar=yes, scrollbars=yes, menubar=yes, width=800, height=600');
    uid='';
  } else {
    openNewWindow('/performer/memo/'+uid, '', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=270, height=800');
  }
}

function openViewerMemo(performerID) {
  if(!performerID) {
    openNewWindow('/memo/user_memo/', '', 'resizable=yes, toolbar=yes, scrollbars=yes, menubar=yes, width=440, height=590');
    performerID='';
  } else {
    openNewWindow('/memo/user_memo/'+performerID, '', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=440, height=590');
  }
}

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('/viewers/add_point', 'join', '');
}

function openVIPJoin() {
  openNewWindow('/vip/add_point_v', 'join', '');
}

function openFreeUserJoin() {
  openNewWindow('/member/add_point_m', 'join', '');
}

function openJoin(free_goods_id) {
  // redirect the guests to the join page if free_goods_id is undefined
  if (free_goods_id == undefined) {
    var free_goods_id='';
  }
  MM_openBrWindow("/join/" + free_goods_id, 'join', 'toolbar=1,location=1,status=1,scrollbars=1,menubar=1,resizable=1');
}

function openVideoList(pfname) {
  if(isVIP()){
      openNewWindow('/video/viewer/search/video/?user_name=' + pfname, 'video', '');
  }else if(isUser()){
      openNewWindow('/vip_upgrade/vipSpecial', 'video', 'width=740,height=950,scrollbars=yes');
  }else{
      openNewWindow('/vip_upgrade/vipSpecial_guest', 'video', 'width=740,height=790,scrollbars=yes');
  }
  //openNewWindow('/member_video/', 'member_video', '');
}

function openAddPoint2(user_type) {
  if (user_type == 206) {
    openNewWindow('/vip/add_point_v/', 'join', '');
  } else {
    openNewWindow('/viewers/add_point/', 'join', '');
  }
}

function openJoin2() {
  openNewWindow('/guest/join/', 'guestjoin', '');
  //window.resizeTo(1080,800);
  //window.location.href = "/guest/join";
}


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

function page_reload(){

if(!window.opener.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 add_favorite(id,ajax){

    
  //if(ajax){
    ajax_request('/favorite/add?contact_id='+id+'&ajax=1', 'web');
    //ajax_request('/favorite/add?contact_id='+id+'&ajax=1', 'fav');
    //if(isVIP()){
    //  xmlHttpGet('/search/performer/favorite/vip/?tpl=web', 'favoritehere');
    //} else {
    //  xmlHttpGet('/search/performer/favorite/viewer/?tpl=web', 'favoritehere');
    //}
  //} else {
  //  openNewWindow('/favorite/add?contact_id='+id,'mygirl','resizable=yes,scrollbars=yes, width=700');
  //}
}

function delete_favorite(id,ajax,tpl){

  if(ajax){
    ajax_request('/favorite/delete?contact_id='+id+'&ajax='+ajax, tpl);
    //if(isVIP()){
    //  xmlHttpGet('/search/performer/favorite/vip/?tpl='+tpl, 'favoritehere');
    //} else {
    //  xmlHttpGet('/search/performer/favorite/viewer/?tpl='+tpl, 'favoritehere');
    //}
  }

}

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 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 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 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;
  }
}

// ---------------------------------------------------------------------------------
// D2P Toolbar
// ---------------------------------------------------------------------------------
//function showD2PToolbar() {
//  if(userName) {
//    document.write('<div class="d2_toolbar"><TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 ><TBODY><TR><TD height=23><IFRAME src="' + d2p_url + 'toolbarD2P/www.caribbeancomgirl.com');
    //document.write('?user_name=' + userName);
//    document.write('" frameBorder=0 width="100%" scrolling=no height=23></IFRAME></TD></TR></TBODY></TABLE></div>');
//  }
//}
function showD2PToolbar() {
  if(siteID == 20000597) {
    document.write('<div class="d2_toolbar"><TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 ><TBODY><TR><TD height=23><IFRAME src="/d2ptb"');
    document.write('" frameBorder=0 width="100%" scrolling=no height=23></IFRAME></TD></TR></TBODY></TABLE></div>');
  }
}

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 ) {
     document.getElementById("d2ptoolbar").style.display = "none";
     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);
}


//function refresh_d2pbar(){
//  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 iFrameBody = document.getElementById("d2ptoolbar").contentWindow.document.body;
//      if (iFrameBody) {
//        iFrameBody.innerHTML = str;
//        document.getElementById("d2ptoolbar").style.height = 23;
//      }
//    }else{
//      return;
//    }
//  }
//  xmlhttp.send(null);
//}

//-->

function Vote(radio){

  for ( i = 0 ; i < radio.length ; i++){
     if (radio[i].checked){
       var ans = radio[i].value;
     }
  }

  if(!ans) {
    alert("答えを選択してください");
  } else {
    var xmlhttp = getXmlhttp();
    var url = "/questionnaire/add/?answer="+ans;
    xmlhttp.open('POST', url, true);

    xmlhttp.onreadystatechange = function(){
      if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
        res = xmlhttp.responseText;
        if(res == 1){
          alert("投票ありがとうございました");
        }
        if(res == 2){
          alert("投票できませんでした");
          loadQuestionnaire();
        }
        if(res == 3){
          alert("投票はお一人様1回限りです");
          loadQuestionnaire();
        }
      }
    }
    xmlhttp.send(null);
  }

}

//d2p TOOLBAR FUNCTION

function d2p_toolbar_login(){
  window.location = "/viewers/";
}

function d2p_toolbar_logout(){
  window.location = "/viewers/logout/";
}

function d2p_toolbar_site_join(){
  if(userType){
     if(isVIP()){
        window.location = "/vip/add_point_v/";
     }else if (isUser()){
        window.location = "/viewers/add_point/";
     }else{
        window.location = "/guest/join/";
     }
  }else{
     window.location = "/guest/join/"
  }
}

function redirect_to_https(){
  var loc = new String(window.parent.document.location);
  if (loc.indexOf("http://")!= -1){
      var prefix = "https://";
      var domain = "secure.caribbeancomgirl.com";
      var pathname = location.pathname;
      queryStr = hu = window.location.search.substring(1);
      secure_url = prefix+domain+pathname+'?'+queryStr;
     window.location =  secure_url;
  }

}


