var DHTML = (document.getElementById || document.all || document.layers);

function getObjDiv(divId)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(divId);
	this.style = document.getElementById(divId).style;
  }
  else if (document.all)
  {
	this.obj = document.all[divId];
	this.style = document.all[divId].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[divId];
   	this.style = document.layers[divId];
  }
}
function inviDiv(objId,flag)
{
	if (!DHTML) return;
	var x = new getObjDiv(objId);
	x.style.visibility = (flag) ? 'hidden' : 'visible'
}
function inviDiv_Delayed(objId,flag,delay)
{
	var jsStr = "window.setTimeout('inviDiv(\"" + objId + "\"," + flag + ")'," + delay + ");";
	eval(jsStr);
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function MM_effectShake(targetElement)
{
	Spry.Effect.DoShake(targetElement);
}
function MM_effectHighlight(targetElement, duration, startColor, endColor, restoreColor, toggle)
{
	Spry.Effect.DoHighlight(targetElement, {duration: duration, from: startColor, to: endColor, restoreColor: restoreColor, toggle: toggle});
}
function MM_effectBlind(targetElement, duration, from, to, toggle)
{
	Spry.Effect.DoBlind(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}
function MM_effectGrowShrink(targetElement, duration, from, to, toggle, referHeight, growFromCenter)
{
	Spry.Effect.DoGrow(targetElement, {duration: duration, from: from, to: to, toggle: toggle, referHeight: referHeight, growCenter: growFromCenter});
}
function MM_hide_IntroDiv(e) {
	MM_changeProp('IntroDiv','','visibility','hidden','DIV');
}
function MM_hide_IntroDiv_delayed(delay) {
	window.setTimeout('MM_hide_IntroDiv(true)',delay);
}
//MessageNextMeetingDiv
//MM_changeProp('MessageNextMeetingDiv','','visibility','visible');
function MM_hide_MessageNextMeetingDiv(e) {
	if (e) {
		MM_changeProp('MessageNextMeetingDiv','','visibility','hidden','DIV');
	} else {
		MM_changeProp('MessageNextMeetingDiv','','visibility','visible','DIV');
	}
}
function MM_hide_MessageNextMeetingDiv_delayed(delay) {
	window.setTimeout('MM_hide_MessageNextMeetingDiv(true)',delay);
}
function MM_hide_MessageOfTheDayDiv(e) {
	MM_changeProp('MessageOfTheDayDiv','','visibility','hidden','DIV');
}
function MM_hide_MessageOfTheDayDiv_delayed(delay) {
	window.setTimeout('MM_hide_MessageOfTheDayDiv(true)',delay);
}
function MM_hide_UrgentMessageDiv(e) {
	MM_changeProp('UrgentMessageDiv','','visibility','hidden','DIV');
}
function MM_hide_UrgentMessageDiv_delayed(delay) {
	window.setTimeout('MM_hide_UrgentMessageDiv(true)',delay);
}

function MM_changeProp(objId,x,theProp,theValue) { //v9.0
//  var obj = null; with (document){ if (getElementById) obj = getElementById(objId); }
//  var obj = findObj(objId);
  var obj = null; with (document){ obj =  findObj(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
// Example:
// value1 = 3; value2 = 4;
// messageBox("text message %s and %s", value1, value2);
// this message box will display the text "text message 3 and 4"
function messageBox() {
  var i, msg = "", argNum = 0, startPos;
  var args = messageBox.arguments;
  var numArgs = args.length;
  if(numArgs)  {
    theStr = args[argNum++];
    startPos = 0;  endPos = theStr.indexOf("%s",startPos);
    if(endPos == -1) endPos = theStr.length;
    while(startPos < theStr.length)    {
      msg += theStr.substring(startPos,endPos);
      if (argNum < numArgs) msg += args[argNum++];
      startPos = endPos+2;  endPos = theStr.indexOf("%s",startPos);
      if (endPos == -1) endPos = theStr.length;
    }
    if (!msg) msg = args[0];
  }
  alert(msg);
}// Example: obj = findObj("image1");

function findObj(theObj, theDoc) {

  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}
function expandMe(objId) {
//  var obj = null; with (document){ if (getElementById) obj = getElementById(objId); }
//  var obj = null; with (document){ obj =  findObj(objId); }
	if ( objId.contentDocument ) { // firefox
		objId.height = objId.contentDocument.height;
	} else { // IE
		objId.style.height = objId.contentWindow.document.body.scrollHeight;
	}
//
//  var obj = objId;
//  if (obj) {
//		var h = obj.contentWindow.document.body.scrollHeight;
//		if (obj.height<h) obj.height = h;
//  }
}
function OpenWindow(Page) {
var X = 835;
var Y = 600;
var MX = (screen.availWidth/2)-(X/2);
var MY = (screen.availHeight/2)-(Y/2);
var T = "top="+MY+"px,left="+MX+"px,height="+Y+"px,width="+X+"px,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,fullscreen=0,titlebar=0";
//RWP = window.open(Page,"_blank",T);
RWP = window.open(Page,"OpenWindow",T);
RWP.focus();
}

function MM_jumpMenu(targ,selObj,restore) { //v3.0
	var jo = selObj.options[selObj.selectedIndex].value;
	var js = jo.substring(0,11);

	if (js=='javascript:') {
		js = jo.substring(11);
		//alert("js["+js+"]");
		eval(js);
	} else {
		if (targ!='self') {
			eval("window.open('"+selObj.options[selObj.selectedIndex].value+"','"+targ+"')");
		} else {
			//alert("jo["+jo+"]");
			eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		}
	}
//  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function disableRightClick(e) {
  if(!document.rightClickDisabled) { // initialize
    if(document.layers) {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }
    else document.oncontextmenu = disableRightClick;
    return document.rightClickDisabled = true;
  }
  return false;
}
function MM_iframeSrc(objId,selObj,dir,base) { //v9.0
  var obj = null; with (document){ if (getElementById) obj = getElementById(objId); }
  if (obj){
	var theValue = selObj.options[selObj.selectedIndex].value;
	if (theValue!='') {
	    eval("obj.src='"+dir+theValue+base+"'");
		obj.focus();
	}
  }
}
function MM_iframeSrcReload(selObj,page) { //v9.0
//	var theValue = selObj.options[selObj.selectedIndex].value;
//	var theValue = arr_issue_id[selObj.selectedIndex];
	var theValue = selObj.options[selObj.selectedIndex].value;
	if (theValue!='') {
//	    eval("self.location.href='"+page+"?date="+theValue+"'");
	    eval("self.location.href='"+page+"?issue="+theValue+"'");
	}
}
function reloadMe(page,pos) {
	l = findObj('List').value;
	f = findObj('Filename').value;
//	s = findObj('Subject').value;
//	p = page + '?List='+l+'&Filename='+f+'&Subject='+s+'&pos='+pos;
	p = page + '?List='+l+'&Filename='+f+'&pos='+pos;

	//window.open(p,window.name);
	window.location.href = p;
}
function OpenPreviewWindow(dir) {
	l = findObj('List').value;
	f = findObj('Filename').value;
//	s = findObj('Subject').value;
//	p = 'phpmailer_preview.php?List='+l+'&Filename='+dir+'/'+f+'/index.html&Subject='+s;
	p = 'phpmailer_preview.php?List='+l+'&Filename='+dir+'/'+f+'/index.html';
//	alert(p);
	OpenWindow(p);
}

/* $Id: tbl_change.js,v 1.1 2005/11/23 19:10:30 nijel Exp $ */


/**
 * Modify from controls when the "NULL" checkbox is selected
 *
 * @param   string   the MySQL field type
 * @param   string   the urlencoded field name
 * @param   string   the md5 hashed field name
 *
 * @return  boolean  always true
 */
function nullify(theType, urlField, md5Field, multi_edit)
{
    var rowForm = document.forms['insertForm'];

    if (typeof(rowForm.elements['funcs' + multi_edit + '[' + urlField + ']']) != 'undefined') {
        rowForm.elements['funcs' + multi_edit + '[' + urlField + ']'].selectedIndex = -1;
    }

    // "SET" field , "ENUM" field with more than 20 characters
    // or foreign key field
    if (theType == 1 || theType == 3 || theType == 4) {
        rowForm.elements['field_' + md5Field + multi_edit + '[]'].selectedIndex = -1;
    }
    // Other "ENUM" field
    else if (theType == 2) {
        var elts     = rowForm.elements['field_' + md5Field + multi_edit + '[]'];
        // when there is just one option in ENUM:
        if (elts.checked) {
            elts.checked = false;
        } else {
            var elts_cnt = elts.length;
            for (var i = 0; i < elts_cnt; i++ ) {
                elts[i].checked = false;
            } // end for

        } // end if
    }
    // Other field types
    else /*if (theType == 5)*/ {
        rowForm.elements['fields' + multi_edit + '[' + urlField + ']'].value = '';
    } // end if... else if... else

    return true;
} // end of the 'nullify()' function


/**
 * Unchecks the "NULL" control when a function has been selected or a value
 * entered
 *
 * @param   string   the urlencoded field name
 *
 * @return  boolean  always true
 */
function unNullify(urlField, multi_edit)
{
    var rowForm = document.forms['insertForm'];

    if (typeof(rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']']) != 'undefined') {
        rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']'].checked = false
    } // end if

    if (typeof(rowForm.elements['insert_ignore_' + multi_edit]) != 'undefined') {
        rowForm.elements['insert_ignore_' + multi_edit].checked = false
    } // end if

    return true;
} // end of the 'unNullify()' function

var day;
var month;
var year;
var hour;
var minute;
var second;
var clock_set = 0;

/**
 * Opens calendar window.
 *
 * @param   string      calendar.php parameters
 * @param   string      form name
 * @param   string      field name
 * @param   string      edit type - date/timestamp
 */
function openCalendar(params, form, field, type) {
    window.open("selectdate.php?" + params, "calendar", "width=400,height=200,status=no");
    dateField = eval("document." + form + "." + field);
    dateType = type;
}

/**
 * Formats number to two digits.
 *
 * @param   int number to format.
 * @param   string type of number
 */
function formatNum2(i, valtype) {
    f = (i < 10 ? '0' : '') + i;
    if (valtype && valtype != '') {
        switch(valtype) {
            case 'month':
                f = (f > 12 ? 12 : f);
                break;

            case 'day':
                f = (f > 31 ? 31 : f);
                break;

            case 'hour':
                f = (f > 24 ? 24 : f);
                break;

            default:
            case 'second':
            case 'minute':
                f = (f > 59 ? 59 : f);
                break;
        }
    }

    return f;
}

/**
 * Formats number to two digits.
 *
 * @param   int number to format.
 * @param   int default value
 * @param   string type of number
 */
function formatNum2d(i, default_v, valtype) {
    i = parseInt(i, 10);
    if (isNaN(i)) return default_v;
    return formatNum2(i, valtype)
}

/**
 * Formats number to four digits.
 *
 * @param   int number to format.
 */
function formatNum4(i) {
    i = parseInt(i, 10)
    return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
}

/**
 * Initializes calendar window.
 */
function initCalendar() {
    if (!year && !month && !day) {
        /* Called for first time */
        if (window.opener.dateField.value) {
            value = window.opener.dateField.value;
            if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
                if (window.opener.dateType == 'datetime') {
                    parts   = value.split(' ');
                    value   = parts[0];

                    if (parts[1]) {
                        time    = parts[1].split(':');
                        hour    = parseInt(time[0],10);
                        minute  = parseInt(time[1],10);
                        second  = parseInt(time[2],10);
                    }
                }
                date        = value.split("-");
                day         = parseInt(date[2],10);
                month       = parseInt(date[1],10) - 1;
                year        = parseInt(date[0],10);
            } else {
                year        = parseInt(value.substr(0,4),10);
                month       = parseInt(value.substr(4,2),10) - 1;
                day         = parseInt(value.substr(6,2),10);
                hour        = parseInt(value.substr(8,2),10);
                minute      = parseInt(value.substr(10,2),10);
                second      = parseInt(value.substr(12,2),10);
            }
        }
        if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
            dt      = new Date();
            year    = dt.getFullYear();
            month   = dt.getMonth();
            day     = dt.getDate();
        }
        if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
            dt      = new Date();
            hour    = dt.getHours();
            minute  = dt.getMinutes();
            second  = dt.getSeconds();
        }
    } else {
        /* Moving in calendar */
        if (month > 11) {
            month = 0;
            year++;
        }
        if (month < 0) {
            month = 11;
            year--;
        }
    }

    if (document.getElementById) {
        cnt = document.getElementById("calendar_data");
    } else if (document.all) {
        cnt = document.all["calendar_data"];
    }

    cnt.innerHTML = "";

    str = ""

    //heading table
    str += '<table class="calendar"><tr><th width="50%">';
    str += '<form method="NONE" onsubmit="return 0">';
    str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
    str += '<select id="select_month" name="monthsel" onchange="month = parseInt(document.getElementById(\'select_month\').value); initCalendar();">';
    for (i =0; i < 12; i++) {
        if (i == month) selected = ' selected="selected"';
        else selected = '';
        str += '<option value="' + i + '" ' + selected + '>' + month_names[i] + '</option>';
    }
    str += '</select>';
    str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
    str += '</form>';
    str += '</th><th width="50%">';
    str += '<form method="NONE" onsubmit="return 0">';
    str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
    str += '<select id="select_year" name="yearsel" onchange="year = parseInt(document.getElementById(\'select_year\').value); initCalendar();">';
    for (i = year - 25; i < year + 25; i++) {
        if (i == year) selected = ' selected="selected"';
        else selected = '';
        str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
    }
    str += '</select>';
    str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
    str += '</form>';
    str += '</th></tr></table>';

    str += '<table class="calendar"><tr>';
    for (i = 0; i < 7; i++) {
        str += "<th>" + day_names[i] + "</th>";
    }
    str += "</tr>";

    var firstDay = new Date(year, month, 1).getDay();
    var lastDay = new Date(year, month + 1, 0).getDate();

    str += "<tr>";

    dayInWeek = 0;
    for (i = 0; i < firstDay; i++) {
        str += "<td>&nbsp;</td>";
        dayInWeek++;
    }
    for (i = 1; i <= lastDay; i++) {
        if (dayInWeek == 7) {
            str += "</tr><tr>";
            dayInWeek = 0;
        }

        dispmonth = 1 + month;

        if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
            actVal = "" + formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
        } else {
            actVal = "" + formatNum4(year) + formatNum2(dispmonth, 'month') + formatNum2(i, 'day');
        }
        if (i == day) {
            style = ' class="selected"';
            current_date = actVal;
        } else {
            style = '';
        }
        str += "<td" + style + "><a href=\"javascript:returnDate('" + actVal + "');\">" + i + "</a></td>"
        dayInWeek++;
    }
    for (i = dayInWeek; i < 7; i++) {
        str += "<td>&nbsp;</td>";
    }

    str += "</tr></table>";

    cnt.innerHTML = str;

    // Should we handle time also?
    if (window.opener.dateType != 'date' && !clock_set) {

        if (document.getElementById) {
            cnt = document.getElementById("clock_data");
        } else if (document.all) {
            cnt = document.all["clock_data"];
        }

        str = '';
        init_hour = hour;
        init_minute = minute;
        init_second = second;
        str += '<form method="NONE" class="clock" onsubmit="returnDate(\'' + current_date + '\')">';
        str += '<input id="hour"    type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_hour, \'hour\'); init_hour = this.value;" value="' + formatNum2(hour, 'hour') + '" />:';
        str += '<input id="minute"  type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_minute, \'minute\'); init_minute = this.value;" value="' + formatNum2(minute, 'minute') + '" />:';
        str += '<input id="second"  type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_second, \'second\'); init_second = this.value;" value="' + formatNum2(second, 'second') + '" />';
        str += '<br />';
        str += '<input type="submit" value="' + submit_text + '"/>';
        str += '</form>';

        cnt.innerHTML = str;
        clock_set = 1;
    }

}

/**
 * Returns date from calendar.
 *
 * @param   string     date text
 */
function returnDate(d) {
    txt = d;
    if (window.opener.dateType != 'date') {
        // need to get time
        h = parseInt(document.getElementById('hour').value,10);
        m = parseInt(document.getElementById('minute').value,10);
        s = parseInt(document.getElementById('second').value,10);
        if (window.opener.dateType == 'datetime') {
            txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
        } else {
            // timestamp
            txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
        }
    }

    window.opener.dateField.value = txt;
    window.close();
}
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)

{

  if(popUpWin)

  {

    if(!popUpWin.closed) popUpWin.close();

  }

  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}
var messageWin;
function messageWindow(title, msg) {
	if(messageWin) {
		/*
		var obj1 = findObj('bt',messageWin.document);
		obj1.focus();
		*/
    	if(!messageWin.closed) messageWin.close();
  	}
  	var width="300", height="225";
	var left = (screen.width/2) - width/2;
  	var top = (screen.height/2) - height/2;
  	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=auto,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  	messageWin = window.open("","msgWindow", styleStr);
  	var head = '<head><title>'+title+'</title></head>';
  	var body = '<center>'+msg+'<br><form><input id="bt" name="bt" type="button" value="close" onClick="self.close()"></form></body></html>';
	messageWin.document.write(head + body);
//	messageWin.focus();
//	var h = messageWin.document.body.height;
//	if (messageWin.height<h) messageWin.height = h;
	/*
	var obj2 = findObj('bt',messageWin.document);
	obj2.focus();
	*/
}
function messageWindowDialog(title, msg) {
	if(messageWin)   {
    	if(!messageWin.closed) messageWin.close();
  	}
  	var width="300", height="125";
	var left = (screen.width/2) - width/2;
  	var top = (screen.height/2) - height/2;
  	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  	messageWin = window.showModalDialog("","msgWindow", styleStr);
  	var head = '<head><title>'+title+'</title></head>';
  	var body = '<center>'+msg+'<br><p><form><input type="button" value="   Done   " onClick="self.close()"></form>';
	messageWin.document.write(head + body);
}
function printIssue(objName) {
	var frm = findObj(objName);
	frm.focus();
	if ((navigator.userAgent.indexOf("MSIE")>=0)) {
		frm.print();
	} else {
		var win = frm.contentWindow;
		win.print();
	}
}

