// JavaScript Document
var time = 3000;
var numofitems = 6;

//menu constructor
function menu(allitems,thisitem,startstate){ 
  callname= "GL"+thisitem;
  divname="SUBGLOBAL"+thisitem;  
	this.numberofmenuitems = 6;
	this.caller = document.getElementById(callname);
	this.thediv = document.getElementById(divname);
	this.thediv.style.visibility = startstate;
}
				 
//menu methods
function ehandler(event,theobj){
  for (var i=1; i<= theobj.numberofmenuitems; i++){
	  var shutdiv =eval( "menuitem"+i+".thediv");
    shutdiv.style.visibility="hidden";
	}
	theobj.thediv.style.visibility="visible";
}
				
function closesubnav(event){
  if ((event.clientY <48)||(event.clientY > 107)){
    for (var i=1; i<= numofitems; i++){
      var shutdiv =eval('menuitem'+i+'.thediv');
			shutdiv.style.visibility='hidden';
		}  
	}
}


/**
 * JavaScript for P_BLOG
 *
 * $Id: script.js, 2005/03/19 15:38:53 Exp $
 */


/**
 * Toggle Button DOM
 */
function toggle(targetId) {
    var target = document.getElementById(targetId);
    if (target.style.display == "block") {
        target.style.display = "none";
    } else {
        target.style.display = "block";
    }
    return false;
}


/**
 * ADMIN MODE TABLE STATUS
 */
function selectTables(check){
    var i;
    for (i = 0; i < document.forms.dbtables.tables.length; i++) {
        document.forms.dbtables.tables[i].checked = check;
    }
}



/**
 * INPUT CHECK
 *
 */
function inputCheck() {
    if (document.forms.addform.name.value == '') {
        alert('タイトルが入力されていません。');
        document.forms.addform.name.focus();
        return false;
    } else if (document.forms.addform.category.value == '') {
        alert('カテゴリーが入力されていません。');
        document.forms.addform.category.focus();
        return false;
    } else if (document.forms.addform.comment.value == '') {
        alert('コメントが入力されていません。');
        document.forms.addform.comment.focus();
        return false;
    }
    return true;
}

function inputCheck_e() {
    if (document.forms.addform.name.value == '') {
        alert('No Title');
        document.forms.addform.name.focus();
        return false;
    } else if (document.forms.addform.category.value == '') {
        alert('No Category');
        document.forms.addform.category.focus();
        return false;
    } else if (document.forms.addform.comment.value == '') {
        alert('No Comment');
        document.forms.addform.comment.focus();
        return false;
    }
    return true;
}

function inputCheckBin() {
    if (document.forms.addform.bin_title.value == '') {
        alert('タイトルが入力されていません。');
        document.forms.addform.bin_title.focus();
        return false;
    } else if (document.forms.addform.binfile.value == '') {
        alert('ファイルが選択されていません。');
        document.forms.addform.binfile.focus();
        return false;
    } else if (document.forms.addform.bin_category.value == '') {
        alert('カテゴリーが入力されていません。');
        document.forms.addform.bin_category.focus();
        return false;
    } else if (document.forms.addform.bincomment.value == '') {
        alert('コメントが入力されていません。');
        document.forms.addform.bincomment.focus();
        return false;
    }
    return true;
}

function inputCheckBin_e() {
    if (document.forms.addform.bin_title.value == '') {
        alert('No Title');
        document.forms.addform.bin_title.focus();
        return false;
    } else if (document.forms.addform.binfile.value == '') {
        alert('No File');
        document.forms.addform.binfile.focus();
        return false;
    } else if (document.forms.addform.bin_category.value == '') {
        alert('No Category');
        document.forms.addform.bin_category.focus();
        return false;
    } else if (document.forms.addform.bin_comment.value == '') {
        alert('No Comment');
        document.forms.addform.bin_comment.focus();
        return false;
    }
    return true;
}

/*Input Check for Forum*/
function ForumInputCheck() {
    if (document.forms.addform.user_name.value == '') {
        alert('名前が入力されていません。');
        document.forms.addform.user_name.focus();
        return false;
    } else if (document.forms.addform.title.value == '') {
        alert('タイトルが入力されていません。');
        document.forms.addform.title.focus();
        return false;
    } else if (document.forms.addform.comment.value == '') {
        alert('コメントが入力されていません。');
        document.forms.addform.comment.focus();
        return false;
    } else if (document.forms.addform.user_pass.value == '') {
        alert('パスワードが入力されていません。');
        document.forms.addform.user_pass.focus();
        return false;
    }
    return true;
}

function ForumReplyCheck() {
    if (document.forms.addform.user_name.value == '') {
        alert('名前が入力されていません。');
        document.forms.addform.user_name.focus();
        return false;
    } else if (document.forms.addform.comment.value == '') {
        alert('コメントが入力されていません。');
        document.forms.addform.comment.focus();
        return false;
    } else if (document.forms.addform.user_pass.value == '') {
        alert('パスワードが入力されていません。');
        document.forms.addform.user_pass.focus();
        return false;
    }
    return true;
}

/**
 * CONFIRM DELETION
 *
 */
function confirmDelete() {
    if (document.forms.del.id.value != '') {
        if (! confirm('削除してもよろしいですか？')) {
	    document.forms.del.id.focus();
	    return false;
	}
    }
    return true;
}

function confirmDelete_e() {
    if (document.forms.del.id.value != '') {
        if (! confirm('OK to delete this?')) {
	    document.forms.del.id.focus();
	    return false;
	}
    }
    return true;
}


/**
 * TAG BUTTON FUNCTIONS
 *
 * Implemented : by Gabriele Caniglia <www.musimac.it>
 * Modified    : by Kazufumi Tomori
 *
 */

/* --- BASE FUNCTION ---- */
function insertAtCursor(comment, myValue) {
    //IE support
    if (document.selection) {
        comment.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
    } else if(comment.selectionStart || comment.selectionStart == '0') { //MOZILLA/NETSCAPE support
        var startPos = comment.selectionStart;
        var endPos = comment.selectionEnd;
        comment.value = comment.value.substring(0, startPos) + myValue + comment.value.substring(endPos, comment.value.length);
    } else {
        comment.value += myValue;
    }
}
/*
'tag_value' comes from the HTML markup (DOM API) and explains itself enough; :-)
'bin' is boolean: true for targetting the binaries form textarea, false for the logs form textarea;
*/
function Tag(tag_value, bin) {
	cmt_txt = bin ? document.forms.addform.bincomment : document.forms.addform.comment;
	var TagLookup = {
		'p'			:	'<p></p>',
		'div'		:	'<div class=""></div>',
		'span'		:	'<span class=""></span>',
		'strong'	:	'<strong></strong>',
		'img'		:	'<img src="./resources" width="" height="" alt="" />',
		'a'			:	'<a href="" title=""></a>',
		'ul'		:	'<ul>\n<li></li>\n</ul>',
		'ol'		:	'<ol>\n<li></li>\n</ol>',
		'quote'		:	'<blockquote cite="http://" title="">\n<p></p>\n</blockquote>',
		'br'		:	'<br />',
		'abbr'      :   '<abbr title=""></abbr>',
		'tag'		:	'<>'
	};
    cmt_txt.focus();
    insertAtCursor(cmt_txt, TagLookup[tag_value]);
}


function wrap(elem, cls_val, attr) {
    // Class definition
    if (cls_val != '') {
        cls = ' class="' + cls_val + '"';
    } else {
        cls = '';
    }
    // Attribute
    if (attr != '') {
        attr = ' ' + attr + '=""';
    } else {
        attr = '';
    }
    // Switch by UA 
    if ((document.getSelection) && (!window.opera)) { // for Mozilla
        comment = document.getElementById('comment');
        var selLength = comment.textLength;
        var selStart  = comment.selectionStart;
        var selEnd    = comment.selectionEnd;
        if (selEnd == 1 || selEnd == 2) { selEnd = selLength; }
        var str1 = (comment.value).substring(0, selStart);
        var str2 = (comment.value).substring(selStart, selEnd);
        var str3 = (comment.value).substring(selEnd, selLength);
        comment.value = str1 + '<' + elem + cls + attr + '>' + str2 + '</' + elem + '>' + str3;
        comment.focus();
    } else if ((document.selection) && (!window.opera)) { // for WinIE
        var str = document.selection.createRange().text;
        document.getElementById('comment').focus();
        var sel = document.selection.createRange();
        sel.text = "<" + elem + cls + attr + ">" + str + "</" + elem + ">";
        return;
    } else if (window.getSelection) { // for Safari
        comment = document.getElementById('comment');
        var str = window.getSelection();
        comment.value += '<' + elem + cls + attr + '>' + str + '</' + elem + '>';
        comment.focus();
    } else {
        comment = document.getElementById('comment');
        comment.value += '<' + elem + cls + attr + '></' + elem + '>';
    }
}


function imgSet(num) {
    var fid = document.getElementById('img' + num);
    fid.src = 'file:///' + document.getElementById('myfile' + num).value;
}

function Attach(num) {

    // Get image size
    var fid = document.getElementById('img' + num);
    var fw  = fid.width;
    var fh  = fid.height;

    if (fw == 0) { fw = ''; }
    if (fh == 0) { fh = ''; }
    
    var comment = document.getElementById('comment');
    var fv      = document.getElementById('myfile' + num).value;    
    var fp      = fv.replace(/\\/g, '/').split('/');
    var fn      = fp.length - 1;
    var f       = fp[fn];
    var img_src = '<img src="./resources/%27%20+%20f%20+%20%27" width="' + fw + '"  height="' + fh + '" alt="" />';
    
    if (fv != '') { // If file value is not empty...
        if (document.getSelection) { // for Mozilla
            var selLength = comment.textLength;
            var selStart  = comment.selectionStart;
            var selEnd    = comment.selectionEnd;
            if (selEnd == 1 || selEnd == 2) { selEnd = selLength; }
            var str1 = (comment.value).substring(0, selStart);
            var str2 = (comment.value).substring(selStart, selEnd);
            var str3 = (comment.value).substring(selEnd, selLength);
            comment.value = str1 + img_src + str3;
            comment.focus();
        } else if (document.selection) { // for WinIE
            var str = document.selection.createRange().text;
            document.getElementById('comment').focus();
            var sel = document.selection.createRange();
            sel.text = img_src;
            return;
        } else if (window.getSelection) { // for Safari
            var str = window.getSelection();
            comment.value += img_src;
            comment.focus();
        } else {
            comment.value += img_src;
        }
    } else { // If file is not selected...
        comment.value += '<img src="./resources" width="" height="" alt="" />';
    }
}

/*
==============================================================
clickable cite attribute DOM
==============================================================
original source written by Simon Willson
: http://simon.incutio.com/
*/
function clickableCite() {
    q = document.getElementsByTagName('blockquote');
    for (i=0; i<q.length; i++) {
        cite = q[i].getAttribute('cite')
        if (cite) {
            newlink = document.createElement('a');
            newlink.setAttribute('href', cite);
            newlink.setAttribute('title', cite);
            newlink.appendChild(document.createTextNode('→ Source'));
            newdiv = document.createElement('div');
            newdiv.className = 'citesource';
            newdiv.appendChild(newlink);
            q[i].appendChild(newdiv);
        }
    }
}
window.onload = clickableCite;


/*
==============================================================
Smiley
==============================================================
*/
function smiley(icon) {
    comment = document.getElementById("comment");
	icon = ' ' + icon + ' ';
	comment.value += icon;
}


