// portal.js var loadedjs = false; var preloadFlag = true; function changeImages() { if (loadedjs && preloadFlag) { for (var i=0; i0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p); } if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i= 4 ) ) { window.external.AddFavorite( url,who ); }else{ } } function launchIntro( prefix ) { var page = "/intro.php"; pop_up = window.open( page,'pop_up','scrollbars=no,resizable=no,width=650,height=456,left=325,top=150,screenX=325,screenY=150'); pop_up.focus (); } function expandEmail( linkObj, subject, msgbody ) { if ( linkObj.href.indexOf('BODY') < 0 ) { if( document.all ) { var extra = ''; if( subject ) extra = extra + '&subject=' + subject; if( msgbody ) extra = extra + '&body=' + msgbody; linkObj.href = linkObj.href + extra; } } } /* BASIC TOOLS */ function isAlien(a) { return isObject(a) && typeof a.constructor != 'function'; } function isArray(a) { return isObject(a) && a.constructor == Array; } function isBoolean(a) { return typeof a == 'boolean'; } function isEmpty(o) { var i, v; if (isObject(o)) { for (i in o) { v = o[i]; if (isUndefined(v) && isFunction(v)) { return false; } } } return true; } function isFunction(a) { return typeof a == 'function'; } function isNull(a) { return typeof a == 'object' && !a; } function isNumber(a) { return typeof a == 'number' && isFinite(a); } function isObject(a) { return (a && typeof a == 'object') || isFunction(a); } function isString(a) { return typeof a == 'string'; } function isUndefined(a) { return typeof a == 'undefined'; } //Powered by DCScript function DOMCall(name) { if (document.getElementById) return document.getElementById(name); if (document.layers) return document.layers[name]; else if (document.all) return document.all[name]; } // showHide can be 'show', 'hide', or boolean true/false (true for show, false for hide) function showHide( myDiv, showHide, displayStyle ) { if(typeof displayStyle == 'undefined' || !displayStyle) displayStyle="block"; if(document.createTextNode) { myElem = DOMCall(myDiv); if( myElem ) { if( showHide == 'show' || showHide == true) { myElem.style.display = displayStyle; } else { myElem.style.display = "none"; } } // else alert('myDiv: ' + myDiv ); } } // similar to showHide EXCEPT that this ftn checks the "checked" status of passed // element to determine whether the div is shown or hidden // if checked then showHide is applied to myDiv, else opposite function checkShowHide( myCheckElement, myDiv, myShowHide, displayStyle ) { if( typeof myShowHide == 'undefined' || !myShowHide ) myShowHide = 'show'; if( myCheckElement.checked ) { showHide( myDiv, myShowHide, displayStyle ); } else { // pass in the opposite if( myShowHide == 'hide' ) showHide( myDiv, 'show' ); else showHide( myDiv, 'hide' ); } } // unset all radio options & set "defaultOption" if set function resetRadios( subElem, defaultOption ) { if( subElem ) { var subLen = subElem.length; //alert('resetRadios...'+elemName+' found - length:' + subLen); /* for( var j = 0; j < subLen; j++ ) { var subOption = subElem[j]; var subChecked = subOption.checked; var subValue = subOption.value; alert( j+': checked -'+subChecked+' value - '+subValue); } */ subElem[ defaultOption ].click(); } //else alert ('resetRadios...not found'); } // opt1 = show // opt2 = hide function toggleDiv(opt1,opt0) { if(document.createTextNode) { DOMCall(opt0).style.display = "none"; DOMCall(opt1).style.display = "block"; } } function toggleVisibility(divName) { if(document.createTextNode) { if(DOMCall(divName).style.display == "none") showHide(divName, 'show'); else showHide(divName, 'hide'); } } // toggle field function toggleFields(checkObj,elementID,opt1,opt0) { if(document.createTextNode) { var options = DOMCall(elementID); if( options ) { var chosenOption = options.getElementsByTagName("div"); if(checkObj.checked) { chosenOption[1].style.display = "none"; xbObj(opt1).style.display = "block"; } else { chosenOption[1].style.display = "none"; xbObj(opt0).display = "block"; } } } } // Needed to pass users over to the MDF store pages function passMDFAddress() { document.addressForm.target = "hiddenFrame"; document.addressForm.submit(); return true; } function resize_iframe( myElement ) { myObj = DOMCall( myElement ); //resize the iframe according to the size of the window myObj.height=document.body.offsetHeight - myObj.offsetTop - 26; } function resize_col( myElement, parentElement ) { myObj = DOMCall( myElement ); parentObj = DOMCall( parentElement ); var temp = document.body.height; //resize the iframe according to the size of the window //alert("body height: " + temp); // myObj.height = parentObj.height - 25; } function hiliteMissingFields( formName ) { // this is here so that pages don't baulk when this isn't defined // e.g. before a page is submitted return false; } function hiliteRequiredFields( formName ) { var myForm = document.forms[ formName ]; var myRequiredFields; // if required_fields_list not set, then read from required_fields element if(myForm.elements['required_fields_list']) myRequiredFields = myForm.elements['required_fields_list']; else myRequiredFields = myForm.elements['required_fields']; //alert(formName + myRequiredFields.value); if(myRequiredFields.value) { var myRequiredArray = myRequiredFields.value.split(","); for(i=0; i 0 ) idName = id + String(i); if(element = document.getElementById(idName)) { exists = 0; var existingClassNames = element.className.split(" "); for(x in existingClassNames) { if(existingClassNames[x] == newClassName) { exists = 1; } } if(!exists) { element.className = element.className + " " + newClassName; return true; } } i++; } while (i < maxI); return false; } function removeClassName(id, classNameToRemove) { if(element = document.getElementById(id)) { var existingClassNames = element.className.split(" "); element.className = null; for(cn = 0; cn < existingClassNames.length; cn++) { if(existingClassNames[cn] != classNameToRemove) { if(element.className) { element.className = element.className + " " + existingClassNames[cn]; } else { element.className = existingClassNames[cn]; } } } return true; } return false; } /* function hiliteMissingFields( formName, requiredFields) { fieldString = ''; if(requiredFields && fieldString){ fieldString = fieldString+","+requiredFields; } else { fieldString = requiredFields; } var myRequiredFields = fieldString.split(",");; // The commented fields are kind of nice for debugging. (cs) //var reqList = "Required fields: \n"; // special treatment for geocoverage // can be abstracted to other fields like it (if there are any) weirdOnes = new Array('geographic_coverage'); for(idx in weirdOnes){ testString = weirdOnes[idx]; for( i = 0; i < myRequiredFields.length; i++ ) { if(myRequiredFields[i].substr(0,testString.length) == testString){ myRequiredFields[i] = testString; } } } for( i = 0; i < myRequiredFields.length; i++ ) { myLabelObj = document.getElementById( "label_" + myRequiredFields[i] ); //reqList = reqList + myLabelObj.id + ",\n"; if( myLabelObj ) myLabelObj.className = "focused"; } //alert(reqList); } */ // -- DEBUG FUNCTIONS --// function iterateForm( myForm ) { document.write("OUTPUTTING FORM-----
"); for( var i = 0; i < myForm.elements.length; i++ ) { var eElem = document.adminDetail.elements[i]; var eName = eElem.name; var eType = eElem.type; document.write( i+': '+eName+' ('+eType+')
'); if( eType == 'radio' ) { var subElem = eval("myForm." + eName); var subLen = subElem.length; document.write('   --LENGTH: '+subLen+'
'); for( var j = 0; j < subLen; j++ ) { var subOption = subElem[j]; var subChecked = subOption.checked; var subValue = subOption.value; document.write( '   --'+j+': checked -'+subChecked+' value - '+subValue+'
'); } } } document.write("END OUTPUTTING FORM-----
"); } function setDateSelectsToday( myForm, fieldName ) { if( myForm.elements[ fieldName+'[month]'] ) { currentDate = new Date(); var fMon = myForm.elements[ fieldName+'[month]' ]; var fDay = myForm.elements[ fieldName+'[day]' ]; var fYear = myForm.elements[ fieldName+'[year]' ]; var curMon = currentDate.getMonth() + 1; var curDay = currentDate.getDate(); var curYear = currentDate.getFullYear(); // do the month & day ... easy ones as values match keys fMon.selectedIndex = curMon; fDay.selectedIndex = curDay; // now pull the index that matches the curYear value for( var i = 0; i < fYear.options.length; i++ ) { if( fYear.options[i].value == curYear ) { fYear.selectedIndex = i; break; } } } } function checkall( myForm, myFieldName ) { var myElement = ''; for( var i=0; i < myForm.elements.length; i++ ) { myElement = myForm.elements[ i ]; if( myElement.type == "checkbox" && (myElement.name == myFieldName || myElement.name.substring(0, myElement.name.search(/\[/)) == myFieldName.substring(0,myFieldName.search(/\[/)) )) /* The second half of the OR checks for arrays of checkboxes with hardcoded indicies */ { myElement.checked = true; } } } function uncheckall( myForm, myFieldName ) { var myElement = ''; for( var i=0; i < myForm.elements.length; i++ ) { myElement = myForm.elements[ i ]; if( myElement.type == "checkbox" && (myElement.name == myFieldName || myElement.name.substring(0, myElement.name.search(/\[/)) == myFieldName.substring(0,myFieldName.search(/\[/)) ))/* The second half of the OR checks for arrays of checkboxes with hardcoded indicies */ { myElement.checked = false; } } } // Dynamically in-line edit forms function findPosX(obj) { // obj is an actual object (vs name of object) var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft obj = obj.offsetParent; } } else if (obj.x) curleft += obj.x; // alert("curleft: "+curleft); return curleft; } function findPosY(obj) { // obj is an actual object (vs name of object) var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop obj = obj.offsetParent; } } else if (obj.y) curtop += obj.y; // alert("curtop: "+curtop); return curtop; } function displayEditBox( anchorDivName, direction, showDivName, leftOffset ) { // find the location of the anchorDiv and let’s position the showDiv nearby // let’s move showDiv to a nice place either to the left (if direction is -1) else to the right var anchorDivObj = DOMCall( anchorDivName ); if( direction == -1 ) { // set box to appear to the left var newX = findPosX( anchorDivObj ) - leftOffset; // make sure this is larger than the width of the box //var newX = findPosX( anchorDivObj ); } else { // set box to appear to the right var newX = findPosX( anchorDivObj ); //var newX = findPosX( anchorDivObj ); } //var newY = findPosY( anchorDivObj ) - 175; // we want it slightly above the link, to prevent it from being cut off var newY = findPosY( anchorDivObj ); showDivObj = DOMCall( showDivName ); showDivObj.style.top = newY + "px"; // “px” required for Mozilla and IE showDivObj.style.left = newX + "px"; // now that it’s positioned, let’s display it showDivObj.style.display = "block"; } function show_form ( el ) { if( DOMCall(el).style.display == "block" ) DOMCall(el).style.display = "none"; else DOMCall(el).style.display = "block" } function editCategory( myDivName, myFormName, cID, title, description ) { // change category name into an editable text field with a "go" button and a "cancel" // see flickr.com for example var myDiv = DOMCall(myDivName); var myForm = document.forms[myFormName]; myForm.catID.value = cID; myForm.title.value = title; myForm.description.value = description; myDiv.style.display = "block"; } loadedjs = true; function getFile( itemID ) { var which = document.getElementById(itemID); var where = which.options[ which.selectedIndex ].value openWindow( where, 'DownloadResource' ); } // adding function trim to the prototype for string. call this function like so: stringName.trim() String.prototype.trim = function (){ return this.replace(/^\s*/, '').replace(/\s*$/, ''); } // this could be modified without too much trouble to make a pregSplit like preg_split in php function splitTrim(str, splitOn){ if('string' != typeof(str)) { if(typeof(str) == 'object') return str; // don't touch it if it's already an array str = str+''; // otherwise, implicitly cast it as string } if(!splitOn){ splitOn=','; } retVal = str.split(splitOn); for(i in retVal){ if(!isFunction(retVal[i])){ retVal[i].trim(); } } return retVal } // adding function inArray to prototype for array. Call this function like so: arrayName.inArray('testvalue') Array.prototype.inArray = function (value) { var i; for (i=0; i < this.length; i++) { if (this[i] === value) { return true; } } return false; }; // adding function arrayKey to prototype for array. Call this function like so: arrayName.arrayKey('testvalue') Array.prototype.arrayKey = function (value) { var i; for (i=0; i < this.length; i++) { if ( (this[i] && (this[i] == value)) || (!this[i] && (this[i] === value)) ){ return i; } } return false; }; // adding function remove to prototype for array. Call this function like so: arrayName.remove('testvalue') Array.prototype.remove = function (value){ for(var i=0;i 0) copyInfo(subformInfo, children[i], subformType); var theName = children[i].name; var theID = children[i].id; if(theID) { children[i].id = theID + "[" + subformCounters[subformType] + "]" if(Array('P', 'LABEL', 'DIV', 'SPAN').inArray(children[i].tagName)) { if(subformInfo[theID]) { // nodeText = document.createTextNode(subformInfo[theID]); // children[i].appendChild(nodeText); // using innerHTML to support adding strings that might contain html (line breaks, etc.) // the only DOM-friendly way I could think of to accomodate this would be to write/download an HTML parser // debatable whether it's worth the trouble ever, but it's definitely not worth it right now - fw children[i].innerHTML = subformInfo[theID]; } } else if(children[i].tagName == 'A') { if(subformInfo[theName+'_href']) children[i].href = subformInfo[theName+'_href']; } if(theID == subformInfo['noshow']) { children[i].style.display = 'none'; children[i].style.width = '0'; } } if(theName) { var val1, val2; val1 = subformCounters[subformType]; if(subformInfo[subformTypeID]) val2 = subformInfo[subformTypeID]; else { val2 = 0; } if(theName == 'delete') children[i].id = val1 + '_' + val2 + '_' + subformType; else if(theName == 'edit') { children[i].id = val1 + '__' + val2 + '__' + subformType; } else if(theName == 'back' || theName == 'close') { children[i].id = val1 + '___' + val2 + '___' + subformType; } else if(theName == 'attachment_link_text') //special case { if(subformInfo['attachment_link_text']) { nodeText = document.createTextNode(subformInfo['attachment_link_text']); children[i].appendChild(nodeText); } if(subformInfo['attachment_link_href']) { children[i].href = subformInfo['attachment_link_href']; } } else { if(theName == 'disclosure_device_custom4ID_list') // abstract this out for all multi-selects... in the future { children[i].name = "disclosure_device_custom4ID_list[" + subformCounters[subformType] + "][]"; subformInfo[theName] = splitTrim(subformInfo[theName]); for(var index=0; index