// JavaScript Document
//XMLHttpRequestオブジェクト生成
var xmlHttp = createXmlHttpRequest();

//setZip_code();


//郵便番号テキストフィールドのonkeyupイベントで実行される処理。リクエストを生成し、レスポンスを取得
function setZip_code(file){
	//リクエストをオープンする。単に設定がおこなわれるだけで実際の送受信はまだ発生しない
	var url = 'http://'+document.domain+'/user_data/popupjs/php/' + file;
	xmlHttp.open('GET', url, true);
	//バックエンドプログラムからレスポンスを受信し処理を行うためのコールバック関数を用意しておく
	xmlHttp.onreadystatechange = handleHttpEvent;
	//リクエストを送信
	xmlHttp.send(null);
}

//HTTPレスポンスデータを処理し、XMLを解析しフォームに値をはめこむコールバック関数
function handleHttpEvent(){
	//応答が帰ってきた(xmlHttp.readyState == 4)場合で、サーバ処理が成功(xmlHttp.status == 200)した場合
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		// サーバからの応答をXMLDocumentオブジェクトとして取得
		// ここからはXML解析とフォームにデータをはめ込む処理
		var rtnText = xmlHttp.responseText;
		if (rtnText){
			var print_html_inner = document.getElementById('print_html_inner');
			print_html_inner.innerHTML = rtnText;
			var getWidth = getPosWidth();
			var getHeigth = getPosHeight();
			openDiv(getHeigth);
		}
	}
}

function closeDiv(){
	$('#print_html_inner').animate({
							 height: 0 + 'px'
							 }, 1000);
	setTimeout("clearHtml()", 900);
	setTimeout("clearHtml()", 1000);
}
function clearHtml(){
	var print_html_inner = document.getElementById('print_html_inner');
	print_html_inner.innerHTML = "";
	$('#print_html').css({
							 display:'none'
							 });
	$('#print_html_inner').css({
							 display:'none'
							 });
}
function openDiv(height){
	
	$('#print_html').css({
							display:'block',
							height: $('body').height() + 'px',
							backgroundcolor:'#FFFFFF',
							opacity:'0.33'
							 });
	//$('#print_html').fadeTo("fast", 0.33);
	$('#print_html_inner').css({
							top:$(this).scrollTop() + 50 +'px',
							left: ($("body").width() / 2) - ($("#print_html_inner").width() / 2) + 'px',
							display:'block',
							opacity:'1'
							 });
	$('#contentArea').css({
							display:'block',
							opacity:'10'
							 });
	$('#print_html_inner').animate({
							 height: $('#contentArea').height() + 'px'
							 }, 1000);
}

function getPosHeight(){
	var varheight = 0;
	var varwinheight = $('body').height();
	
	if(navigator.userAgent.indexOf("MSIE") != -1){
		if(typeof document.body.style.maxHeight != "undefined"){
			varheight = document.documentElement.clientHeight;
			varheight = (document.documentElement.scrollTop || document.body.scrollTop) + (varheight / 2) - (varwinheight / 2);
		}else{
			varheight = document.body.clientHeight;
			varheight = (document.documentElement.scrollTop || document.body.scrollTop) + (varheight / 2) - (varwinheight / 2);
		}
	}else{
		varheight = document.body.clientHeight;
		//varheight = self.innerHeight;
		varheight = (document.documentElement.scrollTop || document.body.scrollTop) + (varheight / 2) - (varwinheight / 2);
	}
	return varheight;
}
function getPosWidth(){
	var varwidth = document.documentElement.clientWidth || document.body.clientWidth || document.body.scrollWidth;
	var varwinwidth = $('body').width();
	varwidth = (varwidth / 2) - (varwinwidth / 2);
	return varwidth;
}

//ブラウザ別にXMLHttpRequestオブジェクトを生成
function createXmlHttpRequest(){    //Win ie用
    if(window.ActiveXObject){
        try {
            //MSXML2以降用
            return new ActiveXObject("Msxml2.XMLHTTP"); //[1]'
        } catch (e) {
            try {
                //旧MSXML用
                return new ActiveXObject("Microsoft.XMLHTTP"); //[1]'
            } catch (e2) {
                return null;
            }
         }
    } else if(window.XMLHttpRequest){
        //Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
        return new XMLHttpRequest(); //[1]'
    } else {
        return null;
    }
}
