var tab_num = 7;

$(document).ready(function(){
	$(".url > a").linkwrapper();	
});




// URL折り返し対策
(function() {
  jQuery.fn.linkwrapper = function(config) {
    config = jQuery.extend({
      pattern: '(.)'
    }, config);
    var pattern = new RegExp(config.pattern, 'g');
    var tag = jQuery.browser.opera ? '&#8203;' : '<wbr />';
    return this.each(function() {
      jQuery(this).html(jQuery(this).text().replace(pattern, '$1' + tag));
    });
  };
})(jQuery);


// BACKTOP
function backToTop() {
  var x1 = x2 = x3 = 0;
  var y1 = y2 = y3 = 0;
  if (document.documentElement) {
      x1 = document.documentElement.scrollLeft || 0;
      y1 = document.documentElement.scrollTop || 0;
  }
  if (document.body) {
      x2 = document.body.scrollLeft || 0;
      y2 = document.body.scrollTop || 0;
  }
  x3 = window.scrollX || 0;
  y3 = window.scrollY || 0;
  var x = Math.max(x1, Math.max(x2, x3));
  var y = Math.max(y1, Math.max(y2, y3));
  window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
  if (x > 0 || y > 0) {
      window.setTimeout("backToTop()", 25);
  }
}

// ROLLOVER
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

function plusZero( num )	{
	num = '00' + num;
	num = num.substring( num.length - 2, num.length );
	return num ;
}

function ow( order_id ) {
	open_window('http://testcgi.info/results/coupon/html/coupon/coupon_print.php?o='+order_id,'晴れポン：クーポン印刷',640,600);
}

//******************************************************************************
// <summary> ポップアップ画面をオープンする
// <param  > path   : オープンするページのパス
//           note   : 備考
//           width  : 幅
//           heigth : 高さ
// <returns> 
// <remarks> 
function open_window(path,note,width,height)
{
	//幅、高さを設定
	wx = (width == null ? 600 : width);
	wy = (height == null ? 400 : height);
	
	//位置を設定
	x = (screen.width - wx) / 2;
	y = (screen.height - wy) / 2;
	
	note = "harepon";
	
	//オープン
	window.open(path,
	            note, 
	            "scrollbars=yes" +
	            ",toolbar=no" +
	            ",location=no" +
	            ",directories=no" +
	            ",left=" + x +  
	            ",top=" + y + 
	            ",width=" + wx + 
	            ",height=" + wy);

}

function print_coupon( order_id )
{
	var fm = document.getElementById('frm_pr');
	fm.submit();
	
	if(confirm("クーポンを印刷してもよろしいですか？\n【注意！】\n・印刷用の画面は1回のみ表示されます。\n・プリンタの設定や、インク及び用紙のご確認を行ってください。\n・プリンタの設定等で印刷が出来なかった場合は、お問合わせフォームよりご連絡ください。"))
	{
		fm.submit();
	}
}

function PrintPage(){
	if(document.getElementById || document.layers){
		window.print();		//印刷をします
	}
}

window.onload = initRollovers;
