/*
-----------------------------------------------------------
シックボックス
-----------------------------------------------------------
*/


//シックボックス表示
function thickbox(elm_id)
{
	try {   
        //クリックの度に画面の初期化
        //document.getElementById("windowContent").src = "https://www.lighthousela.net/reportform/form/?location="+location.href;   
        

        var html = '<iframe id="windowContent" src="https://www.lighthousela.net/reportform/form" frameborder="0" height="600" scrolling="no" width="610"></iframe>';   
        $("#frame").empty().append(html);
          
		document.isOpen = true;
        //var html = $('#'+elm_id).html();
		$("body").append("<div id='TB_overlay' style='position: absolute;top: 0;left: 0;z-index:100;width: 100%;height: 100%;background-color: #000;filter:alpha(opacity=60);opacity: 0.6;'></div>");
		//$("#TB_overlay").show().click(function(e){TB_remove(elm_id);});
		$(window).resize(function(e){TB_position(elm_id);});
		TB_position(elm_id);
		$("#"+elm_id).fadeIn("slow", function(e){onFadeIn(elm_id);});
	} catch(e) {
		alert( e );
	}
}

//シックボックスクローズ
function TB_remove(elm_id) {
	document.isOpen = false;
	$("#frame").empty();
	if(window.opera){ //o6,o7用
		$("#"+elm_id).fadeOut("normal", function(){
			$('#TB_overlay').remove();
			$("#"+elm_id).hide();
		});
	}else if(document.all){ //e4,e5,e6用
		$('#TB_overlay').remove();
			$("#"+elm_id).hide();
	}else if(document.layers){ //n4用
		$("#"+elm_id).fadeOut("normal", function(){
			$('#TB_overlay').remove();
			$("#"+elm_id).hide();
		});
	}else if(document.getElementById){ //n6,n7,m1,s1用
		$("#"+elm_id).fadeOut("normal", function(){
			$('#TB_overlay').remove();
			$("#"+elm_id).hide();
		});
	}
}

function onFadeIn(elm_id){
	$("#"+elm_id).css({display:"block", opacity: "1.0"});
}

function TB_position(elm_id) {
	var width=620;
	var height=450;
	
	updatePopupPosition(width,height,elm_id);
	updateOverlay();
}

function updatePopupPosition(width,height,elm_id){
	//$("#popup").css({display:"none"});
	
	var w = width;
	var h = height;
	
	var width  = clientWidth() - parseInt(w);
	var height = clientHeight() - parseInt(h);
	var left   = (width > 0 ? width : 0) / 2 + scrollLeft();
	var top    = (height > 0 ? height : 0) / 2 + scrollTop();
	$("#"+elm_id).css({left: left+"px", top: top+"px" });
}

function updateOverlay(){
	var pageH = getPageH();
	$("#TB_overlay").css("height",pageH +"px");
}


function clientWidth(){
	return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0;
}

function clientHeight(){
	return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
}

function scrollLeft(){
	return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
}

function scrollTop(){
	return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
}

/*
-----------------------------------------------------------
雑用関数
-----------------------------------------------------------
*/

function parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}


function getPageH(){
	//画面の高さ？
  	if (window.innerHeight && window.scrollMaxY) {	
		return window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		return document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		return document.body.offsetHeight;
  	}
	return 1000;
}

function getScrollPosY() {
    if (typeof window.pageYOffset != 'undefined') {
        return window.pageYOffset;
    }
    else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) {
        return document.documentElement.scrollTop;
    }
    else if (typeof document.body.scrollTop != 'undefined') {
        return document.body.scrollTop;
    }
    return 0;
}