//<!-

var userName = '';
var userId = '';
var gender = '';
var NuserName = '';
var userType = '';
var profile_id = '';
var profile_name = '';
var nightWork = 0;

n = getCookie('NetiA');
if(n) {
  var narr = n.split(':');
  var NetiName = narr[0];
  NuserName = NetiName.toLowerCase();
}


c = getCookie('vauth');
if(c && n) {
  var arr = c.split(':');
  var vauthName = arr[0];
  userName = vauthName.toLowerCase();
  userId = arr[1];
  userType = arr[2];
  nightWork = arr[5];
  if(arr[2] == 210)
    gender = 'f';
  else
    gender = 'm';
}

p  = getCookie('vauth_profile');
if(p){
    var p_arr = p.split(':');
    profile_id = p_arr[0];
    profile_name = decodeURIComponent(p_arr[1]);
}

var user_arr = new Array();

if(gender == 'f'){
    document.write('<link href="/css/fmember.css" rel="stylesheet" type="text/css" />');
}else if(gender == 'm'){
    document.write('<link href="/css/member.css" rel="stylesheet" type="text/css" />');
}else{
    document.write('<link href="/css/none.css" rel="stylesheet" type="text/css" />');
}

//document.write('<link href="/css/rules.css" rel="stylesheet" type="text/css" />');
//document.write('<link href="/css/first.css" rel="stylesheet" type="text/css" />');
//document.write('<link href="/css/howto.css" rel="stylesheet" type="text/css" />');
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 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() {
    var obj = getElementFromName(elementId);
    //if (xmlhttp.readyState == 1) {
    //    showLoader(obj);
    //}
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      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() {
    var obj = getElementFromName(elementId);
    //if (xmlhttp.readyState == 1) {
    //    showLoader(obj);
    //}
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      if(obj) obj.innerHTML= xmlhttp.responseText;
                        fixPNGImages(elementId);
    }
  }
  xmlhttp.send(params);
  return;
}

function getXmlhttp() {
  var xmlhttp = null;
  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");
    }
  }
  return xmlhttp;
}

function ajaxRequest(method, url, data, async, callback) {
  var xmlhttp = getXmlhttp();
  if(!xmlhttp) {
    return;
  }

  url +=  (url.indexOf('?')>0?'&_rand=':'?_rand') + Math.random();
  xmlhttp.open(method, url, async);
  xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        //return xmlhttp.responseText;
        callback(xmlhttp);
    }
  }
  xmlhttp.send(data);
}

function showLoader(obj) {
    if(obj) {
        obj.innerHTML = '';
        obj.innerHTML = '<img src="/img/wait.gif">';
    }
}

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 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 isLogin(){
    if(n && c){
	    return (userName == NuserName)?true:false;
    }
    return false;
}
function isVIP() {
        return (userType==206)?true:false;
}
function isMale() {
    return (gender=='m')?true:false;
}
function isFemale() {
    return (gender=='f')?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 getSessionType(profile_id) {
    if(user_arr && user_arr!=null) {
        var user = user_arr[profile_id];
        if(user!=null) {
            return user.session_type;
        }
    }
    return 0;
}

function getComponentBit(profile_id) {
    if(user_arr && user_arr!=null) {
        var user = user_arr[profile_id];
        if(user!=null) {
            return user.component_bit;
        }
    }
    return 0;
}

function isOnline(profile_id){
    if(profile_id == '' || profile_id == null)
        return false;
    var session_type = getSessionType(profile_id);
    if(session_type > 0)
        return session_type; 
    else
        return false;
}

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 updateUserPoints(no_cache){
    if(isLogin() && isMale()){
       xmlHttpGet('/user/updateUserPoints/'+no_cache,'user_points');
    }
}
function updateDelayPoint(){
    setTimeout('updateUserPoints(1)',3000);
}
function updateUnreadMail() {
    if(isLogin()){
       xmlHttpGet('/mail/countUnread', 'mail_num');
    }
}
function updateUserBD(){
    if(isLogin()){
       xmlHttpGet('/profile/birthday','bday');
    }
}
function hideMiniAction(id) {
    if (!id || !isLogin())
        return;
    if (id != profile_id)
        return;
    if ($("#mini_action"))
        $("#mini_action").hide(); 
}
function openNewWindow(theURL,winName,features) {
    var w = window.open(theURL,winName,features);
}
function composeMail(pid){
    if(gender == 'f'){
        openNewWindow('/mail/compose/'+pid, 'mail', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=700, height=450');
    }else{
        openNewWindow('/mail/compose/'+pid, 'mail', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=700, height=520');
    }
}
function commentMail(prod_id, pid){
    openNewWindow('/mail/comment/'+prod_id+'/'+pid, 'mail', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=700, height=450');
}
function pointPurchase(){
    if(isLogin()){
        openNewWindow('/goods?type=add', 'pointPurchase', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=840, height=800');
    }else{
        openNewWindow('/goods?type=join', 'pointPurchase', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=840, height=800');
    }
}
function pointPurchaseBank(){
    if(isLogin()){
        openNewWindow('/goods/bank?type=add', 'pointPurchase', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=840, height=800');
    }else{
        openNewWindow('/goods/bank?type=join', 'pointPurchase', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=840, height=800');
    }
}
function pointAdd(){
    openNewWindow('/goods?type=add', 'pointAdd', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=840, height=800');
}
function addFavorite(pid){
    openNewWindow('/favorite/add/'+pid, 'favorite', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=700, height=450');
}
function editBlockFavorite(pid){
    openNewWindow('/favorite/edit_block/'+pid, 'favorite', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=800, height=500');
} 
function editFavorite(pid){
    openNewWindow('/favorite/edit/'+pid, 'favorite', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=800, height=500');
}
function viewerChat(pid){
    if(isLogin()){
        openNewWindow('/chat/'+pid+'/115', 'chat'+pid, 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=600, height=500');
        deleteEle();
    }else{
        openNewWindow('/guest?next=/chat/'+pid+'/115', 'guest', 'resizable=yes, toolbar=yes, scrollbars=yes, menubar=yes, width=900, height=850');
        //openNewWindow('/login?next=/chat/'+pid+'/115', 'chat'+pid, 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=800, height=550');
    }
}
function productClaim(id){
    openNewWindow('/productClaim/'+id, 'productClaim', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=650, height=340');
}
function productRecommend(id){
    openNewWindow('/productClaim/'+id+'?recommend=1', 'productClaim', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=650, height=340');
}
function profileClaim(id){
    openNewWindow('/profileClaim/'+id, 'profileClaim', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=650, height=340');
} 
function chat(){
    openNewWindow('/chat', 'chat', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=600, height=500');
}
function forceTwoChat(){
    var check = openNewWindow('/chat?force_2shot=1', 'chat', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=600, height=500');
    deleteEle();
}
function videoUpload(){ 
    if(isLogin() && gender == 'f'){
        openNewWindow('/video/upload', 'videoUpload', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=750, height=600');
    }else{
        alert('女の子専用の機能です。');
    }
}    
function videoHowto(){  
    openNewWindow('/video/howto', 'videoHowto', 'resizable=yes, toolbar=yes, scrollbars=yes, menubar=yes, width=900, height=850');
}
function videoPlayer(vid){
    openNewWindow('/video/player/'+vid, 'videoPlayer', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=325, height=275');
} 
function openProfile(uid){
    openNewWindow('/user/'+uid, 'profile', 'resizable=yes, toolbar=yes, scrollbars=yes, menubar=yes, width=900, height=850');
}
function openSendMail(uid){ 
    openNewWindow('/user/sendMail/'+uid, 'mail', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=700, height=450');
}
function openGuest(){
    var next = location.href;
    openNewWindow('/guest?next='+next, 'guest', 'resizable=yes, toolbar=yes, scrollbars=yes, menubar=yes, width=900, height=850');
}
function openChatroom(id){
    if(id == undefined)
        id = 1;
    openNewWindow('/chatroom/join/'+id, 'chatroom'+id, 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=900, height=635');
}
function createChatroom(){
    openNewWindow('/chatroom/create', 'chatroom', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=900, height=635');
}
function chatroomHowto(){
    openNewWindow('/askUs/howtochat/chatroom', 'chatroomHowto', 'resizable=yes, toolbar=no, scrollbars=yes, menubar=no, width=800, height=850');
}
function openPromo(name){
    openNewWindow('/promo/'+name, 'promo', 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=820, height=627');
}
function closeCurrentWindow(){
    window.close();
}
function refresh(){
    window.location.reload();
}
function getWink(pid){
    if(!isFemale()){
        xmlHttpGet('/wink/get/'+pid, 'wink');
    }
}
function submitWink(pid){
    if(document.getElementById('wink_message').value == "メッセージを添えたい時は、このボックスに入力しボタンを押して下さい。"){
        var w_message = '';
    }else{
        var w_message = document.getElementById("wink_message").value;
    }
    var params = 'message='+w_message;
    xmlHttpPost('/wink/save/'+pid, params, 'wink');
}
function clearTextBox(){
    if(document.getElementById('wink_message').value == "メッセージを添えたい時は、このボックスに入力しボタンを押して下さい。"){
        document.getElementById('wink_message').value = '';
    }
}

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 show_d2ptb(){
    var version = check_browser_version();
    if(isLogin() && version >= 7){
        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;
                if(str){
                    document.getElementById("d2ptoolbar").style.display = 'block';
                    var iFrameBody = document.getElementById("d2ptoolbar").contentWindow.document.body;
                    if (iFrameBody)  {
                        iFrameBody.innerHTML = str;
                        document.getElementById("d2ptoolbar").style.height = 23;
                    }
                }else{
                    document.getElementById("d2ptoolbar").style.display = 'none';
                }
            }else{
                return;
            }
        }
        xmlhttp.send(null);
    }
}

function redirect(uid,uid2){
    if(isLogin()){
        openNewWindow('/user/chat/'+uid+'/115', 'chat'+uid, 'resizable=yes, toolbar=no, scrollbars=no, menubar=no, width=600, height=500');
    }else{
        openNewWindow('/guest?next=/user/chat/'+uid+'/115', 'guest', 'resizable=yes, toolbar=yes, scrollbars=yes, menubar=yes, width=900, height=850');
    }
}

function open2shotFemale(){
    //alert('チャットを開始します');
    var ele = document.getElementById('chatStart');
    ele.style.display = 'block';
    ele.innerHTML = '<a href="javascript:;" onClick="forceTwoChat();"><img src="/images/chatroom/popup/2shot_startbt.jpg"></a>';
    //chat();
}
function open2shotMale(pid){
    //alert('チャットを開始します');
    var ele = document.getElementById('chatStart');
    ele.style.display = 'block';
    ele.innerHTML = '<a href="javascript:;" onClick="viewerChat('+pid+');"><img src="/images/chatroom/popup/2shot_startbt.jpg"></a>';
}

function deleteEle(){
    var ele = document.getElementById('chatStart');
    ele.style.display = 'none';
}
//-->
