/*
 * ============================================================================
 * 共通 javascripts
 *                                   最終更新 2007/06/15 15:00 add By TOZAWA.
 * ============================================================================
 */

// ----	-------------------------------------------------------------------- //
// ----	関数一覧 ----------------------------------------------------------- //
/*
< 01 >	// ----	(04) 日時短縮表示
070523	function d_time_view($src, $sw)
< 02 >	// ----	(04) メニューリンク有り表示
070522	function menu_js_lite($bgc, $tourl)

	------- (0090) -----------------------------------------------------
*/
// ----	-------------------------------------------------------------------- //
// ----	-------------------------------------------------------------------- //

// ----	削除確認 --------------------------------------------------------------
//						2007/06/13 17:00 add by TOZAWA.
// ----	-----------------------------------------------------------------------
function del_chk(src)
{
	if (window.confirm("削除します\nよろしいですか？")) {
		location.href = src;
	}
}

// ----	素材削除確認 ----------------------------------------------------------
//						2007/06/30 21:30 add by TOZAWA.
// ----	-----------------------------------------------------------------------
function del_mate_chk(src)
{
	if (window.confirm("素材を削除します\n削除すると、この素材を使用している全てのコンテンツで\n素材が表示されなくなります。\nよろしいですか？")) {
		location.href = src;
	}
}

// ----	公開確認 --------------------------------------------------------------
//						2007/06/13 17:00 add by TOZAWA.
// ----	-----------------------------------------------------------------------
function view_chk(src)
{
	if (window.confirm("公開すると、その他のテストが非公開となります。\nよろしいですか？")) {
		location.href = src;
	}
}

// ----	公開確認 --------------------------------------------------------------
//						2007/06/13 17:00 add by TOZAWA.
// ----	-----------------------------------------------------------------------
function edit_chk(src)
{
//	if (window.confirm("編集します\nよろしいですか？")) {
		location.href = src;
//	}
}

// ----	公開確認 --------------------------------------------------------------
//						2007/06/13 17:00 add by TOZAWA.
// ----	-----------------------------------------------------------------------
function tourl(src)
{
	location.href = src;
}

// ----	公開確認 --------------------------------------------------------------
//						2007/06/13 17:00 add by TOZAWA.
// ----	-----------------------------------------------------------------------
function tourl_submit(frm,src)
{
	document.frm.submit();
	location.href = src;
}

// ----	マッチング入力チェック ------------------------------------------------
//						 2007/06/15 15:10 add by KONDO.
// ----	-----------------------------------------------------------------------
function chk_match(frm)
{
	var length = frm.elements.length;
	var item = "";
	var items = "";

	n = 0; checked_count = 0;
	while (n < length) {
		if (frm.elements[n].type=="radio") {
//			item = frm.elements[n].name+" = "+frm.elements[n].value+", ";
//			items = items+item+"\n";
			if (frm.elements[n].checked) {
				checked_count++;
			}
		}

		n++;
	}
	if (checked_count!=10) {
		alert("あなたのチェックした数 "+checked_count+" ケ所\nあと "+(10-checked_count)+" ケ所チェックしてください");
	} else {
		frm.submit();
	}
}



function replaceEle(){
	if(document.getElementById){
//		var obj = document.getElementById("menu");
//		obj.innerHTML = obj.innerHTML.replace(/<dt>/gi, '<dt onmouseover="popupMenu(this);" onmouseout="hiddenMenu(this);">');
//		obj.innerHTML = obj.innerHTML.replace(/<li>/gi, '<li onmouseover="popupMenu2(this);" onmouseout="hiddenMenu2(this);">');
	}
}
	
function popupMenu( obj ){
	var menu = obj.getElementsByTagName("ul").item(0);
	if(menu){
		menu.style.display = "block";
		openShim(obj,menu);
	}
	
}
function popupMenu2( obj ){
	if(obj.tagName.match(/li/i)){
		obj.style.backgroundColor = "#fbdc00";
	}
}
	
function hiddenMenu( obj ){
	var menu = obj.getElementsByTagName("ul").item(0);
	if(menu){
		menu.style.display = "none";
		closeShim(obj);
	}
	
}
function hiddenMenu2( obj ){
	if(obj.tagName.match(/li/i)){
		obj.style.backgroundColor = "#ffffff";
	}
}

//Opens a shim, if no shim exists for the menu, one is created
function openShim(menu,menuItem)
{
    if (menu==null) return;
    var shim = getShim(menu);
    if (shim==null) shim = createMenuShim(menu,getShimId(menu));
    
    //Change menu zIndex so shim can work with it
    menu.style.zIndex = 100;
    
    var width = (menu.offsetWidth == 0 ? menuItem.renderedWidth : menu.offsetWidth);
    var height;
    
    if (menu.offsetHeight == 0)
    {
        var menus = getMenuItemCount(menu);
        height = menuItem.renderedHeight * menus;
    }
    else
    {
        var height = menu.offsetHeight;
    }
    
    shim.style.width = width;
    shim.style.height = height;
    shim.style.top = menu.style.top;
    shim.style.left = menu.style.left;
    shim.style.zIndex = menu.style.zIndex - 1;
    shim.style.position = "absolute";
    shim.style.display = "block";
}

//Closes the shim associated with the menu
function closeShim(menu)
{
    if (menu==null) return;
    var shim = getShim(menu);
    if (shim!=null) shim.style.display = "none";
}

//Creates a new shim for the menu
function createMenuShim(menu)
{
    if (menu==null) return null;

    var shim = document.createElement("<iframe scrolling='no' frameborder='0'"+
                                      "style='position:absolute; top:0px;"+
                                      "left:0px; display:none'></iframe>"); 
    shim.name = getShimId(menu);
    shim.id = getShimId(menu);
    //Unremark this line if you need your menus to be transparent for some reason
    //shim.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";

    if (menu.offsetParent==null || menu.offsetParent.id=="") 
    {
//        window.document.body.appendChild(shim);
    }
    else 
    {
        menu.offsetParent.appendChild(shim); 
    }

    return shim;
}

//Creates an id for the shim based on the menu id
function getShimId(menu)
{
    if (menu.id==null) return "__shim";
    return "__shim"+menu.id;
}

//Returns the shim for a specific menu
function getShim(menu)
{
    return document.getElementById(getShimId(menu));
}

function getMenuItemCount(menu)
{
    var count = 0;
    var child = menu.firstChild;

    while (child)
    {
        if (child.nodeName=="DIV") count = count + 1;
        child = child.nextSibling;
    }
    return count;    
}
