/*****************************************************************************
* PAGE DESCRIPTION
******************************************************************************
*
* NAME: scripts.js
* LANGUAGE: JavaScript
* DATE: 2.12.2002
* AUTHOR: Kirsi Koponen, Jyväskylän yliopisto
* DESCRIPTION: Useful javascript functions
*
******************************************************************************
* COPYRIGHT (C) KORPPI-PROJEKTIRYHMÄ
* Limited rights granted. Please refer to license
******************************************************************************
* UPDATES
******************************************************************************
*
* 2.12.2002 KK
* First version with functions
* hideElement(id)
* submitForm(form,id)
* toggleElement(id)
*
* Usage:
* submitForm(this.form, "add");
*
* 4.12.2002 / pjk
* Added function moveFocus(id) which moves focus to element.
*
* 7.2.2003 / mn
* Moved check_all from course/teacher/modifyGroup.jsp
*****************************************************************************/
/**
* Hides wanted element.
*/
function hideElement(id) {
if (document.getElementById) {
obj=document.getElementById(id);
if (obj==null) return;
obj.style.visibility="hidden";
obj.disabled=true;
}
}
/**
* Function to submit form where one additional parameter is needed to send with form.
*/
function submitForm(form,obj) {
if (obj==null) {
form.submit();
return true;
}
form.action=form.action+"&"+obj.name+"="+obj.value;
form.submit();
return true;
}
function submitButton(id) {
var obj = getObject(id);
if ( obj ) obj.click();
}
/**
* Returns object with id or null if not found
*/
function getObject(id) {
if (document.getElementById) {
obj=document.getElementById(id);
return obj;
}
return null;
}
/**
* Toggles element's disabled property.
*/
function toggleElement(id,onOff) {
if (document.getElementById) {
obj=document.getElementById(id);
if (obj==null) return;
obj.disabled=onOff;
}
}
/**
* Moves focus to element.
*/
function moveFocus(id) {
if (document.getElementById) {
obj=document.getElementById(id);
if (obj==null) {
//alert("moveFocus(): object is null");
return;
}
obj.focus();
}
}
/**
* Returns keycode either from e (Mozilla) or form window.event (IE)
*/
function getKeyCode(e) {
if (!e) var e = window.event;
if (e.keyCode) return e.keyCode;
if (e.which) return e.which;
return 0;
}
/**
* set button text
*/
function setButton(id,value) {
var obj = getObject(id);
if ( obj ) obj.value = value;
}
/**
* set button name
*/
function setButtonName(id,value) {
var obj = getObject(id);
if ( obj ) obj.name = value;
}
/**
* Selects (or un-selects) all checkboxes. Moved from course/teacher/modifyGroup.jsp
*/
function checkAll(f,elementName) {
var numChecked = 0, numNotChecked = 0;
for (e=0; e elementEnd )
addition = -1;
else return;
var filledWeek = -1;
var filledYear = -1;
for (w=elementStart; w!=elementEnd+addition; w += addition) {
if ( fillArray[1][w] != "" ) {
filledWeek = parseInt(fillArray[1][w]);
var slashPos = fillArray[1][w].indexOf("/");
if ( slashPos > 0 ) {
filledYear = parseInt(fillArray[1][w].substring(slashPos+1));
}
}
if ( fillArray[1][w] == "" && filledWeek > 0 ) {
oldFilledWeek = filledWeek;
filledWeek += addition;
if ( filledWeek > 52 ) { // If forwards to next year.
filledWeek = 1;
filledYear++; // -= addition;
}
else
if ( filledWeek <= 0 ) { // If backwards to previous year.
filledWeek = 52;
filledYear--; // += addition;
}
tmp = filledWeek;
if ( filledYear > 0 ) tmp += "/"+filledYear;
fillArray[1][w] = tmp;
f.elements[fillArray[0][w]].value = tmp;
}
}
return fillArray;
}
/**
* Fills blank weeks. Moved from course/teacher/modifyGroup.jsp
*/
function fillWeeks(f,elementName) {
var fillArray = new Array(2);
fillArray[0] = new Array(); // element number
fillArray[1] = new Array(); // element value
str = "";
var elements = 0;
for (e=0; e 0 ) {
fillArray = fillBlankWeeks(f, fillArray, 0, elements-1);
}
// Then backwards.
var elements = 0;
for (e=0; e 0 ) {
fillArray = fillBlankWeeks(f, fillArray, elements-1, 0);
}
}
/**
* Function checks if s is fromat dd.mm.yy or dd.mm and in that case returns
* a week representing that, otherwise return just s
* vesal 23.1.2005
*/
function checkWeek(s) {
d = s.split(".");
if ( d.length < 2 ) return s; // not format dd.mm
dd = d[0];
mm = d[1];
thisyear = (new Date()).getYear() + 1900;
if ( d.length < 3 ) yy = thisyear;
else yy = 1*d[2];
if ( yy < 1900 ) yy += 2000;
sy = ""; if ( yy != thisyear ) sy = "/"+(yy-2000);
return YMDarrToYWDarr([yy,mm,dd])+sy;
}
/**
* Function returns week number from string like 12.2.2004
* vesal 23.1.2005
*/
function YMDarrToYWDarr(S) {
with (new Date(S[0], S[1] - 1, S[2])) {
var DoW = getDay();
setDate(getDate() - (DoW + 6) % 7 + 3);
var ms = valueOf();
setMonth(0);
setDate(4);
var WN = Math.round((ms - valueOf()) / (604800000)) + 1;
if (DoW == 0) {
DoW = 7;
}
return WN;
}
}
/**
* Function is used on course/teacher/extraInfo.jsp page to renumber ordernums
* of fields.
* Pauli Kujala 14.4.2003
*/
function renumberOrdernums(f, elementName) {
var i=1;
for (e=0; ePlease wait...
');
}
var topwindow;
function help(osoite,target) {
// window1 = window.open (osoite,target,"")
// topwindow = Window;
window1 = window.open(osoite, target , 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=600,left = 100,top = 100');
// window1 = window.open(osoite, target , 'toolbar=1,menubar=0,scrollbars=1,location=0,statusbar=1,resizable=1,width=800,height=600,left = 100,top = 100');
if ( window1 ) window1.focus();
else document.location.href = osoite;
}
/**
* Following variables and functions are for checking all radios in
* show "partial free spaces".
*/
var prevClicked = null;
/**
* Selects all radioboxes witha a value val
* Do not select those where id=r (request)
*/
function selectAll(f,elementName,val) {
for (e=0; e' ) { prevClicked = but; selectAll(f,elementName,val); return; }
if ( but.value == '->' ) {
but.value = '=>';
if ( prevClicked != null ) prevClicked.value = '->';
prevClicked = but;
}
}
var doNotSelect = new Array();
var n = 0;
var valChecked = 0;
for (e=0; e 0 ) n = 0;
if ( newState != null ) {
for (e=0; e');
}
function writeSelAllTestButton(name,val) {
document.write('');
}