function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

window.onload = function()
{
  $(".div_blist").each(function()
   {
     var content = this.innerHTML.replace(/<[^<>]+>/g, "\r\n");
     //alert(content);
     $(this).html(billings(content));
     $(this).css("display", "block");
   }
  );
}
function trim(str)
{
  return str.replace(/^\s*([\S\s]*?)\s*$/, '$1');
}

var pat_ie                        = /MSIE [6-9]\.[0-9]{1,2}/;
var notIE                         = !navigator.userAgent.match(pat_ie);
function billings(b_str)
{
  var gw_list = [];
  var paypal_list = [];
  var temp = [];

  // parse gw_list
  var pat_gw_list = /gw,([^,]+),([^,]+)\n/g;
  var pat_gw_item = /gw,([^,]+),([^,]+)/;
  if(temp = b_str.match(pat_gw_list))
  {
    for(t=0;t<temp.length;t++)
    {
      var m;
      if(m = trim(temp[t]).match(pat_gw_item))
      {
        gw_list.push({
          title:m[1], 
          amount:m[2]
        });
      }
    }
  }

  // parse paypal_list
  var pat_paypal_list = /paypal,([^,]+),([^,]+),([^,]+)\n/g;
  var pat_paypal_item = /paypal,([^,]+),([^,]+),([^,]+)/;
  if(temp = b_str.match(pat_paypal_list))
  {
    for(t=0;t<temp.length;t++)
    {
      var m;
      if(m = trim(temp[t]).match(pat_paypal_item))
      {
        paypal_list.push({
          title:m[1], 
          amount:m[2],
          paypal_id:m[3]
        });
      }
    }
  }


  try
  {
    var html = "";
    html+=''+
    '<img src="img/green_world.gif"><br>'+
    '<div style="margin:5px;padding:10px;background-color:#eeeeee">';
    html+='<span class="billing_item"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>WebATM付款</span><br>';
    for(g in gw_list)
    {
      html+='<a href="http://ts.payonline.com.tw/atm_any.php?client=3094&amount='+gw_list[g].amount+'&pay_sob='+encodeURI(gw_list[g].title)+'" target="_blank">'+gw_list[g].title+'($'+gw_list[g].amount+')</a><br><br>';
    }
    html+='<span class="billing_item"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>列印專屬條碼到超商櫃檯繳款</span><br>';
    for(g in gw_list)
    {
      html+='<a href="http://ts.payonline.com.tw/cvs_any.php?client=3094&amount='+gw_list[g].amount+'&pay_sob='+encodeURI(gw_list[g].title)+'" target="_blank">'+gw_list[g].title+'($'+gw_list[g].amount+')</a><br><br>';
    }
    html+='<span class="billing_item"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>透過超商付款機付款(7-11 ibon / 全家Famiport / 萊爾富 Life-et)</span><br>';
    for(g in gw_list)
    {
      html+='<a href="http://ts.payonline.com.tw/new3in1.php?client=3094&amount='+gw_list[g].amount+'&pay_sob='+encodeURI(gw_list[g].title)+'" target="_blank">'+gw_list[g].title+'($'+gw_list[g].amount+')</a><br><br>';
    }
    
    if(paypal_list.length)
    {
      html+='<span class="billing_item"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>PayPal付款</span>';
      for(p in paypal_list)
      {
        html+=''+
        paypal_list[p].title+'($'+paypal_list[p].amount+')'+
        '<form action="https://www.paypal.com/cgi-bin/webscr" enctype="application/x-www-form-urlencoded" method="post" target="_blank"><input name="cmd" type="hidden" value="_s-xclick" /> <input name="hosted_button_id" type="hidden" value="'+paypal_list[p].paypal_id+'" /> <input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" /> <img src="https://www.paypal.com/zh_HK/i/scr/pixel.gif" border="0" alt="" width="1" height="1" /></form><br/>';
      }
    }
 
    html+=''+
    '<span class="billing_item"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>郵局轉帳付款帳號為 郵局700 帳號00013270518683</span>'+
    '<div style="margin:10px">'+
    '繳費後請 email 以下資料 至 service@no1pua.com 確認付款成功<br>'+
    '<div style="margin:10px">'+
    '*付款單號或轉帳帳號後5碼(透過郵局帳戶付款者)<br>'+
    '*姓名<br>'+
    '*性別<br>'+
    '*出生日期<br>'+
    '*星座<br>'+
    '*職業/職稱<br>'+
    '*學歷<br>'+
    '*居住縣市<br>'+
    '*E-mail<br>'+
    '*手機<br>'+
    '(資料皆會完全保密不外露)'+
    '</div>'+
    '</div>'+
    '</div>';
    return html;
  }catch(e)
  {
    alert(e.message);
  }
}

function billing(sob, amount, paypal_id)
{
  try
  {
    var html = "";
    html+=''+
    '<img src="img/green_world.gif"><br>'+
    '<div style="margin:5px;padding:10px;background-color:#eeeeee">'+
    '<a href="http://ts.payonline.com.tw/atm_any.php?client=3094&amount='+amount+'&pay_sob='+encodeURI(sob)+'" class="billing_item" target="_blank"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>點此用WebATM付款</a><br>'+
    '<a href="http://ts.payonline.com.tw/cvs_any.php?client=3094&amount='+amount+'&pay_sob='+encodeURI(sob)+'" class="billing_item" target="_blank"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>點此列印專屬條碼到超商櫃檯繳款</a><br>'+
    '<a href="http://ts.payonline.com.tw/new3in1.php?client=3094&amount='+amount+'&pay_sob='+encodeURI(sob)+'" class="billing_item" target="_blank"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>點此透過超商付款機付款(7-11 ibon / 全家Famiport / 萊爾富 Life-et)</a><br>';
    if(paypal_id)
    {
      html+=''+
      '<span class="billing_item" target="_blank"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>PayPal付款</span><br>'+
      '<form action="https://www.paypal.com/cgi-bin/webscr" enctype="application/x-www-form-urlencoded" method="post" target="_blank"><input name="cmd" type="hidden" value="_s-xclick" /> <input name="hosted_button_id" type="hidden" value="'+paypal_id+'" /> <input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" /> <img src="https://www.paypal.com/zh_HK/i/scr/pixel.gif" border="0" alt="" width="1" height="1" /></form>';
    }
    html+=''+
    '<span class="billing_item" target="_blank"><img src="img/love.gif" border="0" style="width:15px;height:15px" hspace="5"/>郵局轉帳付款帳號為 郵局700 帳號00013270518683</span><br>'+
    '<div style="margin:10px">'+
    '繳費後請 email 以下資料 至 service@no1pua.com 確認付款成功<br>'+
    '<div style="margin:10px">'+
    '*付款單號或轉帳帳號後5碼(透過郵局帳戶付款者)<br>'+
    '*姓名<br>'+
    '*性別<br>'+
    '*出生日期<br>'+
    '*星座<br>'+
    '*職業/職稱<br>'+
    '*學歷<br>'+
    '*居住縣市<br>'+
    '*E-mail<br>'+
    '*手機<br>'+
    '(資料皆會完全保密不外露)'+
    '</div>'+
    '</div>'+
    '</div>';
    //document.getElementById("div_billing").innerHTML = html;
    document.write(html);
  }catch(e)
  {
    setTimeout("billing('"+sob+"', '"+amount+"', '"+paypal_id+"')", 500);
  }
}


(function (){
  try
  {
    var w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
    var h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight; 
    $("#floatAD").show();
    $("#floatAD").makeFloat(
      {
        x:      (Math.round(w/2) + 370),
        y:      400,
        speed:  "normal"
      }
    );
  }catch(e)
  {
    setTimeout(arguments.callee, 500);
  }
})();

// anti-AD !!!
(function(){
  try
  {
      jQuery("img[src*='china.GIF']").each(function(){
        if(this.parentNode.href.match(/-l=zt/)) this.src = this.src.replace(/china/, "taiwan");
      });
      jQuery("a[title*='SWeTE']").css("display", "none");
      jQuery("div[id='WebLite-language-selector-footer']").css("display", "none");
      jQuery("div").each(function(){
        if(
          this.style.height == "18px" &&
          this.style.width == "100%"
        )
        {
          this.style.display = "none";
          return;
        }
      });
  }catch(e){
    //alert(e.message);
  }
  setTimeout(arguments.callee, 1000);
})();

// create tabs ...
(function(){
  try
  {
    $("#tabs").css("display", "block");
  	$("#tabs").tabs({event:"mouseover"});
  }catch(e){
    //alert(e.message);
  }
  setTimeout(arguments.callee, 1000);
})();


// if (typeof Meebo == 'undefined') {
// Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};
// (function(q){
// 	var args = arguments;
// 	if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); }
// 	var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild); s=d.createElement('script');
// 	m.id='meebo'; m.style.display='none'; m.innerHTML='<iframe id="meebo-iframe"></iframe>';
// 	s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;
// 	b.insertBefore(s, b.firstChild);
// 
// })({network:'no1pua_ka30su'});
// Meebo('makeEverythingSharable');
// }
// Meebo("domReady");
