/* -----------------------------------------------

functions

----------------------------------------------- */

function open_win(url,width,height) {
	
	//ポップアップ
	var win = window.open(url, "_blank", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=" + width + ",height=" + height + "\"");
	win.focus();
}


//ロールオーバー処理

function initRollOver() {

	//グローバルメニュー

	var image_cache = new Object();

	$("#sub_menu a img").not("[src*='_on.']").each(function(i) {

		var imgsrc = this.src;

		var dot = this.src.lastIndexOf('.');

		var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);

		image_cache[this.src] = new Image();

		image_cache[this.src].src = imgsrc_on;

		$(this).hover(

			function() { this.src = imgsrc_on;

			},

			function() { this.src = imgsrc;

			}

		);

	});

	//サブメニュー

	var image_cache2 = new Object(); 

	$("#sub_menu a img").not("[src*='_on.']").each(function(i) {

		var imgsrc = this.src;

		var dot = this.src.lastIndexOf('.');

		var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);

		image_cache2[this.src] = new Image();

		image_cache2[this.src].src = imgsrc_on;

		$(this).hover(

			function() { this.src = imgsrc_on;

				$(this).parent().parent().css("background", "#fff");

			},

			function() { this.src = imgsrc;

				$(this).parent().parent().css("background", "transparent");

			}

		);

	});

}

//外部リンク
window.onload = function() {

	var node_a = $('a');

	var thisPage = location.href;

	for (var i in node_a) {

		if (node_a[i].className == 'newwin') {

			node_a[i].onclick = function() {

			window.open(this.href, '', '');

			return false;

		};

	}

}

};


//ページスクロール

function pageTopScroll() {

	var scrj = 1;

	var scdist = document.body.parentNode.scrollTop;

	if(scrj<50 && scdist) {

		scdist = (scdist>2) ? Math.ceil(scdist*.2) : 1;

		scrj++;

		scrollBy(0,-scdist);

		setTimeout("pageTopScroll()",20);

	} else {

		scrollTo(0,0);

		scrj = 1;

	}

}

//ページクローズ

function close_win(){

var nvua = navigator.userAgent;

if(nvua.indexOf('MSIE') >= 0){

	if(nvua.indexOf('MSIE 5.0') == -1) {

		top.opener = '';

	}

}

else if(nvua.indexOf('Gecko') >= 0){

	top.name = 'CLOSE_WINDOW';

	wid = window.open('','CLOSE_WINDOW');

}

	top.close();

}


//検索ボックス
$(function(){
	$("input#q").val("")
	   .css("color","#969696");
	$("#wrapper #keybox #searchbox").css("background-position","0 0");
	$("input#q").focus(function(){
		if(this.value == ""){
			$(this).val("").css("color","#000");
			$("#wrapper #keybox #searchbox").css("background-position","0 -26px");
		}
	});
	$("input#q").blur(function(){
		if(this.value == ""){
			$(this).val("")
			     .css("color","#969696");
			$("#wrapper #keybox #searchbox").css("background-position","0 0");
		}
		if(this.value != ""){
			$(this).css("color","#000");
			$("#wrapper #keybox #searchbox").css("background-position","0 -26px");
		}
	});
});


//エクストラバナー
$(function(){
	$( '#extra_bnr' ).scrollFollow( {
		speed: 1200,
		offset: 0,
		killSwitch: 'exampleLink',
		onText: 'Disable Follow',
		offText: 'Enable Follow'
	} );
} );


//郵便番号から住所を検索
function getAddress() {
	zip1 = document.getElementById("post1").value;
	zip2 = document.getElementById("post2").value;
	zipCode = zip1 + zip2;

	if(zipCode == ""){
		alert("郵便番号を入力してください");
	}else{
		var resturl = '/shared/inc/getzip.php';

		//debug
		//alert(zipCode);
		//alert(window.location.protocol);
		//var zipHost = window.location.protocol+"//www.c4m.co.jp/webapi/zip/zip2address.php";
		var zipHost = "http://www.c4m.co.jp/webapi/zip/zip2address.php";

        $.ajax({
//			dataType: 'data',
            url : resturl,
            type : "get",
            data : ({ "zip": zipCode, "request": zipHost }),
            success: function(request) {
//				alert(request);
				inputAddress(request);
            },
			error: function(xhr, status, e) {
				//for debug msg
				//alert(xhr+"----------------------"+status+"-------------------------"+e);
			}
        });
	
	}
}

function inputAddress(req) {
//	var text = req.responseText;
	var text = req;
//	alert(text);
	if ( navigator.appVersion.indexOf( "KHTML" ) > -1 ) {
		var esc = escape( text );
		if ( esc.indexOf("%u") < 0 && esc.indexOf("%") > -1 ) {
			text = decodeURIComponent( esc );
		}
	}
	data = text.split(",");
	document.inputform.address1.selectedIndex = data[0];
	document.getElementById("address2").value = data[2];
}

