﻿function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var imgObj = new Image();
function showImgWin(imgName) {
	imgObj.src = imgName;
	setTimeout("createImgWin(imgObj)", 100);
}
function createImgWin(imgObj) {
	if (! imgObj.complete) {
		setTimeout("createImgWin(imgObj)", 100);
		return;
	}
	imageWin = window.open("", "imageWin",
	"width=" + imgObj.width + ",height=" + imgObj.height);
	imageWin.document.write("<html><body style='margin:0'>");
	imageWin.document.write("<a href='JavaScript:self.close();'><img src='" + imgObj.src + "' border='0' title='"+imgObj.src+"'></a>");
	imageWin.document.write("</body><html>");
	imageWin.document.title = imgObj.src;
}

function openMapWin(url) {
	var address = document.getElementsByName("address")[0].value;
	var objPasirh = document.getElementsByName("parish")[0];
	var parish = objPasirh.options[objPasirh.selectedIndex].text;
	queryString = "?address=" + encodeURIComponent(parish) + encodeURIComponent(address) + "&zoom=" + document.getElementById("zoom").value;
	window.open(url + queryString, "map", "width=590,height=500");
}

function submitForm(actionName){
    with(document.forms[0]){
        action = actionName;
        submit();
    }
    return false;
}

function mapMarker() {
    GEvent.addListener(map, 'click', function(overlay, point) {

      if (marker) {
        // 前回のマーカーを消す
        map.removeOverlay(marker);
      }

      if (point) {

        document.getElementById("show_x").value = point.x;
        document.getElementById("show_y").value = point.y;

        marker = createMarker(point);
        map.addOverlay(marker);

      }
      
      document.getElementById("zoom").value = map.getZoom();
      
    });

    GEvent.addListener(map, 'moveend', function(overlay, point) {
    	document.getElementById("zoom").value = map.getZoom();
    });
}

function setMapInfo() {

	window.opener.document.getElementById("lon").value = document.getElementById("show_x").value;
	window.opener.document.getElementById("lat").value = document.getElementById("show_y").value;
	window.opener.document.getElementById("zoom").value = document.getElementById("zoom").value;
	window.close();
}

function setInnerURL(url, param_id) {
	var id = window.document.getElementById(param_id).value;

	window.opener.document.getElementById("pickup_url").value = url + id;
	window.close();

}

function blurText(srch){
	keyword = document.forms[srch].freeword.value;
	if(keyword==""){
		document.forms[srch].freeword.value = "フリーワードで探す";
		document.forms[srch].freeword.style.color = "#808080";
	}
}
function focusText(srch){
	keyword = document.forms[srch].freeword.value;
	document.forms[srch].freeword.style.color = "#000000";
	if(keyword=="フリーワードで探す"){
		document.forms[srch].freeword.value = "";
	}
}

function submitText(srch){
	keyword = document.forms[srch].freeword.value;
	document.forms[srch].freeword.style.color = "#000000";
	if(keyword=="フリーワードで探す"){
		document.forms[srch].freeword.value = "";
	}
	document.forms[srch].submit();
}

function blurText2(srch){
	keyword = document.forms[srch].keywords.value;
	if(keyword==""){
		document.forms[srch].keywords.value = "フリーワードで探す";
		document.forms[srch].keywords.style.color = "#808080";
	}
}
function focusText2(srch){
	keyword = document.forms[srch].keywords.value;
	document.forms[srch].keywords.style.color = "#000000";
	if(keyword=="フリーワードで探す"){
		document.forms[srch].keywords.value = "";
	}
}
function selectShop (id, name, type) {

	window.opener.document.forms[0].shop_name.value = name;
	window.opener.document.forms[0].shop_id.value = id;
	window.opener.document.forms[0].shop_type.value = type;
	window.opener.document.getElementById("view_name").innerHTML = name;

	window.close();
}

var isCheking = false;
function checkId() {
	var id = document.getElementById("pic_member_id").value;

	if (id == '') {
		return;
	}
	if (isCheking) {
		alert("会員IDをチェック中です。");
		return;
	}
	isCheking = true;

	HTML_AJAX.defaultServerUrl = "MemberScript.php";
	HTML_AJAX.call("MemberScript",
		   "chkId",
		   function(result) {
                result = eval(result);
		   		if (result) {
		   			alert("「" + id + "」は登録可能です。");
		   		} else {
		   			alert("「" + id + "」は登録できません。");
		   		}
		   },
		   id);
	isCheking = false;
}
var isCheking = false;
function checkId4Update() {
	var id = document.getElementById("pic_member_id").value;
	var user_id = document.getElementById("pic_user_id").value;


	if (id == '' || user_id == '') {
		return;
	}
	if (isCheking) {
		alert("会員IDをチェック中です。");
		return;
	}
	isCheking = true;

	HTML_AJAX.defaultServerUrl = "MemberScript.php";
	HTML_AJAX.call("MemberScript",
		   "chkId",
		   function(result) {
                result = eval(result);
		   		if (result) {
		   			alert("「" + id + "」は登録可能です。");
		   		} else {
		   			alert("「" + id + "」は登録できません。");
		   		}
		   },
		   id, user_id);
	isCheking = false;
}

var img = new Image();
function showImgWinByRecommend(imgName) {
	img.src = imgName;
	setTimeout("createImgWinRecommend(img)", 100);
}
function createImgWinRecommend(img) {
	if (! img.complete) {
		setTimeout("createImgWinRecommend(img)", 100);
		return;
	}
	
	var width = 950;
	var height = 0;
	if (img.width < width) {
		width = img.width;
		height = img.height;
	} else {
		height = img.height * (width / img.width);
		img.height = height;
		img.width = width;
	}

	imageWin = window.open("", "imageWin",
	"width=" + (parseInt(width) + 18) + ",height=" + height + ",scrollbars=yes");
	imageWin.document.write("<html><body style='margin:0'>");
	imageWin.document.write("<a href='JavaScript:self.close();'><img src='" + img.src + "' border='0' title='"+img.src+"' style=\"width:" + img.width + ";height:" + img.height + ";\"></a>");
	imageWin.document.write("</body><html>");
	imageWin.focus();
	imageWin.document.title = img.src;
}

function getElementsByClass(searchClass) {
    var classElements = new Array();
    var allElements = document.getElementsByTagName("*");
    for (i = 0, j = 0; i < allElements.length; i++) {
	if (allElements[i].className == searchClass) {
	    classElements[j] = allElements[i];
	    j++;
	}
    }
    return classElements;
}
function blurText3(srch){
	keyword = document.form1.keywords.value;
	if(keyword==""){
		document.form1.keywords.value = "フリーワードで探す";
		document.form1.keywords.style.color = "#808080";
	}
}
function focusText3(srch){
	keyword = document.form1.keywords.value;
	document.form1.keywords.style.color = "#000000";
	if(keyword=="フリーワードで探す"){
		document.form1.keywords.value = "";
	}
}
/**
 * 支払方法を選択したときに振り込みを選択で振込期日が選択できるようにする。
 * @param value 支払方法の選択値
 */
function changePaymentWay(value) {
	var transferSelect = document.getElementById("transfer");
	if (value == 2) {
		transferSelect.disabled = false;
	} else {
		transferSelect.options[0].selected = true;
		transferSelect.disabled = true;
	}
}


function createBills(shop_type) {
	var ids = document.getElementsByName('ids[]');
	var idArray = "";
	for (i = 0; i < ids.length; i++) {
		if (i != (ids.length - 1)) {
			idArray += ids[i].value + ",";
		} else {
			idArray += ids[i].value;
		}
	}
	window.open('./bill_create_from_list?shop_type=' + shop_type + '&ids=' + idArray, '請求書作成', 'width=330, height=300, menubar=no, toolbar=no, scrollbars=no');
}

function createSelectBill(shop_type) {
	var ids = document.getElementsByName('ids[]');
	var idArray = "";
	for (i = 0; i < ids.length; i++) {
		if (i != (ids.length - 1)) {
			idArray += ids[i].value + ",";
		} else {
			idArray += ids[i].value;
		}
	}
	window.open('./bill_create_from_select_list?shop_type=' + shop_type + '&ids=' + idArray, '請求書作成', 'width=330, height=300, menubar=no, toolbar=no, scrollbars=no');
}

function checkConfirm() {

	var checkBoxs = document.getElementsByName('unconfirmed[]');

	var isCheck = false;
	
	for (var i = 0; i < checkBoxs.length; i++) {
		
		if (checkBoxs[i].checked == true) {
			
			isCheck = true;
		}
	}
	
	if (isCheck) {
	
		document.form1.submit();
		
	} else {
		
		alert("変更対象にチェックをしてください。");
	}
}
function singleDelete(id) {

	location.href="bill_confirmed_delete_single_confirm?id=" + id;
}
function do_search_engine() {
	
	var txt_value = document.getElementById('txt_search').value;
	var radios = document.getElementsByName('search_engine');
	
	for (i = 0; i < radios.length; i++) {
		if (radios[i].checked) {
			
			if (radios[i].value == "1") {
				document.getElementById('txt_google').value = txt_value;
				document.getElementById('frm_google').submit();
				
			} else if (radios[i].value == "2") {
				document.getElementById('txt_yahoo').value = txt_value;
				document.getElementById('frm_yahoo').submit();
			}
		}
	}
}


var set=0;
function doublePush() {
	if (set == 0) {
		set=1;
	} else {
		var forms = document.getElementsByTagName("form");
		for (var j = 0; j < forms.length; j++) {
			var elements = forms[j].elements;
			for (var i = 0; i < elements.length; i++) {
				if (elements[i].type == "submit") {
					elements[i].disabled = true;
				}
				if (elements[i].type == "button") {
					elements[i].disabled = true;
				}
			}
		}
		return false;
	}
}

