//Create HTML5 elements for IE < 9 (see also css.php)
document.createElement("header");
document.createElement("footer");
document.createElement("aside");
document.createElement("mark");
//global variables
var hlpWinH = 500, hlpWinW = 800, hlpWinT = 100; //help window height, width, top
var evtWinH = 200, evtWinW = 510, evtWinT = 100; //event window height, width, top
//shortcut functions
function $I(el) { return document.getElementById(el); }
function $N(el) { return document.getElementsByName(el); }
function $T(el) { return document.getElementsByTagName(el); }
function $C(el) { return document.getElementsByClassName(el); }
//general functions
function help(page,back){ //show user guide. If back, show back button to back
var hlpWinL = (screen.width-hlpWinW)/2;
var hlpWin = window.open('','hlpWin','menubar=no,location=no,toolbar=no,height=' + hlpWinH +',width=' + hlpWinW + ',top=' + hlpWinT + ',left=' + hlpWinL + ', scrollbars');
var parObj = {xP:24,hP:page};
if (back !== undefined) { parObj.bP = back; }
index(parObj,'hlpWin');
hlpWin.focus();
}
function scrollY(cp,par) { //save/restore sBox y-scroll value to/from local storage
var elm = $I('sBox');
if(typeof(Storage) !== "undefined" && elm != null) {
var item = 'sBox'+cp;
if (par == 'save') { //save y-scroll value
sessionStorage.setItem(item,elm.scrollTop);
} else { //goto y-scroll value
if (sessionStorage.getItem(item) !== "undefined") {
elm.scrollTop = sessionStorage.getItem(item);
}
}
}
}
function newE(dt,cid,st,et){ //new event - date, cat ID and times (optional)
var evtWinL = (screen.width-evtWinW)/2;
var evtWin = window.open('','evtWin','menubar=no,location=no,toolbar=no,height=' + evtWinH +',width=' + evtWinW + ',top=' + evtWinT + ',left=' + evtWinL + ', scrollbars=0');
var parObj = {xP:30,action:'add'};
if (dt != 0) { parObj.evD = dt; }
if (cid > 0) { parObj.catID = cid; }
if (arguments.length > 2) { parObj.evTs = st; parObj.evTe = et; }
index(parObj,'evtWin');
evtWin.focus();
return false;
}
function editE(id,date){ //edit event
var evtWinL = (screen.width-evtWinW)/2;
var evtWin = window.open('','evtWin','menubar=no,location=no,toolbar=no,height=' + evtWinH + ',width=' + evtWinW + ',top=' + evtWinT + ',left=' + evtWinL + ', scrollbars=0');
var parObj = {xP:31,action:'edi0',eid:id,evD:date};
index(parObj,'evtWin');
evtWin.focus();
return false;
}
function showE(id,date,cal){ //show event
var evtWinL = (screen.width-evtWinW)/2;
var evtWin = window.open('','evtWin','menubar=no,location=no,toolbar=no,height=' + evtWinH + ',width=' + evtWinW + ',top=' + evtWinT + ',left=' + evtWinL + ', scrollbars=0');
var parObj = {xP:32,eid:id,evD:date};
if (cal !== undefined) { parObj.cal1x = cal; } //if defined, use cal; but don't store in session
index(parObj,'evtWin');
return false;
}
function winFit() { //resize window height to fit its content
neededIH = document.body.offsetHeight + 6;
currentIH = window.innerHeight || document.documentElement.clientHeight;
if (window.resizeBy) {
window.resizeBy(0,neededIH-currentIH);
} else {
currentOW = window.outerWidth;
currentOH = window.outerHeight;
window.resizeTo(currentOW,neededIH+currentOH-currentIH);
}
}
// AJAX functions
function checkE(obj,evtID,evtDt) { //toggle the event check mark
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
if (xhr.responseText != '0') {
obj.innerHTML = xhr.responseText;
}
}
}
xhr.open("POST","common/checkevt.php",true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("evtID="+evtID+"&evtDt="+evtDt);
}
function detach(obj,evtID,fName) { //detach file from event
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
if (xhr.responseText != '0') {
obj.parentNode.innerHTML = xhr.responseText;
}
}
}
xhr.open("POST","common/detach.php",true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("evtID="+evtID+"&fName="+fName);
}
//general functions
function index(pars,target) { //dummy form to turn GET into POST
pars.lcI = 'i'; //internal hit
var form = document.createElement("form");
form.method = "post";
form.action = "index.php";
if (target !== undefined) {
form.target = target;
}
for(var key in pars) {
var input = document.createElement("input");
input.setAttribute("type","hidden");
input.setAttribute("name",key);
input.setAttribute("value",pars[key]);
form.appendChild(input);
}
document.body.appendChild(form);
form.submit();
}
/*
function indexGET(pars,target) { //goto page via index
var url = 'index.php?lcI=i' //lcI=i => internal hit
for(var key in pars) {
url += '&' + key + '=' + pars[key];
}
var a = document.createElement('a');
a.setAttribute("type","hidden");
a.href=url;
if (target !== undefined) {
a.target = target;
}
document.body.appendChild(a);
a.click();
}
*/
function done(action) { //close window and refresh calendar (action: c = close; r = reload opener)
if (action.indexOf('r') > -1) { reload(); } //refresh calendar
if (action.indexOf('c') > -1) { window.close(); }
}
function reload() { //refresh calendar
window.opener.location = window.opener.location.href; //reload
}
function styleWin(page) { //styling page (new window)
var pageObj = new Object();
pageObj.xP = page;
var styleWin = window.open('','styleWin',"top=100,left=200,width=1000,height=800");
index(pageObj,'styleWin');
styleWin.focus();
return false;
}
function check1(boxName,thisBox,toggle) { //check 1 of N check boxes
var chBoxes = $N(boxName);
var checked = thisBox.checked;
for (var i=(chBoxes.length-1);i >= 0;i--) {
chBoxes[i].checked = false;
}
thisBox.checked = (toggle !== undefined && !checked) ? false : true;
}
function checkZ(boxName,checked) { //check box 0 of N check boxes
var chBoxes = $N(boxName+'[]');
for (var i=(chBoxes.length-1);i >= 0;i--) {
chBoxes[i].checked = false;
}
$I(boxName+'0').checked = true;
}
function checkN(boxName,checked) { //check any of N check boxes
var chBoxes = $N(boxName+'[]');
var check = false;
for (var i=(chBoxes.length-1);i >= 0;i--) {
if (chBoxes[i].checked) { check = true; }
}
$I(boxName+'0').checked = (check == true) ? false : true;
}
function checkA(boxName) { //check all check boxes
var chBoxes = $N(boxName+'[]');
for (var i=(chBoxes.length-1);i >= 0;i--) {
chBoxes[i].checked = true;
}
}
function toggleLabel(optBut,text1,text2) {
elm = $I(optBut);
elm.innerHTML = (elm.innerHTML == text1) ? text2 : text1;
}
function showX(elmID,on) { //show or hide element
if ($I(elmID)) { $I(elmID).style.display = (on ? "block" : "none"); }
}
function show(elmID) { //show or hide one element;
var elm = $I(elmID);
elm.style.display = (elm.style.display == "block") ? "none" : "block";
}
function showSm(elmID) {
var elm = $I(elmID);
elm.style.width = (elm.style.width.substr(0,1) > "0") ? "0px" : "150px";
}
function showOp(elmID,formName) { //show or hide and submit
var elm = $I(elmID);
elm.style.height = (elm.style.height.substr(0,1) > "0") ? "0px" : "250px";
if (elm.style.height.substr(0,1) == "0") { document.forms[formName].submit(); }
}
function hide_times(t) { //toggle visibility of event times
if (t.checked) {
$I("dTimeS").style.visibility = "hidden";
$I("dTimeE").style.visibility = "hidden";
} else {
$I("dTimeS").style.visibility = "visible";
$I("dTimeE").style.visibility = "visible";
t.form.sti.value = t.form.eti.value = "";
}
}
function delConfCat(ID,confText) {
if (confirm(confText+'?')) {
index({delExe:'y',cid:ID});
}
}
function delConfUsr(ID,confText) {
if (confirm(confText+'?')) {
index({delExe:'y',uid:ID});
}
}
function delConfGrp(ID,confText) {
if (confirm(confText+'?')) {
index({delExe:'y',gid:ID});
}
}
function putLocal(elmID) { //save to local storage
var elm = $I(elmID);
if(typeof(Storage) !== "undefined") {
localStorage.elmID = elm.value;
}
}
function getLocal(elmID) { //get from local storage
var elm = $I(elmID);
if (typeof(Storage) !== "undefined") {
elm.value = localStorage.elmID;
}
}
function update(jscolor,bgcol,color,bdcol) { //jscolor color changer
if (bgcol) {
var bArr = bgcol.split(',');
for(var i=0; i < bArr.length; i++) {
$I(bArr[i]).style.backgroundColor = '#'+jscolor;
}
}
if (color) {
var cArr = color.split(',');
for(var i=0; i < cArr.length; i++) {
$I(cArr[i]).style.color = '#'+jscolor;
}
}
if (bdcol) {
var dArr = bdcol.split(',');
for(var i=0; i < dArr.length; i++) {
$I(dArr[i]).style.borderColor = '#'+jscolor;
}
}
}
function sml(m1,m2,m3,subject) { //open mail client
if (confirm(smlConfirm+':\n'+m1+'@'+m2+'.'+m3)) {
subject = subject.replace(' ','%20');
location.href='mailto:'+m1+'@'+m2+'.'+m3+'?subject='+subject;
}
}
//thumbnail functions
function toClipboard(elm) {
var copyText = $I('s'+elm.id); //get the textfield
copyText.select(); //select the text field
document.execCommand('Copy'); //copy the text inside the text field
}
function deleteTn(elm,confText) {
var tnId = elm.id.replace('%20',' ');
var tnName = tnId.substr(4,1) == '~' ? tnId.substr(5) : tnId;
if (confirm(confText+' '+tnName+'?')) {
index({delTn:tnId});
}
}
//drag functions
var theElm,posX,posY;
function dragMe(elmID,e) {
theElm = $I(elmID); //object to drag
if (!e) var e = window.event //if ie
posX = theElm.offsetLeft - e.clientX;
posY = theElm.offsetTop - e.clientY;
document.onmousemove=moveMe;
document.onmouseup=new Function("theElm=''");
return false;
}
function moveMe(e) {
if (!e) var e = window.event //if ie
if (theElm) {
newPosX = posX + e.clientX;
newPosY = posY + e.clientY
if (newPosX > 0 && (newPosX + theElm.offsetWidth) < window.innerWidth) {
theElm.style.left = newPosX + "px";
}
if (newPosY > 0) {
theElm.style.top = newPosY + "px";
}
}
}
//end drag functions
function printNice() {
var oriHTML = document.body.innerHTML;
var bgColor = document.body.style.backgroundColor;
var els = $T("*");
var regexNP = /noPrint/;
var regexSB = /scrollBox/;
document.body.style.backgroundColor = "white";
for (var i=(els.length-1);i >= 0;i--) {
if (regexNP.test(els[i].className)) {
els[i].style.display = "none";
}
if (regexSB.test(els[i].className)) {
els[i].style.position = "static";
els[i].style.overflow = "visible";
}
}
window.print();
document.body.innerHTML = oriHTML;
document.body.style.backgroundColor = bgColor;
return false;
}
//==== text box popup function ====
function pop(parent,popContent,popClass,popMaxChar){
var offsetX = -60, offsetY = 16; //x, y offset of box
var maxLineLen = 80; //default max line length in box
var popobj;
var maxBoxWidth = "auto";
if (typeof popMaxChar == 'number') maxLineLen = popMaxChar;
var lines = popContent.split("
") //split on
for (var i=0,len=lines.length; i]+)>)/ig,"").length > maxLineLen) maxBoxWidth = (5 * maxLineLen) + "px";
}
if (!$I("htmlPop")) { //pop object not yet existing
var details = document.createElement("div");
details.id = "htmlPop";
document.body.appendChild(details);
}
popobj = $I("htmlPop");
popobj.style.width = maxBoxWidth;
popobj.className = popClass;
popobj.innerHTML = popContent;
popobj.style.visibility = "visible";
parent.onmousemove = function(e) {
if (!e) var e = window.event; //if ie
var rightedge = window.innerWidth-20; //window edge
var bottomedge = window.innerHeight-10;
if (rightedge-cursorX(e)-offsetX < popobj.offsetWidth) { //if pop hits the right edge
popobj.style.left = rightedge-popobj.offsetWidth-5+"px"; //don't move it
} else {
popobj.style.left = (cursorX(e) < -offsetX) ? "5px" : cursorX(e)+offsetX+"px"; //move it with mouse
}
if (bottomedge-cursorY(e)-offsetY < popobj.offsetHeight) { //if pop hits the bottom edge
popobj.style.top = cursorY(e)-popobj.offsetHeight-(offsetY/2)+"px"; //flip it up
} else {
popobj.style.top = cursorY(e)+offsetY+"px"; //move it with mouse
}
};
parent.onmouseout = function() {
parent.onmousemove = null;
popobj.style.visibility = "hidden";
};
return;
}
//==== compatibility functions ====
function cursorX(e) { //get cursor X-position relative to page
return e.pageX ? e.pageX : e.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
}
function cursorY(e) { //get cursor Y-position relative to page
return e.pageY ? e.pageY : e.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}