/***************************************************************************************
	Created by Songhyun Dong with Editplus 2.11c on 
----------------------------------------------------------------------------------------
	Description :
	- system script
****************************************************************************************/
function send_memo(mm_uid){
	var key = "index.php?db=member&actKey=memo&sKey=compose.simple&hide_header=1&hide_memo_header=1&mm_uid=" + mm_uid;
	window.open(key,
	'Memo',
	'toolbar=no,location=(20,20),directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=500'
	);
}

function view_info(mm_uid){
	var key = "index.php?db=member&actKey=profile&hide_header=1&hide_memo_header=1&mm_uid=" + mm_uid;
	window.open(key,
	'profile',
	'toolbar=no,location=(20,20),directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=600'
	);
}

function sman(key){
	var url = "sman.php?key=" + key;
	window.open(url,
	'sMan',
	'toolbar=no,location=(20,20),directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=900,height=600'
	);
}

function editDoc(db, key){
	var url = "sman.php?control=group&actKey=edit.docs&id="+ db +"&key=" + key;
	window.open(url,
	'sMan',
	'toolbar=no,location=(20,20),directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=900,height=600'
	);
}

function send_mail(mail){
	var key = "index.php?db=member&actKey=mailer&hide_header=1&hide_memo_header=1&mail=" + mail;
	window.open(key,
	'mailer',
	'toolbar=no,location=(20,20),directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=600'
	);
}

function go_homepage(mm_uid){
	alert("Coming soon!");
}

function goMenu(menu){
	location.href= menu;
}

function selectWindow(opt){
	var key = "index.php?db=member&actKey=memo&sKey=selectMB&hide_header=1&hide_memo_header=1&opt=" + opt;
	window.open(key,
	'selectWindow',
	'toolbar=no,location=(20,20),directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=600'
	);
}

function mbSystem(actKey, option){
	var key = "index.php?db=member&actKey=" + actKey;
	if(option == 1){
		key += "&hide_header=1";
		window.open(key,
		'memberSystem',
		'toolbar=no,location=(20,20),directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=640,height=600'
		);
	}else{
		location.href = key;
	}
}

function memberLayer(mm_uid, option){
	/*
		- option
		0 : nothing
		1 : email only
		2 : home only
		3 : email + home
	*/

	var iLyr = "<table width=100 border=0 cellpadding=0 cellspacing=0>";
	iLyr += "<tr><td><a style='cursor:hand' onclick=\'send_memo("+ mm_uid +")\'>&nbsp;- send memo</a></td></tr>";
	iLyr += "<tr><td><a style='cursor:hand' onclick=\'view_info("+ mm_uid +")\'>&nbsp;- view info</a></td></tr>";
	if(option == 1){
		iLyr += "<tr><td><a style='cursor:hand' onclick=\'send_mail("+ mm_uid +")\'>&nbsp;- send mail</a></td></tr>";
	}else if(option == 2){
		iLyr += "<tr><td><a style='cursor:hand'>&nbsp;- homepage</a></td></tr>";
	}else if(option == 3){
		iLyr += "<tr><td><a style='cursor:hand' onclick=\'send_mail("+ mm_uid +")\'>&nbsp;- send mail</a></td></tr>";
		iLyr += "<tr><td><a style='cursor:hand' onclick=\'go_homepage("+ mm_uid +")\'>&nbsp;- homepage</a></td></tr>";
	}
	iLyr += "</table>";

	src(iLyr, 'info');
}

// extract from phpMyAdmin
var marked_row = new Array;
function tableBgChange(colorDefault,pointColor,markColor,theRow,theRowNum,theAction){
	var theDefaultColor = colorDefault;
	var thePointerColor = pointColor;
	var theMarkColor = markColor;
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
}