var req; var fieldId; var fieldAction = false; var multiValue; var multiValList; var calendarZ = 10; function ajaxSubmitHandler() { if (fieldAction != "add" && fieldAction != "remove") { return true; } else { return false; } } function setFieldAction(newAction) { fieldAction = newAction; } function fieldHandler(inputId, inputFunction, inputValue, inputAction, metaFunction) { /* myAlert("navigator.appName="+navigator.appName); myAlert("navigator.appVersion="+navigator.appVersion); myAlert("navigator.appMinorVersion="+navigator.appMinorVersion); myAlert("navigator.appCodeName="+navigator.appCodeName); */ req = null; fieldId = inputId; fieldAction = inputAction; fieldForm = getFormName(fieldId); //fieldForm = document.getElementById(fieldId).form.getAttribute("id"); //url = document.URL; //TODO: FIX THIS!!!! //url = "/post.php?action=" + document.URL; url = "ajax_post.php"; //REMOVE THIS !!!!! //TODO: FIX ABOVE!!! params = 'form_name=' + fieldForm + '&ajax_post=true' if (fieldAction == 'remove') { multiValue = getMultiRemoveChecked(); if (multiValue == null) { handle_response(false,"No boxes are checked"); return; } else { params = params + "&_multi_remove[" + fieldId + "]=true"; for (i = 0; i < multiValue.length; i++) params = params + "&" + multiValue[i] + "=checked"; } } else { if (fieldAction == 'add' && !isArray(inputValue)) { params = params + '&_multi_add[' + fieldId + ']=Add'; params = params + '&' + fieldId + '=' + escape(inputValue); multiValue = inputValue; if (multiValue == "" || multiValue == null) { handle_response(false,"You must enter or select something to add it."); return; } } else { if (isArray(inputValue)) { for(i=0;i0 ) detailString = detailString + "
"; detailString = detailString + allDetails[i].firstChild.data; //detailString = detailString + allDetails[i].textContent; //myAlert(allDetails[i].textContent); } //myAlert("detailString = "+detailString); handle_response(funcStatus, detailString); } else { //myAlert("There was a problem retrieving the XML data:\n" + req.statusText); } } } /** * This is a homemade function to check whether or not a variable is an array */ function isArray(a) { if (typeof a == 'object' && a.constructor == Array) return true; else return false; } /** * Given a form field id, this will traverse up the DOM tree until the parent form is found. */ function getFormName(givenId) { temp = document.getElementById(givenId); while (temp.tagName.toLowerCase() != 'form') temp = temp.parentNode; return temp.getAttribute('id'); } /** * This function checks the parent form of the field that is being validated to see if there are any field errors * returns true if a field error is found * returns false if there are no field errors found */ function fieldErrorsExist() { formObject = document.getElementById(fieldForm); //Cycle through all form field elements to check for validation errors for (i=0;i'; tempObject.appendChild(newNode); if (multiContainerExists()) return true; else return false; } function removeMultiContainer() { if (!multiContainerIsEmpty()) return false; try { tNode = document.getElementById(fieldId+"_multi_div"); tNode.parentNode.removeChild(tNode); } catch(x) { return false; } return true; } /** * This function searches for the multi container */ function multiContainerExists() { if (document.getElementById(fieldId + '_multi_div') == null) return false; else return true; } function multiContainerIsEmpty() { if (!multiContainerExists()) return false; multiDiv = document.getElementById(fieldId+"_multi_div"); for (i = 0; i < multiDiv.childNodes.length; i++) { tN = multiDiv.childNodes[i]; if (tN.nodeType == 1 && tN.tagName.toLowerCase() == "input" && tN.type.toLowerCase() == "checkbox") return false; } return true; } function getMultiRemoveChecked() { if (!multiContainerExists()) return null; multiDiv = document.getElementById(fieldId+"_multi_div"); tCNames = new Array(); cNameCount = 0; for (i = 0; i < multiDiv.childNodes.length; i++) { tN = multiDiv.childNodes[i]; if (tN.nodeType == 1 && tN.tagName.toLowerCase() == "input" && tN.type.toLowerCase() == "checkbox" && tN.checked) { tCNames[cNameCount] = tN.id; cNameCount++; } } if (cNameCount > 0) return tCNames; return null; } function myAlert(message) { temp = document.getElementById("ajax_error_output"); if (temp != null) { temp.innerHTML = message; } alert(message); } function formatDate(dateString) { year = dateString.substring(0,4); month = dateString.substring(5,7); day = dateString.substring(8,10); months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); newString = day + ' ' + months[Number(month)-1] + ' ' + year; return newString; } function formatTime(timeString) { hour = timeString.substring(0,2); minute = timeString.substring(3,5); if (hour > 11) newString = "pm"; else newString = "am"; if (hour > 12) hour = Number(hour)-12; newString = hour + ":" + minute + newString; return newString; } /** * This will start the process for creating a calendar pop-up */ function initiateCalendarPopup(eventId) { fieldId = eventId; if (calendarPopupExists(eventId) && calendarLocationUpdate(eventId)) { return false; } url = "https://"+document.domain+"/calendar/view.php?event_id=" + eventId + "&ajax=true"; // Create the HTTPRequest req = generateRequest(); //If the request is invalid, give an alert and return if (req == null) { return true; } //alert(url); req.onreadystatechange = calendarReqChange; req.open("GET", url, true); req.send(null); return false; } /** * This is the event handler for the HTTP stream, when the stream updates it gets called */ function calendarReqChange() { try { if (req.readyState == 4) { //alert("current req.status="+req.status); if (req.status == 200) { XMLresponse = req.responseXML.documentElement; fullEvent = XMLresponse.getElementsByTagName('event'); funcStatus = XMLresponse.getElementsByTagName('status')[0].firstChild.data; detailString = ""; if (funcStatus == '1' && calendarResponse(XMLresponse)) { return; } else { window.location.replace("/calendar/view.php?event_id="+fieldId); } } else { window.location.replace("/calendar/view.php?event_id="+fieldId); } } } catch (x) { window.location.replace("/calendar/view.php?event_id="+fieldId); } } function calendarResponse(XMLresponse) { // alert("we have a calendar response!"); eventId = XMLresponse.getElementsByTagName('event_id')[0].firstChild.data; if (!calendarPopupAdd(eventId)) { // alert("calendar popup not added!"); window.location.replace("/calendar/view.php?event_id="+eventId); } // alert("calendar popup should exist"); eventNode = document.getElementById("popup_container_"+eventId); eventShadow = document.getElementById("popup_shadow_"+eventId); // alert("eventNode.id = "+eventNode.id); // alert("eventShadow.id = "+eventShadow.id); html = ""; eventTitle = XMLresponse.getElementsByTagName('title')[0].firstChild; calTitle = XMLresponse.getElementsByTagName('cal_title')[0].firstChild; eventDate = XMLresponse.getElementsByTagName('good_date')[0].firstChild; eventTime = XMLresponse.getElementsByTagName('good_time')[0].firstChild; eventDesc = XMLresponse.getElementsByTagName('description')[0].firstChild; eventLoca = XMLresponse.getElementsByTagName('location')[0].firstChild; eventSpon = XMLresponse.getElementsByTagName('sponsor_name')[0].firstChild; eventAdmn = XMLresponse.getElementsByTagName('admin')[0].firstChild; eventUrl = XMLresponse.getElementsByTagName('url')[0].firstChild; html = html + ''; html = html + ''; html = html + ''; eventNode.innerHTML = html; // alert("eventNode.innerHTML = "+eventNode.innerHTML); document.getElementById('popup_bg_rs_'+eventId).style.height = (eventNode.offsetHeight-44) + "px"; document.getElementById('popup_bg_rs_'+eventId).style.width = "202px"; update = calendarLocationUpdate(eventId); // alert(eventNode.offsetHeight + "px"); if (update) update = calendarShadowUpdate(eventId); return update; } function calendarPopupExists(eventId) { if (document.getElementById("popup_container_" + eventId) != null && document.getElementById("popup_shadow_" + eventId) != null) return true; else return false; } function calendarPopupAdd(eventId) { if (!calendarPopupExists(eventId)) { container = document.createElement('DIV'); container.style.visibility = "hidden"; document.body.appendChild(container); container.style.position = 'absolute'; container.id = 'popup_container_'+eventId; container.style.width = "202px"; shadow = document.createElement('DIV'); shadow.style.visibility = "hidden"; document.body.appendChild(shadow); shadow.style.position = 'absolute'; shadow.id = 'popup_shadow_'+eventId; shadow.setAttribute("class","popup_shadow"); shadow.className = "popup_shadow"; } return calendarPopupExists(eventId); } function calendarLocationUpdate(eventId) { eventParent = document.getElementById("event_link_"+eventId); eventNode = document.getElementById("popup_container_"+eventId); eventContainer = document.getElementById("calendar_month_view"); if (eventNode != null && eventParent != null && eventContainer != null) { eventNode.style.visibility = "hidden"; eventNode.style.zIndex = calendarZ++; document.getElementById("popup_close_"+eventId).style.zIndex = calendarZ++; // alert(document.getElementById("popup_background_"+eventId).style.zIndex); // alert(document.getElementById("popup_data_"+eventId).style.zIndex); // alert(document.getElementById("popup_close_"+eventId).style.zIndex); pL = eventParent.offsetLeft; pW = eventParent.offsetWidth; pT = eventParent.offsetTop; pH = eventParent.offsetHeight; while (eventParent.offsetParent != null) { eventParent = eventParent.offsetParent; pL = pL + eventParent.offsetLeft; pT = pT + eventParent.offsetTop; } eW = eventNode.offsetWidth; eH = eventNode.offsetHeight; cL = eventContainer.offsetLeft; cT = eventContainer.offsetTop; cW = eventContainer.offsetWidth; cH = eventContainer.offsetHeight; while (eventContainer.offsetParent != null) { eventContainer = eventContainer.offsetParent; cL = cL + eventContainer.offsetLeft; cT = cT + eventContainer.offsetTop; } if ((pL + pW + eW) < (cW + cL) && (pT - eH) > cT) { // To the right and above eventNode.style.left = (pL + pW) + "px"; eventNode.style.top = (pT - eH) + "px"; } else if ((pL - eW) > cL && (pT - eH) > cT) { // To the left and above eventNode.style.left = (pL - eW) + "px"; eventNode.style.top = (pT - eH) + "px"; } else if ((pL + pW + eW) < (cW + cL) && (pT + pH + eH) < (cT + cH)) { // To the bottom right eventNode.style.left = (pL + pW) + "px"; eventNode.style.top = (pT + pH) + "px"; } else if ((pL - eW) > cL && (pT + pH + eH) < (cT + cH)) { // To the bottom left eventNode.style.left = (pL - eW) + "px"; eventNode.style.top = (pT + pH) + "px"; } else { return false; } eventNode.style.visibility = "visible"; return true; } return false; } function calendarShadowUpdate(eventId) { try { eventNode = document.getElementById("popup_container_"+eventId) shadowNode = document.getElementById("popup_shadow_"+eventId) baseHeight = Math.floor(eventNode.offsetHeight/2); baseNum = Math.floor((baseHeight-30)/5); shadowNode.style.width = ((baseNum * 2) + 210) + 'px'; shadowNode.style.height = baseHeight + 'px'; shadowNode.style.top = (eventNode.offsetTop + baseHeight + 50) + 'px'; shadowNode.style.left = (eventNode.offsetLeft + 50) + 'px'; html = ""; html = html + ''; for (i = 0; i < baseNum; i++) html = html + ''; html = html + ''; shadowNode.innerHTML = html; shadowNode.style.visibility = "visible"; } catch (x) { alert("There was an exception while updating the shadow"); alert(x); return false; } return true; } function calendarPopupClose(eventId) { eventNode = document.getElementById("popup_container_" + eventId); shadowNode = document.getElementById("popup_shadow_" + eventId); if (eventNode != null) { eventNode.parentNode.removeChild(eventNode); } if (shadowNode != null) { shadowNode.parentNode.removeChild(shadowNode); } }