//'***this file contians useful javascripts that are commonly accessed*** //alert("Script Loaded!") //establish this page url thisPageUrl=window.location //end location //the time function startTime() { var today=new Date() var h=today.getHours() var m=today.getMinutes() var s=today.getSeconds() // add a zero in front of numbers less than 10 m=checkTime(m) s=checkTime(s) document.getElementById('time').innerHTML=h+":"+m+":"+s v=setTimeout('startTime()',500) } function checkTime(i) { if (i<10) {i="0" + i} return i } //end the time //admin session count down function adminSession() { //var s=setTimeout('alert("1800ms have passed since onbody load trigger event... this is a test... ")',1800); var myDate=new Date(); var myMilliTime=myDate.getTime(); //alert("Miliseconds since 1970: "+myMilliTime); var myTen=myMilliTime+600000; //alert("Ten minutes from now: "+myTen) myDate.setTime(myTen); //alert("10 minutes from now: "+myDate); sessionAlert="Your session will end shortly. Please save your work or refresh this page to maintain your session. Otherwise you will need to log in again to make further comments\nMessaged Displayed: "+myDate; var t=setTimeout('alert(sessionAlert)',600000); //var u=setTimeout('window.location="/de-bug.asp?error=Please restart your debug session&debug=end"',900000); var u=setTimeout('window.location="/admin/index.asp"',900000); } //end admin count down //MOUSE OVER STYLE CHANGES function highlight(myObj) { //alert("highlight"); myObj.className="variant"; } function lowlight(myObj) { //alert("Lowlight"); myObj.className="depreciated"; } //END STYLE CHANGES function changerecordsinpage(rip,thispage,myselect,activeTab) { //alert("Form Name: "+formname) //alert("Records In page: "+rip); //alert("This Page: "+thispage); var answer = confirm("Changing the number of records in this page will return you to the first page of results.\n\nAre you sure you want to continue?"); if (!answer) { //document.forms.[formname].recordsinpage.selectedIndex=0; //form.reset(); myselect.selectedIndex=0; return false; } else window.location = thispage+"?activetab="+activeTab+"&recordsinpage="+rip; } function confirmdelete(message) { //This function displays a message that is passed to it and waits for the user to respond //alert("Running Confirm Script!"); var answer = confirm(message); if (!answer) return false; else return true; } function validateemail(address,fieldname) { //THIS FUNCTION VALIDATES AN EAMIL ADDRESS thisfieldname=fieldname.name; //thisformname=document.forms.thisfieldname.form; //alert("Your entered: "+address+" in the "+fieldname.name+" field in the form named "+thisformname); var c=1 if (address.indexOf("@") != "-1" && address.indexOf(".") != "-1" && address!= "") { return true; } else if (address=="") { // some functions already do checking to confirm field has content. // this funciton does not have this functionality. // therefore blank field should be permitted and handled return true; } else { //alert("Your email address is: "+address); alert("Your email address seems to contain invalid characters.\n\nPlease correct this mistake and try again"); //document.forms.adduser.email.focus(); //this.focus(); c=2 //return c; } if (c==1) { return true; } else { //alert(c); //fieldname.select(); //fieldname.focus(); //validateemail=c; //fieldname.value=address; return c; } } // FUNCTION ONLY VALIDATE EMAIL CONTENTS, NOT VALIDATING ENTRY MADE // EXECUTES ON BLUR function emailOnly(address,fieldname) //(20/3/06): Think 'fieldname' should be ID? { var c=validateemail(address,fieldname); if (c==2) { document.getElementById(fieldname).focus(); //alert("Return Focus to email field?"); return false; } else return true; } // ENABLES AN IDENTIFIED CHECKBOX ON CRITERIA function enableCheckBox(sourceObj,targetId,criteria) { //alert("Source Object: "+sourceObj+"\nTarget ID: "+targetId+"\nCriteria: "+criteria); if (eval("sourceObj"+criteria)) { document.getElementById(targetId).disabled=false; document.getElementById(targetId).checked=true; } else { document.getElementById(targetId).disabled=true; document.getElementById(targetId).checked=false; } } function validate(form,noelements,showprogress) { //THIS FUNCTION WILL confirm entry in to any field identified to it as being mandatory (hopefully) // using getElementById() ?? var c=1; //alert("Form:"+form); //alert("Elements:"+noelements) for (i=1;i<=noelements;i++) { var thiscontent=document.getElementById(i).value; var thiselementname=document.getElementById(i).name; if (thiscontent=="") { alert("Mandatory information missing!\n\n"+thiselementname+" is a mandatory field.\nPlease enter the requested information in the relevant field!"); c=2; document.getElementById(i).focus(); return false; } if (thiselementname=="email") { //alert("Now validating the email address: "+thiscontent); c=validateemail(thiscontent,"email"); //alert(c); if (c==2) { form.email.select(); form.email.focus(); return false; } } //var vals=vals+i+":"+thiscontent+"\n" //alert(i) } //alert(vals) if (c!=1) return false; else { if (showprogress!="") { //'***upload show progress: //return true; //function ShowProgress() // { //alert("Running ShowProgress() with barref="+barref); strAppVersion = navigator.appVersion; if (document.getElementById(showprogress).value != "") { if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4) { winstyle = "dialogWidth=385px; dialogHeight:140px; center:yes"; //window.showModelessDialog('&b=IE',null,winstyle); window.showModelessDialog(barref+'&b=IE',null,winstyle); } else { //window.open('&b=NN','','width=370,height=115', true); window.open(barref+'&b=NN','','width=370,height=115', true); } } return true; // } } else return true; //end show prgress } } //SPECIAL VALIDATE CHECK A FIELD WHEN IT LOOSES FOCUS function specialValidate(fieldContent,contentType,fieldId) { //fieldContent is content of field to be validated //contentType is the type of content the field should contain //fieldId the ID of the field we are validating c=1; //alert("c:"+c+"\nFields Content: "+fieldContent+"\nContent Type: "+contentType+"\nField ID: "+fieldId); //alert("This field name: "+document.getElementById(fieldId).name); if (fieldContent=="") { alert("You must enter "+contentType+" in this field!"); document.getElementById(fieldId).focus(); c=2; return false; } if (contentType=="number") { if (isNaN(fieldContent)) { alert("You must enter "+contentType+" in this field!"); document.getElementById(fieldId).focus(); c=2; return false; } } if (contentType=="email") { c=validateemail(fieldContent,fieldid); if (c==2) { document.getElementById(fieldId).focus(); return false; } } if (c==2) { document.getElementById(fieldId).focus(); return false; } else return true; } function showalert(message) { //seems we need to use a function to account for load order alert(message); } //**** begin max length code /* Cross browser getElement */ function _getElement(name) { if (document.getElementById(name)) { // IE5+, Netscape 6, Mozilla return (document.getElementById(name)); } else { // Netscape 4 return (eval("document." + name)); } } function textCounter(counterId, obj, maxlimit) { var re re = new RegExp("\r\n","g") x = obj.value.replace(re,"").length ; if (x > maxlimit) { return false; } else { c = _getElement(counterId); left = maxlimit - obj.value.length; c.innerHTML = left + ''; return true; } } function textAreaMaxLength(field, maxlimit) { if (field.value.length > maxlimit) { field.value = field.value.substring(0, maxlimit); } } function maxLength(myField,myLength) { //alert("Running maxLength Check\nMyField: "+myField) //alert("MyField: "+myField) var mblength=document.getElementById(myField).value.length; //alert (mblength); if (mblength>myLength) { //calculate over length overlength=mblength-myLength; alert("CONTENT TOO LONG!\n\nThis area is limited to "+myLength+" characters. Your current message contains "+mblength+" characters and therefore needs to be reduced in length by "+overlength+" characters.\n\nPlease delete some of your text, or rephrase it to reduce its length."); document.getElementById(myField).focus(); return false; } } //**** end max length code //OPEN A WINDOW: function openWin(winurl,winname,winwidth,winheight) { var winl = (screen.width - winwidth) / 2; var wint = (screen.height - winheight) / 2; //winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl //alert("Opening a new window with the following properties:\nURL: "+winurl+"\nWindow Name: "+winname+"\nWindow Width: "+winwidth+"\nWindow Height: "+winheight) window.open(winurl,winname,"width="+winwidth+",height="+winheight+",top="+wint+",left="+winl+",location=no,menubar=no,directories=no,toolbar=no,status=no,titlebar=no,resizable=yes,scrollbars=yes,modal=yes,dialog=yes,minimizable=no"); //return false; } //END WINDOW OPEN function myGoTo(myURL) { //alert("Taking you to: "+myURL); window.location=myURL; } //enable a text field when 'other/new' selected in drop down //e.g. enableOther(this.value,'coursename','other/new','1') function enableOther(selectValue,enableFieldId,triggerValue,selectId) { //alert("You selected: "+selectValue); //alert("Your free text field id is: "+enableFieldId); var enablefield=document.getElementById(enableFieldId); var selectfield=document.getElementById(selectId); //enable field type must be "text"..... if (enablefield.type!="text") { //collection of items with this name myenablefield=document.getElementsByName(enableFieldId); //alert(enablefield.length+" items found") enablefield=myenablefield[1] } //var selectobject=document.select.getElementById(selectId); //alert("enablefield type: "+enablefield.type+"\nselectfield type: "+selectfield.type+"\nselectobject type: "+selectobject.type); //alert("enablefield type: "+enablefield.type+"\nselectfield type: "+selectfield.type); if (selectValue==triggerValue) { //alert("You have selected the trigger value: "+triggerValue); //alert("Please enter a course name in the box!\n\nAs you have selected \'Other\' from the drop down you need to enter a ") enablefield.disabled=false; enablefield.focus(); //now change the name of the select box so that 2 values are not assigned //alert("This field initial name: "+selectfield.name); selectfield.name=selectfield.name+"a"; //alert("This field new name: "+selectfield.name) } else { //alert("The selected value does not match the trgger value"); //alert("ID of Select field: "+selectId+"\nName of Select field: "+document.getElementById(selectId).name+"\nID of Enable field: "+enableFieldId+"\nName of Enable field: "+document.getElementById(enableFieldId).name) enablefield.value=""; enablefield.disabled=true; //re-assign the name of the select box: (the free field id should always be the same as the name picked up by the database and the original name of the select box) selectfield.name=enableFieldId; } } //end enable other //disabled specified field function disableField(myid) { var myFormElement=document.getElementById(myid); if (myFormElement) { //alert ("My Form Element to be disabled:\nID: "+myid+"\nName: "+myFormElement.name+"\nType: "+myFormElement.type); document.getElementById(myid).disabled=true; } else { //alert("No object selected"); //This is in case an error is thrown where there is no object to select. } } //end disable field //START ADD TO FIELD FUNCTION function addtofield(announcement,triggerObj,fieldId,confirmMessage,defVal) { //THIS FUNCTION ADDS INFORMATION ENTERED IN TO A 'PROMPT' BOX TO THE IDENTIFIED FIELD //Get default value //var mydefVal=triggerObj.defaultSelected; //alert("defVal: "+defVal); //Disaply Prompt var addTxt=prompt(announcement,"No reason given for status change"); if (addTxt=="") { addTxt="No reason given for status change"; } if (addTxt!=null) { //Get current notes var curVal=document.getElementById(fieldId).value; //Append Prompt Value document.getElementById(fieldId).value=curVal+"\n["+Date()+"] Status Changed by User ID : "+addTxt; //Display alert to descibe where information has been added if (confirmMessage!=null && confirmMessage!="") { alert(confirmMessage); } } else { //return the field calling this function to its default value triggerObj.value=defVal; } } //END ADD TO FIELD FUNCTION //function to highlight menu item... function menuImg(myImg,mouse) { if (mouse=="enter") { document.getElementById(myImg).src="/i/menu/menu_focus.gif"; } else { document.getElementById(myImg).src="/i/spacer.gif"; } } function jseditthis(page,section,field,thistype,edittype,fieldid) { window.open("/admin/edittext.asp?fieldid="+fieldid+"&edittype="+edittype+"&page="+page+"&ninfosection="+section+"&field="+field+"&fieldtype="+thistype+"","editwindow","width=680,height=650,channelmode=no,directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=yes,toolbar=no") } function validatedomain(form) { //alert("Validating your domain name"); var c=1; var domainReq=form.domain.value; if (domainReq=="") { //confirm something is entered alert("You must enter something in the domain name field!\n\nPlease try again"); c=2; form.domain.value="Enter Domain Here!"; form.domain.focus(); return false; } else { //validate content meets domain criteria if(!domainReq.match(/^[A-Za-z0-9_-]+$/)) //if (domainReq.indexOf(" ") > "1") { if (domainReq.match("www.")) { alert("No need to enter \"www.\""); c=2; //form.domain.value="Enter Domain Here!"; form.domain.focus(); return false; } else { alert("Your domain name contains invalid characters.\n\nA domain name must consist of only numbers, leters, or hyphens (-). No other characters, such as spaces or explanation marks are permitted\n\nPlease try again"); c=2; //form.domain.value="Enter Domain Here!"; form.domain.focus(); return false; } } } if (c==1) { return true; } else { return false; } } function clearThis(clearField,unlessMatch) { //this function clears the contents of the referred field only if it matches the passed variable if (clearField.value==unlessMatch) { clearField.value=""; } } function addOther(ddVal,ddId,promptMsg,promptDefault) { //this function detects a comment type of "other" and allows the user to specify a custom comment type via a prompt //alert("TESTING!\n\nYou selected: "+commentType); if (ddVal=="other") { comTypeObj=ddId; noOptions=comTypeObj.length; //alert("noOptions: "+noOptions); thisItemNo=comTypeObj.selectedIndex; //alert("Selected Index: "+thisItemNo); var newVal = prompt(promptMsg,promptDefault); //var newVal=myPrompt(32,"Please enter a custom TYPE name for this comment, e.g:","Urgent!"); //alert("New Type: "+newType); //alert("myPromptVal:"+myPromptVal); if (newVal!="" && newVal!=null) { //comTypeObj.add(newType); //var theSel = document.getElementById('selOriginalWindow'); var newOpt = new Option(newVal, newVal); var selLength = comTypeObj.length; comTypeObj.options[selLength] = newOpt; comTypeObj.selectedIndex=noOptions; } else if (newType==null) { //alert("You decided to cancel!"); comTypeObj.selectedIndex=0 } else { alert("You have not entered anything!\n\"Other\" will be used unless you select another option from the drop down"); } } } function handleEmp(formField,myMsg) { //alert("Running Empty Field Handler\nReplace empty contents with "+myMsg+"\nformField: "+formField); var eFieldVal=formField.value; var eFieldId=formField.id; if (eFieldVal=="") { //alert(formField.name+" missing contents"); formField.value=myMsg; //formField.focus(); //document.getElementById(eFieldId).value=myMsg; //return true; } else { //alert(formField.name+" has contents"); return true; } } //HIDE AND SHOW META BOX IN EDIT MODE function hidemeta(status) { if (status=="hide") { document.getElementById("exiteditmode").className="editmodehide"; } else { document.getElementById("exiteditmode").className="editmodeshow"; } } //GOOGLE WARNING extracted from "left_menu.asp" for validation purposes function googlewarn(form) { var today = new Date(); var mtoday=Date.parse(today); var livedate = new Date(); livedate.setFullYear(2006,02,09); var mlivedate=Date.parse(livedate); var googledate; var m90days=((((999*60)*60)*24)*90) googledate=mlivedate+m90days //test radio button var searching=form.sitesearch[1].checked; //form.sitesearch.value //alert("Searching: "+searching+"\n90 Days in milliseconds: "+m90days+"\nToday: "+today+"\nLive Date: "+livedate+" - in miliseconds since 1970: "+mlivedate+"\nGoogle Date: "+googledate); if (searching==true && mtoday