//'***this file contians useful javascripts that are commonly accessed*** //alert("Script Loaded!") //establish this page url thisPageUrl=window.location //end location //auto log out if session expires function sexpired(currentUrl) { try { if (disableCounter==1) { //the counter can be disabled for special pages.... //alert("For testing: Session Timer Disabled"); clearTimeout(t); clearTimeout(u); } else { window.location="/logout_auto.asp?from="+currentUrl; } } catch(err) { //just incase the disableCounter variable is not declared... window.location="/logout_auto.asp?from="+currentUrl; } } //end auto log out //time out to warn of Session expiry! //runs whenever this page is loaded clearTimeout(t); clearTimeout(u); var swarning="***** WARNING *****\n\nYOUR SESSION WILL EXPIRE IN 5 MINUTES! (approx.)\n\nA session keeps you logged on to this web site. If you have been inactive for an extended period (i.e. Not saved or changed pages) your session will expire.\n\nThis is for security reasons and prevents others from using your account if you were to leave your computer active.\n\nTO RENEW YOUR SESSION either SAVE your most recent entries, REFRESH this page using the Refresh button, or VISIT another page in the site.\n\nThis warning was displayed on\n"+Date(); var t=setTimeout("alert(swarning)",900000); //var t=setTimeout("alert(swarning)",4000); var u=setTimeout("sexpired(window.location())",1200000); //var u=setTimeout("sexpired(thisPageUrl)",10000); var sm=19 var ss=59 var ms=500 try { if (disableCounter==1) { //the counter can be disabled for special pages.... //alert("For testing: Session Timer Disabled"); clearTimeout(t); clearTimeout(u); } } catch(err) { //do nothing } //end timeout //the time function startTime() { if ((ss==0 || ss=="00") && (sm==0 || sm=="00")) { sexpired(thisPageUrl); } var today=new Date() var h=today.getHours() var m=today.getMinutes() var s=today.getSeconds() ms=ms-500; if (ms==(-500)) { ms=500; ss=ss-1; if (ss==(-01)) { ss=59; sm=sm-1; } } // add a zero in front of numbers less than 10 m=checkTime(m) s=checkTime(s) if (ms==500) { //sm=checkTime(sm) ss=checkTime(ss) } document.getElementById('time').innerHTML=h+":"+m+":"+s document.getElementById('session').innerHTML=sm+":"+ss v=setTimeout('startTime()',500) } function checkTime(i) { if (i<10) {i="0" + i} return i } //end the time //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 seems to contain invalid characters.\n\nYou must enter your correct email address for us to send a quote to you by return."); //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) { 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,barref) { //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"); 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()"); 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(barref+'&b=IE',null,winstyle); } else { 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) { //alert("Opening a new window with the following properties:\nURL: "+winurl+"\nWindow Name: "+winname+"\nWindow Width: "+winwidth+"\nWindow Height: "+winheight) window.open(winurl,winname,"left=50,top=50,width="+winwidth+",height="+winheight+",location=no,menubar=no,directories=no,toolbar=no,status=no,titlebar=no,resizable=yes,scrollbars=yes,modal=yes,dialog=yes,minimizable=no"); //return false; } //OPEN A WINDOW WITH SCROLLING: function openSWin(winurl,winname,winwidth,winheight) { //alert("Opening a new window with the following properties:\nURL: "+winurl+"\nWindow Name: "+winname+"\nWindow Width: "+winwidth+"\nWindow Height: "+winheight) window.open(winurl,winname,"left=50,top=50,width="+winwidth+",height="+winheight+",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 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"); } } } //Alert user if they are leaving a page without potentially saving changes... function leaveCheck(xlink) { var really=confirm("WARNING!\n\nYou have clicked a link that will take you to a new page ("+xlink+"). Leaving the page now will NOT save any changes you have made on it. You are advised to finish any edits and save them before accessing this link!\n\nIf you DO NOT want to save changes, click \"OK\" otherwise click \"Cancel\" to continue editing this page."); if (!really) { return false; } else { return true; } } //changes a button to 'Please Wait' and disables it... function pleaseWait(myButton) { myButton.value="Please Wait..." myButton.disabled=true; } //ENROLLMENT FUNCTION 4th May 2007 function ajaxFunction() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } return xmlHttp; } function enrol(userid,courseid) { alert("Please wait.... (this can take some time)\n\nEnrollment Documents will open in new windows...\n*** You must make sure POP-UP blockers are disabled! ***"); if(courseid=="") { alert("You cannot enrol a student without first setting a course!"); return false; } if(userid=="") { alert("Sorry, we cannot find the ID of this student. Please try again!"); return false; } var receipt; var letter; //SET UP AJAX: xmlHttp=ajaxFunction(); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { var ASPJobDone=xmlHttp.responseText; //alert(ASPJobDone); //if(ASPJobDone!="" && ASPJobDone!="Enrollment Failed!") if(ASPJobDone!="" && ASPJobDone.indexOf("Enrollment Failed!")<0) { document.getElementById(userid+"status").innerHTML="Enrolled"; //alert("Enrolled Number: "+ASPJobDone); alert(ASPJobDone); enrolDocs(userid,courseid); window.focus(); } else { alert(ASPJobDone); } } } xmlHttp.open("GET","/users/enrol/enrol.asp?courseid="+courseid+"&id="+userid,true); xmlHttp.send(null) } function delayMe(delayby) { //alert("Start Delay?"); var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date < delayby); //alert("end delay"); return delayby; } function enrolDocs(userid,courseid) { //now do the window bits.... //myWidth=(screen.availWidth/2)-10; myWidth=790; myLeft=(screen.availWidth-myWidth)/2; //alert("myWidth: "+myWidth); win2=(screen.availWidth/2) //alert("win2: "+win2); myHeight=screen.availHeight-40; receipt = window.open("/users/enrol/receipt.asp?id="+userid+"&courseid="+courseid,"Receipt","left="+myLeft+",top=5,width="+myWidth+",height="+myHeight+",location=no,menubar=no,directories=no,toolbar=no,status=no,titlebar=no,resizable=yes,scrollbars=yes,modal=yes,dialog=yes,minimizable=no"); //letter = window.open("/users/enrol/letter.asp?id="+userid,"Letter","left="+win2+",top=5,width="+(myWidth-5)+",height="+myHeight+",location=no,menubar=no,directories=no,toolbar=no,status=no,titlebar=no,resizable=yes,scrollbars=yes,modal=yes,dialog=yes,minimizable=no"); //var printDelay = delayMe(2000); //receipt.print(); //letter.print(); //delay... var closeDelay = delayMe(15000); var closeWindows=confirm("Would you like to close these windows now?\n\n[N.B. If no window opened then potentially you did not heed my warning about POP-UP blockers!]"); if(closeWindows==true) { receipt.close(); //letter.close(); } else { //alert('closeWindows: '+closeWindows); } } function printPage() { window.print(); }