function ntjBanner(image,url){
	this.m_image = new Image();
	this.m_image.src = image;
	this.m_url = url;
	this.src = this.m_image.src;
}
ntjBanner.prototype.set=function(img){
	img.src=this.m_image.src;
	var url = this.m_url;
	if(url!=""){
		if(navigator.appVersion.indexOf("MSIE")!=-1){
			img.onmouseover=function(){img.style.cursor = "hand";};
			img.onmouseout=function(){img.style.cursor = "default";};
		}else{
			img.onmouseover=function(){img.style.cursor = "pointer";};
			img.onmouseout=function(){img.style.cursor = "default";};
		}
		img.onclick=function(){window.open(url,'','')};
	}
};
/*
// 全体設定

//
*/

//var header_banner = new ntjBanner("http://www.navitime.co.jp/pcstorage/img/banner_enq.jpg","https://pr.navitime.co.jp/enquete/");
//var header_banner_top = new ntjBanner("http://www.navitime.co.jp/pcstorage/img/banner_quiz.jpg","http://pr.navitime.co.jp/");

// for Default
//var header_banner = new ntjBanner("http://www.navitime.co.jp/pcstorage/img/null.gif","");
//var header_banner_top = new ntjBanner("http://www.navitime.co.jp/pcstorage/img/null.gif","");

//var header_banner = new ntjBanner("http://www.navitime.co.jp/pcstorage/img/banner_wcup.gif","http://www.navitime.co.jp/pcstorage/html/wcup/");
//var header_banner_top = new ntjBanner("http://www.navitime.co.jp/pcstorage/img/banner_wcup.gif","http://www.navitime.co.jp/pcstorage/html/wcup/");

function setPath(p){ path = p;}

function getCopyright(){
	document.write('&copy; ');
	var now = new Date()
	document.write(now.getFullYear());
	document.write(' NAVITIME JAPAN. All Rights Reserved.');
}

function setLoadImages(){
	MM_preloadImages(
				"img/icon_address.gif"
				,"img/icon_address_act.gif"
				,"img/icon_station.gif"
				,"img/icon_station_act.gif"
				,"img/icon_post.gif"
				,"img/icon_post_act.gif"
				,"img/icon_tel.gif"
				,"img/icon_tel_act.gif"
				,"img/icon_spot.gif"
				,"img/icon_spot_act.gif");
}

function openWindow(url,x,y,scrollbar){
	scrollbar = scrollbar == null ? "" : ",scrollbars=yes";
	window.open(url,"","width="+x+",height="+y+",statusbars=yes"+scrollbar);
}

function selectPullDown()
{
	var LCode = document.pullDown.categoryList.value;
	var ACode = document.pullDown.areaList.value;
	
	document.pullDown.LCode.value = LCode;
	document.pullDown.ACode.value = ACode;
    document.pullDown.submit();
	
}

var agent = navigator.userAgent;
var appver = navigator.appVersion;
var navi = navigator.appName;


var isDom = (document.getElementById!=null);
var isOpera = (agent.indexOf("Opera")>-1);
var isIe4 = (document.all && !isDom && !isOpera);
var isIe5 = (document.all && isDom && !isOpera);
var isIe = (isIe4 || isIe5);
var isFF = (agent.indexOf("Firefox")>-1);
var isNN = (navi.indexOf("Netscape",0)>-1 && !isFF);
var isNN4 = (document.layers && isNN);
var isNN6 = (isDom && isNN);
var isWin = (agent.indexOf('Win') != -1);
var isMac = (agent.indexOf('Mac') != -1);
var isSafari = (agent.indexOf("Safari")>-1);
var isChrome = (agent.indexOf("Chrome")>-1);

function getWindowWidth(){

	if(isNN || isOpera || isFF) return window.innerWidth;
	if(isIe5) return document.body.clientWidth;
	return 0;
}
function getWindowHeight(){
	if(isNN || isOpera || isFF) return window.innerHeight;
	if(isIe5) return document.body.clientHeight;
	return 0;
}

function LinkActive(obj){
	obj.style.background="#fff799";
	obj.style.color="#555555";
	obj.style.cursor = "hand";
	obj.className='layeractive';
}
function LinkDefault(obj){
	obj.style.background="#FFFFFF";
	obj.style.color="#4444AA";
	obj.style.textDecoration ="Underline";
	obj.style.cursor = "hand";
	obj.className='layerlink';
}
function LinkSelect(obj){
	obj.style.background="#8888CC";
	obj.style.color="#FFFFFF";
	obj.style.cursor = "default";
	obj.className='layerselect';
}

var m_cookie = document.cookie;
function getCookie(name){
	name+="=";
	m_cookie+=";";
	var start = m_cookie.indexOf(name);
	if(start!=-1){
		var end = m_cookie.indexOf(";",start);
		var value = m_cookie.substring(start+(name.length),end);
			return decodeURL(value);
//			return window.decodeURIComponent ? window.decodeURIComponent(value) : unescape(value);
	}
	return '';
}

function decodeURL(str){
	var s0, i, j, s, ss, u, n, f;
	s0 = "";                // decoded str
	for (i = 0; i < str.length; i++){   // scan the source str
		s = str.charAt(i);
		if (s == "+"){
			s0 += " ";
		}else{
			if (s != "%"){
				s0 += s;
			}else{
				u = 0;          // unicode of the character
				f = 1;          // escape flag, zero means end of this sequence
				while (true) {
					ss = "";    // local str to parse as int
						for (j = 0; j < 2; j++ ) {  // get two maximum hex characters to parse
							sss = str.charAt(++i);
							if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
								ss += sss;          // if hex, add the hex character
							}else{
								--i; break;
							}    // not a hex char., exit the loop
						}
					n = parseInt(ss, 16);           // parse the hex str as byte
					if (n <= 0x7f){u = n; f = 1;}   // single byte format
					if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
					if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
					if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
					if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}    // not a first, shift and add 6 lower bits
					if (f <= 1){break;}             // end of the utf byte sequence
					if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
					else {break;}                   // abnormal, format error
				}
			s0 += String.fromCharCode(u);           // add the escaped character
			}
		}
	}
	return s0;
}

function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            // don't escape
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }
    return s0;
}

function getUser(){
	if(getCookie("info").indexOf(".")==-1) return "";
	return getCookie("info").split(".")[0];
}

function getCarrier(){
	if(getCookie("info").indexOf(".")==-1) return "";
	return getCookie("info").split(".")[1];
}

// 旧Safari対応
if (isSafari && RegExp.rightContext == null) {
	var originalMatch = String.prototype.match;
	String.prototype.match = function (regexp) {
	   var result = originalMatch.apply(this, arguments);
	   if (! result)
	      return null;
	   RegExp.leftContext = this.substring(0, String(this).indexOf(String(result)));
	   RegExp.rightContext = this.substring(String(result).length, this.length);
	   return result;
	};
}

// アクセス集計
function countLog(){
	var imgObj = document.createElement("img");
	var Dt = new Date();
	var year = new String(Dt.getYear() + 1900);
	var month =  Dt.getMonth()+1;
	if(month<10){
		month = '0' + new String(month);
	} else {
		month = new String(month);
	}
	var day =  Dt.getDate();
	if(day<10){
		day = '0' + new String(day);
	} else {
		day = new String(day);
	}
	var hour =  Dt.getHours();
	if(hour<10){
		hour = '0' + new String(hour);
	} else {
		hour = new String(hour);
	}
	var min =  Dt.getMinutes();
	if(min<10){
		min = '0' + new String(min);
	} else {
		min = new String(min);
	}
	var sec =  Dt.getSeconds();
	if(sec<10){
		sec = '0' + new String(sec);
	} else {
		sec = new String(sec);
	}
	
	imgObj.src = "http://" + location.host + "/pcstorage/cntlog/" + year + month + day + hour + min + sec + "?ctl=" + arguments[0].type + "&logId=" + arguments[0].logId;
}
function returnHtmlStr(str){
	if(str==null)return null;
	str = str.replace(/&amp;/g, "&");
	str = str.replace(/&#44;/g, ",");
	str = str.replace(/&#46;/g, ".");
	str = str.replace(/&lt;/g, "<");
	str = str.replace(/&gt;/g, ">");
	str = str.replace(/&quot;/g, '"');
	str = str.replace(/&rsquo;/g, "'");
	return str;	
}

function turnHtmlStr(str){
	if(str==null)return null;
	str = str.replace(/\&/g, "&amp;");
	str = str.replace(/\,/g, "&#44;");
	str = str.replace(/\./g, "&#46;");
	str = str.replace(/\</g, "&lt;");
	str = str.replace(/\>/g, "&gt;");
	str = str.replace(/\"/g, "&quot;");
	str = str.replace(/\'/g, "&rsquo;");
	return str;	
}

var addEvent = null;
if(document.addEventListener){
	addEvent = function(){
		arguments[0].node.addEventListener(arguments[0].type,arguments[0].handler,arguments[0].userCapture);
	};
}else if(document.attachEvent){
	addEvent = function(){
		arguments[0].node.attachEvent("on"+arguments[0].type,arguments[0].handler);
	};
}else{
	addEvent = function(){
		var _type = "on"+arguments[0].type;
		var handler = arguments[0].handler;
		if( "function" === arguments[0].node[_type]){
			var _handler = arguments[0].node[_type];
			var __handler = handler;
			handler = function(){
				_handler();
				__handler();
			}
		}
		arguments[0].node[_type] = handler;
	}
}

function requestAdvCountLog(){
	var httpRequest = null;
	if(typeof window.XMLHttpRequest == 'function') {
		try {
			// Firefox, Opera
			httpRequest = new XMLHttpRequest();
			httpRequest.overrideMimeType('text/xml');
		} catch (e) { //IE9対応
			//何も処理を行わない
		}
	} else if(window.ActiveXObject) {
		// IE
		try {
			httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}else if(typeof window.XMLHttpRequest == 'object') {
		// safari
		httpRequest = new XMLHttpRequest();
		httpRequest.overrideMimeType('text/xml');
	}
	
	httpRequest.abort();
	
	var param = "";
	for(var n in arguments[0].param){
		param += '&' + n + '=' + arguments[0].param[n];
	}
	
	httpRequest.open('GET', arguments[0].url+'?'+param , true);
	if(arguments[1]!=null&&arguments[1]!=undefined&&typeof arguments[1]=='function'){		
		httpRequest.onreadystatechange = (function(){
											var f=arguments[0]; 
											return function(){if(httpRequest.readyState=='4')f();}}
										)(arguments[1]);
	}else{
		httpRequest.onreadystatechange = function() {};
	}
	httpRequest.send(null);
}

function requestAdvCountLogWithLink(){
    var f = (function(){
            var url = arguments[0];
            return function(){location.href = url;};
    })(arguments[0].url);
    requestAdvCountLog(arguments[0].advReqParam,f);
}

// 2011/03/10 バブリング停止用に追加 enokido
function cancelBubble(e) {
	if(window.event) {
		window.event.cancelBubble=true;
		window.event.returnValue=false;
	} else {
		e.cancelBubble=true;
		if(e.preventDefault){
			e.preventDefault();
		}
		if(e.stopPropagation){
			e.stopPropagation();
		}
	}
}

// 非同期通信 ライブラリ非依存
function asynchronousRequest(){
	var httpRequest = null;
	if(typeof window.XMLHttpRequest == 'function') {
		// Firefox, Opera
		httpRequest = new XMLHttpRequest();
		httpRequest.overrideMimeType('text/xml');
	} else if(window.ActiveXObject) {
		// IE
		try {
			httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}else if(typeof window.XMLHttpRequest == 'object') {
		// safari
		httpRequest = new XMLHttpRequest();
		httpRequest.overrideMimeType('text/xml');
	}
	
	var param = "";
	for(var n in arguments[0].param){
			param += n + '=' + arguments[0].param[n] + '&';
	}
	if(param.length > 0){
		param = param.substring(0,param.length-1);
	}
	
	var url = arguments[0].url
	if( arguments[0].method == "GET" ){
		url += "?"+param;
	}
	
	
	httpRequest.open(arguments[0].method, url, true);
	
	if(arguments[0].sucessCBFunc!=null&&arguments[0].sucessCBFunc!=undefined&&typeof arguments[0].sucessCBFunc=='function'){
		httpRequest.onreadystatechange = (function(){
											var sf=arguments[0].sucessCBFunc;
											var ef = function(){};
											if(arguments[0].errorCBFunc!=null&&arguments[0].errorCBFunc!=undefined&&typeof arguments[0].errorCBFunc=='function'){
												ef = arguments[0].errorCBFunc;
											}
											return function(){
													if(httpRequest.readyState=='4'){
														if(httpRequest.status == 200){
															sf(httpRequest);
														}else{
															ef(httpRequest);
														}
													}
	
													}}
										)(arguments[0]);
	}else{
		httpRequest.onreadystatechange = function() {};
	}
	
	
	var postParam = null;
	if( arguments[0].method == "POST" ){
		postParam = param;
		var contentType = arguments[0].contentType || "application/x-www-form-urlencoded; charset=UTF-8";
		httpRequest.setRequestHeader("Content-Type", contentType);
	}
	
	httpRequest.send(postParam);
}

function paramStrToJson(paramStr){
    var paramJson = {};
    if(paramStr.length > 0){
        var arr = paramStr.split("&");
        for(var n = 0; n < arr.length; n++){
            var p = arr[n].split("=");
            paramJson[p[0]] = p[1];
        }
    }
    return paramJson;
}

///////////////////////////
//Touch scroll for iPad
///////////////////////////
var resultFieldTouchScroll = function(){this.initialize(arguments[0]);};
resultFieldTouchScroll.prototype = {
	scrollElm:null,	// scroll element
	lastX:0,		// lastX
	lastY:0,		// lastY
	initialize:function(){
		this.scrollElm = arguments[0].scrollElm;
	},
	touchStartCtl:function(e){
		var pos = this.getTouchPos(e);
		this.setLastPos(pos);
	},
	touchMoveCtl:function(e){
		if(e.touches.length == 1){
			e.preventDefault();
		}
		var pos = this.getTouchPos(e);
		var moveDist = this.getMoveDist(pos);
		this.moveScroll(moveDist);
		this.setLastPos(pos);
	},
	getTouchPos:function(e){
		return {'x':e.touches[0].pageX, 'y':e.touches[0].pageY};
	},
	setLastPos:function(pos){
		this.lastX = pos.x;
		this.lastY = pos.y;
	},
	getMoveDist:function(pos){
		var mx = pos.x - this.lastX;
		var my = pos.y - this.lastY;
		return {'mx':mx, 'my':my};
	},
	moveScroll:function(moveDist){
		if(this.scrollElm != null){
			this.scrollElm.scrollTop -= moveDist.my;
		}
	}
};

////////////////////////////////////
//Execution of binding processing
////////////////////////////////////
var touchScrollList = new Array();
function scrollWithTouchDevice(scrollElmId, targetElmId){
	if (navigator.userAgent.match(/iPad|iPhone|Android/)
		&& document.getElementById(scrollElmId) != null
		&& document.getElementById(targetElmId) != null){
		var scrollElm = document.getElementById(scrollElmId).parentNode;
		var targetElm = document.getElementById(targetElmId);
		var touchScroll = new resultFieldTouchScroll({"scrollElm":scrollElm});
		targetElm.addEventListener("touchstart", function(){touchScroll.touchStartCtl.apply(touchScroll,arguments)}, false);
		targetElm.addEventListener("touchmove", function(){touchScroll.touchMoveCtl.apply(touchScroll,arguments)}, false);
		touchScrollList.push(touchScroll);
	}
}
