///////////////////////////////////////////////////////////////////////////////////// // DIY 'getElementsByClass' and do something function //Create an array var allPageTags = new Array(); allPageTags=document.getElementsByTagName("*"); function doSomethingWithClasses(theClass, theStyle, theValue) { //Cycle through the tags using a for loop for (i=0; i= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @else xmlhttp = false; @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } var http = createRequestObject(); function updateDiv(div,scriptURL,queryVars,type,notifyBool) { if (connectComplete == 1){ if (notifyBool == 1) { document.getElementById(div).innerHTML = '
 
'; } connectComplete = 0; divName = div; handleType = type; http.open("GET", scriptURL + "?" + queryVars, true); http.send(null); http.onreadystatechange = handleHttpResponse; } } ////////////////////////////////////////////////////////////////////////////////////// // Comments function commentLike(cId) { updateDiv('comments_comment_like_' + cId, '', 'page_type=comment_like&cid=' + cId,'html',0); document.getElementById('comments_comment_like_' + cId).blur(); } function commentReport(cId) { updateDiv('comments_comment_report_' + cId, '', 'page_type=comment_report&cid=' + cId,'html',0); document.getElementById('comments_comment_report_' + cId).blur(); document.getElementById('comments_comment_report_' + cId).onClick = 'return false;'; } function commentQuote(cId) { var commentMsg = document.getElementById('comments_comment_body_' + cId).innerHTML; commentMsg = stripTags(commentMsg); var commentBox = document.getElementById('comments_comment'); var newMsg = '[quote]' + commentMsg + '[/quote]\r\n'; commentBox.value = newMsg; commentBox.focus(); } ///////////////////////////////////////////////////////////////////////////////////// // Calendar function calendarPop(triggerObj, inputBoxId, calType) { var inputBox = document.getElementById(inputBoxId); var triggerX = bumbleGetX(triggerObj); var triggerY = bumbleGetY(triggerObj) + bumbleGetHeight(triggerObj); var calendarObj = document.createElement('div'); var calendarId = 'calendar_pop_' + inputBoxId; if (calType == 'monthyear') calendarObj.className = 'calendar_pop_container calendar_pop_monthyear'; else calendarObj.className = 'calendar_pop_container'; if (!document.getElementById(calendarId)) { calendarObj.setAttribute('id', calendarId); calendarObj.style.zIndex='9999999'; calendarObj.style.left=triggerX + 'px'; calendarObj.style.top=triggerY + 'px'; document.body.appendChild(calendarObj); updateDiv(calendarId, '', 'page_type=calendar_modal&cal_type=' + calType + '&type=modal&input_box=' + inputBoxId, 'html', 0); } } function calendarPopDestroy(objId) { if (typeof(document.getElementById(objId)) != 'undefined') { var obj = document.getElementById(objId); obj.parentNode.removeChild(obj); } } function calenderPopSelect(inputBoxId, day, month, year) { var inputBox = document.getElementById(inputBoxId); var calendarId = 'calendar_pop_' + inputBoxId; var calendarObj = document.getElementById(calendarId); inputBox.value = day + '/' + month + '/' + year; inputBox.focus(); window.setTimeout('calendarPopDestroy(\'' + calendarId + '\')', 100); } function calendarPopUpdate(calId, action, calType) { if (action == 'next') var m = parseInt(document.getElementById('calendar_pop_month').value) + 1; else if (action == 'prev') var m = parseInt(document.getElementById('calendar_pop_month').value) - 1; else m = document.getElementById('calendar_pop_month').value; var y = document.getElementById('calendar_pop_year').value; if (m > 12) { m = 1; y ++; } else if (m < 1) { m = 12; y --; } var inputBoxId = calId.replace('calendar_pop_', ''); var qs = '&m=' + m + '&y=' + y; updateDiv(calId, '', 'page_type=calendar_modal&cal_type=' + calType + '&type=modal&input_box=' + inputBoxId + qs, 'html', 0); } function calendarPopSubmitMY(inputBoxId) { var allMonths = new Array(' ', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); var thisMonth = document.getElementById('calendar_pop_month').value; var inputBox = document.getElementById(inputBoxId); inputBox.value = allMonths[parseInt(thisMonth)] + ' ' + document.getElementById('calendar_pop_year').value; calendarPopDestroy('calendar_pop_' + inputBoxId); } function calendar_show_time_slots(timestamp,type) { location.href='#calendar_days'; updateDiv('calendar_times_container', '', 'page_type=calendar_times&action=book×tamp=' + timestamp + '&type=' + type, 'html', 1); } function update_calendar(action,type) { if (action == 'next') m = parseInt(document.getElementById('calendar_list_months').value) + 1; else if (action == 'prev') m = parseInt(document.getElementById('calendar_list_months').value) - 1; else m = document.getElementById('calendar_list_months').value; y = document.getElementById('calendar_list_years').value; if (m > 12) { m = 1; y ++; } else if (m < 1) { m = 12; y --; } var qs = '&m=' + m + '&y=' + y; updateDiv('calendar_container', '', 'page_type=calendar&action=book&' + 'type=' + type + qs, 'html', 1); } function calendar_book(timestamp,type) { var chosen_date = new Date(); chosen_date.setTime(timestamp + '000'); chosen_hour = chosen_date.getHours(); if (chosen_hour > 12) chosen_hour -= 12; else if (chosen_hour == 0) chosen_hour = 12; if (chosen_hour > 11) chosen_suffix = 'AM'; else chosen_suffix = 'PM'; chosen_mins = chosen_date.getMinutes(); if (chosen_mins < 10) chosen_mins = '0' + chosen_mins; var chosen_date_formatted = chosen_date.getDate() + '/' + (chosen_date.getMonth() + 1) + '/' + chosen_date.getFullYear() + ' at ' + chosen_hour + ":" + chosen_mins + ' ' + chosen_suffix; if (confirm("You have requested a booking for " + chosen_date_formatted +".\n\nAre you sure you wish to proceed?\n\n ")) { updateDiv('calendar_container', '', 'page_type=calendar&type=' + type + '&action=bookslot&slottime=' + timestamp, 'html', 1); } } ///////////////////////////////////////////////////////////////////////////////////// // Product review submission function shopRatingChange(rating, e) { if (!e) var e = window.event; if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement; if (targ.nodeType == 3) // defeat Safari bug targ = targ.parentNode; var imgStarOff = targ.src.replace('rate_star.gif', 'rate_star_off.gif'); var imgStarOn = targ.src.replace('rate_star_off.gif', 'rate_star.gif'); var idParts = targ.id.split('-'); var thisStar = ''; for (var r=1; r <= 5; r++) { thisStar = document.getElementById(idParts[0] + '-' + idParts[1] + '-' + r); if (r <= rating) thisStar.src = imgStarOn; else thisStar.src = imgStarOff; } } function submitRating(e) { if (!e) var e = window.event; if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement; if (targ.nodeType == 3) // defeat Safari bug targ = targ.parentNode; var idParts = targ.id.split('-'); var rating = idParts[2]; var pid = idParts[1]; window.location.href = '/?page=_product_review&pid=' + pid + '&action=new&rating=' + rating; } function submitReview(pid) { if (document.getElementById('new_name') != null) var name = parseQS(document.getElementById('new_name').value); if (document.getElementById('new_location') != null) var location = parseQS(document.getElementById('new_location').value); var rating = parseQS(document.getElementById('new_rating').value); var review = parseQS(document.getElementById('new_review').value); updateDiv('review_form', '/', 'page_type=product_review&pid=' + pid + '&action=new&name=' + name + '&location=' + location + '&rating=' + rating + '&review=' + review, 'html', 1) } // swap product details with additional extra function shopSwapProductDetails(mainPid, extraId) { var shortDescription = document.getElementById('shop_product_short_description_' + mainPid); var longDescription = document.getElementById('shop_product_long_description_' + mainPid); var image = document.getElementById('shop_product_image_' + mainPid); var price = document.getElementById('shop_product_price_' + mainPid); var addItem = document.getElementById('shop_product_additem_' + mainPid); shortDescription.innerHTML = shopProductExtras[extraId]['short_description']; longDescription.innerHTML = shopProductExtras[extraId]['long_description']; image.src = '/?page_type=show_image&w=' + image.width + '&h=' + image.height + '&img=' + shopProductExtras[extraId]['image']; price.innerHTML = '£' + shopProductExtras[extraId]['price']; addItem.value = extraId; } function getAddressFromPostcode(postCodeEl,returnInputsDelim) { if (postCodeEl && typeof postCodeEl == 'object') { window.clearTimeout(postCodeTimeout); postCodeTimeout = window.setTimeout(function() { if (postCodeEl.value == postCodeStr) return false; else { postCodeStr = postCodeEl.value; if (typeof(postCodeCall) == 'object') { postCodeCall.abort(); } postCodeCall = new bumbleAJAXCall('/?page_type=address_from_postcode&postcode=' + postCodeStr,function(str) { processAddressFromPostcode(str,returnInputsDelim); } ); } }, 50); } } function processAddressFromPostcode(str,returnInputsDelim) { if (str != '') { var addrArr = str.split('@@@@'); addressSelectFromPostcode(addrArr,returnInputsDelim); } } function addressSelectFromPostcode(addressDelim,returnInputsDelim) { // returnInputsDelim = element IDs for address fields, comma separated (address 1, address 2, town, county) var returnInputsArr = returnInputsDelim.split(','); var addressSelectObj = document.createElement("div"); var len = addressDelim.length; for (var i = 0; i < len; i++) { var thisAddr = addressDelim[i].split(', '); var thisLink = document.createElement("a"); thisLink.href = '#'; thisLink.className = 'modal_select_link'; var thisAddressStr = thisAddr[0]; if (thisAddr[1] != '') thisAddressStr += ', ' + thisAddr[1]; if (thisAddr[5] != '') thisAddressStr += ', ' + thisAddr[5]; if (thisAddr[6] != '') thisAddressStr += ', ' + thisAddr[6]; thisLink.innerHTML = thisAddressStr; thisLink.setAttribute('data-addr1', thisAddr[0]); thisLink.setAttribute('data-addr2', thisAddr[1]); thisLink.setAttribute('data-town', thisAddr[5]); thisLink.setAttribute('data-county', thisAddr[6]); thisLink.onclick = function() { var addr1 = document.getElementById(returnInputsArr[0]); var addr2 = document.getElementById(returnInputsArr[1]); var town = document.getElementById(returnInputsArr[2]); var county = document.getElementById(returnInputsArr[3]); addr1.value = this.getAttribute('data-addr1'); addr2.value = this.getAttribute('data-addr2'); town.value = this.getAttribute('data-town'); county.value = this.getAttribute('data-county'); if (typeof postcodeBox == 'object') postcodeBox.hide(); return false; }; addressSelectObj.appendChild(thisLink); } var postcodeBox = new bumbleBox('', 'Please select your address', '90%', 'auto', 'object', '', true, '', addressSelectObj); postcodeBox.show(); } var postCodeCall = ''; var postCodeTimeout = ''; var postCodeStr = ''; var postcodeBox = ''; ///////////////////////////////////////////////////////////////////////////////////// // Validate forms function checkform(formname) { /* Tool methods */ function cf_adderr(o) { // create image, add to and colourise the error fields var errorIndicator=document.createElement('img'); errorIndicator.alt=errorAlt; errorIndicator.src=errorImg; errorIndicator.title=errorTitle; o.className=errorClass; o.parentNode.insertBefore(errorIndicator,o); // Check if there is no error message if(!document.getElementById(errorID)) { // create errormessage and insert before submit button var em = document.createElement('div'); em.style.textAlign='left'; em.id = errorID; var newp = document.createElement('p'); newp.innerHTML = errorMsg; // clone and insert the error image newp.appendChild(errorIndicator.cloneNode(true)); em.appendChild(newp); // find the submit button for(var i=0; i < formname.getElementsByTagName('input').length; i++){ if(/submit/i.test(formname.getElementsByTagName('input')[i].type)) { var sb = formname.getElementsByTagName('input')[i]; break; } } if(sb) { sb.parentNode.insertBefore(em,sb); } } } function cf_isEmailAddr(str) { return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/); } if(!document.getElementById || !document.createTextNode || !formname.required) { return; } else { var errorID='error_alert'; var errorClass='input_error' var errorMsg='Some fields are missing or invalid.
Please enter or change the fields marked with a '; var errorImg='library/templates/default/resources/form_alert.gif'; var errorAlt='Error'; var errorTitle='Please complete this field'; var reqfields=formname.required.value.split('||'); // Cleanup old mess // if there is an old errormessage field, delete it if(document.getElementById(errorID)){ var em=document.getElementById(errorID); em.parentNode.removeChild(em); } // remove old images and classes from the required fields for(var i=0; i < reqfields.length; i++) { var f=document.getElementById(reqfields[i]); if(!f) continue; if(f.previousSibling && /img/i.test(f.previousSibling.nodeName)) { f.parentNode.removeChild(f.previousSibling); } f.className='inputbox'; } // loop over required fields for(var i=0; i < reqfields.length; i++) { // check if required field is there var f=document.getElementById(reqfields[i]); if(!f) continue; // test if the required field has an error, // according to its type else switch(f.type.toLowerCase()) { case 'text': if(f.value=='' && f.id!='email' && (f.attributes.alt.value) != 'Email') cf_adderr(f); if((f.id=='email' || ((f.attributes.alt.value) == 'Email')) && !cf_isEmailAddr(f.value)) cf_adderr(f); break; case 'hidden': // if hidden, then we're looking for a radio selection instead, using name instead of ID var formnameName = formname.name; var radioObject = eval('document.' + formnameName + '.' + f.id + ';'); var radioObjectNum = (radioObject.length == 'undefined') ? 1 : radioObject.length; var radioChecked = 0; for(var r = 0; r < radioObjectNum; r++) { if(radioObject[r].checked) { radioChecked = 1; break; } } if (radioChecked == 0) cf_adderr(f); break; case 'textarea': if(f.value=='') cf_adderr(f); break; case 'checkbox': if(!f.checked) cf_adderr(f); break; case 'select-one': if(!f.selectedIndex && f.selectedIndex==0) cf_adderr(f); break; } } return !document.getElementById(errorID); } } function validateField(field, valType, compareField) { var fieldId = field.id; if (typeof valInProgress != 'undefined' && typeof valInProgress[fieldId] != 'undefined') window.clearTimeout(valInProgress[fieldId]); else if (typeof valInProgress == 'undefined') valInProgress = new Array(); validationMessage(fieldId, 'wait'); valInProgress[fieldId] = window.setTimeout("actualValidate('" + fieldId + "', '" + valType + "', '" + compareField + "')", 500); } function actualValidate(fieldId, valType, compareField) { var field = document.getElementById(fieldId); var fieldValue = field.value; var validated = false; if (document.getElementById(compareField)) var compareVal = document.getElementById(compareField).value; switch (valType) { case "password": if (fieldValue.length < 6) var valMsg = 'Password must be 6 or more characters long'; else validated = true; break; case "confirm": if (fieldValue.length < 6) var valMsg = 'Password must be 6 or more characters long'; else if (fieldValue != compareVal) var valMsg = 'This must be the same as the password'; else validated = true; break; case "email": if (!fieldValue.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/)) var valMsg = 'This doesn\'t appear to be a proper email address'; else validated = true; break; case "postcode": field.value = formatPostcode(fieldValue); fieldValue = field.value; if(!isValidPostcode(fieldValue)) var valMsg = 'This doesn\'t appear to be a valid postcode'; else validated = true; break; case "none": validated = true; break; default: // check if empty or not if (fieldValue != '') validated = true; else var valMsg = 'This field cannot be empty.'; break; } validationMessage(fieldId, validated, valMsg); } function validationMessage(fieldId, validated, valMsg) { var field = document.getElementById(fieldId); var valIcon = document.getElementById('valid_icon_' + fieldId); var iconOK = '/library/templates/default/resources/validate_ok.gif'; var iconFailed = '/library/templates/default/resources/validate_failed.gif'; var iconWait = '/library/templates/default/resources/validate_wait.gif'; if (valIcon == null) { var posX = findPosX(field) + field.offsetWidth + 25; var posY = findPosY(field) + field.offsetHeight - 21; var newValIcon = document.createElement('div'); var bodyElement = document.getElementsByTagName('body'); newValIcon.setAttribute('id', 'valid_icon_' + fieldId); field.parentNode.appendChild(newValIcon); //bodyElement[0].firstChild.parentNode.insertBefore(newValIcon, bodyElement[0].firstChild); valIcon = document.getElementById('valid_icon_' + fieldId); valIcon.style.display = 'inline'; valIcon.style.position = 'absolute'; valIcon.style.marginTop = '-2px'; valIcon.style.marginLeft = '10px'; //valIcon.style.top = posY + 'px'; //valIcon.style.left = posX + 'px'; valIcon.style.padding = '2px 2px 2px 30px'; valIcon.style.height = '19px'; valIcon.style.backgroundPosition = '2px 2px'; valIcon.style.backgroundRepeat = 'no-repeat'; } if (validated == 'wait') { valIcon.style.backgroundColor = 'Transparent'; valIcon.style.backgroundImage = 'url(' + iconWait + ')'; valIcon.innerHTML = ' '; } else if (validated == true) { valIcon.style.backgroundColor = 'Transparent'; valIcon.style.backgroundImage = 'url(' + iconOK + ')'; valIcon.innerHTML = ' '; } else { valIcon.style.backgroundColor = '#fff'; valIcon.style.backgroundImage = 'url(' + iconFailed + ')'; valIcon.innerHTML = valMsg; } } function isValidPostcode(p) { var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2}[A-Z]? ?[0-9][A-Z]{2}/i; return postcodeRegEx.test(p); } function modalMessagesScrollDown() { var messageBox = document.getElementById('modal_messages_messages'); var scrollEl = document.getElementById('modal_messages_bottom'); messageBox.scrollTop = scrollEl.offsetTop; var messageInput = document.getElementById('modal_message_new'); messageInput.value = ''; messageInput.focus(); } var thisBumbleBox; function modalMessagesSubmitMsg() { var messageContent = document.getElementById('modal_message_new').value; messageContent = parseQS(messageContent); var messageWindow = document.getElementById('modal_messages_messages'); var bottomAnchor = document.getElementById('modal_messages_bottom'); var newBubble = document.createElement("div"); newBubble.className = 'modal_messages_message you'; newBubble.style.opacity='0.5'; var throbber = document.createElement("div"); throbber.className = 'bumbleThrobber top dark'; newBubble.appendChild(throbber); messageWindow.insertBefore(newBubble, bottomAnchor); window.setTimeout('modalMessagesScrollDown()', 100); var userId = document.getElementById('modal_messages_uid').value; window.setTimeout(function() { var updateContent = new bumbleAJAXCall('/?page_type=users_messages_modal&action=new&user_id=' + userId + '&message=' + messageContent, function() { window.setTimeout(modalMessagesScrollDown, 100); }, messageWindow); }, 1000); } function modalMessagesView(userId) { if (!userId || userId == 'undefined') userId = ''; thisBumbleBox = new bumbleBox('/?page_type=users_messages_modal&user_id=' + userId, 'Messages', '90%', '90%', 'ajax', modalMessagesScrollDown, false); thisBumbleBox.show(); } function recalcFormProductTotal() { window.setTimeout('recalcFormProductTotalAction()', 100); } function recalcFormProductTotalAction() { var fields = document.getElementById('check_products_delim'); var thisEl = ''; var thisId = ''; var valueField = ''; var thisValue = ''; var thisValueParts = ''; var thisSelectObj = ''; var totalValue = 0; if (fields != null && fields.value != '') { var fieldsArr = fields.value.split(','); for (var i = 0; i < fieldsArr.length; i++) { valueField = null; if (fieldsArr[i] != '') { thisEl = document.getElementById(fieldsArr[i]); if (thisEl != null) { if (thisEl.tagName == 'INPUT' || thisEl.tagName == 'input') { if (thisEl.type == 'checkbox' && thisEl.checked == true) { // item has been ticked - add price thisId = fieldsArr[i].replace(/\_form\_/, '', fieldsArr[i]); ; valueField = document.getElementById('product_value_' + thisId); } else if (thisEl.type == 'hidden') { // item has extras - parent item's price will be added too // check an option has been selected from extras before adding this price thisId = fieldsArr[i].replace(/\product\_value\_/, '', fieldsArr[i]); thisSelectObj = document.getElementById('extra_item_' + thisId); if (thisSelectObj != null && thisSelectObj.selectedIndex > 0) { valueField = document.getElementById(fieldsArr[i]); } } if (valueField != null) totalValue += parseInt(valueField.value); } else if (thisEl.tagName == 'SELECT' || thisEl.tagName == 'select') { thisValue = thisEl.value; if (thisValue != '') { thisValueParts = thisValue.split(','); if (thisValueParts[1] != null) totalValue += parseInt(thisValueParts[1]); } } } } } document.getElementById('form_products_total_value').innerHTML = totalValue; } } /* formats a VALID postcode nicely: AB120XY -> AB1 0XY */ function formatPostcode(p) { if (isValidPostcode(p)) { var postcodeRegEx = /(^[A-Z]{1,2}[0-9]{1,2}[A-Z]?)([0-9][A-Z]{2}$)/i; p = p.toUpperCase(); return p.replace(postcodeRegEx,"$1 $2"); } else { return p; } } function findPosX(obj) { var curleft = 0; if(obj.offsetParent) while(1) { curleft += obj.offsetLeft; if(!obj.offsetParent) break; obj = obj.offsetParent; } else if(obj.x) curleft += obj.x; return curleft; } function findPosY(obj) { var curtop = 0; if(obj.offsetParent) while(1) { curtop += obj.offsetTop; if(!obj.offsetParent) break; obj = obj.offsetParent; } else if(obj.y) curtop += obj.y; return curtop; } function addToWishlist() { document.getElementById('shop_wishlist_toggle').value='1'; document.getElementById('shop_product_form').submit(); return false; } // For shop - when using additional products, check if any are ticked function checkTickedProducts(thisFormId) { thisForm = document.getElementById(thisFormId); numExtra = thisForm.num_extra.value; if(thisForm.xtra_val_1) { noneTicked=1; for (x=1; x<=numExtra; x++) { thisElement=eval("thisForm.xtra_bool_"+x); if(thisElement.checked) { noneTicked=0; } } if (noneTicked==1) { alert('Please tick the items you require before adding to cart'); return false; } } else { return true; } } // Cart accessories function shopCartShowAccessories(catId) { var accContainer = document.getElementById('shop_cart_accessories_products'); var accArr = eval('accessories_' + catId); accContainer.innerHTML = ''; for (var i=0; i < accArr.length; i++) { var lineHTML = '
'; lineHTML += '' + accArr[i]['short_description'] + ''; lineHTML += 'Add to basket'; lineHTML += '£' + accArr[i]['price'] + ' ' + accArr[i]['unit'] + ''; lineHTML += '

' + accArr[i]['short_description'] + '

'; lineHTML += '
' + accArr[i]['long_description'] + '
'; lineHTML += '
'; accContainer.innerHTML += lineHTML; } accContainer.style.display = 'block'; window.location.hash = "accessories"; } // tidy strings before passing via query string function parseQS(str) { str = str.replace(/\%/g, '[percent]'); str = encodeURIComponent(str); str = str.replace(/\%5Bpercent\%5D/g, '%25'); return str; } // get all input names within element function getAllInputs(el) { var oChild = el.firstChild; var inputsArr = []; if (oChild) { while(oChild) { var oChildChild = oChild.firstChild; if (oChildChild) { var elsArr = getAllInputs(oChild); if (elsArr.length > 0) inputsArr = inputsArr.concat(elsArr); } if (oChild.name && typeof oChild.name != 'undefined') { inputsArr.push(String(oChild.name)); } oChild = oChild.nextSibling; } } return inputsArr.unique(); } // Strip HTML tags function stripTags(strMod){ if (arguments.length<3) strMod=strMod.replace(/<\/?(?!\!)[^>]*>/gi, ''); else{ var IsAllowed=arguments[1]; var Specified=eval("["+arguments[2]+"]"); if(IsAllowed){ var strRegExp=']*>'; strMod=strMod.replace(new RegExp(strRegExp, 'gi'), ''); }else{ var strRegExp=']*>'; strMod=strMod.replace(new RegExp(strRegExp, 'gi'), ''); } } return strMod; } // Confirmations function confirmAction(msg) { if (!msg) var msg = 'Are you sure you wish to delete this item?'; return confirm(msg); } // Popup windows var newwin; function launchwin(winurl,winname,winfeatures) { if(newwin) { newwin.close(); } newwin = window.open(winurl,winname,winfeatures); newwin.focus(); } function placeFocus() { if (document.forms.length > 0) { var field = document.forms[0]; for (i = 0; i < field.length; i++) { if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) { document.forms[0].elements[i].focus(); break; } } } } function showModalInfo(e, itemType, itemId) { var modalBox = document.getElementById('modal_info_container'); if (!e) var e = window.event; var currentPosX = e.pageX - 50; var currentPosY = e.pageY - 100; modalBox.style.left = currentPosX + 'px'; modalBox.style.top = currentPosY + 'px'; modalBox.style.display = 'block'; updateDiv('modal_info_content', '/', 'page_type=modal_content&type=' + itemType + '&id=' + itemId, 'html', 1); } function hideModalInfo() { var modalBox = document.getElementById('modal_info_container'); var modalContent = document.getElementById('modal_info_content'); modalContent.innerHTML = ''; modalBox.style.display = 'none'; } // Return characters pressed, in input boxes etc, and filter (e.g. numbers only) function getkey(e) { if (window.event) return window.event.keyCode; else if (e) return e.which; else return null; } function swapimage(imageid, imagefile) { document.getElementById(imageid).src = 'library/images/' + imagefile; } function goodchars(e, goods) { var key, keychar; key = getkey(e); if (key == null) return true; // get character keychar = String.fromCharCode(key); keychar = keychar.toLowerCase(); goods = goods.toLowerCase(); // check goodkeys if (goods.indexOf(keychar) != -1) return true; // control keys if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 ) return true; // else return false return false; } function changeqty(dir, id) { currentqty = parseInt(document.getElementById(id).value); if (dir=='up') document.getElementById(id).value = currentqty+1; else if (dir=='down' && currentqty > 1) document.getElementById(id).value = currentqty-1; else if (dir=='down' && currentqty < 2) document.getElementById(id).value = 1; } function checksearch(searchform,searchbox) { if (document.forms[searchform].elements[searchbox].value == "") { alert( "Please enter your criteria in the search box." ); document.forms[searchform].elements[searchbox].focus(); return false; } else if (document.forms[searchform].elements[searchbox].value.length < 3) { alert( "Search term should be more than 2 characters" ); document.forms[searchform].elements[searchbox].focus(); return false; } else return true; } function showFormComment(fieldId) { document.getElementById('form_comment_' + fieldId).style.display = 'block'; } function checkAndShowCommentBox(fieldId, formName) { var specialConcat = document.getElementById('_special_' + fieldId).value; var specialIndexes = specialConcat.split(','); var formField = document.getElementById('_form_' + fieldId); if (formField.type == 'hidden') { // if hidden, then we're looking for a radio selection instead, using name instead of ID var radioObject = eval('document.' + formName + '.' + '_form_' + fieldId + ';'); var radioObjectNum = (radioObject.length == 'undefined') ? 1 : radioObject.length; var radioChecked = 0; for(var r = 0; r < radioObjectNum; r++) { if(radioObject[r].checked) { var fieldSelected = r - 1; break; } } } else { var fieldSelected = formField.selectedIndex - 1; } var key = ''; for (key in specialIndexes) { if (specialIndexes[key] == fieldSelected) { showFormComment(fieldId); var comments = 1; } } if (comments != 1) { document.getElementById('form_comment_' + fieldId).style.display = 'none'; } } function formsDisabledWarning(inputObj) { alert('Please view the attachment before answering this question.'); inputObj.blur(); } function formsEnableField(fieldId) { fieldObj = document.getElementById('_form_' + fieldId); fieldObj.onfocus = ''; } function commentsEditComment(commentId) { var commentDiv = document.getElementById('comments_comment_body_' + commentId); var parentDiv = commentDiv.parentNode; var commentText = commentDiv.innerHTML; commentText = commentText.replace(/
/gi, ''); commentText = commentText.replace(/
/gi, ''); var boxWidth = parentDiv.offsetWidth - 100; var thisURL = window.location.pathname + '#comments' + commentId; var newHTML = '
'; newHTML += ''; newHTML += ''; newHTML += ''; newHTML += ''; newHTML += '
'; commentDiv.innerHTML = newHTML; } function show_ee() { // } function shopSlideShow(imagesDelim, width, height,offSet) { width = window.innerWidth || document.documentElement.clientWidth; height = window.innerHeight || document.documentElement.clientHeight; width = width - 100; height = height - 100; width = width > 900 ? 900 : width; height = height > 700 ? 700 : height; var imagesArr = imagesDelim.split(','); var firstImg = '/?page_type=show_image&img=' + imagesArr[0] + '&w=' + width + '&h=' + height + '&canvas=frame&bgcolour=ffffff&q=90'; var callBack = 'shopSlideShowGenerate(\'' + addslashes(imagesDelim) + '\', ' + width + ', ' + height + ', \'' + offSet + '\')'; manualiBox(firstImg, 'type=1&width=' + (width) + '&height=' + (height), callBack); shopSlideShowGenerate(addslashes(imagesDelim), width, height, offSet); } function shopSlideShowGenerate(imagesDelim, width, height, offSet) { var contentDiv = document.getElementById('ibox_content'); var imagesArr = imagesDelim.split(','); var len = imagesArr.length; var randNum = Math.floor((Math.random()*100000)+1); var thisContainer = 'gallery_slider_' + randNum; var htmlStr = ''; contentDiv.innerHTML = htmlStr; var thisSlider = new bumbleSlider(thisContainer, width, height, 2000, 2000, offSet, 1, 'slide', 1); } function embedCourseExam(examModrw, divId) { updateDiv(divId,'','page_type=course_exam&exam_modrw=' + examModrw,'html',1); } function proceedCourseAnswer(obj, attemptId, examModrw, questionKey, answerKey, validateBool) { var parentId = obj.parentNode.id; var validateQS = validateBool == 1 ? '&validate=1&answer_key=' + answerKey + '&question_key=' + questionKey: ''; updateDiv(parentId,'','page_type=course_exam&attempt_id=' + attemptId + '&exam_modrw=' + examModrw + validateQS,'html',0); } function addslashes(str) { str=str.replace(/\\/g,'\\\\'); str=str.replace(/\'/g,'\\\''); str=str.replace(/\"/g,'\\"'); str=str.replace(/\0/g,'\\0'); return str; } function stripslashes(str) { str=str.replace(/\\'/g,'\''); str=str.replace(/\\"/g,'"'); str=str.replace(/\\0/g,'\0'); str=str.replace(/\\\\/g,'\\'); return str; } function findPosX(obj) { var curleft = 0; if(obj.offsetParent) while(1) { curleft += obj.offsetLeft; if(!obj.offsetParent) break; obj = obj.offsetParent; } else if(obj.x) curleft += obj.x; return curleft; } function findPosY(obj) { var curtop = 0; if(obj.offsetParent) while(1) { curtop += obj.offsetTop; if(!obj.offsetParent) break; obj = obj.offsetParent; } else if(obj.y) curtop += obj.y; return curtop; } function getStats() { var screenres; var screencolor; var flashvn; var browser; var browservn; var os; if (screen.width) screenres=screen.width+" x "+screen.height; else screenres="Unknown"; if (screen.colorDepth) screencolor=screen.colorDepth; else screencolor="Unknown"; browser=''; browservn=''; alert("Screen res: "+screenres+", "+screencolor+" bit\nBrowser: "+browser+" "+browservn); } function listCategoryTree(type, containerId, parentId, divPrefix) { if (!divPrefix) var divPrefix = containerId; updateDiv(containerId,'','page_type=output_categories&parent_id=' + parentId + '&type=' + type + '&container_id=' + containerId + '&div_prefix=' + divPrefix,'html',0,''); } function swapGalImg(parentDiv, imgFile) { var containerDiv = document.getElementById(parentDiv); if (containerDiv != null) { // get width and height var largeWidth = containerDiv.clientWidth; var largeHeight = containerDiv.clientHeight; var largeImgFile = '/?page_type=show_image&img=' + imgFile + '&w=' + largeWidth + '&h=' + largeHeight + '&canvas=crop'; var fullImgFile = '/library/images/' + imgFile; // make sure container is positioned relatively containerDiv.style.position = 'relative'; containerDiv.style.overflow = 'hidden'; // loop elements to find image var oChild = containerDiv.firstChild; if (oChild) { while(oChild) { if ((oChild.tagName == 'img' || oChild.tagName == 'IMG') && oldImg == null) { var oldImg = oChild; } else { oChild.parentNode.removeChild(oChild); } oChild = oChild.nextSibling; } } // if old image exists if (oldImg != null) { // position top left oldImg.style.position = 'absolute'; oldImg.style.top = 0; oldImg.style.left = 0; oldImg.style.zIndex = 10; } // create new element and position top left, zindex 0 var newImg = document.createElement("img"); newImg.src = largeImgFile; newImg.style.position = 'relative'; newImg.style.zIndex = 0; newImg.style.top = 0; newImg.style.left = 0; newImg.style.cursor = 'pointer'; newImg.onclick = function() { manualiBox(fullImgFile) } containerDiv.appendChild(newImg); // fade out old one, callback destroy if (oldImg != null) { var fadeOut = new bumbleTransitionObj(oldImg, 'opacity', 100, 0, '', 500, 'cos', '', 'if (this.obj.parentNode != null) this.obj.parentNode.removeChild(this.obj)', 100); } // new img onclick = ibox } }