-1)
{
var s = strcode.indexOf("", e);
// Add to scripts array
scripts.push(strcode.substring(s_e+1, e));
// Strip from strcode
strcode = strcode.substring(0, s) + strcode.substring(e_e+1);
}
// Loop through every script collected and eval it
for (var i = 0; i < scripts.length; i++)
{
try
{
eval.call(null, scripts[i]);
}
catch (ex)
{
document.getElementById(idOfFieldForInfo).innerHTML = "See skript ei tööta: " + scripts[i];
}
}
}
/**
* This function preloads given images.
*
* @param images the array of images
* @return the array of preloaded images
*/
function preloadImages(images)
{
var p = images.length;
var preLoad = new Array();
for (i = 0; i < p; i++)
{
preLoad[i] = new Image();
preLoad[i].src = images[i].src;
if (images[i].width)
{
preLoad[i].width = images[i].width;
}
if (images[i].height)
{
preLoad[i].height = images[i].height;
}
}
return preLoad;
}
//использование Math.round() даст неравномерное распределение!
function getRandomInt(min, max)
{
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* This function shows the slideshow.
*
* @param idOfBoxForImages the ID of the box for images
* @param preLoad the array of the preloaded images
* @param widthOfBox the width of the box
* @param heightOfBox the height of the box
* @param images the images
*/
function runSlideShow(idOfBoxForImages, preLoad, widthOfBox, heightOfBox, images)
{
var t;
var randomIndex = getRandomInt(0, preLoad.length - 1);
document.getElementById(idOfBoxForImages).style.backgroundImage = "url(" + preLoad[randomIndex].src + ")";
var distanceFromTop = (heightOfBox - preLoad[randomIndex].height) / 2;
var distanceFromLeft = (widthOfBox - preLoad[randomIndex].width) / 2;
document.getElementById(idOfBoxForImages).style.backgroundPosition = distanceFromLeft + "px " + distanceFromTop + "px";
document.getElementById(idOfBoxForImages).onclick = function ()
{
window.open(images[randomIndex].href, images[randomIndex].target);
}
;
t = setTimeout(function ()
{
runSlideShow(idOfBoxForImages, preLoad, widthOfBox, heightOfBox, images);
}, 5000);
}
/**
* This function walks through the info fields and if it finds one then it fills
* it with the info message.
*
* @param fields the fields
*/
function handleInfoFields(fields)
{
for (var key in fields)
{
if (document.getElementById("inf_" + key))
{
document.getElementById("inf_" + key).innerHTML = fields[key].error;
}
}
}
/**
* This function creates a new division for the log-in form for the case it is
* abruptly needed.
*
* @author kalmer
* @param string the beginning of the ID: wrapperForLoginFormOf
* or messageAboutLogInButtonOf
* @param string id the ID of the element where the new division will be put
* aside
* @return the ID of the new division
*/
function createDivForLogInForm(beginning, id)
{
var idOfNewDiv = beginning + id;
if (!document.getElementById(idOfNewDiv))
{
newDiv = document.createElement("div");
newDiv.id = idOfNewDiv;
if (beginning == "messageAboutLogInButtonOf")
{
newDiv.className = "viga";
}
console.log(" 1265: " + id + ", " + newDiv.id);
document.getElementById(id).parentNode.appendChild(newDiv);
}
return idOfNewDiv;
}
function escapeHtml(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
};
/**
* This function inserts or updates or deletes an object.
*
* @param idObj the object itself
* @param idParent the parent
* @param typeOObj the type of the object
* @param typeOAction the type of the action: either delete,
* insert, find or update
* @param where the location, either before or after
* the main row
* @param functionsToCall the functions to be called
* @param urlBeginning the beginning of the URL
* @param confirm Is it needed to load a confirmation box?
* @param additionalType This is needed for the cases if there are many buttons
* in the same form.
* @param formName the name of the form
* @param handledValue the value of the object
* @param boxForAll the ID of the box that contains all the existing objects
* and the form for the new one
* @param fieldForInfo the ID of the message field if it is different from the
* standard
* @param destination the end part of the URL
* @param idOfDivisionForThisFunction If the system logs the user out then after
* logging in, we need to call the same function again. Therefore, there is
* a hidden division with this function.
* @param width the width of body
*/
function handleObj(idObj,
idParent,
typeOObj,
typeOAction,
where,
functionsToCall,
urlBeginning,
confirm,
additionalType,
formName,
handledValue,
boxForAll,
fieldForInfo,
destination,
idOfDivisionForThisFunction,
width)
{
var oldIdObj;
if (!idObj)
{
oldIdObj = ""
idObj = "";
}
else
{
oldIdObj = idObj;
}
if (idParent)
{
var parent = idParent;
}
else
{
var parent = "";
}
switch (typeOAction)
{
case "find":
{
document.getElementById(fieldForInfo).innerHTML = "Otsitakse...";
var form = document.getElementById(formName);
break;
}
case "insert":
{
var newStr = "new_";
if (where)
{
var whereToAdd = where + "_";
var fieldForInformation = "inf_" + newStr + whereToAdd + typeOObj + idObj;
var form = document.getElementById("formForNew_" + whereToAdd + typeOObj + idObj);
}
else
{
var whereToAdd = "";
idObj = parent;
if (formName)
{
var form = document.getElementById(formName);
}
else
{
var form = document.getElementById("formForNew_" + whereToAdd + typeOObj + parent);
}
}
console.log(" 1260: "+fieldForInfo);
document.getElementById(fieldForInfo).innerHTML = "Lisatakse...";
var thisObj = "";
break;
}
default:
{
var newStr = "";
var whereToAdd = "";
console.log(" 1617: "+fieldForInfo);
document.getElementById(fieldForInfo).innerHTML = "Hallatakse...";
if (formName)
{
var form = document.getElementById(formName);
}
else
{
var form = document.getElementById("formFor_" + typeOObj + oldIdObj);
}
var thisObj = idObj;
break;
}
}
if (!where)
{
var where = "";
}
xmlHttp = GetXmlHttpObject()
if (xmlHttp == null)
{
document.getElementById(fieldForInfo).innerHTML = "Brauser ei toeta HTTP päringut.";
return
}
xmlHttp.onreadystatechange = function ()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
{
if (xmlHttp.responseText)
{
var response = eval("(" + xmlHttp.responseText + ")");
}
else
{
var response =
{
};
}
var elForSuffix = document.getElementById(newStr + typeOObj + "suffix" + idObj);
if (elForSuffix)
{
var suffix = document.getElementById(newStr + typeOObj + "suffix" + idObj).value;
}
else
{
var suffix = '';
}
if (response.err)
{
idOfWrapper = createDivForLogInForm("wrapperForLoginFormOf", fieldForInfo);
if (response.facebookAccount)
{
buildNotLoggedIn(urlBeginning, idOfWrapper, fieldForInfo, response.facebookAccount);
}
else
{
buildNotLoggedIn(urlBeginning,
idOfWrapper,
fieldForInfo,
false,
false,
false,
width);
}
if (confirm)
{
var errParts = explode(")", response.err);
var lastPartsOErr = explode("(", errParts[errParts.length - 2]);
if (lastPartsOErr)
{
var idFeedback = lastPartsOErr[lastPartsOErr.length - 1];
document.getElementById("val_" + newStr + whereToAdd + "feedback" + suffix).value = idFeedback;
document.getElementById("boxForConfirmation").style.visibility = "visible";
}
}
document.getElementById(fieldForInfo).innerHTML = response.err;
}
else if (response[typeOObj])
{ // validation error
document.getElementById(fieldForInfo).innerHTML = "Palun vaata andmed üle.";
handleInfoFields(response[typeOObj]);
}
else
{
if (confirm)
{
window.location.href = "http://www.trykikeskus.ee/kolmlovi/pages/taename.php";
}
else
{
var divs = getElementsByClassName("viga", form);
for (var div in divs)
{
divs[div].innerHTML = "";
}
if (document.getElementById(newStr + "suffix" + idObj))
{
var suffix = document.getElementById(newStr + "suffix" + idObj).value;
}
else
{
var suffix = "";
}
if (handledValue)
{
var handledVal = handledValue;
}
else if (additionalType)
{
var handledVal = document.getElementById("val_" + newStr + whereToAdd + typeOObj + additionalType + suffix + oldIdObj).value;
}
else
{
var handledVal = document.getElementById("val_" + newStr + whereToAdd + typeOObj + suffix + oldIdObj).value;
}
if (response[typeOObj + "s"])
{
console.log(" 1749: "+boxForAll);
document.getElementById(boxForAll).innerHTML = response[typeOObj + "s"];
parseScript(document.getElementById(boxForAll).innerHTML, fieldForInfo);
}
if (response["ids_" + typeOObj + "s"])
{
for ( var key in response["ids_" + typeOObj + "s"])
{
if (key == "each")
{
break;
}
if (document.getElementById("script_" + typeOObj + key))
{
eval(document.getElementById("script_" + typeOObj + key).innerHTML);
}
}
}
if (document.getElementById("script_" + newStr + typeOObj))
{
eval(document.getElementById("script_" + newStr + typeOObj).innerHTML);
}
if (functionsToCall && (functionsToCall.length > 0))
{
// calling additional functions
for (var func in functionsToCall)
{
if (typeof functionsToCall[func] == 'string')
{
var functionToCall = functionsToCall[func].replace("[ID]", response.idObj);
console.log(" 1943: " + functionToCall);
eval(functionToCall);
}
}
}
idObj = oldIdObj;
if ((typeOAction != "update"))
{
var listName = "list_" + typeOObj + "s" + parent;
if (document.getElementById(listName))
{
Sortable.create(listName,
{
constraint: false,
ghosting: true,
onUpdate: function ()
{
var options =
{
method: 'post',
parameters: Sortable.serialize(listName)
};
new Ajax.Request("?function=reorder_" + typeOObj + "s&idParent=" + parent, options)
}
}
);
}
if (typeOAction == 'delete')
{
var elementToRemove = document.getElementById("boxFor_" + typeOObj + idObj);
if (elementToRemove)
{
var parent = elementToRemove.parentNode;
elementToRemove.parentNode.removeChild(elementToRemove);
if (parent.tagName == 'ul')
{
if (!parent.hasChildNodes())
{
parent.parentNode.removeChild(parent);
}
}
}
document.getElementById(fieldForInfo).innerHTML = handledVal;
}
else
{
if (where)
{
document.getElementById("inf_" + typeOObj + idObj).innerHTML = handledVal;
}
else
{
console.log(" 1818: "+fieldForInfo);
if (additionalType)
{
document.getElementById(fieldForInfo).innerHTML = handledVal;
}
else
{
if (fieldForInfo)
{
document.getElementById(fieldForInfo).innerHTML = handledVal;
}
else
{
document.getElementById("inf_" + newStr + typeOObj + parent).innerHTML = handledVal;
}
}
}
}
}
else
{
handleInfoFields(response[typeOObj]);
console.log(" 1555: "+fieldForInfo + ", " + handledVal);
document.getElementById(fieldForInfo).innerHTML = handledVal;
}
console.log(" 1650: " + "functionsFor" + idOfDivisionForThisFunction);
if (document.getElementById("functionsFor" + idOfDivisionForThisFunction))
{
eval(document.getElementById("functionsFor" + idOfDivisionForThisFunction).innerHTML.replace(/§AMPERSAND§/g, "&"));
}
}
}
}
};
if (destination.indexOf("?") > -1)
{
var beginningOfUrlToTransmit = urlBeginning + destination + "&"
}
else
{
var beginningOfUrlToTransmit = urlBeginning + destination + "?"
}
if (additionalType)
{
var additionalTypeToTransmit = "&additionalType=" + additionalType;
}
else
{
var additionalTypeToTransmit = "";
}
if (idObj)
{
idOfObjectInUrl = "&idObj=" + idObj;
}
else
{
idOfObjectInUrl = "";
}
if (parent)
{
var parentElement = "&idParent=" + parent;
}
else
{
var parentElement = "";
}
if (formName)
{
var formNameToTransmit = "&form=" + formName;
}
else
{
var formNameToTransmit = "";
}
if (where)
{
where = "&where=" + where;
}
else
{
where = "";
}
var callbackFunctionsInUrl = "";
if (functionsToCall)
{
for (indexOfFunction in functionsToCall)
{
if (typeof functionsToCall[indexOfFunction] == 'string')
{
callbackFunctionsInUrl += "&callbackFunctions[]=" + functionsToCall[indexOfFunction];
}
}
}
if (boxForAll)
{
wrapperInUrl = "&wrapper=" + boxForAll;
}
else
{
wrapperInUrl = "";
}
if (fieldForInfo)
{
fieldForInfoInUrl = "&fieldForInfo=" + fieldForInfo;
}
else
{
fieldForInfoInUrl = "";
}
xmlHttp.open("POST", beginningOfUrlToTransmit + "function=" + typeOAction + "_" + typeOObj + idOfObjectInUrl + parentElement + where + additionalTypeToTransmit + formNameToTransmit, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
if (form)
{
var params = getFormParams(form);
console.log(" 2149 ");
params += wrapperInUrl + fieldForInfoInUrl + callbackFunctionsInUrl;
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(params);
}
else
{
xmlHttp.send();
}
}
/**
* This function centers the chosen divison in the viewport considering the
* height to where the window is scrolled.
*
* @author kalmer
* @param options The options: idOfObject is the ID of the
* division.
*/
function center(options)
{
try
{
var idOfObject = options.idOfObject || null;
var centerX, centerY;
if (self.innerHeight)
{
console.log(" 1877 ");
centerX = document.documentElement.scrollWidth;
centerY = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
{
console.log(" 1883 ");
centerX = document.documentElement.clientWidth;
centerY = document.documentElement.clientHeight;
}
else if (document.body)
{
console.log(" 1889 ");
centerX = document.body.clientWidth;
centerY = document.body.clientHeight;
}
console.log(" 1890: " + centerX);
var div = document.getElementById(idOfObject);
var offsetLeft = (centerX - div.offsetWidth) / 2;
console.log(" 1893: " + offsetLeft);
var top = window.pageYOffset || document.documentElement.scrollTop;
var offsetTop = top + (centerY - div.offsetHeight) / 2;
if (offsetTop < top)
{
offsetTop = top;
}
div.style.top = offsetTop + 'px';
div.style.left = offsetLeft + 'px';
}
catch (e)
{
console.log(e.message)
}
}
/**
* This function gets the address from map.
*
* @param results the Google results
* @param status the Google status
* @param idFieldForInfo the ID of the field where we put running info
* @returns the address of the position on the map
*/
function getAddress(results, status, idFieldForInfo)
{
var address = "";
if (status == google.maps.GeocoderStatus.OK)
{
if (results[0])
{
for (var index = 0, index2 = results.length; index < index2; index++)
{
switch (index)
{
case 0:
case 2:
case 4:
{
if (address == "")
{
address = results[index].formatted_address;
}
else
{
address += " " + results[index].formatted_address;
}
break;
}
default:
{
break;
}
}
}
}
}
else
{
document.getElementById(idFieldForInfo).innerHTML = "Geocoder jooksis kokku staatusega " + status + ".";
}
return address;
}
/**
* This function shows the chosen action place on the map.
*
* @param idMap the ID of the map
* @param chosenMarker the chosen marker
* @param event the mouse event (Google)
* @param latitude the latitude of the chosen action place
* @param longitude the longitude of the chosen action place
* @param idBoxToShowHide the ID of the box where everything around the map and action places reside
* @param idButton the ID of the button for showing and hiding action places
* @param idBoxForMessage the ID of the box for informative messages
* @param urlBeginning the beginning of the main URL
*/
function showOnMap(idMap, chosenMarker, event, latitude, longitude, idBoxToShowHide, idButton, idBoxForMessage, urlBeginning)
{
var boxToShowHide = document.getElementById(idBoxToShowHide);
if (boxToShowHide && boxToShowHide.style.display == "block")
{
new google.maps.event.trigger(eval(chosenMarker), "click", event, latitude, longitude);
}
else
{
showHide(idBoxToShowHide, idButton, "Kuva toimumiskohad!", "Peida toimumiskohad!", new Array("showSomething('" + idBoxForMessage + "', '" + idBoxToShowHide + "', 'Päritakse toimumiskohti...', 'locations', 'Toimumiskohad kuvatud.', '" + urlBeginning + "haldus/toimumiskohad/?map=" + idMap + "&fieldForInfo=" + idBoxForMessage + "&boxForAll=" + idBoxToShowHide + "', new Array('new google.maps.event.trigger(eval(" + chosenMarker + "), \\'click\\', null, " + latitude + ", " + longitude + ");'), null, null, null, '" + urlBeginning + "');"));
}
}
/**
* This function updates album covers.
*
* @author kalmer
* @param integer width the maximal width of the image
* @param integer height the maximal height of the image
* @param string idWrapper the ID of the wrapper
* @param string address the address to the albums Graph
*/
function getAlbumsFromFacebook(options)
{
var width = options.width || null;
var height = options.width || null;
var idWrapper = options.idWrapper || null;
var address = options.address;
var fieldForInformation = "messageAboutAlbums";
document.getElementById(fieldForInformation).innerHTML = "Päritakse albumeid...";
xmlHttpForAlbums = GetXmlHttpObject();
if (xmlHttpForAlbums == null)
{
document.getElementById(fieldForInformation).innerHTML = "Brauser ei toeta HTTP päringut. Palun kasuta näiteks Firefoxi.";
return;
}
xmlHttpForAlbums.onreadystatechange = function()
{
if (xmlHttpForAlbums.readyState == 4 || xmlHttpForAlbums.readyState == "complete")
{
var response = eval("(" + xmlHttpForAlbums.responseText + ")");
if (response.err)
{
document.getElementById(fieldForInformation).innerHTML = response.err;
}
else
{
var images = new Array();
for (var key in response.data)
{
if (width == 120)
{
var ending = "?type=thumbnail";
}
else
{
var ending = "";
}
images[key] =
{
alt: response.data[key].name,
src: "https://graph.facebook.com/" + response.data[key].id + "/picture" + ending,
href: response.data[key].link,
target: "Facebook"
}
;
}
preLoad = preloadImages(images);
runSlideShow("albumsInFacebook", preLoad, width, 120, images);
document.getElementById(fieldForInformation).innerHTML = "Albumid kuvatud.";
}
}
};
xmlHttpForAlbums.open("GET", "http://graph.facebook.com/" + address + "/albums?fields=id,name,link", true);
xmlHttpForAlbums.send(null);
}
/**
* This function inserts a node and replaces the selection.
*
* @param insertNode the node to be inserted
* @param idOfContentEditable the ID of the content-editable division.
*/
function insertNodeAtSelection(insertNode, idOfContentEditable)
{
// get current selection
var sel = document.getSelection();
// get the first range of the selection
// (there's almost always only one range)
var range = sel.getRangeAt(0);
// deselect everything
sel.removeAllRanges();
// remove content of current selection from document
range.deleteContents();
// get location of current selection
var container = range.startContainer;
var pos = range.startOffset;
// make a new range for the new selection
range=document.createRange();
if (container.nodeType==3 && insertNode.nodeType==3)
{
// if we insert text in a textnode, do optimized insertion
container.insertData(pos, insertNode.nodeValue);
// put cursor after inserted text
range.setEnd(container, pos+insertNode.length);
range.setStart(container, pos+insertNode.length);
}
else
{
var afterNode;
if (container.nodeType==3)
{
// when inserting into a textnode
// we create 2 new textnodes
// and put the insertNode in between
var textNode = container;
container = textNode.parentNode;
var text = textNode.nodeValue;
// text before the split
var textBefore = text.substr(0,pos);
// text after the split
var textAfter = text.substr(pos);
var beforeNode = document.createTextNode(textBefore);
afterNode = document.createTextNode(textAfter);
// insert the 3 new nodes before the old one
container.insertBefore(afterNode, textNode);
container.insertBefore(insertNode, afterNode);
container.insertBefore(beforeNode, insertNode);
// remove the old node
container.removeChild(textNode);
}
else
{
// else simply insert the node
afterNode = container.childNodes[pos];
container.insertBefore(insertNode, afterNode);
}
if (afterNode)
{
range.setEnd(afterNode, 0);
range.setStart(afterNode, 0);
}
}
sel.addRange(range);
};
/**
* This function injects a table.
*
* @param idOfContentEditable the ID of the contenteditable division
*/
function doTable(idOfContentEditable)
{
rowstext = prompt("Mitu rida?");
colstext = prompt("Mitu tulpa?");
rows = parseInt(rowstext);
cols = parseInt(colstext);
if ((rows > 0) && (cols > 0))
{
table = document.createElement("table");
table.setAttribute("border", "1");
tbody = document.createElement("tbody");
for (var i = 0; i < rows; i++)
{
tr = document.createElement("tr");
for (var j = 0; j < cols; j++)
{
td = document.createElement("td");
td.setAttribute("tabindex", -1);
td.style.padding = "4px";
td.style.verticalAlign = "middle";
br = document.createElement("br");
td.appendChild(br);
tr.appendChild(td);
}
tbody.appendChild(tr);
}
table.appendChild(tbody);
insertNodeAtSelection(table, idOfContentEditable);
}
}
/**
* This function deletes a table.
*
* @author kalmer
* @param object editArea the edit area
* @param object currentNode the current node in the edit area
*/
function deleteTable(editArea, currentNode)
{
if (!currentNode)
{
selection = document.getSelection();
currentNode = selection.anchorNode;
}
if (currentNode.parentNode)
{
if (currentNode.parentNode.nodeName == "TR")
{
currentNode.parentNode.parentNode.parentNode.parentNode.removeChild(currentNode.parentNode.parentNode.parentNode);
}
else
{
if (currentNode.parentNode != editArea)
{
deleteTable(editArea, currentNode.parentNode);
}
}
}
}
/**
* This function deletes a table's row.
*
* @param object editArea the edit area
* @param object currentNode the current node in the edit area
*/
function deleteTableRow(editArea, currentNode)
{
if (!currentNode)
{
selection = document.getSelection();
currentNode = selection.anchorNode;
}
if (currentNode.parentNode.nodeName == "TR")
{
var amountOfRows = currentNode.parentNode.parentNode.getElementsByTagName("tr").length;
if (amountOfRows < 2)
{
currentNode.parentNode.parentNode.parentNode.parentNode.removeChild(currentNode.parentNode.parentNode.parentNode);
}
else
{
currentNode.parentNode.parentNode.removeChild(currentNode.parentNode);
}
}
else
{
if (currentNode.parentNode != editArea)
{
deleteTableRow(editArea, currentNode.parentNode);
}
}
}
/**
* This function deletes a table's column.
*
* @param object editArea the edit area
* @param object currentNode the current node in the edit area
*/
function deleteTableColumn(editArea, currentNode)
{
if (!currentNode)
{
selection = document.getSelection();
currentNode = selection.anchorNode;
}
if (currentNode.parentNode.nodeName == "TR")
{
for (i = 0; i < currentNode.parentNode.childNodes.length; i++)
{
if (currentNode.parentNode.childNodes[i] == currentNode)
{
var indexOfCurrentCell = i;
break;
}
}
var amountOfRows = currentNode.parentNode.parentNode.childNodes.length;
var tBody = currentNode.parentNode.parentNode;
for (i = 0; i < amountOfRows; i++)
{
var amountOfColumns = tBody.childNodes[i].childNodes.length;
tBody.childNodes[i].removeChild(tBody.childNodes[i].childNodes[indexOfCurrentCell]);
}
if (amountOfColumns < 2)
{
tBody.parentNode.parentNode.removeChild(tBody.parentNode);
}
}
else
{
if (currentNode.parentNode != editArea)
{
deleteTableColumn(editArea, currentNode.parentNode);
}
}
}
/**
* This function inserts a table's row.
*
* @param object editArea the edit area
* @param object currentNode the current node in the edit area
*/
function insertTableRow(editArea, currentNode)
{
if (!currentNode)
{
selection = document.getSelection();
currentNode = selection.anchorNode;
}
if (currentNode.parentNode.nodeName == "TR")
{
row = currentNode.parentNode.parentNode.parentNode.insertRow(currentNode.parentNode.rowIndex + 1);
for (i = 0; i < currentNode.parentNode.childNodes.length; i++)
{
cell = row.insertCell(i);
cell.setAttribute("tabindex", -1);
cell.style.padding = "4px";
cell.style.verticalAlign = "middle";
br = document.createElement("br");
cell.appendChild(br);
}
}
else
{
if (currentNode.parentNode != editArea)
{
insertTableRow(editArea, currentNode.parentNode);
}
}
}
/**
* This function inserts a table's column.
*
* @param object editArea the edit area
* @param object currentNode the current node in the edit area
*/
function insertTableColumn(editArea, currentNode)
{
if (!currentNode)
{
selection = document.getSelection();
currentNode = selection.anchorNode;
}
if (currentNode.parentNode.nodeName == "TR")
{
for (i = 0; i < currentNode.parentNode.childNodes.length; i++)
{
if (currentNode.parentNode.childNodes[i] == currentNode)
{
var indexOfCurrentCell = i;
break;
}
}
for (i = 0; i < currentNode.parentNode.parentNode.childNodes.length; i++)
{
cell = currentNode.parentNode.parentNode.childNodes[i].insertCell(indexOfCurrentCell + 1);
cell.setAttribute("tabindex", -1);
cell.style.padding = "4px";
cell.style.verticalAlign = "middle";
br = document.createElement("br");
cell.appendChild(br);
}
}
else
{
if (currentNode.parentNode != editArea)
{
insertTableColumn(editArea, currentNode.parentNode);
}
}
}
/**
* @var string the selected text
*/
var clipboard;
/**
* This function copies the text into the clipboard variable.
*
* @param idOfField the ID of the content-editable area
*/
function copyToClipboard(idOfField)
{
clipboard = getSelectedText();
}
/**
* This function grabs the selected text.
*
* @returns string the selected text
*/
function getSelectedText()
{
if (window.getSelection)
{
return window.getSelection().toString();
}
else if (document.getSelection)
{
return document.getSelection();
}
else if (document.selection)
{
return document.selection.createRange().text;
}
}
/**
* This function removes the preview markers because the form remains open and
* the second click on the save button would not recognize the image as an old
* one anymore.
*
* @author kalmer
* @param idContentEditable the ID of the contenteditable division
* @param string the type of the object, for instance Page
*/
function updateImageLinks(idOfContentEditable, type)
{
var contentEditable = document.getElementById(idOfContentEditable);
var content = contentEditable.innerHTML;
console.log(" 409: "+content);
contentWithNormalizedLinks = content.replace(/&preview/g, "");
var pattern = new RegExp("(filesOfObjects\/)previews\/(" + type + "\/\d+\/)\d+\/(472x\/)", "g");
contentEditable.innerHTML = contentWithNormalizedLinks.replace(pattern, function(match, p1, p2, p3, offset, string)
{
return [p1, p2, p3].join('');
}
);
console.log(" 411: "+contentEditable.innerHTML);
}
/**
* This function pastes the data from the clipboard variable.
*
* @author kalmer
* @param idOfContentEditable the ID of the content-editable division.
* @param string what the type of the text or the text itself
*/
function paste(idOfContentEditable, what)
{
if (typeof what == "undefined")
{
var clipboard1 = clipboard;
}
else
{
var clipboard1 = what;
}
if (window.getSelection)
{
// all browsers, except IE before version 9
var selection = window.getSelection();
if (selection.rangeCount > 0)
{
var range = selection.getRangeAt(0);
range.collapse(false);
range.insertNode(document.createTextNode(clipboard1));
}
}
else
{
// Internet Explorer before version 9
var textRange = document.selection.createRange();
textRange.collapse(false);
textRange.pasteHTML(document.createTextNode(clipboard1));
}
}
/**
* This function inserts the chosen image in the editor into the target.
*
* @author kalmer
* @param typeOfObject the type of the file object
* @param idObject the ID of the object itself
* @param idParent the ID of the parent of the object
* @param beginningOfUrl the beginning of URL
* @param idOfContentEditable the ID of the content-editable division.
* @param idOfWrapperOfLoginForm the ID of the wrapper of the login form
* @param width the width of body
*/
function insertPreviewIntoText(typeOfObject,
idObject,
idParent,
beginningOfUrl,
idOfContentEditable,
idOfWrapperOfLoginForm,
width)
{
var ending = typeOfObject + idObject;
var fieldForInformation = "messageFor_" + ending;
document.getElementById(fieldForInformation).innerHTML = "Lisatakse faili...";
var xmlHttpForFile = GetXmlHttpObject();
if (xmlHttpForFile == null)
{
document.getElementById(fieldForInformation).innerHTML = "Brauser ei toeta HTTP päringut. Palun kasuta näiteks Firefoxi.";
return;
}
xmlHttpForFile.onreadystatechange = function ()
{
if (xmlHttpForFile.readyState == 4 || xmlHttpForFile.readyState == "complete")
{
var response = eval("(" + xmlHttpForFile.responseText + ")");
if (response.err)
{
if (response.facebookAccount)
{
buildNotLoggedIn(beginningOfUrl,
idOfWrapperOfLoginForm,
fieldForInformation,
response.facebookAccount);
}
else
{
buildNotLoggedIn(beginningOfUrl,
idOfWrapperOfLoginForm,
fieldForInformation,
null,
null,
false,
width);
}
document.getElementById(fieldForInformation).innerHTML = response.err;
}
else if (response.formFieldError)
{
document.getElementById(fieldForInformation).innerHTML = "Palun vaata andmed üle.";
for (erroneousField in response.formFieldError)
{
document.getElementById("messageFor_" + erroneousField).innerHTML = response.formFieldError[erroneousField].error;
}
}
else
{
var textNode = document.createElement("span");
console.log(" 556: "+response.file);
textNode.innerHTML = response.file;
insertNodeAtSelection(textNode, idOfContentEditable);
console.log(" 559: "+textNode.innerHTML);
document.getElementById(fieldForInformation).innerHTML = "Fail on pandud sisusse.";
}
}
};
var idPreviewField = "previewField_" + ending;
console.log(" 560: "+document.getElementById(idPreviewField).value);
if (document.getElementById(idPreviewField))
{
console.log(" 563 ");
var previewField = "&" + idPreviewField + "=" + document.getElementById(idPreviewField). value;
}
else
{
console.log(" 568 ");
var previewField = "";
}
var idAltField = "alt_" + ending;
xmlHttpForFile.open("POST", beginningOfUrl + "?function=insertFile", true);
params = "idObject=" + idObject + "&typeOfObject=" + typeOfObject + "&idParent=" + idParent + "&" + idAltField + "=" + document.getElementById(idAltField).value + previewField + "&width=" + width;
xmlHttpForFile.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttpForFile.setRequestHeader("Content-length", params.length);
xmlHttpForFile.setRequestHeader("Connection", "close");
xmlHttpForFile.send(params);
}
/**
* This function inserts a linkin the editor into the target.
*
* @param link the link
* @param beginningOfUrl the beginning of the URL
* @param idOfContentEditable the ID of the content-editable division.
*/
function insertLink(link, beginningOfUrl, idOfContentEditable)
{
document.execCommand('unlink', false, null);
var a = document.createElement("a");
a.setAttribute("href", link);
if (link.indexOf(beginningOfUrl) < 0)
{
a.setAttribute("target", "_blank");;
}
var range = document.getSelection().getRangeAt(0);
a.appendChild(range.extractContents());
range.insertNode(a);
}
/**
* This function executes a browser-specific command.
*
* @param command the command
* @param idOfField the ID of the field where is the target text
* @param value the value that is needed for some commands, for instance for
* formatBlock
*/
function executeCommand(command, idOfField, value)
{
document.execCommand(command, false, value);
}
/**
* This function removes all the selections before marking a new one.
*/
function handleSelections()
{
var selection = rangy.getSelection();
console.log(" 550: "+selection);
selection.removeAllRanges();
var savedSelection = rangy.saveSelection();
console.log(" 553: "+savedSelection);
}
/**
* This function extracts the value of href and makes it visible.
*
* @author kalmer
* @param idOfContentEditable the ID of the current node, actually of the
* contenteditable division
*/
function parseHrefFromSelection(idOfContentEditable)
{
var htmlOfSelection = getSelectionHTML();
var re = new RegExp("(href=\")([^\"]*)(\")");
var m = re.exec(htmlOfSelection);
if (m == null)
{
console.log(" 659: "+"linkFor_" + idOfContentEditable);
document.getElementById("linkFor_" + idOfContentEditable).getElementsByTagName('input')[0].value = "";
document.getElementById("linkFor_" + idOfContentEditable).style.display = "none";
}
else
{
document.getElementById("linkFor_" + idOfContentEditable).getElementsByTagName('input')[0].value = m[2];
document.getElementById("linkFor_" + idOfContentEditable).style.display = "block";
}
}
function getSelectionHTML()
{
var userSelection;
if (window.getSelection)
{
// W3C Ranges
userSelection = window.getSelection();
// Get the range:
if (userSelection.getRangeAt)
{
var range = userSelection.getRangeAt(0);
}
else
{
var range = document.createRange();
range.setStart (userSelection.anchorNode, userSelection.anchorOffset);
range.setEnd (userSelection.focusNode, userSelection.focusOffset);
}
// And the HTML:
var clonedSelection = range.cloneContents ();
var div = document.createElement ('div');
div.appendChild (clonedSelection);
return div.innerHTML;
}
else if (document.selection)
{
// Explorer selection, return the HTML
userSelection = document.selection.createRange ();
return userSelection.htmlText;
}
else
{
return '';
}
};
/**
* This function inserts a text node after a table node because if in the text
* editor, there is only a table and nothing more, it is impossible to get out
* of the table.
*
* @param idOfContentEditable the ID of the content-editable division.
*/
function insertTextNodeAfterTable(idOfContentEditable)
{
var textNode = document.createElement("br");
if (typeof savedSelection != "undefined")
{
rangy.restoreSelection(savedSelection);
}
var selection = document.getSelection();
if (selection.focusNode.parentNode.parentNode.parentNode.nodeName == "TABLE")
{
var parent = selection.focusNode.parentNode.parentNode.parentNode.parentNode;
//if the parents lastchild is the targetElement...
if(parent.lastchild == selection.focusNode.parentNode.parentNode.parentNode)
{
// add the newElement after the target element.
parent.appendChild(textNode);
}
else
{
/*
* else the target has siblings, insert the new element between the
* target and it's next sibling.
*/
parent.insertBefore(textNode, selection.focusNode.parentNode.parentNode.parentNode.nextSibling);
}
//selection.focusNode.parentNode.parentNode.parentNode.parentNode.appendChild(textNode);
}
}
/**
* This function inserts a text node before a table node because if in the text
* editor, there is only a table and nothing more, it is impossible to get out
* of the table.
*
* @author kalmer
*/
function insertTextNodeBeforeTable()
{
var textNode = document.createElement("br");
var selection = document.getSelection();
if (selection.focusNode.parentNode.parentNode.parentNode.nodeName == "TABLE")
{
var parent = selection.focusNode.parentNode.parentNode.parentNode.parentNode;
parent.insertBefore(textNode, selection.focusNode.parentNode.parentNode.parentNode);
//selection.focusNode.parentNode.parentNode.parentNode.parentNode.appendChild(textNode);
}
}/*!
* enquire.js v2.1.0 - Awesome Media Queries in JavaScript
* Copyright (c) 2013 Nick Williams - http://wicky.nillia.ms/enquire.js
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
*/
;(function (name, context, factory) {
var matchMedia = context.matchMedia;
if (typeof module !== 'undefined' && module.exports) {
module.exports = factory(matchMedia);
}
else if (typeof define === 'function' && define.amd) {
define(function() {
return (context[name] = factory(matchMedia));
});
}
else {
context[name] = factory(matchMedia);
}
}('enquire', this, function (matchMedia) {
'use strict';
/*jshint unused:false */
/**
* Helper function for iterating over a collection
*
* @param collection
* @param fn
*/
function each(collection, fn) {
var i = 0,
length = collection.length,
cont;
for(i; i < length; i++) {
cont = fn(collection[i], i);
if(cont === false) {
break; //allow early exit
}
}
}
/**
* Helper function for determining whether target object is an array
*
* @param target the object under test
* @return true if array, false otherwise
*/
function isArray(target) {
return Object.prototype.toString.apply(target) === '[object Array]';
}
/**
* Helper function for determining whether target object is a function
*
* @param target the object under test
* @return true if function, false otherwise
*/
function isFunction(target) {
return typeof target === 'function';
}
/**
* Delegate to handle a media query being matched and unmatched.
*
* @param options
* @param options.match callback for when the media query is matched
* @param [options.unmatch] callback for when the media query is unmatched
* @param [options.setup] one-time callback triggered the first time a query is matched
* @param [options.deferSetup=false] should the setup callback be run immediately, rather than first time query is matched?
* @constructor
*/
function QueryHandler(options) {
this.options = options;
!options.deferSetup && this.setup();
}
QueryHandler.prototype = {
/**
* coordinates setup of the handler
*
* @function
*/
setup : function() {
if(this.options.setup) {
this.options.setup();
}
this.initialised = true;
},
/**
* coordinates setup and triggering of the handler
*
* @function
*/
on : function() {
!this.initialised && this.setup();
this.options.match && this.options.match();
},
/**
* coordinates the unmatch event for the handler
*
* @function
*/
off : function() {
this.options.unmatch && this.options.unmatch();
},
/**
* called when a handler is to be destroyed.
* delegates to the destroy or unmatch callbacks, depending on availability.
*
* @function
*/
destroy : function() {
this.options.destroy ? this.options.destroy() : this.off();
},
/**
* determines equality by reference.
* if object is supplied compare options, if function, compare match callback
*
* @function
* @param {object || function} [target] the target for comparison
*/
equals : function(target) {
return this.options === target || this.options.match === target;
}
};
/**
* Represents a single media query, manages it's state and registered handlers for this query
*
* @constructor
* @param query the media query string
* @param [isUnconditional=false] whether the media query should run regardless of whether the conditions are met. Primarily for helping older browsers deal with mobile-first design
*/
function MediaQuery(query, isUnconditional) {
this.query = query;
this.isUnconditional = isUnconditional;
this.handlers = [];
this.mql = matchMedia(query);
var self = this;
this.listener = function(mql) {
self.mql = mql;
self.assess();
};
this.mql.addListener(this.listener);
}
MediaQuery.prototype = {
/**
* add a handler for this query, triggering if already active
*
* @param handler
* @param handler.match callback for when query is activated
* @param [handler.unmatch] callback for when query is deactivated
* @param [handler.setup] callback for immediate execution when a query handler is registered
* @param [handler.deferSetup=false] should the setup callback be deferred until the first time the handler is matched?
*/
addHandler : function(handler) {
var qh = new QueryHandler(handler);
this.handlers.push(qh);
this.matches() && qh.on();
},
/**
* removes the given handler from the collection, and calls it's destroy methods
*
* @param {object || function} handler the handler to remove
*/
removeHandler : function(handler) {
var handlers = this.handlers;
each(handlers, function(h, i) {
if(h.equals(handler)) {
h.destroy();
return !handlers.splice(i,1); //remove from array and exit each early
}
});
},
/**
* Determine whether the media query should be considered a match
*
* @return true if media query can be considered a match, false otherwise
*/
matches : function() {
return this.mql.matches || this.isUnconditional;
},
/**
* Clears all handlers and unbinds events
*/
clear : function() {
each(this.handlers, function(handler) {
handler.destroy();
});
this.mql.removeListener(this.listener);
this.handlers.length = 0; //clear array
},
/*
* Assesses the query, turning on all handlers if it matches, turning them off if it doesn't match
*/
assess : function() {
var action = this.matches() ? 'on' : 'off';
each(this.handlers, function(handler) {
handler[action]();
});
}
};
/**
* Allows for registration of query handlers.
* Manages the query handler's state and is responsible for wiring up browser events
*
* @constructor
*/
function MediaQueryDispatch () {
if(!matchMedia) {
throw new Error('matchMedia not present, legacy browsers require a polyfill');
}
this.queries = {};
this.browserIsIncapable = !matchMedia('only all').matches;
}
MediaQueryDispatch.prototype = {
/**
* Registers a handler for the given media query
*
* @param q the media query
* @param {object || Array || Function} options either a single query handler object, a function, or an array of query handlers
* @param options.match fired when query matched
* @param [options.unmatch] fired when a query is no longer matched
* @param [options.setup] fired when handler first triggered
* @param [options.deferSetup=false] whether setup should be run immediately or deferred until query is first matched
* @param [shouldDegrade=false] whether this particular media query should always run on incapable browsers
*/
register : function(q, options, shouldDegrade) {
var queries = this.queries,
isUnconditional = shouldDegrade && this.browserIsIncapable;
if(!queries[q]) {
queries[q] = new MediaQuery(q, isUnconditional);
}
//normalise to object in an array
if(isFunction(options)) {
options = { match : options };
}
if(!isArray(options)) {
options = [options];
}
each(options, function(handler) {
queries[q].addHandler(handler);
});
return this;
},
/**
* unregisters a query and all it's handlers, or a specific handler for a query
*
* @param q the media query to target
* @param {object || function} [handler] specific handler to unregister
*/
unregister : function(q, handler) {
var query = this.queries[q];
if(query) {
if(handler) {
query.removeHandler(handler);
}
else {
query.clear();
delete this.queries[q];
}
}
return this;
}
};
return new MediaQueryDispatch();
}));/*
* http://tech.pro/tutorial/650/javascript-draggable-elements
*/
/**
* This function hooks an event to the given element.
*
* @author Mihael Kuehl
* @param element the element
* @param eventName the name of the event
* @param callback the function to call if the event will be triggered
*/
function hookEvent(element, eventName, callback)
{
if (typeof(element) == "string")
{
element = document.getElementById(element);
}
if (element == null)
{
return;
}
if (element.addEventListener)
{
element.addEventListener(eventName, callback, false);
}
else if (element.attachEvent)
{
element.attachEvent("on" + eventName, callback);
}
}
/**
* This function unhooks an event from the given element.
*
* @author Michael Kuehl
* @param element the element
* @param eventName the name of the event
* @param callback the function to be called after unhooking
*/
function unhookEvent(element, eventName, callback)
{
if (typeof (element) == "string")
{
element = document.getElementById(element);
}
if (element == null)
{
return;
}
if (element.removeEventListener)
{
element.removeEventListener(eventName, callback, false);
}
else if(element.detachEvent)
{
element.detachEvent("on" + eventName, callback);
}
}
/**
* cancel the event and return (we don't want anyone else who might listen to the mousedown event interfering with the drag - for instance, text selection)
*
* @author Michael Kuehl
* @param e the system event
* @returns false if cancelled
*/
function cancelEvent(e)
{
e = e ? e : window.event;
if (e.stopPropagation)
{
e.stopPropagation();
}
if (e.preventDefault)
{
e.preventDefault();
}
e.cancelBubble = true;
e.cancel = true;
e.returnValue = false;
return false;
}
function Latitude(x, y)
{
this.X = x;
this.Y = y;
this.Add = function (val)
{
var newPos = new Latitude(this.X, this.Y);
if (val != null)
{
if(!isNaN(val.X))
{
newPos.X += val.X;
}
if (!isNaN(val.Y))
{
newPos.Y += val.Y
}
}
return newPos;
}
this.Subtract = function (val)
{
var newPos = new Latitude(this.X, this.Y);
if (val != null)
{
if (!isNaN(val.X))
{
newPos.X -= val.X;
}
if (!isNaN(val.Y))
{
newPos.Y -= val.Y
}
}
return newPos;
}
this.Min = function (val)
{
var newPos = new Latitude(this.X, this.Y)
if (val == null)
{
return newPos;
}
if (!isNaN(val.X) && this.X > val.X)
{
newPos.X = val.X;
}
if (!isNaN(val.Y) && this.Y > val.Y)
{
newPos.Y = val.Y;
}
return newPos;
}
this.Max = function(val)
{
var newPos = new Latitude(this.X, this.Y)
if (val == null)
{
return newPos;
}
if (!isNaN(val.X) && this.X < val.X)
{
newPos.X = val.X;
}
if (!isNaN(val.Y) && this.Y < val.Y)
{
newPos.Y = val.Y;
}
return newPos;
}
this.Bound = function (lower, upper)
{
var newPos = this.Max(lower);
return newPos.Min(upper);
}
this.Check = function ()
{
var newPos = new Latitude(this.X, this.Y);
if (isNaN(newPos.X))
{
newPos.X = 0;
}
if (isNaN(newPos.Y))
{
newPos.Y = 0;
}
return newPos;
}
this.Apply = function (element)
{
if (typeof (element) == "string")
{
element = document.getElementById(element);
}
if (element == null)
{
return;
}
if (!isNaN(this.X))
{
element.style.left = this.X + 'px';
}
if (!isNaN(this.Y))
{
element.style.top = this.Y + 'px';
}
}
}
function absoluteCursorPostion(eventObj)
{
eventObj = eventObj ? eventObj : window.event;
if (isNaN(window.scrollX))
{
return new Latitude(eventObj.clientX + document.documentElement.scrollLeft + document.body.scrollLeft,
eventObj.clientY + document.documentElement.scrollTop + document.body.scrollTop);
}
else
{
return new Latitude(eventObj.clientX + window.scrollX,
eventObj.clientY + window.scrollY);
}
}
function dragObject(element,
attachElement,
lowerBound,
upperBound,
startCallback,
moveCallback,
endCallback,
attachLater)
{
if (typeof (element) == "string")
{
element = document.getElementById(element);
}
if (element == null)
{
return;
}
if (lowerBound != null && upperBound != null)
{
var temp = lowerBound.Min(upperBound);
upperBound = lowerBound.Max(upperBound);
lowerBound = temp;
}
var cursorStartPos = null;
var elementStartPos = null;
var dragging = false;
var listening = false;
var disposed = false;
function dragStart(eventObj)
{
if (dragging || !listening || disposed)
{
return;
}
dragging = true;
if (startCallback != null)
{
startCallback(eventObj, element);
}
cursorStartPos = absoluteCursorPostion(eventObj);
elementStartPos = new Latitude(parseInt(element.style.left), parseInt(element.style.top));
elementStartPos = elementStartPos.Check();
hookEvent(document, "mousemove", dragGo);
hookEvent(document, "mouseup", dragStopHook);
return cancelEvent(eventObj);
}
function dragGo(eventObj)
{
if (!dragging || disposed)
{
return;
}
var newPos = absoluteCursorPostion(eventObj);
newPos = newPos.Add(elementStartPos).Subtract(cursorStartPos);
newPos = newPos.Bound(lowerBound, upperBound)
newPos.Apply(element);
if (moveCallback != null)
{
moveCallback(newPos, element);
}
return cancelEvent(eventObj);
}
function dragStopHook(eventObj)
{
dragStop();
return cancelEvent(eventObj);
}
function dragStop()
{
if (!dragging || disposed)
{
return;
}
unhookEvent(document, "mousemove", dragGo);
unhookEvent(document, "mouseup", dragStopHook);
cursorStartPos = null;
elementStartPos = null;
if (endCallback != null)
{
endCallback(element);
}
dragging = false;
}
this.Dispose = function ()
{
if (disposed)
{
return;
}
this.StopListening(true);
element = null;
attachElement = null
lowerBound = null;
upperBound = null;
startCallback = null;
moveCallback = null
endCallback = null;
disposed = true;
}
this.StartListening = function ()
{
if (listening || disposed)
{
return;
}
listening = true;
hookEvent(attachElement, "mousedown", dragStart);
}
this.StopListening = function (stopCurrentDragging)
{
if (!listening || disposed)
{
return;
}
unhookEvent(attachElement, "mousedown", dragStart);
listening = false;
if (stopCurrentDragging && dragging)
{
dragStop();
}
}
this.IsDragging = function ()
{
return dragging;
}
this.IsListening = function ()
{
return listening;
}
this.IsDisposed = function ()
{
return disposed;
}
if (typeof (attachElement) == "string")
{
attachElement = document.getElementById(attachElement);
}
if(attachElement == null)
{
attachElement = element;
}
if (!attachLater)
{
this.StartListening();
}
}/**
* This function updates the participant data
*
* @param options.idOfHuman the ID of the human
* @param options.idOfEvent the ID of the event
* @param options.fieldForInformation the ID of the info field
* @param options.fieldForEstablishment the ID of the field for participant's establishment
* @param options.fieldForSpecialNeeds the ID of the field for the participants' special needs
* @param options.beginningOfUrl the beginning of the URL
*/
function updateParticipant(options)
{
var idOfHuman = options.idOfHuman;
var idOfEvent = options.idOfEvent;
var fieldForInformation = options.fieldForInformation;
var fieldForEstablishment = options.fieldForEstablishment;
var fieldForSpecialNeeds = options.fieldForSpecialNeeds;
var beginningOfUrl = options.beginningOfUrl;
document.getElementById(fieldForInformation).innerHTML = "Päritakse osaleja andmeid...";
var xmlHttpForParticipant = GetXmlHttpObject();
if (xmlHttpForParticipant == null)
{
document.getElementById(fieldForInformation).innerHTML = "Brauser ei toeta HTTP päringut. Palun kasuta näiteks Firefoxi.";
return;
}
xmlHttpForParticipant.onreadystatechange = function ()
{
if (xmlHttpForParticipant.readyState == 4 || xmlHttpForParticipant.readyState == "complete")
{
var response = eval("(" + xmlHttpForParticipant.responseText + ")");
if (response.err)
{
document.getElementById(fieldForInformation).innerHTML = response.err;
}
else
{
document.getElementById(fieldForEstablishment).innerHTML = response.establishment;
document.getElementById(fieldForSpecialNeeds).innerHTML = response.specialNeeds;
document.getElementById(fieldForInformation).innerHTML = "Osaleja andmed laetud.";
}
}
};
xmlHttpForParticipant.open("GET", beginningOfUrl + "konkureerimine/?function=updateParticipant&human=" + idOfHuman + "&event=" + idOfEvent, true);
xmlHttpForParticipant.send(null);
}
function showPeriods(values, track, disabledValues) {
// var valuesWithIdx =new Array();
var endValue;
var askEnd =true;
var lastPeriod =true;
var olderPeriod;
var width;
var sliderWrapperWidth =560;
/*for(idx=0;idx=0;idx--) {
if(askEnd) {
endValue =values[idx];
askEnd =false;
continue;
}
width =(endValue-values[idx])*sliderWrapperWidth /24-10;
if(disabledValues[idx] ==0) {
trackName ='Track_' +track +'_Period_1';
} else {
trackName ='Track_' +track +'_Parent_Period_1';
}
pictureDiv ='Track_' +track +'_Period_Picture_1';
pictureImg ='Track_' +track +'_Period_Picture_Picture_1';
left=(values[idx])*sliderWrapperWidth /24 +5;
if(lastPeriod) {
document.getElementById(trackName).style.left=left +'px';
if(width >0) {
document.getElementById(trackName).style.width=width+'px';
document.getElementById(trackName).style.display ='block';
document.getElementById(pictureDiv).style.position='absolute';//olderPeriod.style.left;
document.getElementById(pictureDiv).style.top='-5px';//olderPeriod.style.left;
document.getElementById(pictureDiv).style.left=left +width /2 -50 +'px';
// document.getElementById('Track_' +track +'_Period_Picture_Picture_1').style.width='30px';
// document.getElementById('Track_' +track +'_Period_Picture_Picture_1').style.height='30px';
// document.getElementById('Track_' +track +'_Period_Picture_1').style.backgroundColor='blue';
document.getElementById(pictureDiv).style.display='block';
document.getElementById(pictureImg).src='../../assets/images/pictograms/' +disabledValues[idx];// +disabledValues[idx];
} else {
document.getElementById(trackName).style.display ='none';
}
lastPeriod =false;
} else {
olderPeriod =XHTMLElement.element(trackName, 'Track_' +track, 'copy');
olderPictureDiv =XHTMLElement.element(pictureDiv, 'Track_' +track, 'copy');
olderPictureImg =XHTMLElement.element(pictureImg, olderPictureDiv, 'copy');
olderPeriod.style.left=left +'px';
// olderPeriod.style.top =$('Track_' +track +'_Period_1').style.top;
if(width >0) {
olderPeriod.style.width=width+'px';
olderPeriod.style.display ='block';
// document.getElementById('Track_' +track +'_Period_Picture_1').style.left=(values[idx])*sliderWrapperWidth /24 +5+'px';
olderPictureDiv.style.position='absolute';//olderPeriod.style.left;
olderPictureDiv.style.top='-5px';//olderPeriod.style.left;
olderPictureDiv.style.left=left +width /2 -50 +'px';
// document.getElementById('Track_' +track +'_Period_Picture_Picture_1').style.width='30px';
// document.getElementById('Track_' +track +'_Period_Picture_Picture_1').style.height='30px';
// document.getElementById('Track_' +track +'_Period_Picture_1').style.backgroundColor='blue';
olderPictureDiv.style.display='block';
olderPictureImg.src='../../assets/images/pictograms/' +disabledValues[idx];// +disabledValues[idx];
} else {
olderPeriod.style.display ='none';
}
}
askEnd =true;
}
}
/**
* This function gets the path to the root folder.
*
* @author kalmer
* @param parent If we have a parent window then its name.
* @returns the path to the root folder
*/
function getPathToRootDir(parent)
{
if (parent)
{
var pathinfo = window.parent.location.pathname;
}
else
{
var pathinfo = window.location.pathname;
}
var deep =substr_count(pathinfo, "/");
if(substr(pathinfo, 1, "tennis24".length) == "tennis24")
{
deep--;
}
var path_to_root = "./";
for(var i =1; i time)
{
var date2 = new Date(time);
field.value =date2.print("%B %e, %Y %H:%M");
}
}
field =document.getElementById("registrationDeadline");
if(field.value)
{
dateOOtherField =new Date(field.value);
if(dateOOtherField.getTime() >time)
{
var date2 = new Date(time);
field.value =date2.print("%B %e, %Y %H:%M");
}
}
}
break;
case "registrationDeadline":
{
field =document.getElementById("endOHappening");
if(field.value)
{
dateOOtherField =new Date(Date.parse(field.value));
if(dateOOtherField.getTime()