var ure_support = {};

ure_support.hookker = function(original, wrapper){
	return function(){ 
		wrapper.apply(this,arguments); 
		return original.apply(this,arguments); 
	}
}

ure_support.hide_pass = function(){
	var hide_pass = ['100827','100776','100615','100616','100330','100200','100211','100198','100617','100040','100620','100012','100309','100043','100042','100825','100831','100623','100238','100239','100514','100068','100829','100317','100769','100618','100828','100081','100701','100125','100050','100653','100782','100127','100331','100103','100212','100008','100011','100826','100788','100794','100241','100242','100243','100814'];
	jQuery.each(hide_pass,function(){
		$('li:has([name="passfamily-familyId"][value="' + this + '"])').hide();
	});
}

ure_support.remove_country = function(){
	var remove_country = ['UK','ENG','IE','WAL','SCO'];
	jQuery.each(remove_country,function(){
		$('td:has([name="passlist-countryBox"][value="' + this + '"])').remove();
		$('.passsearchform-country > [value="' + this + '"]').remove();
	});
}

ure_support.select_city = function(origin, destination){
	if(origin)
		$('#ptpsearchform-origincityname').val(origin).keyup();
	if(destination)
		$('#ptpsearchform-destinationcityname').val(destination).keyup();
}

$(function(){
	// IOS
	if(navigator.userAgent.toLowerCase().match(/iphone|ipad|ipod|android/)){
		tb_show = ure_support.hookker(tb_show,function() {
			window.location = '#';
		});
	}
	// Notfixed
	//if($('.cart-segment-passengers:contains("この区間の手配は確定していません。")').length)
	if($('.cart-segment-passengers').text().match(/この区間の手配は確定していません。|Segment to be confirmed/))
		tb_init($('a[href="/order/user/ure/privacy"]').attr('href','/info/help/Notfixed.html?TB_iframe=true&height=550&width=700'));
	// NoFlash
	try{
		$('#passsearchform-map').append($('<img src="/img/cart/nomap.gif" />').width($('#passsearchform-map').width()));
	} catch(e) {}
	// Age
	$('.ptpsearchform-extraOptions a').attr('href','/info/help/Age.html?TB_iframe=true&height=600&width=500');
	// Tabindex
	$('.railengine :input').removeAttr('tabindex');
	// H1
	if(window.location.search == '') {
		if($('#cart').length)
			$('#ttlURE').text('自動予約チケット一覧');
		if($('#ptpsearch').length && $('#passsearch').length)
			$('#ttlURE').text('鉄道チケット・パス検索');
	}
	// ATOC Error
	if($('.railengine-message-error').text().match(/ATOC|同時に購入/)) {
		$('#waiting-page').show();
		location.href='/ure/?re_domain=cart&re_oper=overview&te_option=atoc_error';
	}
	if(window.location.search.match(/te_option=atoc_error/))
		tb_show('','/info/help/Cannot.html?TB_iframe=true&height=350&width=700','');
	// PASS LIST
	if($('#passlist-country-type').length || $('#passsearch').length ){
		ure_support.remove_country();
		$('#passlist-passBox').hide();
		ure_support.hide_pass();
		$('#passlist-country-type :checkbox').click(function(){
			ure_support.hide_pass();
		});
	}
});

