//'***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 //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()"); 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); } else { window.open('&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 (newVal==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"; } } function setCookie(c_name,value,expiredays) { var exdate=new Date() exdate.setDate(exdate.getDate()+expiredays) document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) } function changeCSS(theClass,element,value) { var cssRules; if (document.all) { cssRules = 'rules'; } else //if (document.getelementById) { cssRules = 'cssRules'; } //alert("cssRules: "+cssRules); //alert("document.styleSheets.length:"+document.styleSheets.length); for (var S = 0; S < document.styleSheets.length; S++) { for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) { if (document.styleSheets[S][cssRules][R].selectorText == theClass) { document.styleSheets[S][cssRules][R].style[element] = value; } } } } function getCookie(c_name) { //alert("For testing: GET COOKIE!"); if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) } } else { setCookie(c_name,"0",1); return "No Cookie?"; } //return ""; } var sizeDif; //load text size as a global var.... var myTextSize=""; myTextSize=getCookie("asuDirect_Text_Size"); //alert("For Testing.....\nText Size Adjustment (Line 705): "+myTextSize); if (myTextSize=="" || isNaN(myTextSize)) { sizeDif=0; myTextSize=0; } else { sizeDif=Number(myTextSize); } //alert("For Testing.....\nText Size Adjustment (Line 716): "+myTextSize); function changeSIZE(dispObj,element,value) { //alert("sizeDif: "+sizeDif); //var cssRules; //cssRules = 'cssRules'; //cssRules = 'rules'; if (document.all) { cssRules = 'rules'; } else if (document.getElementById) { cssRules = 'cssRules'; } //for testing: //cssRules = 'rules'; //alert("cssRules: "+cssRules); //alert("document.styleSheets.length:"+document.styleSheets.length); //alert("For testing...\nThe fist rule\nof the first style\nof the first sheet\nis: "+document.styleSheets[0][cssRules][0].value); //alert("For testing...\ngetExpression('"+getExpression+"')\nis: "+document.styleSheets[0].rules[0].style.getExpression(element)); for (var S = 0; S < document.styleSheets.length; S++) { for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) { //get current size var newSize; var textSize; textSize=document.styleSheets[S][cssRules][R].style.fontSize; if(textSize!="" && textSize!=null && textSize!=undefined && textSize!="undefined" && textSize!="null") //if (textSize.length) { //alert("S="+S+"\nR="+R); //alert("textSize: "+textSize); textSize=textSize.replace(/px/,""); //alert("textSize: "+textSize); if (value=="Larger") { newSize=((Number(textSize)+Number("2"))); } else if (value=="Smaller") { newSize=((Number(textSize)-Number(2))); } else if (value!="") { newSize=((Number(sizeDif))+(Number(textSize))); } else { newSize=""; } //alert("newSize: "+newSize+"\nisNaN(newSize): "+isNaN(newSize)); if (newSize!="" && isNaN(newSize)!=true) { newSize=newSize+"px"; document.styleSheets[S][cssRules][R].style.fontSize=newSize; } } } } if (value=="Larger") { sizeDif=Number(sizeDif)+Number(2); } else if (value=="Smaller") { sizeDif=Number(sizeDif)-Number(2); } setCookie("asuDirect_Text_Size",sizeDif,1); if (sizeDif>=0) { //alert("For Testing: Displaying positive size adjustment"); dispObj.innerHTML="+"+sizeDif; } else { //alert("For Testing: Displaying negative size adjustment"); dispObj.innerHTML=sizeDif; } } function checkDate(myDay,myMonth,myYear) { //1 jan 31 //2 feb 28/29 //3 mar 31 //4 apr 30 //5 may 31 //6 jun 30 //7 jul 31 //8 aug 31 //9 sep 30 //10 oct 31 //11 nov 30 //12 dec 31 var c=1; if(myMonth=="04" || myMonth=="06" || myMonth=="09" || myMonth=="11") { if(myDay=="31") { alert("You have entered an invalid date!"); c=2; return false; } } else if(myMonth=="02") { var daysInFeb=28; //check for leap year myYearBy4=Number(myYear)/4; myYearBy4Int=(myYearBy4).toFixed(0); myYearDif=myYearBy4-myYearBy4Int; if(myYearDif==0) { daysInFeb=29; } if(myDay>daysInFeb) { alert("You have entered an invalid date!"); c=2; return false; } } if(c==2) { return false; } else { return true; } } // allow ONLY alphanumeric keys, no symbols or punctuation // onblur="alphan(this);" function alphan(checkObj) { //alert("Checking for illegal chacters..."); var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.'-@ "; var checkStr = checkObj.value; var allValid = true; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } } if (!allValid) { //alert("Please enter only letter and numeric characters in the \""+checkObj.name+"\" field."); alert("Please enter only letter and numeric characters in the current field.\n\nYou will need to delete any illegal punctuation marks from this field before proceeding."); checkObj.focus(); return (false); } }