var img_host = 'http://img.i-part.com.tw';
var host = 'http://www.i-part.com.tw';
//==[ chk relative return 1 , 0 ]==//
function chkRelative(tNo,f){
	$.getJSON(host+"/post_office/proscenium.php?jsoncallback=?",{method:'stamp.hasRelationship',flno:tNo},
		function(data){
            if(data.result==-1){ // no login
                msggo("請先登入",host+"/signup.php?f="+encodeURIComponent(location.href));
            }else if(data.result==-3){
                msggo("參數錯誤","http://www.i-part.com.tw");
            }else{
                if(typeof(f)=="function"){
                    f(data);
                }
            }
		}
	);
}

function setRelative(tNo,f){
    if(confirm("請問確定要使用1張郵票。\n\n開通跟他的所有互動嗎？")){
        $.getJSON(host+"/post_office/proscenium.php?jsoncallback=?",{method:'stamp.setRelationship',flno:tNo},
            function(data){
                if(data.result=="-1"){
                    msggo("請先登入",host+"/signup.php?f="+encodeURIComponent(location.href));
                }else if(data.result=="-3"){
                    msggo("參數錯誤","http://www.i-part.com.tw");
                }else if(data.result==-4){
                    popNoStamp(data.ib);
                }else if(data.result==-5){
                    alert('系統忙碌中請稍後再試一次...');
                    location.reload();
                }else if(data.result > 0){
                    alert('成功與對方開通互動關係。');
                    location.reload();
                }
            }
        );
    }    
}

//==[ for Ajax ]==//
function setRelativeForFileMy(tNo,f){
    if(confirm("請問確定要使用1張郵票。\n\n開通跟他的所有互動嗎？")){
        $.getJSON(host+"/post_office/proscenium.php?jsoncallback=?",{method:'stamp.setRelationshipForFileMy',flno:tNo},
            function(data){
                if(data.result=="-1"){
                    msggo("請先登入",host+"/signup.php?f="+encodeURIComponent(location.href));
                }else if(data.result=="-3"){
                    msggo("參數錯誤","http://www.i-part.com.tw");
                }else if(data.result==-4){
                    popNoStamp(data.ib);
                }else if(data.result==-5){
                    alert('系統忙碌中請稍後再試一次...');
                    location.reload();
                }else if(data.result > 0){
                    if(typeof(f)=="function"){
                        f(data.result);
                    }else{
                        alert('成功與對方開通互動關係。');
                        location.reload();
                    }
                }
            }
        );
    }    
}


//==[ popup no stamp ]==//
function popNoStamp(ib){
    if(ib < 100){
        if(confirm("你目前ｉ幣不足夠購買郵票！\n\n請問要前往加值嗎？")){
            window.open('http://www.i-part.com.tw/pay/value.php');
        }
    }else{
        get_blockUI('<div id="stampSet" style="width:250px;height:315px">'+
  '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">'+
    '<tr>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_lt.gif);background-position:top left;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
      '<td bgcolor="#eeeeee" style="border-top:1px solid #c2c2c2"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_rt.gif);background-position:top right;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
    '</tr>'+
    '<tr>'+
      '<td bgcolor="#EEEEEE" style="border-left:1px solid #c2c2c2">&nbsp;</td>'+
      '<td bgcolor="#FFFFFF" style="background-color:#FFFFFF;padding:5px 5px 15px 15px">'+
        '<table width="100%" border="0" cellspacing="0" cellpadding="0">'+
          '<tr>'+
            '<td style="color:#e52e5c">抱歉，你目前沒有郵票！</td>'+
            '<td align="right" valign="top"><img id="stampClose" src="'+img_host+'/images/ifile/button_close.gif" width="14" height="14" border="0" style="cursor:pointer" onclick="location.href=location.href;"></td>'+
          '</tr>'+
        '</table>'+
      '<table width="100%" border="0" cellpadding="3" cellspacing="0">'+
        '<tr>'+
          '<td valign="top" style="padding-top:15px">'+
           '<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-bottom:1px solid #dddddd;margin-bottom:8px">'+
            '<tr>'+
              '<td><strong>使用 i幣購買郵票</strong></td>'+
            '</tr>'+
          '</table>'+
            '選擇要購買的張數：<br>'+
            '<input type="radio" name="rdo_popNoStamp_buy" id="rdo_popNoStamp_buy_90" value="90">'+
            '90 i幣購買 6 張郵票 <br>'+
            '<input type="radio" name="rdo_popNoStamp_buy" id="rdo_popNoStamp_buy_270" value="270">'+
            '270 i幣購買 21 張郵票 <br>'+
            '<input type="radio" name="rdo_popNoStamp_buy" id="rdo_popNoStamp_buy_540" value="540">'+
            '540 i幣購買 55 張郵票'+
            '<div style="background-color:#f3f3f3">'+
            '<table border="0" cellspacing="0" cellpadding="0" style="margin-top:8px">'+
              '<tr>'+
                '<td>你目前有：&nbsp;</td>'+
                '<td align="right"><strong style="color:#ee6600"><span id="span_popNoStamp_ib"></span></strong> <img src="'+img_host+'/images/icon_icoin_s.gif" width="11" height="11" style="vertical-align:middle"></td>'+
              '</tr>'+
            '</table>'+
            '</div>'+
            '<div align="center" style="margin-top:8px">'+
               '<input type="button" id="popNoStamp_btnBuyStamp" value="&nbsp;&nbsp;購買&nbsp;&nbsp;">'+
             '</div> '+
            '</td>'+
          '</tr>'+
      '</table>'+
      '<table width="100%" border="0" cellpadding="3" cellspacing="0">'+
        '<tr>'+
          '<td valign="top" style="padding-top:15px">加值 <img src="'+img_host+'/images/vip_icon3.gif" width="32" height="15" hspace="0" style="vertical-align:middle">白金VIP，從此公寓互動暢通無阻！'+
            '<div align="center" style="margin-top:8px">'+
              '<input type="button" value="&nbsp;&nbsp;立即加值&nbsp;&nbsp;" onclick="window.open(\'http://www.i-part.com.tw/pay/value.php\');">'+
            '</div></td></tr>'+
      '</table></td>'+
      '<td bgcolor="#EEEEEE" style="border-right:1px solid #c2c2c2">&nbsp;</td>'+
    '</tr>'+
    '<tr>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_lb.gif);background-position:bottom left;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="6"></td>'+
      '<td bgcolor="#EEEEEE" style="border-bottom:1px solid #c2c2c2"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_rb.gif);background-position:bottom right;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="6"></td>'+
    '</tr>'+
  '</table>'+
'</div>'+
'<script>'+
	'$("#span_popNoStamp_ib").text('+ib+');'+
    '$("input[name=rdo_popNoStamp_buy]").each('+
        'function(i){'+
            'if($(this).val() > '+ib+'){'+
                '$(this).attr("disabled",true);'+
            '}'+
        '}'+
    ');'+
	'$("#popNoStamp_btnBuyStamp").click('+
        'function(){'+
            'var useIB = $("input[id^=rdo_popNoStamp_buy_]:checked").val();'+
            'if(typeof(useIB)!="undefined"){'+
                'if(confirm("您確定要花費 "+useIB+" I幣購買郵票嗎？")){'+
                '$.getJSON("'+host+'/post_office/proscenium.php?jsoncallback=?",{method:\'stamp.purchase\',ib:useIB},'+
                    'function(data){'+
                        'if(data.result>0){'+
                            'alert("購買成功。");'+
                            'location.reload();'+
                        '}else if(data.result==\'-1\'){'+
                            'msggo("請先登入","'+host+'/signup.php?f='+encodeURIComponent(location.href)+'");'+
                        '}else if(data.result==\'-2\'){'+
                            'msggo("I幣不足","'+host+'/pay/value.php");'+
                        '}else if(data.result==\'-3\'){'+
                            'msggo("參數錯誤","http://www.i-part.com.tw");'+
                        '}else{'+
                            'alert("購買失敗");'+
                            'location.reload();'+
                        '}'+
                    '}'+
                ');'+
                '}'+
            '}else{'+
                'alert("購買失敗");'+
                'location.reload();'+
            '}'+
        '}'+
    ');'+
'<\/script>',250,315);
    }
}

//==[ popup stampReadme ]==//
function popStampReadme(){
    get_blockUI('<div id="stampExplain" style="width:250px;height:238px;">'+
  '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">'+
    '<tr>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_lt.gif);background-position:top left;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
      '<td bgcolor="#eeeeee" style="border-top:1px solid #c2c2c2"><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
        '<tr>'+
          '<td height="25"><img src="'+img_host+'/images/icon04.gif" width="13" height="11" style="vertical-align:middle"> 郵票說明</td>'+
          '<td align="right" valign="top"><img src="'+img_host+'/images/ifile/button_close.gif" width="14" height="14" border="0" id="stampClose" style="cursor:pointer"></td>'+
        '</tr>'+
      '</table></td>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_rt.gif);background-position:top right;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
    '</tr>'+
    '<tr>'+
      '<td bgcolor="#EEEEEE" style="border-left:1px solid #c2c2c2">&nbsp;</td>'+
      '<td bgcolor="#FFFFFF" style="background-color:#FFFFFF;padding:15px">．一般住戶間需在初次留言時使用郵票開通互動關係，<font color="#e52e5c">開通後均不再需要郵票</font>。 <br>'+
      '．購買的郵票使用期限為<strong style="color:#e52e5c">60</strong>天，到期前再次購買可一併延長使用期限。<br> '+
      '．推薦您升級白金VIP，交友溝通零距離，無需郵票即可與所有住戶免費互動。<br>．郵票到期前升級成白金VIP，則郵票期限會一併延長，若購買30天的白金VIP，則郵票期限延長30天，以此類推。'+
      '<div align="center" style="margin-top:8px"><img src="'+img_host+'/images/arraw20.gif" width="8" height="8" hspace="4" style="vertical-align:middle"><a href="http://www.i-part.com.tw/pay/value.php" target=_blank>加值郵票</a>&nbsp;&nbsp;<img src="'+img_host+'/images/arraw20.gif" width="8" height="8" hspace="4" style="vertical-align:middle"><a href="http://www.i-part.com.tw/html/10action/0504/index.htm" target=_blank>瞭解更多</a></div>'+
      '</td>'+
      '<td bgcolor="#EEEEEE" style="border-right:1px solid #c2c2c2">&nbsp;</td>'+
    '</tr>'+
    '<tr>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_lb.gif);background-position:bottom left;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="6"></td>'+
      '<td bgcolor="#EEEEEE" style="border-bottom:1px solid #c2c2c2"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_rb.gif);background-position:bottom right;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="6"></td>'+
    '</tr>'+
  '</table>'+
'</div>',250,238);
}


//想知道剪影是誰start
function popShadowReadme(){
    get_blockUI('<div id="shadowSet" style="width:400px;height:161px;">'+
  '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">'+
    '<tr>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_lt.gif);background-position:top left;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
      '<td bgcolor="#eeeeee" style="border-top:1px solid #c2c2c2"><img src="images/space.gif" width="1" height="5"></td>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_rt.gif);background-position:top right;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
    '</tr>'+
    '<tr>'+
      '<td bgcolor="#EEEEEE" style="border-left:1px solid #c2c2c2">&nbsp;</td>'+
      '<td bgcolor="#FFFFFF" style="background-color:#FFFFFF;padding:5px 5px 15px 15px">'+
      '<div align="right"><img src="'+img_host+'/images/ifile/button_close.gif" width="14" height="14" border="0" id="stampClose" style="cursor:pointer"></div>'+
      '<table border="0" cellspacing="0" cellpadding="3">'+
        '<tr>'+
          '<td valign="top"><strong style="font-size:11pt;color:#666666">想知道隱身剪影中的住戶是誰嗎？</strong>'+
            '<div align="center" style="height:10px"></div>'+
            '<font color="#e52e5c">你可以花一張郵票</font>，看看他是誰？<img src="'+img_host+'/images/arraw20.gif" width="8" height="8" hspace="4" style="vertical-align:middle"><a href="javascript:;" onclick="popStampReadme();">郵票是什麼</a><br>'+
            '<span style="color:#666666; font-size:9pt">利用郵票來開通妳們彼此的關係，從此以後可以暢所欲言！</span>'+
            '<div align="center" style="height:6px"></div>'+
            '<font color="#e52e5c">或是</font> <img src="'+img_host+'/images/arraw20.gif" width="8" height="8" hspace="4" style="vertical-align:middle"><a href="http://www.i-part.com.tw/pay/value.php" target=_blank style="color:#e52e5c">加值白金VIP</a><br>'+
            '<span style="color:#666666; font-size:9pt">無需再使用郵票就可以看到所有的留言與鄰居拜訪喔！</span></td>'+
          '</tr>'+
      '</table></td>'+
      '<td bgcolor="#EEEEEE" style="border-right:1px solid #c2c2c2">&nbsp;</td>'+
    '</tr>'+
    '<tr>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_lb.gif);background-position:bottom left;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="6"></td>'+
      '<td bgcolor="#EEEEEE" style="border-bottom:1px solid #c2c2c2"><img src="'+img_host+'/images/space.gif" width="1" height="5"></td>'+
      '<td style="background-image:url('+img_host+'/images/ilife/aquarium/coner_gray_rb.gif);background-position:bottom right;background-repeat:no-repeat"><img src="'+img_host+'/images/space.gif" width="1" height="6"></td>'+
    '</tr>'+
  '</table>'+
'</div>',400,161);
}

//==[ center blockUI ]==//
function get_blockUI(html,width,height){
    var winWidth = $(window).width();
    var winHeight = $(window).height();
    var divWidth = width;
    var divHeight = height;
    var leftPx = parseInt((parseInt(winWidth)-parseInt(divWidth))/2);
    var topPx = parseInt((parseInt(winHeight)-parseInt(divHeight))/2);

    $.blockUI({
        message: html, fadeOut:0, focusInput:false,
        css:{cursor:"default", textAlign:"left", left:leftPx, top:topPx, width:divWidth, height:divHeight, border:"none",backgroundColor:''},
        overlayCSS:{cursor:"default", opacity: "0.5"}
    });
    $('#stampClose').attr('title','關閉提示框').click(function(){ $.unblockUI(); });
}

//==[ msg GO ]==//
function msggo(msg,loc){
    alert(msg);
    location.href=loc;
}

