
UA = (navigator.userAgent.indexOf('MSIE 6',0) != -1) ? 'target' : 'other';

$(function(){
// [画像]プリロード
  $('.over img,.fontsize li img,.sidecategory p img').each(function(){
  t = new Array($(this).attr('src').replace('_off.','_on.'),$(this).attr('src').replace('_on.','_off.'));
  c = new Array($(this).attr('src').replace('_open.','_close.'),$(this).attr('src').replace('_close.','_open.'));
  p = new Array();
	  for(i=0;i<t.length;i++){
		  p[i] = new Image();
		  p[i].src = t[i],c[i];
 	 }
  });

// [サイド]カテゴリメニュー
  tm = 'このカテゴリメニューを開く';
  tm2 = 'このカテゴリメニューを閉じる';
  $('.sidecategory h2').click(function(){
	v = $(this).next().next().children().attr('src');
	is = (v.indexOf('_close.',0) != -1) ? 'close':'open';
  	if(is != 'open'){
		v = v.replace('_close.','_open.');
		$(this).next().next().children().attr('src',v);
		$(this).next().next().attr('title',tm);
		$(this).attr('title',tm);
	}else{
		v = v.replace('_open.','_close.');
		$(this).next().next().children().attr('src',v);
		$(this).next().next().attr('title',tm2);
		$(this).attr('title',tm2);
	}
    $(this).next().slideToggle('slow');
  });
  $('.sidecategory p').click(function(){
	v = $(this).children().attr('src');
	is = (v.indexOf('_close.',0) != -1) ? 'close':'open';
  	if(is != 'open'){
		v = v.replace('_close.','_open.');
		$(this).children().attr('src',v);
		$(this).attr('title',tm);
		$(this).prev().prev().attr('title',tm);
	}else{
		v = v.replace('_open.','_close.');
		$(this).children().attr('src',v);
		$(this).attr('title',tm2);
		$(this).prev().prev().attr('title',tm2);
	}
    $(this).prev().slideToggle('slow');
  });
  $('.sidecategory h2,.sidecategory p').hover(function(){
    $(this).css('cursor','pointer');
  },
  function(){
    $(this).css('cursor','auto');
  });

// [メニュー]ロールオーバー
  $('.over').hover(function(){
		v = $(this).children().attr('src');
		v = v.replace('_off.','_on.');
    	$(this).children().attr('src',v);
  },
  function(){
		v = v.replace('_on.','_off.');
    	$(this).children().attr('src',v);
  });

// [フォーム]フォーム部品フォーカス
  $('input[@type="text"],select,textarea').focus(function(){
																					   $(this).css({'background-color':'#fffdd9','outline':'1px dotted #000'});
																					   });
  $('input[@type="text"],select,textarea').blur(function(){
																					   $(this).css({'background-color':'#fff','outline':'none'});
																					   });
  $('input[@type="checkbox"],input[@type="radio"]').focus(function(){
																					   $(this).css('outline','1px dotted #000');
																					   });
  $('input[@type="checkbox"],input[@type="radio"]').blur(function(){
																					   $(this).css('outline','none');
																					   });

// スタイル調整
	// ファイル名を取ってくる
	var path = document.location.href;
	ex = new Array();
	ex[0] = (path.indexOf('guide') != -1) ? 'target':'other';
	ex[1] = (path.indexOf('faq') != -1) ? 'target':'other';
	// ご利用ガイドとよくある質問のみ[class=mainbg]の高さを調整
	if((ex[0] == 'target')||(ex[1] == 'target')){
	  switch(UA){
		  case 'target':
	  	ph = ($('#sidenavi').height())-81;
		  $('#contentscolumn .mainbg').css('height',ph);
		  break;
	  
	  	case 'other':
	  	ph = ($('#sidenavi').height())-81;
		  $('#contentscolumn .mainbg').css('min-height',ph);
		  break;
		  
	  	default:
		  ph = ($('#sidenavi').height())-81;
		  $('#contentscolumn .mainbg').css('min-height',ph);
	  }
	}
// [フォーム]フォーム部品スタイル調整
  $('input[@type="checkbox"]').css('margin','0 7px 0 0');

// [マイページ]一覧系スタイル調節
  $('.mypagelist .title').next().css('background-image','none');
  $('.mypagelist .mypagetb tr:first td,.mypagelist .mypagetb tr:first .section').css('background-image','none');
  $('.mypagelist:last').css('margin-bottom','0');
  $('.mypagelist + .databtn').css('margin-top','28px');
  $('#contentscolumn .notitle.mypagelist .section:first,#contentsall .notitle.mypagelist .section:first').css('background-image','none');
  $('.buy tr:eq(1) th,.buy tr:eq(1) td').css('background-image','none');
	($('.note li:first-child').text().indexOf('・')==0) ? $('.note').toggleClass('note03') : null;

// [カテゴリ]トップスタイル調節
  $('.pickup > .bg > .clear:last').css('background-image','none');

// 検索結果
  $('.reitem:last').css('margin-bottom','18px');

// テーブル行背景
  $('.mypagelist .mypagetb tr:odd,.mypagelist .section:odd').addClass('odd');
  $('.mypagelist .mypagetb tr:even,.mypagelist .section:even').addClass('even');
  $('.dvdinfo .next,.dvdinfo .prev').css('cursor','pointer');

// [カテゴリトップ]DVD情報カウント
  dvdcounter = $('.dvditem li').size();
//  if((dvdcounter%2)!=0){
//  $('.dvdinfo li:last').after('<li>&nbsp;</li>');
//  }
//  dvdcounter = Math.ceil(dvdcounter/2);

  
//  num=1;
//  $('#count').html(num+'\/'+dvdcounter);
//$('#count').html(dvdcounter);
//$('.next').click(function(){
//	num++;
//	if(num > dvdcounter){
//		num = 1;
//	}
//	$('#count').html(num+'\/'+dvdcounter);
//  });
//  $('.prev').click(function(){
//	num--;
//	if(num < 1){
//		num = dvdcounter;
//	}
//	$('#count').html(num+'\/'+dvdcounter);
//  });
	
// [カート]配送先の選択：フォーム開閉
  $('input:radio[value=new],input:radio[id=mr_form_payno1]').is(':checked') ? $('.expand').css('display','block') : $('.expand').css('display','none');
  $('input:radio[value=new],input:radio[id=mr_form_payno1]').click(function(){
    $('.expand').slideDown('slow');
  });
  $('input:radio').not('input:radio[value=new],input:radio[id=mr_form_payno1]').click(function(){
    $('.expand').slideUp('slow');
  });

// [カート]配送先の選択：背景
  $('.cartop input:radio:checked').parent().parent().parent().parent().parent().addClass('cartdf');
  $('.cartop input:radio').click(function(){
  $('input:radio[name^=deli_select]:checked,input:radio[name^=payno]:checked').parent().parent().parent().parent().parent().addClass('cartdf');
  $('input:radio').not('input:radio:checked').each(function(){
		$(this).parent().parent().parent().parent().parent().removeClass('cartdf');
  });
  });
	
	
  });

function getCount() {
	return dvdcounter;
}

// [マイページ]チェックボックス全選択・全解除
function allcheck(obj){
	for(var i=0;i<document.forms[1].length;i++){
		if(document.forms[1][i].type=="checkbox"){
			document.forms[1][i].checked = obj.checked;
		}
	}
}

function allcheck02(obj2){
	if(obj2.checked == false){
		document.forms[1].allcheck01.checked = false;
		document.forms[1].allcheck02.checked = false;
		return;
	}

	for(var i=0;i<document.form.length;i++){
		if(document.forms[1][i].type=="checkbox"){
			if(document.forms[1][i].checked==false &&	document.forms[1][i].name!="allcheck01" && document.forms[1][i].name!="allcheck02"){
				return;
			}
		}
	}
	document.forms[1].allcheck01.checked = true;
	document.forms[1].allcheck02.checked = true;
}


// [詳細検索]チェックボックス全選択・全解除
$(function(){
		   $('#allcheck').click(function(){
										 $('.categoryd input:checkbox[name^=jn]').attr('checked', this.checked);
										 });
		   });

// ポップアップ
function popup(url,w,h){
	window.open(url,"openwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
}

// 郵便番号から住所を登録
function setAddress(zip1, zip2, prf_no, address1, address2){
	var zip1 = eval("document.form." + zip1 + ".value");
	var zip2 = eval("document.form." + zip2 + ".value");

	if(!zip1.match(/[0-9][0-9][0-9]/g)) {
		return false;	
	}
	if(!zip2.match(/[0-9][0-9][0-9][0-9]/g)) {
		return false;	
	}

	var successCallback = function (response)
	{
		var res_array = response.split(',');
		var obj_prf_no = eval("document.form." + prf_no);
		var obj_address1 = eval("document.form." + address1);
		var obj_address2 = eval("document.form." + address2);

		obj_prf_no.selectedIndex = res_array[0];
		obj_address1.value = res_array[1];
		obj_address2.value = res_array[2];
	};
	var errorCallback = function (xml, status, e)
	{
		alert('error');
	};
		$.ajax({
			'type':     "POST",
			 'url':      "/setaddress.php",
			'data':     {'zip1': zip1, 'zip2': zip2},
			'success':  successCallback,
			'error':    errorCallback
		});

	return false;
}

// 問い合わせフォームの内容を変更
function changeFormContents(){
	if (document.form.cnt_type.selectedIndex == 0) {
		 $("#item").show();
		 $("#item_no").show();
		 $("#msg").html("※商品の返品・交換・キャンセルをご希望される場合は、その理由も明記いただけますようお願いいたします。");
	}
	else {
		 $("#item").hide();
		 $("#item_no").hide();
		 $("#msg").html("※お問い合わせの際は、ブラウザ・OS・接続環境を明記してください。情報が不足している場合、回答にお時間が掛かる場合があります。");
	}
}


//  チェックされてるか
function checkAllCkBox(form)
{
	var fg = false;
	for (i = 0; i < form.elements.length; i++ ) {
		
		// エレメントがチェックボックスの時に処理を行う。
		if (form.elements[i].type == "checkbox" ) {
			// チェックボックスがONの時はその値を設定する。
			if (form.elements[i].checked == true) {
				fg = true;
				break;
			}
		}
	}

	if( fg == false ){
		alert('チェックボックスにチェックをいれてください');
		return false;
	}
	

	return fg;
}

//  チェックされてるか
function checkSKU(form, gdm_no)
{
	
	var fg = false;
	var sku;
	
	for (i = 0; i < form.elements.length; i++ ) {

		// エレメントがチェックボックスの時に処理を行う。
		if (form.elements[i].type == "radio" ) {
			// チェックボックスがONの時はその値を設定する。
			if (form.elements[i].checked == true) {
				sku = form.elements[i].value;
				fg = true;
				break;
			}
		}
	}

	if( fg == false ){
		alert('チェックボックスにチェックをいれてください');
		return false;
	}
	
	location.href = 'index.php?no='+gdm_no+'&md=al&sku=' + sku;

	return fg;
}

//$('#item').html('aaaa');

// カートの新しい住所に送るときの住所フォームの表示切替
//function viewNewAddress(thisname,val,tablename){
//
//	obj = document.getElementsByName(thisname);
//
//	for (var i = 0; i < obj.length; i++){
//		if(obj[i].checked == true){
//			thisval = obj[i].value;
//		}
//	}
//	if( thisval == val ){
//		document.getElementById(tablename).style.display = 'block';
//	}else{
//		document.getElementById(tablename).style.display = 'none';
//	}
//
//}


