/**
 * js/pageControl.js
 * Revision 1.0
 * Date 2004/11/25
 */

/**
 * requireCheck
 * 記入必須項目のチェック
 * @author Dome
 * @since version 1.0.0
 * @param INPUT（対象入力項目）
 */
function requireCheck(INPUT) {

	var requireFields;
	var fieldNames;
    var fieldCheck;
    var fieldsNeeded;

	/*requireFields = new Array("name", "mail", "message");
	fieldNames = new Array("お名前", "メールアドレス", "お問い合わせ内容");
	*/
	requireFields = new Array("mail", "message");
	fieldNames = new Array("メールアドレス", "お問い合わせ内容");
    fieldCheck   = true;
    fieldsNeeded = "";

    for (var fieldNum = 0; fieldNum < requireFields.length; fieldNum++) {
        if ((INPUT.elements[requireFields[fieldNum]].value == "") ||
            (INPUT.elements[requireFields[fieldNum]].value == " ")) {
			if (fieldsNeeded.length > 0) {
            	fieldsNeeded += ", ";
			}
			fieldsNeeded += fieldNames[fieldNum];
            fieldCheck = false;
        }
    }
	
    if (fieldCheck == true) {
		return true
    } else {
        alert ("\n以下の項目をご入力ください。\n\n" + fieldsNeeded);
        return false;
    }

}


/**
 * confirmDelete
 * 削除確認
 * @author Dome
 * @since version 1.0.0
 */
function confirmDelete() {

	if (confirm("削除しますか？")) {
		return true;
	} else {
		return false;
	}

}


/**
 * confirmReset
 * リセット確認
 * @author Dome
 * @since version 1.0.0
 */
function confirmReset() {

	if (confirm("リセットしますか？")) {
		return true;
	} else {
		return false;
	}

}


/**
 * magazineWindowOpen
 * @author Dome
 * @since version 1.0.0
 * @param ptype（Getパラメータ）
 */
function magazineWindowOpen(ptype) {

	window.open("about:blank", "MMSUB", "width=500, height=200, scrollbars=yes, status=yes, resizable=yes");
	document.frmMagazine.target = "MMSUB";
	document.frmMagazine.action = "http://api.lolipop.jp/api/api.php?cmd=mm&type=" + ptype;
	document.frmMagazine.submit();
	
}


/**
 * borderOutset
 * borderStyleをoutsetへ
 * @author Dome
 * @since version 1.0.0
 * @param targetID（対象ID）
 */
function borderOutset(targetID) {
	if (window.document.all) {
		window.document.all(targetID).style.borderStyle = 'outset';
	} else if (window.document.getElementById) {
		window.document.getElementById(targetID).style.borderStyle = 'outset';
	}
}


/**
 * borderSolid
 * borderStyleをsolidへ
 * @author Dome
 * @since version 1.0.0
 * @param targetID（対象ID）
 */
function borderSolid(targetID) {
	if (window.document.all) {
		window.document.all(targetID).style.borderStyle = 'solid';
	} else if (window.document.getElementById) {
		window.document.getElementById(targetID).style.borderStyle = 'solid';
	}
}


/**
 * openBlank
 * 対象ページを別ウィンドウで開く
 * @author Dome
 * @since version 1.0.0
 * @param targetURL（対象ページURL）
 */
function openBlank(targetURL) {

	window.open(targetURL, "_blank");

}


/**
 * openDialog
 * ダイアログを表示
 * @author Dome
 * @since version 1.0.0
 * @param targetURL（対象ページURL）
 * 　　   targetID（対象オブジェクトID）
 * 　　   targetValue（対象オブジェクト値）
 */
function openDialog(targetURL, targetID, targetValue) {
	
	var ret;
	
	ret = window.showModalDialog(targetURL, targetValue, "status:no;dialogWidth:725px;dialogHeight:540px");
	
	if (ret != null) {
		if (ret.length > 0) {
			if (window.document.all) {
				window.document.all(targetID).value = ret;
			} else if (window.document.getElementById) {
				window.document.getElementById(targetID).value = ret;
			}
		}
	} else {
		if (window.document.all) {
			window.document.all(targetID).value = "";
		} else if (window.document.getElementById) {
			window.document.getElementById(targetID).value = "";
		}
	}

}

/**
 * openSubWindow Method（サブウィンドウで開く）
 * @param	targetURL（対象ページのURL）
 * @param	targetHeight（高さ）
 * @param	targetWidth（幅）
 */
function openSubWindow(targetURL, targetHeight, targetWidth) {

	window.open(targetURL, "subWindow", "width=" + targetWidth + ", height=" + targetHeight + ", top=0, left=0, scrollbars=1");
	
}


/**
 * linkSubmit
 * aタグにSubmit効果を
 * @author Dome
 * @since version 1.0.0
 * @param targetForm（対象フォーム）
 */
function linkSubmit(targetForm) {

	window.document.forms[targetForm].submit();

}


/**
 * pageBack
 * 前のページに戻る
 * @author Dome
 * @since version 1.0.0
 */
function pageBack() {

    history.back();
	
}


/**
 * changeHeightSet
 * 親要素の高さを指定
 * @author Dome
 * @since version 1.0.0
 * @param contentsHeight（コンテンツ要素の高さ）
 */
function changeHeightSet(contentsHeight) {

	var lineboxHeight;	// ラインボックス要素の高さ
	var mainboxHeight;	// メインボックス要素の高さ
	
	mainboxHeight = contentsHeight + 170;
	lineboxHeight = mainboxHeight + 150;
	
	if (window.document.all) {
		window.document.all("box1").height = lineboxHeight;
		window.document.all("box2").height = mainboxHeight;
		window.document.all("contents").height = contentsHeight;
	} else if (window.document.getElementById) {
		window.document.getElementById("box1").height = lineboxHeight;
		window.document.getElementById("box2").height = mainboxHeight;
		window.document.getElementById("contents").height = contentsHeight;
	}
	
}


/**
 * setFlash Method
 * Flash表示関連タグの出力
 * 「このコントロールをアクティブ化して使用するにはクリックしてください。」対策
 * @param	width	width属性
 * @param	height	height属性
 * @param	id		id属性、name属性
 * @param	align	align属性
 * @param	src		src属性、value属性
 * @param	bgcolor	bgcolor属性	
 */
function setFlash(width, height, id, align, src, bgcolor) {

	var tag;

	tag = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="' + id + '" align="' + align + '">';
	tag += '<param name="movie" value="' + src + '">';
	tag += '<param name="quality" value="high">';
	tag += '<param name="bgcolor" value="' + bgcolor + '">';
	tag += '<embed src="' + src + '" quality="high" bgcolor="' + bgcolor + '" width="' + width + '" height="' + height + '" name="' + id + '" align="' + align + '" type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/go/getflashplayer"></embed>';
	tag += '</object>';
	
	document.write(tag);

}

/**
 * setWM Method
 * Flash表示関連タグの出力
 * 「このコントロールをアクティブ化して使用するにはクリックしてください。」対策
 * @param	width
 * @param	height
 * @param	autoStart
 * @param	url
 */
function setWM(width, height, autoStart, url) {

	var tag;

	tag = '<object width="' + width + '" height="' + height + '" data="' + url + '" type="video/x-ms-wmv">\n';
	tag += '<param name="src" value="' + url + '" >\n';
	tag += '<param name="autoStart" value="' + autoStart + '" >\n';
	tag += '</object>\n';
	
	document.write(tag);

}
