
function commify(n) {
  var reg = /(^[+-]?\d+)(\d{3})/;   // 정규식
  n += '';                          // 숫자를 문자열로 변환

  while (reg.test(n))
    n = n.replace(reg, '$1' + ',' + '$2');
	
 // n = Number(n);
  
  return n;
}

function str_unit(num,unitstr)
{
	if ( num == "0" )
		str = "없음";
	else	
		str = num+unitstr;
	
	return str;	
	
}

function ct_html(arr_ct,ct_type)
{
		var pre_type;
		
		var pre_str = "ct";
		var price_type = [
		"_teen_",
		"_sli_",
		"_lig_",
		"_tal_",
		"_val_",
		"_mid_",
		"_spe_",
		"_pre_"
		
		];
		
		
		
		for(i = 0 ; i < price_type.length ; i++)
		{
			 pre_type = pre_str + ct_type + price_type[i];
			// alert(pre_type);
			
			$("#"+pre_type+"d_pay").html(str_unit(commify(arr_ct[i].d_pay),"원"));
		
			if ( price_type[i] == "_teen_" )
			{
				$("#"+pre_type+"free_call").html(str_unit(commify(arr_ct[i].free_call),"알"));
				$("#"+pre_type+"free_sns").html(str_unit(commify(arr_ct[i].free_sns),"알"));
			}
			else
			{
				$("#"+pre_type+"free_call").html(str_unit(commify(arr_ct[i].free_call),"분"));
				$("#"+pre_type+"free_sns").html(str_unit(commify(arr_ct[i].free_sns),"건"));
			}
			$("#"+pre_type+"free_data").html(arr_ct[i].free_data);
			
			$("#"+pre_type+"device_price").html(str_unit(commify(arr_ct[i].device_price),"원"));
			$("#"+pre_type+"join_price").html(str_unit(commify(arr_ct[i].join_price),"원"));
			$("#"+pre_type+"usim_price").html(str_unit(commify(arr_ct[i].usim_price),"원"));
			$("#"+pre_type+"bond_price").html(str_unit(commify(arr_ct[i].bond_price),"원"));
			$("#"+pre_type+"sum").html(str_unit(commify(
												Number(arr_ct[i].d_pay) +
												Number(arr_ct[i].device_price) +
												Number(arr_ct[i].join_price) +
												Number(arr_ct[i].usim_price) +
												Number(arr_ct[i].bond_price)
												),"원"));
		
		}
	
}


$(function () {
	
		
		ct_html(Msg_Str.ct24,"24");
		ct_html(Msg_Str.ct30,"30");

		$('#twitter_icon').css( 'cursor', 'pointer' );
		$('#twitter_icon').click(function()
		{
			TwitterUrl= "http://twitter.com/?status="+encodeURIComponent("스마트폰 소셜커머스 크랙 http://crack.bz");
			window.open(TwitterUrl,"open");
		});
		
		$('#facebook_icon').css( 'cursor', 'pointer' );
		$('#facebook_icon').click(function()
		{
			FacebookUrl= "http://www.facebook.com/sharer.php?u="+encodeURIComponent("http://crack.bz/temp") + "&t="+encodeURIComponent("스마트폰 소셜커머스 크랙 http://crack.bz");
			window.open(FacebookUrl,"open");
		});
		
		$('#p_detail').css( 'cursor', 'pointer' );
		$('#p_detail').click(function()
		{
			window.open(Product_detail_website,"open");
		});
	
		
		$('#btn_24_new_join').click(function()	{ window.open(join_form_link.ct24[0].link,"open"); });
		$('#btn_24_num_move').click(function()	{ window.open(join_form_link.ct24[1].link,"open"); });
		$('#btn_24_chg_new').click(function()	{ window.open(join_form_link.ct24[2].link,"open"); });
		$('#btn_24_chg_dev').click(function()	{ window.open(join_form_link.ct24[3].link,"open"); });
	
		$('#btn_30_new_join').click(function()	{ window.open(join_form_link.ct30[0].link,"open"); });
		$('#btn_30_num_move').click(function()	{ window.open(join_form_link.ct30[1].link,"open"); });
		$('#btn_30_chg_new').click(function()	{ window.open(join_form_link.ct30[2].link,"open"); });
		$('#btn_30_chg_dev').click(function()	{ window.open(join_form_link.ct30[3].link,"open"); });
	
	
		$('#imageLayout').countdown({
			until: liftoffTime, 
			compact: true, 
			format: 'HMS',
    		layout: $('#imageLayout').html()
		});
		
		$('.choiceA').mouseover(function() {
		  activateThisColumn('choiceA','pricetable');
		});
		$('.choiceB').mouseover(function() {
		  activateThisColumn('choiceB','pricetable');
		});
		$('.choiceC').mouseover(function() {
		  activateThisColumn('choiceC','pricetable');
		});
		$('.choiceD').mouseover(function() {
		  activateThisColumn('choiceD','pricetable');
		});
		$('.choiceE').mouseover(function() {
		  activateThisColumn('choiceE','pricetable');
		});
		$('.choiceF').mouseover(function() {
		  activateThisColumn('choiceF','pricetable');
		});
		$('.choiceG').mouseover(function() {
		  activateThisColumn('choiceG','pricetable');
		});
		$('.choiceH').mouseover(function() {
		  activateThisColumn('choiceH','pricetable');
		});
		
		$('.choiceA3').mouseover(function() {
		  activateThisColumn('choiceA3','pricetable3');
		});
		$('.choiceB3').mouseover(function() {
		  activateThisColumn('choiceB3','pricetable3');
		});
		$('.choiceC3').mouseover(function() {
		  activateThisColumn('choiceC3','pricetable3');
		});
		$('.choiceD3').mouseover(function() {
		  activateThisColumn('choiceD3','pricetable3');
		});
		$('.choiceE3').mouseover(function() {
		  activateThisColumn('choiceE3','pricetable3');
		});
		$('.choiceF3').mouseover(function() {
		  activateThisColumn('choiceF3','pricetable3');
		});
		$('.choiceG3').mouseover(function() {
		  activateThisColumn('choiceG3','pricetable3');
		});
		$('.choiceH3').mouseover(function() {
		  activateThisColumn('choiceH3','pricetable3');
		});
				/*
		$('.choiceA').mouseover({
			activateThisColumn('choiceA');
		});
		*/
});

