//New main.js - replaces smartmenus.js Now uses Smartmenus 6.03 //Includes a bunch of parts - combined into one big JS file to reduce the number of objects. //Includes: a large array of US county information. //Might move smartmenus into a seperate JS file - now that our object count is very high (using lots of JS libraries for AJAX and other stuff). //sBaseurl - used for tinyurls //global variables //number of map layers - aka basic facility search types (this can cause some trouble with missing factypes - ex. our hidden types: coal to oil, nuclear fuel, etc var iMaplayers=23; //used for adding units to added facility - trying to make it global var unitCounter; var sServer="https://ejmap.org/"; var sClienturl="https://ejmap.org/"; var sBaseurl="https://ejmap.org/"; var geoXml; var toggleState = 1; var iFacilitystep=1; //hopefully makes it a global variable, so it can be access within function(data) in SaveData var sHtml_id="test"; //should this be an array of datatables - eg dtable['facility'] var sub_facility=""; var sub_childfacilities=""; var sub_corporation=""; var sub_people=""; var sub_groups=""; var sub_school=""; var sub_resource=""; var sub_link=""; var sub_videolink=""; var sub_tag=""; var sub_phile=""; var sub_control=""; var sub_unit=""; var sub_unitstatus=""; var sub_fuel=""; var sub_product=""; //create an array of datatables for searches var datatable_search_facility=""; var datatable_search_groups=""; var datatable_search_people=""; var datatable_search_resource=""; var datatable_search_corporation=""; var datatable_list_event=""; var datatable_list_resource=""; //For editing people/group to facility level of involvement function EditInvolvement (iLevel, iSubid, sSubidname, iMainid, sMainidname, sRelatedtable) { var sLevel=$("#level_"+iSubid).html(); if (sLevel=='Interested') iLevel=1; else if (sLevel=='Active') iLevel=0; //gsRelatedtable - either people or groups $.post(sServer+"server-test/webservice/ajax_editrelation.php", { 'gsLoginhash': aEditarray['sLoginhash'], 'giSubid': iSubid, 'gsSubidname': sSubidname, 'giMainid': iMainid, 'gsMainidname': sMainidname, 'giLevel': iLevel, 'giUid': aEditarray['iUid'], 'giSuperuser': aEditarray['iSuperuser'], 'gsRelatedtable': sRelatedtable }, function (data) { //error if (data==0) { } else if (data==1) { if (iLevel==0) $("#level_"+iSubid).html("Interested"); else $("#level_"+iSubid).html("Active"); } } ); //need to disable the regular form action... this works! return false; } //For removing online account - for people and groups, based on editinvolvement function RemoveOnlineAccount (iMainid, sMainidname) { $.post(sServer+"server-test/webservice/ajax_removeaccount.php", { 'gsLoginhash': aEditarray['sLoginhash'], 'giMainid': iMainid, 'gsMainidname': sMainidname, 'giUid': aEditarray['iUid'], 'giSuperuser': aEditarray['iSuperuser'] }, function (data) { //error if (data==0) { } else if (data==1) { alert ("Account removed"); window.location.href='index.php?giLogout=1'; } } ); //need to disable the regular form action... this works! return false; } //javascript passes objects by reference, but simpler variables by value - since aEditarray is an object this should work... //copied from AddRelation function Init_aEditarray(aEditarray) { //creates rest of editarray object (some of it is created earlier in php) aEditarray['sUsername']=''; aEditarray['sPassword']=''; aEditarray['sAdd']=''; aEditarray['sEdit']=''; aEditarray['sDelete']=''; aEditarray['iAddRel']='0'; aEditarray['iAddRelid']=''; aEditarray['iAddRelTable']=''; aEditarray['iDeleteRel']=''; aEditarray['iUnsubscribe']=''; aEditarray['sAddstate']=''; aEditarray['iDeleteid']=''; aEditarray['sDeletetable']=''; //this serialize function causes spaces to be replaced with pluses //I could server-side replace + with space, assumes that the user didn't add a + character for regular reasons... aEditarray['sPost']=$("form").serialize(); aEditarray['sGet']=''; aEditarray['sFiles']=''; aEditarray['aiCurpage']=new Array(); aEditarray['iDownloadid']=0; aEditarray['sIp']=0; aEditarray['iTraffic']=0; aEditarray['sSitedir']=''; aEditarray['sState']=''; } //maintable and mainid - already set by php //Adds a Relation - for subforms using automcomplete... based on DeleteRelation //oDatatable - sub_facility or others... //sDeleteidname - delete idname - eg. iFacilityid function AddRelation(sAddtable, iAddid, oDatatable, sAddidname) { Init_aEditarray(aEditarray); //overwrites some of the add related variables aEditarray['iAddRel']='1'; aEditarray['iAddRelid']=iAddid; aEditarray['iAddRelTable']=sAddtable; //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_addrelation.php", { 'giAjax': "1", 'aEditarray': encoded }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { $('#'+sAddtable+'_message').show(); $('#'+sAddtable+'_message').html(myObject['sClient']); } else if (myObject['iExit']!=null) { //hide user message for that subtable_message //$('#'+sAddtable+'_message').hide(); $('.notify').hide(); $('#'+sAddtable+'_message').html(myObject['sClient']); $('#'+sAddtable+'_message').show(); var oSettings = oDatatable.fnSettings(); var aiNew = oDatatable.fnAddData(myObject['aRow']); var nNewTr = oSettings.aoData[ aiNew[0] ].nTr; oSettings.aoData[ aiNew[0] ].nTr.id=sAddidname+'_'+iAddid; //show table - in case it was hidden before, if there were zero results $('#sub-'+sAddtable).show(); $('#sub-'+sAddtable+'_wrapper').show(); $('#sub-'+sAddtable+'_info').show(); $('#sub-'+sAddtable+'_paginate').show(); //id=autocomplete_$sSubtable - hopefully sets the value of the input text box to '' $('#autocomplete_'+aEditarray['iAddRelTable']).val(''); $('#autocomplete_'+aEditarray['iAddRelTable']).blur(); } } ); //need to disable the regular form action... this works! return false; } //add links objects and add relation between the facility and the link //get values from gsUrl_link, gsName_link and gsDescription_link //based on addrelation //Note: need to stripslashes or possibly jsondecoding will fix the sUrl value... //Returns: // {"sClient":"
Link added.
It will be listed publicly within a week (unless you requested privacy or it contradicts the network mission).
", // "iExit":0,"sUrl":"http:\/\/tes65.org","sName":"asdfad"} //However - not displaying sClient! Need to display in id:link_message //decided to use a shorter message. Link added. Doesn't tell the user that it won't be public right a way. //set input fields to empty, once the AJAX has executed function AddLink() { Init_aEditarray(aEditarray); var sAddtable='link'; var iAddid=''; var sAddidname='iLinkid'; var oDatatable_addlink=sub_link; //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_addlink.php", { 'giAjax': "1", 'aEditarray': encoded, 'giAddlink' : "1" }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { $('#'+sAddtable+'_message').show(); $('#'+sAddtable+'_message').html(myObject['sClient']); } else if (myObject['iExit']!=null) { //hide user message for that subtable_message //$('#'+sAddtable+'_message').hide(); //maybe hide all other user messages - for class notify? $('.notify').hide(); //now show it $('#'+sAddtable+'_message').html("Link added."); $('#'+sAddtable+'_message').show(); var oSettings = oDatatable_addlink.fnSettings(); var aiNew = oDatatable_addlink.fnAddData(myObject['aRow']); var nNewTr = oSettings.aoData[ aiNew[0] ].nTr; //need to get iAddid out of myObject iAddid=myObject['iAddid']; oSettings.aoData[ aiNew[0] ].nTr.id=sAddidname+'_'+iAddid; //show table - in case it was hidden before, if there were zero results $('#sub-'+sAddtable).show(); $('#sub-'+sAddtable+'_wrapper').show(); $('#sub-'+sAddtable+'_info').show(); $('#sub-'+sAddtable+'_paginate').show(); } //set input fields to empty $('#url_link').val(''); $('#name_link').val(''); $('#description_link').val(''); } ); //need to disable the regular form action... unsure if this works... return false; } //based on AddLink function AddVideoLink() { Init_aEditarray(aEditarray); var sAddtable='videolink'; var iAddid=''; var sAddidname='iVid'; var oDatatable_addlink=sub_videolink; //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_addlink.php", { 'giAjax': "1", 'aEditarray': encoded, 'giAddvideolink' : "1" }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { $('#'+sAddtable+'_message').show(); $('#'+sAddtable+'_message').html(myObject['sClient']); } else if (myObject['iExit']!=null) { //hide user message for that subtable_message //$('#'+sAddtable+'_message').hide(); //hide notifications $('.notify').hide(); //now show this one $('#'+sAddtable+'_message').html("YouTube link added."); $('#'+sAddtable+'_message').show(); var oSettings = oDatatable_addlink.fnSettings(); var aiNew = oDatatable_addlink.fnAddData(myObject['aRow']); var nNewTr = oSettings.aoData[ aiNew[0] ].nTr; //need to get iAddid out of myObject iAddid=myObject['iAddid']; oSettings.aoData[ aiNew[0] ].nTr.id=sAddidname+'_'+iAddid; //show table - in case it was hidden before, if there were zero results $('#sub-'+sAddtable).show(); $('#sub-'+sAddtable+'_wrapper').show(); $('#sub-'+sAddtable+'_info').show(); $('#sub-'+sAddtable+'_paginate').show(); } //set input fields to empty $('#videourl_link').val(''); $('#videoname_link').val(''); //$('#description_link').val(''); } ); //need to disable the regular form action... unsure if this works... return false; } //based on AddLink, loosely? //add a photocaption //send sLoginhash, sDescription, iPhoid //aEditarray['sLoginhash'], - get sDescription from the user-entered field. function AddPhotoCaption(iPhoid) { //get sDescription from the input field. sDescription=$('#photo_description'+iPhoid).val(); $.post(sServer+"server-test/webservice/ajax_addcaption.php", { 'giAjax': "1", 'gsLoginhash' : aEditarray['sLoginhash'], 'gsDescription': sDescription, 'giPhoid':iPhoid }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { //error message //alert ("fail"); } else if (myObject['iExit']!=null) { //some success message, or change of display to make it obvious that it went through - should i leave the user in edit mode? I guess so. //alert ("success"); //could change the Add Caption to say Edit Caption //$('#addcaption-submit').val('Edit Caption'); //for photogallery need to do something else... like say "added" in alert or just simply on the screen if (substr_count(window.location.href , 'photogallery' , 0, 200)) { $('#added_caption_'+iPhoid).show(); } else { //set display view caption - this only works for people/groups in editview $('#photocaption_display').html(sDescription); DisplayMode('photo'); } } } ); //need to disable the regular form action... unsure if this works... return false; } //based on addlink //uses sub_tag datatable //we are now getting multiple tags returned - in $anArray['asTagreturn'] - probably located in myObject['asTagreturn'] function AddTag(iDeletebutton) { //only executes if the add tag input box is non-null if ($('#gsTag').val()!='') { Init_aEditarray(aEditarray); var sAddtable='tag'; var iAddid=''; var sAddidname='iTagid'; var oDatatable_addlink=sub_tag; //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_addtag.php", { 'giAjax': "1", 'aEditarray': encoded, 'giAddtag' : "1", 'giDeletebutton':iDeletebutton }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { $('#'+sAddtable+'_message').show(); $('#'+sAddtable+'_message').html(myObject['sClient']); } else if (myObject['iExit']!=null) { //hide user message for that subtable_message //$('#'+sAddtable+'_message').hide(); //hide notifications $('.notify').hide(); //now show this one $('#'+sAddtable+'_message').html("Tag added."); $('#'+sAddtable+'_message').show(); var oSettings = oDatatable_addlink.fnSettings(); //loop through myObject['asTagreturn'] //for in solution for array parsing - http://stackoverflow.com/questions/9329446/for-each-in-a-array-how-to-do-that-in-javascript //note a regular for loop doesn't work because asTagreturn has a length of undefined - js doesn't see it as an array for (key in myObject['asTagreturn']) { if (String(Number(key)) === key && myObject['asTagreturn'].hasOwnProperty(key) && (key!=0)) { //creates a new row //var aiNew = oDatatable_addlink.fnAddData(myObject['aRow']); var aiNew = oDatatable_addlink.fnAddData(myObject[key]['aRow']); //var nNewTr isn't used var nNewTr = oSettings.aoData[ aiNew[0] ].nTr; //need to get iAddid out of myObject iAddid=key; oSettings.aoData[ aiNew[0] ].nTr.id=sAddidname+'_'+iAddid; } } //show table - in case it was hidden before, if there were zero results $('#sub-'+sAddtable).show(); $('#sub-'+sAddtable+'_wrapper').show(); $('#sub-'+sAddtable+'_info').show(); $('#sub-'+sAddtable+'_paginate').show(); //empty tag input box $('#gsTag').val(''); } } ); } return false; } //based on addtag function AddUnitStatus() { Init_aEditarray(aEditarray); var sAddtable='unitstatus'; var iAddid=''; var sAddidname='iUsid'; var oDatatable_addlink=sub_unitstatus; aEditarray['iAddRelTable']='unitstatus'; //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_addunitstatus.php", { 'giAjax': "1", 'aEditarray': encoded, 'giAddunitstatus' : "1" }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { $('#'+sAddtable+'_message').show(); $('#'+sAddtable+'_message').html(myObject['sClient']); } else if (myObject['iExit']!=null) { iAddid=myObject['iAddid']; //hide user message for that subtable_message $('#'+sAddtable+'_message').hide(); var oSettings = oDatatable_addlink.fnSettings(); var aiNew = oDatatable_addlink.fnAddData(myObject['aRow']); var nNewTr = oSettings.aoData[ aiNew[0] ].nTr; //need to get iAddid out of myObject iAddid=myObject['iAddid']; oSettings.aoData[ aiNew[0] ].nTr.id=sAddidname+'_'+iAddid; //show table - in case it was hidden before, if there were zero results $('#sub-'+sAddtable).show(); $('#sub-'+sAddtable+'_wrapper').show(); $('#sub-'+sAddtable+'_info').show(); $('#sub-'+sAddtable+'_paginate').show(); } } ); //need to disable the regular form action... unsure if this works... return false; } //based on addunitstatus function AddFuel() { Init_aEditarray(aEditarray); var sAddtable='fuelproduct'; var iAddid=''; //note for products - use a different sAddidname - for use in datatables, in case the same thing goes in and out of the facility var sAddidname='iFuel'; var oDatatable_addlink=sub_fuel; aEditarray['iAddRelTable']='fuelproduct'; //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_addfuel.php", { 'giAjax': "1", 'aEditarray': encoded, 'giAddfuel' : "1" }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { $('#fuelproduct_message').html(myObject['sClient']); $('#fuelproduct_message').show(); alert (myObject['sClient']); } else if (myObject['iExit']!=null) { iAddid=myObject['iAddid']; //hide user message for that subtable_message $('#fuelproduct_message').hide(); var oSettings = oDatatable_addlink.fnSettings(); var aiNew = oDatatable_addlink.fnAddData(myObject['aRow']); var nNewTr = oSettings.aoData[ aiNew[0] ].nTr; //need to get iAddid out of myObject iAddid=myObject['iAddid']; oSettings.aoData[ aiNew[0] ].nTr.id=sAddidname+'_'+iAddid; //show table - in case it was hidden before, if there were zero results $('#sub-fuel').show(); $('#sub-fuel_wrapper').show(); $('#sub-fuel_info').show(); $('#sub-fuel_paginate').show(); } } ); //need to disable the regular form action... unsure if this works... return false; } //based on AddFuel function AddProduct() { Init_aEditarray(aEditarray); var sAddtable='fuelproduct'; var iAddid=''; //note for products - use a different sAddidname - for use in datatables, in case the same thing goes in and out of the facility var sAddidname='iProduct'; var oDatatable_addlink=sub_product; aEditarray['iAddRelTable']='fuelproduct'; //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_addproduct.php", { 'giAjax': "1", 'aEditarray': encoded, 'giAddproduct' : "1" }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { $('#fuelproduct_product_message').html(myObject['sClient']); $('#fuelproduct_product_message').show(); alert (myObject['sClient']); } else if (myObject['iExit']!=null) { iAddid=myObject['iAddid']; //hide user message for that subtable_message $('#fuelproduct_product_message').hide(); var oSettings = oDatatable_addlink.fnSettings(); var aiNew = oDatatable_addlink.fnAddData(myObject['aRow']); var nNewTr = oSettings.aoData[ aiNew[0] ].nTr; //need to get iAddid out of myObject oSettings.aoData[ aiNew[0] ].nTr.id=sAddidname+'_'+iAddid; //show table - in case it was hidden before, if there were zero results $('#sub-product').show(); $('#sub-product_wrapper').show(); $('#sub-product_info').show(); $('#sub-product_paginate').show(); } } ); //need to disable the regular form action... unsure if this works... return false; } //Based on Addlink, note lots of repetition with how aEditarray is defined.... function AddAdmin() { Init_aEditarray(aEditarray); var sAddtable='control'; var iAddid=''; var sAddidname=''; var oDatatable_addadmin=sub_control; //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_add_control.php", { 'giAjax': "1", 'aEditarray': encoded, 'giAddadmin' : "1" }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { $('#'+sAddtable+'_message').show(); $('#'+sAddtable+'_message').html(myObject['sClient']); } else if (myObject['iExit']!=null) { //hide user message for that subtable_message $('#'+sAddtable+'_message').hide(); var oSettings = oDatatable_addadmin.fnSettings(); var aiNew = oDatatable_addadmin.fnAddData(myObject['aRow']); var nNewTr = oSettings.aoData[ aiNew[0] ].nTr; //need to get iAddid out of myObject iAddid=myObject['iAddid']; oSettings.aoData[ aiNew[0] ].nTr.id=sAddidname+'_'+iAddid; //show table - in case it was hidden before, if there were zero results $('#sub-'+sAddtable).show(); $('#sub-'+sAddtable+'_wrapper').show(); $('#sub-'+sAddtable+'_info').show(); $('#sub-'+sAddtable+'_paginate').show(); } } ); return false; } //Oppose Facility - user states their opposition to facility, add to facility_people table function OpposeFacility(iFacilityid, sLoginhash, iUid, iPid, sFname, sLname) { sAddtable='people'; oDatatable=sub_people; //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_opposefacility.php", {'giFacilityid': iFacilityid, 'gsLoginhash': sLoginhash, 'giUid': iUid}, function (data) { var myObject = eval('(' + data + ')'); //error message if (myObject['iExit']==1) { $('#'+sAddtable+'_message').show(); $('#'+sAddtable+'_message').html(myObject['sClient']); } //add them to sub-people datatable //so need their name - which is in session['user'], and could be used as function parameters... //sAddidname = 'iPid' //iAddid = $session['user']['giPid']; else if (myObject['iExit']==0) { //hide user message for that subtable_message $('#'+sAddtable+'_message').hide(); var oSettings = oDatatable.fnSettings(); var aiNew = oDatatable.fnAddData(myObject['aRow']); //var aiNew = {"sFname": sFname, "sLname":sLname}; var nNewTr = oSettings.aoData[ aiNew[0] ].nTr; oSettings.aoData[ aiNew[0] ].nTr.id='iPid_'+iPid; //show table - in case it was hidden before, if there were zero results $('#sub-'+sAddtable).show(); $('#subform370_'+sAddtable+'_wrapper').show(); $('#sub-'+sAddtable+'_wrapper').show(); //$('#sub-'+sAddtable+'_info').show(); //$('#sub-'+sAddtable+'_paginate').show(); $('#oppose_facility').html('You oppose this facility.'); } } ); //need to disable the regular form action... this works! return false; } //maintable and mainid - already set by php //Deletes a Relation - for subforms... //oDatatable - sub_facility or others... //sDeleteidname - delete idname - eg. iFacilityid function DeleteRelation(sDeletetable, iDeleteid, oDatatable, sDeleteidname) { Init_aEditarray(aEditarray); aEditarray['iDeleteid']=iDeleteid; aEditarray['sDeletetable']=sDeletetable; //we don't need sPost so it is set to empty aEditarray['sPost']=''; //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //var JSON_aEditarray=JSON.stringify(encoded); //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_deleterelation.php", { 'giAjax': "1", 'aEditarray': encoded }, function (data) { var myObject = eval('(' + data + ')'); if (myObject['iExit']==1) { $('#'+sDeletetable+'_message').show(); $('#'+sDeletetable+'_message').html(myObject['sClient']); } else if (myObject['iExit']!=null) { $('.notify').hide(); //resource link deleted - tell them how to delete the underlying resource if (sDeletetable=='resource') { $('#'+sDeletetable+'_message').html("You have removed the connection to the resource.
You can also Delete the Resource").show(); } //no delete message - need to replace with deletion message! else { $('#'+sDeletetable+'_message').html('You have deleted the connection.').show(); } if ((sDeleteidname=='iFuelproductid') && (oDatatable==sub_fuel)) { sDeleteidname='ifuel'; } else if ((sDeleteidname=='iFuelproductid') && (oDatatable==sub_product)) { sDeleteidname='iproduct'; } var position=oDatatable.fnGetPosition( $("#"+sDeleteidname+"_"+iDeleteid)[0]) oDatatable.fnDeleteRow(position); } //hide table if there are zero rows if (oDatatable.fnSettings().fnRecordsDisplay()==0) { $('#sub-'+sDeletetable).hide(); $('#sub-'+sDeletetable+'_wrapper').hide(); $('#sub-'+sDeletetable+'_info').hide(); $('#sub-'+sDeletetable+'_paginate').hide(); } } ); //need to disable the regular form action... this works! return false; } //Calls ajax service to save data //sends sEditarray, as a serialized array //need to create a editarray like object in javascript... //returns: html for the section that was edited //when finished: rewrite the html for the editview and displayview of sHtml_id //if sHtml_id_new == 'privacy' then we are on the setprivacy.php page. Send a special setprivacy=1 to ajax_edit, so we can trigger a serverside function. function SaveData(sHtml_id_new) { Init_aEditarray(aEditarray); sHtml_id=sHtml_id_new; aEditarray['sEdit']='1'; $("#clientmessage_wide").hide(); //call webservice //trying it without serializing aEditarray - as there doesn't appear to be a js serialize function! var encoded = $.toJSON(aEditarray); //encodeURIComponent(encoded); if (sHtml_id_new=='privacy') { $.post(sServer+"server-test/webservice/ajax_edit.php", { 'giAjax_edit': "1", 'giSetprivacy':"1", 'aEditarray': encoded , 'sHtml_id': sHtml_id}, function (data) { var myObject = eval('(' + data + ')'); //if fail - write out error message, stay in editview - eg. if data['iExit']==1 //hmm, unsure how to get multiple variables returned... maybe return a json array, and then parse it //haven't teseted this part yet... if (myObject['iExit']==1) { $("#clientmessage_wide").html(myObject['sClient']).show(); } else { //success - write out html to displayview and editview profileboxes - in which case data might be an array with two strings in it //set clientmessage div to empty (if there isn't any error) - it is used by step 3 I think... tends to say "we updated the record." $("#clientmessage_wide").html('Your new privacy settings have been saved.').show(); } } ); } else { //giAjax might not need quotes $.post(sServer+"server-test/webservice/ajax_edit.php", { 'giAjax_edit': "1", 'aEditarray': encoded , 'sHtml_id': sHtml_id}, function (data) { var myObject = eval('(' + data + ')'); //if fail - write out error message, stay in editview - eg. if data['iExit']==1 //hmm, unsure how to get multiple variables returned... maybe return a json array, and then parse it //haven't teseted this part yet... if (myObject['iExit']==1) { $("#clientmessage_wide").html(myObject['sClient']).show(); } else { //SUCCESS - write out html to displayview and editview profileboxes - in which case data might be an array with two strings in it //set clientmessage div to empty (if there isn't any error) - it is used by step 3 I think... tends to say "we updated the record." //if we do this, we need to increase the top margin - replace class='main_smalltopmargin' with 'main' //if there is a client message if (myObject['sClient'].length > 5) { $("#clientmessage_wide").html(myObject['sClient']).show(); //fixes layout - $(".main").removeClass('main').addClass('main_smalltopmargin'); //$("#clientmessage_wide").show(); } else { $("#clientmessage_wide").hide(); $(".main_smalltopmargin").removeClass('main_smalltopmargin').addClass('main'); } $("#"+sHtml_id).html(myObject['sHtml']); //now that we're recreated the html - add the notification message $("#spanclientmessage_"+sHtml_id).html("Your changes have been saved."); //hide other notifications $(".notify").hide(); $("#clientmessage_"+sHtml_id).show(); //these two lines are from displaymode, but I didn't want to use return false... $("#"+sHtml_id+"_display").removeClass("hidebox").addClass("showbox"); $("#"+sHtml_id+"_edit").removeClass("showbox").addClass("hidebox"); //do stuff with a returned email/emailhash if we got one //email goes into js_encoded_email if (myObject['sEmail_first']!='') { $("#js_encoded_email").html("" + "Email" + ""); } //move facility minimap and update the nearby facilities link if ((myObject['fLatitude']!=0) && (myObject['fLatitude']!=null)) { //remove existing marker and add a new one //tricky part is that we need to get the facility id and text (facility name) //would be easier to move the bbMarker one... if I can get it in scope! gMarkers[0].setPosition(new google.maps.LatLng (myObject['fLatitude'],myObject['fLongitude'])); map.setCenter (new google.maps.LatLng (myObject['fLatitude'],myObject['fLongitude'])); //update the nearby facilities link $('#nearby_facilities').attr("href", "searchobject.php?gsTable=facility&gsSearchtype=themap&gsAddress_facility=+++"+myObject['fLatitude']+ "+" + myObject['fLongitude']+ "&gsQuery=Submit&giRadius=25&giRadiusdefault=1"); } } } ); } //need to disable the regular form action... this works! return false; } function HideRemoveAccount() { $("#removeaccount").hide(); $("#remove_account_link").show(); } function RemoveAccount() { $("#removeaccount").show(); $("#remove_account_link").hide(); } var iGlobalmapwidth=''; //For the layers on community map and other maps function Toggle_Layer_System(id) { if (id==2) { $("#layer_system2").toggle(); $("#layer_system_show2").toggle(); } $("#layer_system").toggle(); $("#layer_system_show").toggle(); $("#facility_layer_system").toggle(); if (!$("#layer_system").is(":visible")) { //would like to use 100%, but first i need a parent div with a 100% width or I need to make this position absolute or something //$('#map').css({'width':'100%','height':'700'}); iGlobalmapwidth=$('#map').css('width'); $('#map').css({'width':'100%'}); $('#choosemaplayer').hide(); document.getElementById('facility_layer_system').style.display='none'; } else { //need to set map width to the property stored in CSS... so I might need to store this width as a global variable? //the hard part is that I want to resize the map width, without setting a width parameter - because doing so will override my adaptive layout //$('#map').css({'width':iGlobalmapwidth,'height':'700'}); //$('#map').css({'width':'660','height':'700'}); $('#choosemaplayer').show(); //document.getElementById('demographics_data').style.display='none'; } //google.maps.event.trigger(map, 'resize'); } function Toggle_Layers(sLayer_name) { $("#"+sLayer_name+"_layer_system").toggle(); $("#"+sLayer_name+"_layer_system_show").toggle(); $("#"+sLayer_name+"_layer_system_hide").toggle(); } //turns edit mode on, display mode off //by setting style='display:none' or '' function EditMode(sHtml_id) { $(".notify").hide(); $("#"+sHtml_id+"_edit").removeClass("hidebox").addClass("showbox"); $("#"+sHtml_id+"_display").removeClass("showbox").addClass("hidebox"); //show the cancel link $("#editlink_cancel_"+sHtml_id).show(); //hide the edit link $("#editlink_edit_"+sHtml_id).hide(); //for people/group (and maybe facilities?) init country, state, province, county drop downs. if (sHtml_id=='address') Init_County_State_Province(); } //If the user is in EditMode and hits "cancel" they call this function to get into displaymode function DisplayMode(sHtml_id) { $("#"+sHtml_id+"_display").removeClass("hidebox").addClass("showbox"); $("#"+sHtml_id+"_edit").removeClass("showbox").addClass("hidebox"); //hide the cancel link $("#editlink_cancel_"+sHtml_id).hide(); //show the edit link $("#editlink_edit_"+sHtml_id).show(); return false; } //turns edit mode on, display mode off //by setting style='display:none' or '' function EditMode_subform(sSubtable) { $(".notify").hide(); $("#"+sSubtable+"_edit").removeClass("hidebox").addClass("showbox"); //$("#"+sSubtable+"_display").removeClass("showbox").addClass("hidebox"); //show the cancel link $("#editlink_cancelsubform_"+sSubtable).show(); //hide the edit link $("#editlink_editsubform_"+sSubtable).hide(); } //If the user is in EditMode and hits "cancel" they call this function to get into displaymode function DisplayMode_subform(sSubtable) { //$("#"+sSubtable+"_display").removeClass("hidebox").addClass("showbox"); $("#"+sSubtable+"_edit").removeClass("showbox").addClass("hidebox"); //hide the cancel link $("#editlink_cancelsubform_"+sSubtable).hide(); //show the edit link $("#editlink_editsubform_"+sSubtable).show(); return false; } //Return the user to their profile - displayperson-xx.htm from setprivacy.php function ProfileReturn (iId, sTable) { window.location.href=sClienturl+'edit'+sTable+'-'+iId+ '.htm'; return false; } //checks username for duplicate. Eg. already existing account with that email address. function DuplicateUsername () { var sEmail=$('#gsEmail').val(); $.post(sServer+"server-test/webservice/signup_duplicateusername.php?gsEmail="+sEmail, { giAjax: "1"}, //write out data to the dom... perhaps below the email field - with a //could make this an input text box, it would look more user-friendly in terms of copying function (data) { if (data==1) $("#duplicate_username").html("That email already has an account.
Forgot your password?
").show(); else if (data==0) $("#duplicate_username").html(""); else $("duplicate_username").html("That email already has an account.
Verify your email
"); } ); } //borrowed from google - http://gmaps-samples.googlecode.com/svn/trunk/geocoder/reverse.html //if successful, ask the user if they want to use the result. //if yes, then open the addfacility page - send address in GET (address, city, state, zip, country) //what is the format of the address: so use throughfarename, localityname, administrativeareaname, postalcodenumber //for country - I might need to convert it from USA to United States or the 251 country code //Used to have this on local/national/global map - turned off since those maps are crowded and scrolling is hard //Probably doesn't work with google maps V3 /* function clicked(overlay, latlng) { if (latlng) { geocoder.getLocations(latlng, function(addresses) { if(addresses.Status.code != 200) { alert("reverse geocoder failed to find an address for " + latlng.toUrlValue()); } else { address = addresses.Placemark[0]; var myHtml = address.address; //sends the full address, explode with comma seperation and count the number of elements to determine //whether the street address is included (and city too) //should I replace spaces with + character? spaces in the url might not be good... //sLocation='http://www.energyjustice.net/map-test/addobject.php?gsTable=facility&gsAddress_full='+myHtml; sLocation=sClienturl+'addobject.php?gsTable=facility&gsAddress_full='+myHtml if(confirm('Do you want to add a facility with this location?'+' '+myHtml)) self.location=sLocation; } }); } } */ //Initialize country, county, state, province //used by onload_init, also used when the user clicks on edit, for addresses. //Sets county to null, if the user changes the country. function Init_County_State_Province () { if (document.forms[0]!=undefined) { if (document.forms[0].giCounty!=undefined) { AddCounties3 (document.forms[0].giState.value, document.forms[0].giCounty.value); } if (document.forms[0].giCountry!=undefined) { //The US is default if (document.forms[0].giCountry[document.forms[0].giCountry.selectedIndex].value!=undefined) { var iSelectedvalue=document.forms[0].giCountry[document.forms[0].giCountry.selectedIndex].value } else iSelectedvalue=251; //Canada if (iSelectedvalue==44) { $("#giProvince").show(); $("#giProvince_prompt").show(); $("#giState").hide(); $("#giState_prompt").hide(); $("#intl_state").hide(); $("#intl_state_prompt").hide(); $("#county_search").hide(); $("#county_search_prompt").hide(); if (document.forms[0].giState!=undefined) document.forms[0].giState.value=0; if (document.forms[0].gsState!=undefined) document.forms[0].gsState.value=''; if (document.forms[0].giCounty!=undefined) document.forms[0].giCounty.value=0; } //Other else if ((iSelectedvalue!='') && (iSelectedvalue!=0) && (iSelectedvalue!=251)) { $("#intl_state").show(); $("#intl_state_prompt").show(); $("#giProvince").hide(); $("#giProvince_prompt").hide(); $("#giState").hide(); $("#giState_prompt").hide(); $("#county_search").hide(); $("#county_search_prompt").hide(); if (document.forms[0].giState!=undefined) document.forms[0].giState.value=0; if (document.forms[0].giProvince!=undefined) document.forms[0].giProvince.value=0; if (document.forms[0].giCounty!=undefined) document.forms[0].giCounty.value=0; } //US else { $("#giState").show(); $("#_prompt").show(); $("#county_search").show(); $("#county_search_prompt").show(); $("#giProvince").hide(); $("#giProvince_prompt").hide(); $("#intl_state").hide(); $("#intl_state_prompt").hide(); if (document.forms[0].giProvince!=undefined) document.forms[0].giProvince.value=0; if (document.forms[0].gsState!=undefined) document.forms[0].gsState.value=''; } } } } function substr_count(string,substring,start,length) { var c = 0; if(start) { string = string.substr(start); } if(length) { string = string.substr(0,length); } for (var i=0; i < string.length; i++) { if(substring == string.substr(i,substring.length)) c++; } return c; } //Need to do this onload... //Initializing several fields used in facility search //only do this if they exist (and should only do it if we don't have a saved country or state of Canada... //might need to give the prompt for province an ID so I can hide it, or stick it and the field in a div... //700 lines! //Mostly datatables initialization. Also for facility maps it does the first call to FacilityLayerToggle (to load facility layers) function OnLoad_Init () { $(document).ready(function() { //for marker move suggestions $( "#dialog-form" ).dialog({ autoOpen: false, height: 255, width: 400, modal: true, buttons: { "Submit": function() { //var point = bbMarker.getPosition(); alert("Thanks! We will review your suggestion."); //testing sNotes value from form //alert ("notes: "+sNotes.value); $( "#dialog-form" ).dialog("close"); var move_lng=$( "#dialog-form" ).data("move_lng"); var move_lat=$( "#dialog-form" ).data("move_lat"); var move_uid=$( "#dialog-form" ).data("move_uid"); var move_facilityid=$( "#dialog-form" ).data("move_facilityid"); $.post(sServer+"server-test/webservice/markermovesuggestion-service.php", {giAjax:"1", fLongitude: move_lng , fLatitude: move_lat, iUid: move_uid, iFacilityid: move_facilityid, sClient:"", iExit:"", sLanguage:"", sNotes: sNotes.value}); //function(){}, "JSON"); } }}); //only do this if calendar or event is in the url... //could be modified to only do it if calendar is in the url - no longer using hidden divs... if ((substr_count(window.location.href , 'calendar' , 0, 200)) || (substr_count(window.location.href , 'events' , 0, 200))) { $('#calendar').fullCalendar({ googleCalendarApiKey: 'AIzaSyCd-PLmWJvFyoWGCZT2PQz95ALjE0UsngA', // EJ Calendar events: {googleCalendarId: 'oomjhb6i9427uoj8806efg7ehviiga78@import.calendar.google.com'}, eventBackgroundColor:'#CDFDFD' }); //turns fullcalendaron, other calendar off if ((substr_count(window.location.href , 'calendar' , 0, 200))) { CalendarSwitch(''); } } //add tiptip tooltip to tipclass - currently not in use... $(function(){ $(".TipClass").tipTip(); }); //trying to define a function within a function and it works //ideally should only do this if there are <=20 items in the subform var sSubtablename=''; function RemovePagination(sSubtablename) { $('#sub-'+sSubtablename+'_paginate')[0].style.display = "none"; $('#sub-'+sSubtablename+'_info')[0].style.display = "none"; } //I should only do this validate function if these forms exist... $("#signup_form").validate(); $("#openinviter_form").validate(); $("#find_facilities_form").validate(); $("#login_form").validate(); $("#add_form").validate(); $("#requestcontrol_form").validate(); //Instead of sub_facility, we want to initialize all of the dataTables... //we should have all the data stored in a js array, so we could look for !undefined arrays, or we could have a seperate js array //that tracks which tables can be displayed... //or do "if element with this id exists" then run it... //EDIT -- include a column for deleting relations if ((substr_count(window.location.href , 'edit' , 0, 200)) || (substr_count(window.location.href , 'signup' , 0, 200)) || (substr_count(window.location.href , 'profile' , 0, 200))) { //need two facility tables - one for people/groups, where there are just 3 columns (name, interestlevel, delete) //and one for corporations with 4 columns (name, ownership, subcorp, percent) or maybe 5 if we do delete... //and one for resources - (name and delete) //or Actually we need name, child corporation, and delete - hmm but what is child corporationd doing??? if (substr_count(window.location.href , 'resource' , 0, 200)) { sub_facility=$("#sub-facility").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrtp', "aoColumns": [{"bSortable":false}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null], "fnDrawCallback": function() { $('#sub-facility_paginate')[0].style.display = "none"; } }); } else { sub_facility=$("#sub-facility").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrtp', "aoColumns": [{"bSortable":false}, {"bSortable":false}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null], "fnDrawCallback": function() { $('#sub-facility_paginate')[0].style.display = "none"; } }); } //used for corporations page - shows the facilities that are connected to the corporation and its (one generation) of child corps. sub_childfacilities=$("#sub-childfacilities").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null]}); // might need to define sType for these other ones too... Tentatively just added it to the first column, second is null, hopefully the other columns will autodetect //hmm, unsure if other columns can autodetect... might need to specify length? //I had a problem where sub-facility was defined as 4 columns, but I only gave it 3 's and 's - that didn't work //for facilities we want 4 columns, for other objects (like resources), we only need 2 columns if (substr_count(window.location.href , 'resource' , 0, 200)) { sub_corporation=$("#sub-corporation").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null] }); } else { sub_corporation=$("#sub-corporation").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null] }); } sub_category=$("#sub-category").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null] }); //now trying 4 columns first, last, state/thumbnail, delete sub_people=$("#sub-people").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":true},{"bSortable":true},{"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null] }); //facility has 4 slots - extra for interested/active if (substr_count(window.location.href , 'facility' , 0, 200)) { sub_groups=$("#sub-groups").dataTable({"iDisplayLength":20, "bLengthChange":false,"bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":false}, {"bSortable":false}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null] }); } else { sub_groups=$("#sub-groups").dataTable({"iDisplayLength":20, "bLengthChange":false,"bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":false}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null] }); } sub_school=$("#sub-school").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null]}); sub_resource=$("#sub-resource").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null]}); sub_link=$("#sub-link").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":false},{"bSortable":false}], "aoColumns": [{"sType":"html"}, null]}); sub_videolink=$("#sub-videolink").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null] }); sub_tag=$("#sub-tag").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null] }); sub_phile=$("#sub-phile").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":false}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null]}); //two columns, date and type - could also have a delete one... sub_unitstatus=$("#sub-unitstatus").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [null, null, null] }); sub_unit=$("#sub-unit").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null]}); sub_fuel=$("#sub-fuel").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null, null]}); sub_product=$("#sub-product").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrt', "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null, null]}); } //LIST -- listevent - list resource - hopefully covers "calendar" too. //else if ((substr_count(window.location.href , 'list' , 0, 200)) || (substr_count(window.location.href , 'calendar' , 0, 200))) else if ((substr_count(window.location.href , 'list' , 0, 200)) || (substr_count(window.location.href , 'events' , 0, 200))) { //event has 10 columns - email recently removed. datatable_list_event=$("#datatable-list-event").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true} ], "aoColumns": [{"sType":"html"}, {"sType":"date"}, {"sType":"date"}, null, null, null, null, null, null, null], "aaSorting": [[ 1, "asc" ]], "sDom": 'lfrtip'}); //resources has 4 columns datatable_list_resource=$("#datatable-list-resource").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true} ], "aoColumns": [{"sType":"html"}, null, null, null], "aaSorting": [[ 2, "desc" ]], "sDom": 'lfrtip'}); } //SEARCH mode //var datatable_search_facility=""; else if (substr_count(window.location.href , 'search' , 0, 200)) { //TableToolsInit.sSwfPath = "js/TableTools/media/swf/ZeroClipboard.swf"; //old style - 4 cols - new style 6 cols, includes lat/lng - hidden! datatable_search_facility=$("#datatable-search-facility").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"sType":"html"}, null, null, {"sType":"html"}, null, null], "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":false}, {"bSortable":false , "bVisible":false}, {"bSortable":false, "bVisible":false}], "sDom": 'T<"clear">lfrtip', "oTableTools": {"sSwfPath": "js/TableTools/media/swf/copy_csv_xls_pdf.swf", "aButtons": [ {"sExtends": "csv", "mColumns": [0,1,2,4,5]}, {"sExtends": "xls", "mColumns": [0,1,2,4,5]}, {"sExtends": "copy", "mColumns": [0,1,2,4,5]}, {"sExtends": "pdf", "mColumns": [0,1,2,4,5]}, {"sExtends": "print", "mColumns": [0,1,2,4,5]} ] }} ); datatable_search_corporation=$("#datatable-search-corporation").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null], "sDom": 'lfrtip'}); datatable_search_groups=$("#datatable-search-groups").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null, null, null, null], "sDom": 'lfrtip'}); datatable_search_people=$("#datatable-search-people").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null, null, null, null, null, null], "sDom": 'lfrtip'}); datatable_search_resource=$("#datatable-search-resource").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null], "sDom": 'lfrtip'}); } //DISPLAY mode, one less column in datatables - necessary to avoid a sData javascript error else { //need two facility tables - one for people/groups, where there are just 3 columns (name, interestlevel, delete) //and one for corporations with 4 columns (name, ownership, subcorp, percent) or maybe 5 if we do delete... if (substr_count(window.location.href , 'resource' , 0, 200)) { sub_facility=$("#sub-facility").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "sDom": 'lfrtp', "aoColumns": [{"bSortable":false}], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { $('#sub-facility_paginate')[0].style.display = "none"; } }); } //people and groups else { sub_facility=$("#sub-facility").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}], "aoColumns": [{"sType":"html"}, null] }); } //used for corporations page - shows the facilities that are connected to the corporation and its (one generation) of child corps. sub_childfacilities=$("#sub-childfacilities").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}], "aoColumns": [{"sType":"html"}] }); // might need to define sType for these other ones too... Tentatively just added it to the first column, second is null, hopefully the other columns will autodetect //hmm, unsure if other columns can autodetect... might need to specify length? //I had a problem where sub-facility was defined as 4 columns, but I only gave it 3 's and 's - that didn't work //for facilities we want 4 columns, for other objects (like resources), we only need 2 columns if ((substr_count(window.location.href , 'resource' , 0, 200)) || (substr_count(window.location.href , 'corporation' , 0, 200))) { sub_corporation=$("#sub-corporation").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('corporation'); }} }); } else { sub_corporation=$("#sub-corporation").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}], "aoColumns": [{"sType":"html"}, null, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('corporation'); }} }); } //for people and group - need extra column if maintable=facility -- for active/interested field if ((substr_count(window.location.href , 'facility' , 0, 200)) || (substr_count(window.location.href , 'df' , 0, 200))) { //NOW 3 columsn - changed from 4, to get http://localhost/ejm/displayfacility-68575.htm to work. //4 columns - first name, last name, active/interested, sub_people=$("#sub-people").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}], "aoColumns": [{"sType":"html"}, null, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('people'); }} }); //3 columns - group name, state, active/interested sub_groups=$("#sub-groups").dataTable({"iDisplayLength":20, "bLengthChange":false,"bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":false},{"bSortable":true}], "aoColumns": [{"sType":"html"}, null, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('groups'); }} }); } else { //3 columns - first name, last name, state sub_people=$("#sub-people").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}], "aoColumns": [{"sType":"html"}, null, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('people'); }} }); //2 columns - group name, state (ooh, for facility - we need THREE columns - interested is the third) -- same for people... sub_groups=$("#sub-groups").dataTable({"iDisplayLength":20, "bLengthChange":false,"bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('groups'); }} }); } sub_school=$("#sub-school").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('school'); }} }); sub_resource=$("#sub-resource").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('resource'); }} }); sub_link=$("#sub-link").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":false} ], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('link'); }} }); sub_videolink=$("#sub-videolink").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true} ], "aoColumns": [{"sType":"html"}, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('videolink'); }} }); sub_tag=$("#sub-tag").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { RemovePagination('tag'); } }); sub_phile=$("#sub-phile").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('phile'); }} }); sub_unitstatus=$("#sub-unitstatus").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}], "aoColumns": [null, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('unitstatus'); }} }); sub_unit=$("#sub-unit").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}], "aoColumns": [{"sType":"html"}, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('unitstatus'); }} }); sub_fuel=$("#sub-fuel").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}], "aoColumns": [{"sType":"html"}, null, null, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('fuel'); }} }); sub_product=$("#sub-product").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":true}, {"bSortable":true}], "aoColumns": [{"sType":"html"}, null, null, null], "fnDrawCallback": function() { if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) < 2) { RemovePagination('product'); }} }); //end of if statement } //same size in both cases - no delete column //since there is unlikely to be more than 20 controllers, I'm removing pagination sub_control=$("#sub-control").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { RemovePagination('control'); } }); //this would work if I added the class "dataTable" to all my tables... //$('.dataTable').dataTable({"iDisplayLength":20, "bLengthChange":false}); //for each datatable, hide it if there are zero rows. //actually hide the datatables wrapper - do this if we aren't in search view if ((!substr_count(window.location.href , 'search' , 0, 200)) && (!substr_count(window.location.href , 'events' , 0, 200)) && (!substr_count(window.location.href , 'list' , 0, 200)) ) { if ((sub_facility.fnSettings()!=null) && (sub_facility.fnSettings().fnRecordsDisplay()==0)) { $('#sub-facility_wrapper').hide(); } if ((sub_groups.fnSettings()!=null) && (sub_groups.fnSettings().fnRecordsDisplay()==0)) { $('#sub-groups_wrapper').hide(); } if ((sub_people.fnSettings()!=null) && (sub_people.fnSettings().fnRecordsDisplay()==0)) { $('#sub-people_wrapper').hide(); } if ((sub_school.fnSettings()!=null) && (sub_school.fnSettings().fnRecordsDisplay()==0)) { $('#sub-school_wrapper').hide(); } if ((sub_resource.fnSettings()!=null) && (sub_resource.fnSettings().fnRecordsDisplay()==0)) { $('#sub-resource_wrapper').hide(); } if ((sub_corporation.fnSettings()!=null) && (sub_corporation.fnSettings().fnRecordsDisplay()==0)) { $('#sub-corporation_wrapper').hide(); } if ((sub_link.fnSettings()!=null) && (sub_link.fnSettings().fnRecordsDisplay()==0)) { $('#sub-link_wrapper').hide(); } if ((sub_videolink.fnSettings()!=null) && (sub_videolink.fnSettings().fnRecordsDisplay()==0)) { $('#sub-videolink_wrapper').hide(); } //turned off - as the user can sometimes add a tag. if ((sub_tag.fnSettings()!=null) && (sub_tag.fnSettings().fnRecordsDisplay()==0)) { $('#sub-tag_wrapper').hide(); } if ((sub_phile.fnSettings()!=null) && (sub_phile.fnSettings().fnRecordsDisplay()==0)) { $('#sub-phile_wrapper').hide(); } if ((sub_control.fnSettings()!=null) && (sub_control.fnSettings().fnRecordsDisplay()==0)) { $('#sub-control_wrapper').hide(); } } if (substr_count(window.location.href , '/admin' , 0, 200)) { $('#admin_user').focus(); } if (substr_count(window.location.href , 'verify_account' , 0, 200)) { $('#verify_password').focus(); } if (substr_count(window.location.href , 'signup.php?giStep=1' , 0, 200)) { $("input[name=gsFname]").focus(); } //form wizard add a facility code - imported from displayfieldinc.php if (substr_count(window.location.href , 'addfacility' , 0, 200)) { addfacilityform_init(); } //hide datatable_wrappers if they have zero rows //foreach them - or do it for all divs that have a class of dataTable //oTable.fnSettings().fnRecordsTotal() //$(".dataTables_wrapper").hide(); /* $('.dataTables_wrapper').each(function(i, obj) { //obj.id "sub-facility_wrapper" var tablename= obj.id.replace('_wrapper', ''); tablename= tablename.replace('-', '_'); if (window[tablename].fnSettings().fnRecordsTotal() < 1) { //hide the table tablename= tablename.replace('_', '-'); $("#"+tablename+'_wrapper').hide(); } }); */ //for calendar if (substr_count(window.location.href,'calendar',0,200)) { CalendarSwitch (''); $('.fc-header-right').append(" Add Event"); } else if (( substr_count(window.location.href,'events',0,200)) || (substr_count(window.location.href,'iCurrentpageiEid',0,200))) { CalendarSwitch ('listview'); } // }); //OLD end of document.ready //I decided to include everything in the document.ready function. //Initialize the facility maps //check for gsSearchtype -- hmm - need to define gsSearchtype first... can I make it a JS global? var gsSearchtype=''; if (substr_count(window.location.href , 'nationalmap' , 0, 400)) gsSearchtype='nationalmap'; else if (substr_count(window.location.href , 'globalmap' , 0, 400)) gsSearchtype='globalmap'; else if (substr_count(window.location.href , 'statemap' , 0, 400)) gsSearchtype='statemap'; else if ((substr_count(window.location.href , 'themap' , 0, 400)) || (substr_count(window.location.href , 'community' , 0, 400))) gsSearchtype='themap'; if (gsSearchtype!='') { //sets layer status to 'on' for local and global map, off for national and state map var iStatus=0; if ((gsSearchtype=='themap') || (gsSearchtype=='globalmap')) iStatus=1; var layerstatus=new Array(); layerstatus[1]=new Array(); layerstatus[2]=new Array(); layerstatus[3]=new Array(); layerstatus[4]=new Array(); //same array is also used by FacilityLayerToggle var aFaclayer=new Array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 98); for (key in aFaclayer) { layerstatus[1][aFaclayer[key]]=iStatus; layerstatus[2][aFaclayer[key]]=iStatus; layerstatus[3][aFaclayer[key]]=iStatus; layerstatus[4][aFaclayer[key]]=iStatus; } //load markers //First - check for any existing layers in the URL //Second - if not, then for local/global/state - load all layers. National - do not load. //extract layers from the URL //commented out, as we appear to be already loading this in php - in searchobjectsinc.php we call facilitylayertoggle if ((gsSearchtype=='themap') || (gsSearchtype=='globalmap') || (gsSearchtype=='statemap')) { //FacilityLayerToggle(1, 99, 99, gsSearchtype, ''); } //layers are off by default -- BUT they might be defined in the URL (by a saved url, or biomassoperating style) //need to detect the layers in the url, use this to load layers (ajax/json) and set the checkboxes. else if (gsSearchtype=='nationalmap') { //alert ('need to detect url'); }; } //Initialize country, county, state, province Init_County_State_Province (); //might want to do this only if they exist... $('#stateenergymix').visualize(); $('#stateemissionschart_iCo2').visualize({barGroupMargin: '2', width:370}); $('#stateemissionschart_iSo2').visualize({barGroupMargin: '2', width:370}); $('#stateemissionschart_iNox').visualize({barGroupMargin: '2', width:370});; //kml init, only if on search object if ((substr_count(window.location.href , 'searchobject' , 0, 200)) || (substr_count(window.location.href , 'displayobject.php?gsTable=adm' , 0, 200)) || (substr_count(window.location.href , 'ntiny' , 0, 200))) { kml_init(); } }); //end of document ready function } //end of long OnLoad_init function //canada chosen - turn canada prompt and dropdown on, turn others off //us chosen - turn us prompt and dropdown on, turn others off //other country chosen (that isn't empty string) - turn other country textbox on, turn others off //document.forms[0].giCountry.selectedIndex - look for Canada (44), or US (251) //this handles things that are already selected, but doesn't handle values from past searches that would be stored //in SESSION - but it still might work, so long as iCountry is marked as "selected" and OnLoad_Init is designed //to handle that... //This "forgets" the value that the user already entered. So if they have US selected, then choose Canada, then choose //the US, it won't remember the state they had selected for the US. On the other hand, how often will users do this? //We're setting the other values to null, so as to avoid sending them to the server... //Instead: we could have a "on submit" function that would set them to null if their form fields were hidden... //be sure that if the user switches from the US to another country it sets giState=0. //if the user switches from Canada to another country set iProvince=0 function StateBoxToggle() { //it is undefined if we're doing a user signup and are at step 1 if (document.forms[0].giCountry!=undefined) { var iSelectedvalue=document.forms[0].giCountry[document.forms[0].giCountry.selectedIndex].value //Canada if (iSelectedvalue==44) { $("#giProvince").show(); $("#giProvince_prompt").show(); $("#giState").hide(); $("#giState_prompt").hide(); $("#intl_state").hide(); $("#intl_state_prompt").hide(); $("#county_search").hide(); $("#county_search_prompt").hide(); document.forms[0].giState.value=0; document.forms[0].gsState.value=''; } //other country, non-US, non-Canada else if ((iSelectedvalue!='') && (iSelectedvalue!=0) && (iSelectedvalue!=251)) { $("#intl_state").show(); $("#intl_state_prompt").show(); $("#giProvince").hide(); $("#giProvince_prompt").hide(); $("#giState").hide(); $("#giState_prompt").hide(); $("#county_search").hide(); $("#county_search_prompt").hide(); document.forms[0].giState.value=0; document.forms[0].giProvince.value=0; } //USA else { $("#giState").show(); $("#giState_prompt").show(); $("#county_search").show(); $("#county_search_prompt").show(); $("#giProvince").hide(); $("#giProvince_prompt").hide(); $("#intl_state").hide(); $("#intl_state_prompt").hide(); document.forms[0].giProvince.value=0; document.forms[0].gsState.value=''; } } } //Sets giProvince, giState, gsState to null - based on which country is selected function SubmitForm() { if (document.forms[0].giCountry!=undefined) { var iSelectedvalue=document.forms[0].giCountry[document.forms[0].giCountry.selectedIndex].value; if (iSelectedvalue==44) { document.forms[0].giState.value=0; document.forms[0].gsState.value=''; } else if ((iSelectedvalue!='') && (iSelectedvalue!=0) && (iSelectedvalue!=251)) { document.forms[0].giState.value=0; document.forms[0].giProvince.value=0; } else { document.forms[0].giProvince.value=0; document.forms[0].gsState.value=''; } } } //reset button - in case the layers get messed up from clicking on them too fast before ajax requests are processed. //also resets localmap - for local map we have giLayer_98_1 (the "other" layer, which doesn't exist on national map) //I could modify it so it only sets them to false if they exist, but this seems to work fine - no javascript errors in firebug function ResetNationalMap() { for (var k=1; k<=iMaplayers; k++) { for (var j=1; j<=4; j++) { var sCheckname='giLayer_'+k+'_'+j; if (document.forms['faclayerform'][sCheckname]!=undefined) { document.forms['faclayerform'][sCheckname].checked=false; } //layerstatus is only used for local map - i think (wrong - also for state map) if (layerstatus!=undefined) layerstatus[j][k]=0; } var sCheckname='giLayer_'+k+'_'+99; if (document.forms['faclayerform'][sCheckname]!=undefined) { document.forms['faclayerform'][sCheckname].checked=false; } } for (var j=1; j<4; j++) { if (document.forms['faclayerform']['giLayer_98_'+j]!=undefined) { document.forms['faclayerform']['giLayer_98_'+j].checked=false; } if (layerstatus!=undefined) layerstatus[j][98]=0; } for (var j=1; j<=4; j++) //for (var j=2; j<=4; j++) { var sCheckname='giLayer_'+99+'_'+j; if (document.forms['faclayerform'][sCheckname]!=undefined) { document.forms['faclayerform'][sCheckname].checked=false; } var sCheckname='giLayer_'+98+'_'+j; if (document.forms['faclayerform'][sCheckname]!=undefined) { document.forms['faclayerform'][sCheckname].checked=false; } } if (document.forms['faclayerform']['giLayer_98_99']!=undefined) { document.forms['faclayerform']['giLayer_98_99'].checked=false; } if (document.forms['faclayerform']['giLayer_99_99']!=undefined) { document.forms['faclayerform']['giLayer_99_99'].checked=false; } //map.clearOverlays(); for (keyVar in facilities) { { if (gMarkers[keyVar]!=null) { gMarkers[keyVar].setMap(null); gMarkers[keyVar]=null; } facilities[keyVar]['iLayervisible']=0; } } //new method - sets the array length to zero when finished removing each marker gMarkers.length=0; if (substr_count(window.location.href , 'heat' , 0, 200)) { // map.addOverlay(myTileLayer); myTileLayer.setMap(map); } //sets iLayervisible to 0, also reset gmarkers - unsure if that is needed - as all of its operations are included above. //ToggleAllMarkersOff (); $("span#iCount").html("Total Results: 0"); } //enables or disables all checkboxes //NOTE: "disable" variable is true or false. If it is false, then this Enables all checkboxes. function CheckboxDisable(disable) { if (disable==true) { $("span#waiting").html("Fetching Data..."); } else { $("span#waiting").html(""); } //Alternatively, I could go through the DOM and find all checkboxes... If there was a direct DOM pointer to checkboxes. for (var ik=1; ik<=iMaplayers; ik++) { for (var ij=1; ij<=4; ij++) { var sCheckname10='giLayer_'+ik+'_'+ij; if (document.forms['faclayerform'][sCheckname10]!=undefined) { document.forms['faclayerform'][sCheckname10].disabled=disable; } } var sCheckname10='giLayer_'+ik+'_99'; if (document.forms['faclayerform'][sCheckname10]!=undefined) { document.forms['faclayerform'][sCheckname10].disabled=disable; } } //all of the same status - only exists for statuses other than "operating", hmm, unsure what this really does... document.forms['faclayerform']['giLayer_99_2'].disabled=disable; document.forms['faclayerform']['giLayer_99_3'].disabled=disable; document.forms['faclayerform']['giLayer_99_4'].disabled=disable; if (document.forms['faclayerform']['giLayer_99_1']!=undefined) { document.forms['faclayerform']['giLayer_99_1'].disabled=disable; } if (document.forms['faclayerform']['giLayer_99_99']!=undefined) { document.forms['faclayerform']['giLayer_99_99'].disabled=disable; } if (document.forms['faclayerform']['giLayer_98_99']!=undefined) { document.forms['faclayerform']['giLayer_98_99'].disabled=disable; } for (var ij=1; ij<=4; ij++) { var sCheckname10='giLayer_98_'+ij; if (document.forms['faclayerform'][sCheckname10]!=undefined) { document.forms['faclayerform'][sCheckname10].disabled=disable; } } } //creates layer checkbox array (based on the layer toggle, and existing form of checkboxes) - sends to server //gets facility data from AJAX request //runs initlayers to display them //*More Details* //if they choose an "all" statuses or all facility types - then toggle the related checkboxes //if they choose "proposed" (iStatus=2) then select "expanding" (iStatus: 4) as well, except for 99 (all layers) //if sMaptype: localmap, nationalmap, globalmap, or state (unsure about state - use same types as searchtype) //iRadius is null by default, if non-null - then use for webservice (for localmap changing radius) //instead of using maplayers (number of basic fac types - we might want to use "98" - to support the "other" layer in local map //Or I should create an array of statuses that I can foreach, and a list of faclayers that I can foreach //Could I call this function with iLayerid='' and iStatus='' - and that would apply the checkboxes - eg. turn them into layers //useful for initial condition - ex. biomassoperating - where we have giLayer_11_1=on, and displayfield correctly checks the box //so instead of having to reparse the URL and extract the layers, I can use the form-checkbox logic. //searchobjectsinc.php - calls it with -99 layer and -99 status, and iOn=1 - which makes no sense - it sould be 0,99,99 //NationalMapToggle(1, -99, -99); //iAdmid and iCountry come from the first call to this in searchobjectsinc.php - if we are using national-ca or Ohio - as the urls function FacilityLayerToggle (iOn, iLayerid, iStatus, sMaptype, iRadius, iCountry, sState) //function NationalMapToggle(iOn, iLayerid, iStatus) { //these two arrays are to use in checkbox loops for faclayers - to minimize the number of tests //you can for (key in aFaclayer) and then use aFaclayer[key] to get the 1..99 values //hmm, not sure if 99 should be included in aStatuslayer and aFaclayer - as sometimes we don't want it var aStatuslayer99=new Array (1, 2, 3, 4, 99); var aStatuslayer=new Array (1, 2, 3, 4); var aFaclayer99=new Array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 98, 99); var aFaclayer=new Array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 98); //ban using two or more of the high marker layers for the US national map. So do not ban it for national-ca //Layers include: hydro/oil/gas/coal/landfill - operating/all if ((sMaptype=='nationalmap') && ((iCountry==0) || (iCountry==251))) { var aStatus=new Array (2, 3, 4, 15, 17); if ( ((iLayerid==2) || (iLayerid==3) || (iLayerid==4) || (iLayerid==15) || (iLayerid==17)) && ((iStatus==1) || (iStatus==99))) { for (key in aStatus) { //probably instead of key - i should be using aStatus[key] as the key starts at 0 - so that is what I do if (aStatus[key]!=iLayerid) { var sCheckname5='giLayer_'+aStatus[key]+'_'; if (document.forms['faclayerform'][sCheckname5+'1']!=undefined) document.forms['faclayerform'][sCheckname5+'1'].checked=false; if (document.forms['faclayerform'][sCheckname5+'99']!=undefined) document.forms['faclayerform'][sCheckname5+'99'].checked=false; } } } } //99-99 changing the values of all layers if ((iLayerid==99) && (iStatus==99)) { for (var ikey in aStatuslayer99) { for (var isubkey in aFaclayer99) { var sCheckname5='giLayer_'+aFaclayer[isubkey]+'_'+aStatuslayer[ikey]; if (document.forms['faclayerform'][sCheckname5]!=undefined) { document.forms['faclayerform'][sCheckname5].checked=iOn; } } } } //user is turning off a layer - turn off any "99" layers that are affected if (iOn==false) { //set the "all statuses of this layer" to false if (iLayerid!=99) { var sCheckname5='giLayer_'+iLayerid+'_99'; if (document.forms['faclayerform'][sCheckname5]!=undefined) document.forms['faclayerform'][sCheckname5].checked=false; } //Set the "all facilities of the same status" to false var sCheckname5='giLayer_99_'+iStatus; if (document.forms['faclayerform'][sCheckname5]!=undefined) { document.forms['faclayerform'][sCheckname5].checked=false; } //if we're turning off any layer, set 99,99 to false (if it exists) var sCheckname5='giLayer_99_99'+iStatus; if (document.forms['faclayerform'][sCheckname5]!=undefined) { document.forms['faclayerform'][sCheckname5].checked=false; } } //user is turning on a layer - change any other layers that are affected (expanding), and the 99 ones else { //if the user turns on proposed (iStatus:2) then turn on expanding (iStatus:4) if ((iStatus==2) && (iLayerid!=99)) { var sCheckname_expanding='giLayer_'+iLayerid+'_4'; if (document.forms['faclayerform'][sCheckname_expanding]!=undefined) document.forms['faclayerform'][sCheckname_expanding].checked=true; } //test for the user turning on a layer that causes all statues for that factype to be selected //Starts with assuming that all the statuses for that layer are on. If anyone is turned off then we set, iAll=false. var iAll=true; for (var n=1; n<=4; n++) { var sCheckname5='giLayer_'+iLayerid+'_'+n; if (document.forms['faclayerform'][sCheckname5]!=undefined) { if (document.forms['faclayerform'][sCheckname5].checked==false) iAll=false; } } if (iAll==true) { var sCheckname5='giLayer_'+iLayerid+'_99'; if (document.forms['faclayerform'][sCheckname5]!=undefined) document.forms['faclayerform'][sCheckname5].checked=true; } //negative 99 is weird - probably used to turn everything off, but instead we should use iOn=false for that if (iStatus!=-99) { //look at the iStatus -- does this new layer create an all fac layers of this status var iAll=true; //for (var n=1; n<=iMaplayers; n++) for (var n in aFaclayer) { var sCheckname5='giLayer_'+aFaclayer[n]+'_'+iStatus; if (document.forms['faclayerform'][sCheckname5]!=undefined) { if (document.forms['faclayerform'][sCheckname5].checked==false) iAll=false; } } if (iAll==true) { var sCheckname5='giLayer_99_'+iStatus; if (document.forms['faclayerform'][sCheckname5]!=undefined) { document.forms['faclayerform'][sCheckname5].checked=true; } } } } //Start Building the aCheck array based on the form var aCheck = new Array(); //Build the checkbox array to send to the server //for (var m=1; m<=iMaplayers; m++) //or should I use aFaclayer99? for (var mtemp in aFaclayer) { m=aFaclayer[mtemp]; aCheck[m] = new Array(); //possible statuses, 1, 2, 3, 4, 99 var sCheckname='giLayer_'+m+'_'; //if all is checked - don't include the other parameters, to make the sql simpler if (document.forms['faclayerform'][sCheckname+'99']!=undefined) { if (document.forms['faclayerform'][sCheckname+'99'].checked) { aCheck[m][99]=true; aCheck[m][1]=false; aCheck[m][2]=false; aCheck[m][3]=false; aCheck[m][4]=false; //if the user just clicked on the all status checkbox, then set the checkbox fields to on/off if ((iLayerid==m) && (iStatus==99)) { document.forms['faclayerform'][sCheckname+'1'].checked=true; document.forms['faclayerform'][sCheckname+'2'].checked=true; document.forms['faclayerform'][sCheckname+'3'].checked=true; document.forms['faclayerform'][sCheckname+'4'].checked=true; } } //if all isn't selected - collect all the checkbox values for the array else { //if the user just clicked on the all status checkbox - and turned layers off... then set the boxes to off if ((iLayerid==m) && (iStatus==99)) { document.forms['faclayerform'][sCheckname+'1'].checked=false; document.forms['faclayerform'][sCheckname+'2'].checked=false; document.forms['faclayerform'][sCheckname+'3'].checked=false; document.forms['faclayerform'][sCheckname+'4'].checked=false; } aCheck[m][1]=document.forms['faclayerform'][sCheckname+'1'].checked; aCheck[m][2]=document.forms['faclayerform'][sCheckname+'2'].checked; aCheck[m][3]=document.forms['faclayerform'][sCheckname+'3'].checked; aCheck[m][4]=document.forms['faclayerform'][sCheckname+'4'].checked; aCheck[m][99]=document.forms['faclayerform'][sCheckname+'99'].checked; } } } aCheck[99]=new Array(); var sCheckname3='giLayer_99_'; //if the user just toggled the all factypes of one status - then set the checkbox values for them //unsure why this is in the aCheck building section if (iLayerid==99) { for (var k in aFaclayer) { var sCheckname2='giLayer_'+aFaclayer[k]+'_'+iStatus; if (document.forms['faclayerform'][sCheckname2]!=undefined) document.forms['faclayerform'][sCheckname2].checked=iOn; } } if (document.forms['faclayerform'][sCheckname3+'1'] !=undefined) aCheck[99][1]=document.forms['faclayerform'][sCheckname3+'1'].checked; aCheck[99][2]=document.forms['faclayerform'][sCheckname3+'2'].checked; aCheck[99][3]=document.forms['faclayerform'][sCheckname3+'3'].checked; aCheck[99][4]=document.forms['faclayerform'][sCheckname3+'4'].checked; //this shouldn't ever be checked - as it won't work - it'd display too many results (9000+) //so it should be disabled (at least for the US - what about other countries???) //aCheck[99][99]=false; //remove markers - do it before the AJAX request so the cpu can work on it while we're waiting for the AJAX response //hmm, we want to clear only the non-kml overlays... if (iStatus!=-99) ToggleAllMarkersOff(); //gets an array of facilities in JSON, based on the checked layers //using post because I cannot use GET and send aCheck - as it is too long. //try serializing the entire form contents as a way of sending aCheck //if aCheck is null - all checkboxes are off, then just set facilities to an empty array without running the service //the serialize function gets multiple layers from the checkboxes: so it looks like "giLayer_8_1=on&giLayer_1_1=on" //might need to send this as a POST variable instead - otherwise layers can be too long for the URL var str = $('#faclayerform').serialize(); //if all layers are on or off then simplifies the string if ((iOn==1) && (iLayerid==99) && (iStatus==99)) str='giLayer_99_99=on'; else if ((iOn==0) && (iLayerid==99) && (iStatus==99)) str='giLayer_99_99=off'; else if (document.forms['faclayerform']['giLayer_99_99']!=undefined) { if (document.forms['faclayerform']['giLayer_99_99'].checked) str='giLayer_99_99=on'; } if ((str=="") || (substr_count(str, 'giLayer',0,200)==0)) { //do nothing - we already cleared the overlays... //set the number of results to zero $("span#iCount").html("Number of Results: 0"); } //main case - there is a layer in str else { //first disable all checkboxes CheckboxDisable (true); //may need rewriting to handle biomassoperating and Ohio (eg URL redirects) -- because the searchtype and iAdmid don't show in the URL! var gsSearchtype=''; if (sMaptype!='') gsSearchtype=sMaptype; else if (substr_count(window.location.href , 'nationalmap' , 0, 400)) gsSearchtype='nationalmap'; else if (substr_count(window.location.href , 'globalmap' , 0, 400)) gsSearchtype='globalmap'; else if (substr_count(window.location.href , 'statemap' , 0, 400)) gsSearchtype='statemap'; else if ((substr_count(window.location.href , 'themap' , 0, 400)) || (substr_count(window.location.href , 'community' , 0, 400))) gsSearchtype='themap'; //probably need to add code for LOCAL MAP and global map... var sUrl=''; //Test to see if we can use the JSON cache - for non-US national map if ( (substr_count(str, 'giLayer')>=1) && (gsSearchtype=='nationalmap') && ((iCountry==0) || (iCountry==251))) { //We can use caching if there is only one layer (or a double layer of proposed and expanding) if (substr_count(str, 'giLayer')==1) { var iFirstunderscore=str.indexOf('_'); var iLastunderscore=str.lastIndexOf('_'); var iLastequal=str.lastIndexOf('='); var iLayer=str.substr(iFirstunderscore+1, iLastunderscore-iFirstunderscore-1); //after the second underscore (iStatus length could be 1 or 2 chars (for 99) - next char is an "=" var iStatus=str.substr(iLastunderscore+1, iLastequal-iLastunderscore-1); sUrl=sServer+"js/json/json-"+iLayer+"-"+iStatus+".php"; } //check for proposed and expanding of each type... else if (substr_count(str, 'giLayer')==2) { for (var iJ in aFaclayer) { if ((substr_count(str,'giLayer_'+aFaclayer[iJ]+'_2')==1) && (substr_count(str, 'giLayer_'+aFaclayer[iJ]+'_4')==1)) { sUrl=sServer+"js/json/json-"+aFaclayer[iJ]+"-2and4.php"; } } } //check for 5 layers, and one of them is an "all" layer - then they are probably all for the same type, so we do JSON request for that else if ((substr_count(str, 'giLayer')==5) && (substr_count(str, '99')==1)) { for (var iJ in aFaclayer) { if (substr_count(str,'giLayer_'+aFaclayer[iJ]+'_99')==1) { sUrl=sServer+"js/json/json-"+aFaclayer[iJ]+"-99.php"; } } } } //If we don't find a JSON cache that we can use, then call the ajax service if (sUrl=='') { sUrl=sServer+"server-test/webservice/searchserver-new.php?giAjax=1&"+str; //to add: sAddress_facility, giRadius, and gsSearchtype if ($('#sAddress_facility_hidden').html()!='') sUrl+='&gsAddress_facility='+$('#sAddress_facility_hidden').html(); if (gsSearchtype!='') sUrl+='&gsSearchtype='+gsSearchtype; //User can expand the radius to 50 or 100 miles (default is 25) //alert ('giRadius '+giRadius); //iRadius - comes from localmap - set radius, whereas giRadius comes from the URL if (iRadius==0) sUrl=sUrl; else if ((iRadius!='') && (iRadius!=0)) sUrl+='&giRadius='+iRadius; else if ((giRadius!='') && (giRadius!=0)) sUrl+='&giRadius='+giRadius; else sUrl+='&giRadius=25'; } if ((iCountry!=0) && (iCountry!=251) && (iCountry!=undefined)) sUrl+='&giCountry='+iCountry; if ((sState!='') && (sState!=undefined)) sUrl+='&gsState='+sState; //MAIN AJAX call - get the data //may need to use post (instead of get) to handle a long list of layers $.post(sUrl,{ giAjax: "1", gsSearchtype: gsSearchtype }, function (data) { var tempfacilities = eval('(' + data + ')'); facilities=tempfacilities.facilities; //frees up the memory tempfacilities=''; //Enable all the checkboxes CheckboxDisable (false); //test for too many responses - for a local map bug if (((gsSearchtype=='themap') && (facilities[0]['iCount']>2000)) || ((gsSearchtype=='statemap') && (facilities[0]['iCount']>5000))) { alert ('Error - too many results to display. Probably due to a geocoding or software error.'); } else { $("span#waiting").html("Adding Data to Map..."); //After the data is fetched, display the layers //only send a re-centering point if we have one if (facilities[0]['fLat']==undefined) InitLayers('',''); else InitLayers(facilities[0]['fLat'],facilities[0]['fLong']); $("span#iCount").html("Total Results: "+facilities[0]['iCount']+"
Mapped Results: "+facilities[0]['iMapcount']); //writes over the "adding to map" notice $("span#waiting").html(""); } } ); } } //Shows facilities where facilities[key][iLayervisible]<>0 //For use in debugging layers system //also provide a count of them //builds up a string and then writes it out to a div or span function ShowVisibleFacilities () { var facility_list=''; var visible_count=0; for (keyVar5 in facilities) { if (keyVar5!=0) { if (facilities[keyVar5]['iLayervisible']!=0) { visible_count++; facility_list=facility_list+'
'+keyVar5; } } } $("span#Debug").html("Number of Visible Results: "+visible_count+facility_list); } //create a tinyurl - calls ajax webservice //uses sUrl - which should be in global scope //iFormdata - if 1, then serialize form data //sShare= '', twitter, or facebook : if we're doing this to create url for FB or twitter sharing, then we don't write it out the screen //As of Sept, 2014 - this is replaced by the Jmap GetTinyURL function , except for non-US national map and global map function GetTinyUrl (iFormdata, sShare) { var formstr=''; //clears the old tinyurl... $("span#tinyurl").html(""); //alert (sUrl); //for national and localmap - fetches form results - and adds to the string //the serialized form can include a lot of fields that we don't need - like masUnittype, masFueltype_simple, etc if (iFormdata==1) { formstr = $("form").serialize(); } //get center point: long/lat, zoom level, and map type (map, satellite, or hybrid)- add to url //point.lat() point.lng - return values var point=new google.maps.LatLng(0,0); point=map.getCenter(); //getsize unfortunately returns the original map size - if you use jquery resize, it won't be updated //v3 - there is not getsize function... need to use map.getDiv().offsetWidth; //map.getDiv().offsetHeight; //and possibly add a border to them //var size=new google.maps.size(0,0); //size=map.getSize(); //only difference is miCountry=0 //this doesn't work for state maps - where we need to get the giAdmid on the client side, OR we need to fix it on the server side... var sTinyserviceurl=sServer+"server-test/webservice/tinyurl-service.php?gsUrl="+sUrl+"&"+formstr+"&gsAddress_facility="+sAddress_facility+"&gfLat="+point.lat()+"&gfLng="+point.lng()+"&giZoom="+map.getZoom()+"&gsMaptype="+map.getMapTypeId()+"&giWidth="+(map.getDiv().offsetWidth-2)+"&giHeight="+(map.getDiv().offsetHeight-2); if (substr_count(window.location.href , 'globalmap' , 0, 200)) { sTinyserviceurl=sTinyserviceurl+"&miCountry=0"; } if (substr_count(window.location.href , 'adm' , 0, 200)) { var miAdmid_get = window.location.pathname.replace(/[^0-9]/g, ''); sTinyserviceurl=sTinyserviceurl+"&giAdmid="+miAdmid_get; } $.post(sTinyserviceurl, { giAjax: "1", gsClienturl: sBaseurl}, //write out data to the dom... //could make this an input text box, it would look more user-friendly in terms of copying function (data) { if (sShare=='') { $("span#tinyurl").html(""); $("#tinyurl-text").focus(); } else if (sShare=='facebook') { window.location.href='http://www.facebook.com/share.php?u=http://'+data; } else if (sShare=='twitter') { //this shares a nonclickable url - or maybe only because it is localhost... window.location.href='http://twitter.com/home?status=http://'+data; //this shares a clickable url - problem is that it needs a good name... //window.location.href='http://twitter.com/home?status=link'; } } ); } //A function that reuses values for the basic/advanced facility search when the user toggles between them //reuse: facility name, company name, city, state, county, zip, radius //sFormtype = advanced or basic - the type of the form that we are linking to - for use in the open window //this might be a problem - it should only do this for basic/adv fac search, it shouldn't do it for //adding a person then doing a search function ReuseFormFields (sFormtype) { var sList=''; //for each possible reuse value - check if it is non-null, if so, add it to a string variable if (document.forms[0].gsName.value!=undefined) sList+='&gsName='+ document.forms[0].gsName.value; if (document.forms[0].gsCompanyname.value!=undefined) sList+='&gsCompanyname='+ document.forms[0].gsCompanyname.value; if (document.forms[0].gsCity.value!=undefined) sList+='&gsCity='+ document.forms[0].gsCity.value; if (document.forms[0].giState.value!=undefined) sList+='&giState='+ document.forms[0].giState.value; if (document.forms[0].giCounty.value!=undefined) sList+='&giCounty='+ document.forms[0].giCounty.value; if (document.forms[0].giRadius.value!=undefined) sList+='&giRadius='+ document.forms[0].giRadius.value; if (document.forms[0].gsZip.value!=undefined) sList+='&gsZip='+ document.forms[0].gsZip.value; window.location.href=sClienturl+'searchobject.php?gsTable=facility&gsSearchtype='+sFormtype+sList; } //Disables part of the Advanced Facility Search form - if they enter a non-null value //excecute this "onchange function TogglePowerField () { //if facility min or max power is nonnull - disable unit min and max power if (((document.forms[0].gfFacilitymwminrange.value!=undefined) || (document.forms[0].gfFacilitymwmaxrange.value!=undefined)) && ((document.forms[0].gfFacilitymwminrange.value!=0) || (document.forms[0].gfFacilitymwmaxrange.value!=0))) { document.forms[0].gfUnitmwmaxrange.disabled=1; document.forms[0].gfUnitmwminrange.disabled=1; document.forms[0].gfUnitmwmaxrange.style.backgroundColor="#cccccc"; document.forms[0].gfUnitmwminrange.style.backgroundColor="#cccccc"; } else { document.forms[0].gfUnitmwmaxrange.disabled=0; document.forms[0].gfUnitmwminrange.disabled=0; document.forms[0].gfUnitmwmaxrange.style.backgroundColor="#ffffff"; document.forms[0].gfUnitmwminrange.style.backgroundColor="#ffffff"; } //if unit min or max power is nonnull - disable facility min and max power if (((document.forms[0].gfUnitmwminrange.value!=undefined) || (document.forms[0].gfUnitmwmaxrange.value!=undefined)) && ((document.forms[0].gfUnitmwminrange.value!=0) || (document.forms[0].gfUnitmwmaxrange.value!=0))) { document.forms[0].gfFacilitymwmaxrange.disabled=1; document.forms[0].gfFacilitymwminrange.disabled=1; document.forms[0].gfFacilitymwmaxrange.style.backgroundColor="#cccccc"; document.forms[0].gfFacilitymwminrange.style.backgroundColor="#cccccc"; } else { document.forms[0].gfFacilitymwmaxrange.disabled=0; document.forms[0].gfFacilitymwminrange.disabled=0; document.forms[0].gfFacilitymwmaxrange.style.backgroundColor="#ffffff"; document.forms[0].gfFacilitymwminrange.style.backgroundColor="#ffffff"; } } //If the user selects the "all" option for unit types - deselect the other options. function UnitTypeAll() { if (document.getElementsByName('gasUnittype[]')[0].options[0].selected==true) { for (i=1; i< document.getElementsByName('gasUnittype[]')[0].length; i++) { document.getElementsByName('gasUnittype[]')[0].options[i].selected=false; } } } function UnitStatusTypeAll() { if (document.getElementsByName('gasUnitstatustype[]')[0].options[0].selected==true) { for (i=1; i < document.getElementsByName('gasUnitstatustype[]')[0].length; i++) { document.getElementsByName('gasUnitstatustype[]')[0].options[i].selected=false; } } } function APCTypeAll() { if (document.getElementsByName('gasApctype[]')[0].options[0].selected==true) { for (i=1; i < document.getElementsByName('gasApctype[]')[0].length; i++) { document.getElementsByName('gasApctype[]')[0].options[i].selected=false; } } } function MonitoringTypeAll() { if (document.getElementsByName('gasMonitoringtype[]')[0].options[0].selected==true) { for (i=1; i < document.getElementsByName('gasMonitoringtype[]')[0].length; i++) { document.getElementsByName('gasMonitoringtype[]')[0].options[i].selected=false; } } } //For advanced facility search - toggle the fuel product simple and advanced types in the form //note: 0 is used as an "all" option - so don't grey out the other option. //now to get it working with multiple selects: document.getElementsByName('gasFueltype_simple[]')[0].value //check the first value in the multiple select //iSimple - 1 if the user changed a value in fuelproduct regular, 0 if in advanced function ToggleFuelProduct(iSimple) { //if they select a simple fuel, then remove the advanced fuel (or set it to "all") if ((document.getElementsByName('gasFueltype_simple[]')[0].value!=undefined) && (document.getElementsByName('gasFueltype_simple[]')[0].value!=0) && (iSimple==1)) { document.getElementsByName('gasFueltype_advanced[]')[0].value=0; } //if they select an advanced fuel, then remove the simple fuel (or set it to "all") else if ((document.getElementsByName('gasFueltype_advanced[]')[0].value!=undefined) && (document.getElementsByName('gasFueltype_advanced[]')[0].value!=0) && (iSimple==0)) { document.getElementsByName('gasFueltype_simple[]')[0].value=0; } //first check to see if they set any value to "select all" - in which case it overrides the other options if (document.getElementsByName('gasFueltype_advanced[]')[0].options[0].selected==true) { for (i=1; i< document.getElementsByName('gasFueltype_advanced[]')[0].length; i++) { document.getElementsByName('gasFueltype_advanced[]')[0].options[i].selected=false; } } if (document.getElementsByName('gasFueltype_simple[]')[0].options[0].selected==true) { for (i=1; i < document.getElementsByName('gasFueltype_simple[]')[0].length; i++) { document.getElementsByName('gasFueltype_simple[]')[0].options[i].selected=false; } } } //Toggles date for advanced facility search (unit dates turn off facility dates and vice versa - so users cannot select both) function ToggleDate() { if ( ((document.forms[0].gsEnd_facility_minday.value!=undefined) && (document.forms[0].gsEnd_facility_minday.value!=0)) || ((document.forms[0].gsEnd_facility_minmonth.value!=undefined) && (document.forms[0].gsEnd_facility_minmonth.value!=0)) || ((document.forms[0].gsEnd_facility_minyear.value!=undefined) && (document.forms[0].gsEnd_facility_minyear.value!=0)) || ((document.forms[0].gsStart_facility_minday.value!=undefined) && (document.forms[0].gsStart_facility_minday.value!=0)) || ((document.forms[0].gsStart_facility_minmonth.value!=undefined) && (document.forms[0].gsStart_facility_minmonth.value!=0)) || ((document.forms[0].gsStart_facility_minyear.value!=undefined) && (document.forms[0].gsStart_facility_minyear.value!=0)) ) { document.forms[0].gsUnitstatus_startday.disabled=1; document.forms[0].gsUnitstatus_startmonth.disabled=1; document.forms[0].gsUnitstatus_startyear.disabled=1; document.forms[0].gsUnitstatus_endday.disabled=1; document.forms[0].gsUnitstatus_endmonth.disabled=1; document.forms[0].gsUnitstatus_endyear.disabled=1; } else { document.forms[0].gsUnitstatus_startday.disabled=0; document.forms[0].gsUnitstatus_startmonth.disabled=0; document.forms[0].gsUnitstatus_startyear.disabled=0; document.forms[0].gsUnitstatus_endday.disabled=0; document.forms[0].gsUnitstatus_endmonth.disabled=0; document.forms[0].gsUnitstatus_endyear.disabled=0; } if ( ((document.forms[0].gsUnitstatus_startday.value!=undefined) && (document.forms[0].gsUnitstatus_startday.value!=0)) || ((document.forms[0].gsUnitstatus_startmonth.value!=undefined) && (document.forms[0].gsUnitstatus_startmonth.value!=0)) || ((document.forms[0].gsUnitstatus_startyear.value!=undefined) && (document.forms[0].gsUnitstatus_startyear.value!=0)) || ((document.forms[0].gsUnitstatus_endday.value!=undefined) && (document.forms[0].gsUnitstatus_endday.value!=0)) || ((document.forms[0].gsUnitstatus_endmonth.value!=undefined) && (document.forms[0].gsUnitstatus_endmonth.value!=0)) || ((document.forms[0].gsUnitstatus_endyear.value!=undefined) && (document.forms[0].gsUnitstatus_endyear.value!=0)) ) { document.forms[0].gsStart_facility_minday.disabled=1; document.forms[0].gsStart_facility_maxday.disabled=1; document.forms[0].gsStart_facility_minmonth.disabled=1; document.forms[0].gsStart_facility_maxmonth.disabled=1; document.forms[0].gsStart_facility_minyear.disabled=1; document.forms[0].gsStart_facility_maxyear.disabled=1; document.forms[0].gsEnd_facility_minday.disabled=1; document.forms[0].gsEnd_facility_maxday.disabled=1; document.forms[0].gsEnd_facility_minmonth.disabled=1; document.forms[0].gsEnd_facility_maxmonth.disabled=1; document.forms[0].gsEnd_facility_minyear.disabled=1; document.forms[0].gsEnd_facility_maxyear.disabled=1; } else { document.forms[0].gsStart_facility_minday.disabled=0; document.forms[0].gsStart_facility_maxday.disabled=0; document.forms[0].gsStart_facility_minmonth.disabled=0; document.forms[0].gsStart_facility_maxmonth.disabled=0; document.forms[0].gsStart_facility_minyear.disabled=0; document.forms[0].gsStart_facility_maxyear.disabled=0; document.forms[0].gsEnd_facility_minday.disabled=0; document.forms[0].gsEnd_facility_maxday.disabled=0; document.forms[0].gsEnd_facility_minmonth.disabled=0; document.forms[0].gsEnd_facility_maxmonth.disabled=0; document.forms[0].gsEnd_facility_minyear.disabled=0; document.forms[0].gsEnd_facility_maxyear.disabled=0; } } //a shell function to call createMarker, used in several other functions - avoids duplication //for McNeil - we need the layer or possibly status info, but don't actually want to display the marker. function createMarker_shell (aFacility, iFacilityid, iLayervisible) { //alert ("calling createMarker_shell"); //create a point using two different naming conventions for lat, long, name if ((aFacility['fLatitude']!=undefined) && (aFacility['fLatitude']!='')) { var point = new google.maps.LatLng(aFacility['fLatitude'], aFacility['fLongitude']); var title =aFacility['sName']; } else { var point = new google.maps.LatLng(aFacility['fLa'], aFacility['fLo']); var title =aFacility['sNa']; } var sMarkercolor=''; var iTempstatus=0; //stores the layer that is being displayed by the marker (aka the layer that the marker is a member of) in the facilities array //allows us to test for it later and turn it off facilities[iFacilityid]['iLayervisible']=iLayervisible; if ((aFacility['iPrimaryfacilitytype']!=0) && (aFacility['aiUnitstatus']!=undefined)) iTempstatus=aFacility['aiUnitstatus'][0]; else if (aFacility['aiUnitstatus_factype']==undefined) iTempstatus='99'; else if (aFacility['aiUnitstatus_factype'][iLayervisible]!=undefined) iTempstatus=aFacility['aiUnitstatus_factype'][iLayervisible]; facilities[iFacilityid]['iTempstatus']=iTempstatus; //operating if (iTempstatus=='1') sMarkercolor='green'; //proposed else if (iTempstatus=='2') sMarkercolor='orange'; //closed else if (iTempstatus=='3') sMarkercolor='red'; //expanding else if (iTempstatus=='4') sMarkercolor='grey'; else sMarkercolor='red'; //converts from basic fac types to the icon groups - that use letters. //added a '' for the 0th element var asLayertoicon = new Array ('', 'nuke', 'coal', 'oil', 'gas', 'oil', 'coal', 'gas', 'ethanol', 'ethanol', 'incinerator', 'incinerator', 'incinerator', 'incinerator', 'kiln', 'landfill', 'landfill', 'hydro', 'geo', 'wind', 'solar', 'incinerator', 'nuclear', '' ); //same names as basic fac types - from constants //added a '' for the 0th element var asLayertoname = new Array ('','Nuclear Reactor', 'Coal-Fired Power Plant', 'Oil-Fired Power Plant', 'Natural Gas-Fired Power Plant', 'Oil Refinery', 'Coal-to-Oil Refinery', 'Liquefied Natural Gas Terminal', 'Ethanol Biorefinery', 'Cellulosic Ethanol Biorefinery', 'Trash Incinerator', 'Wood / Biomass Incinerator', 'Poultry Waste Incinerator', 'Tire Incinerating Facility', 'Cement Kiln', 'Landfill', 'Landfill Gas Burner', 'Hydroelectric', 'Geothermal', 'Wind Turbine', 'Solar Photovoltaic or Concentrated', 'Sewage Sludge', 'Nuclear Fuel Chain Facility','Paper Mill'); var sFacname=''; var sFactype=''; if (asLayertoicon[iLayervisible]!=undefined) { sFactype=asLayertoicon[iLayervisible]; sFacname=asLayertoname[iLayervisible]; } //this might include several incinerator types that aren't in the basic-20 - like medical waste incinerator else if (aFacility['iPrimaryfacilitytype']==2) { sFactype='incinerator'; sFacname='Incinerator'; } else sFactype='other'; //choose marker size based on MW - aFacility['fPower']s var sFacsize=''; if ((aFacility['fPower']=='') || (aFacility['fPower']==0)) sFacsize='regular'; else if (aFacility['fPower']>=500) sFacsize='larger'; else if (aFacility['fPower']>=100) sFacsize='large'; else if (aFacility['fPower']>=20) sFacsize='regular'; else sFacsize='small'; var sTexturl='
' + ''+ title + '<\/a>'; if ((aFacility['fLatitude']!=undefined) && (aFacility['fLatitude']!='')) { if (aFacility['sCity']!='') sTexturl+='
'+aFacility['sCity']; if (aFacility['sCity']!='' && aFacility['sState']!='') sTexturl+=', '; if (aFacility['sCity']=='' && aFacility['sState']!='') sTexturl+='
'; if (aFacility['sState']!='') sTexturl+=aFacility['sState']; } else { if (aFacility['sCi']!='') sTexturl+='
'+aFacility['sCi']; if (aFacility['sCi']!='' && aFacility['sSt']!='') sTexturl+=', '; if (aFacility['sCi']=='' && aFacility['sSt']!='') sTexturl+='
'; if (aFacility['sSt']!='') sTexturl+=aFacility['sSt']; } //add power plant type if (sFactype!='other') sTexturl+='
'+sFacname; sTexturl+='<\/div>'; if (sFactype=='other') createMarker_themap(point.lat(), point.lng(), sTexturl, title, aicon[sMarkercolor][sFactype].image, iFacilityid); else createMarker_themap(point.lat(), point.lng(), sTexturl, title, aicon[sMarkercolor][sFactype][sFacsize].image, iFacilityid); } //for local map - when giLayer is in the URL - we need to set facilities[keyvar][iTempstatus] //is this going to give us a status type of 1..20 or 1..4? we want 1..4 function InitTempStatus() { for (keyVar3 in facilities) { //alert ("keyvar3:"+keyVar3); //initialize to zero to avoid trouble facilities[keyVar3]['iTempstatus']=0; //gets the first tempstatus from the aiUnitstatus_factype array if (facilities[keyVar3]['aiUnitstatus_factype']!=undefined) { for (keystatustype in facilities[keyVar3]['aiUnitstatus_factype']) { facilities[keyVar3]['iTempstatus']=facilities[keyVar3]['aiUnitstatus_factype'][keystatustype]; break; } } } } //for facility search - the map - initialize the layers and display the markers //also used by Toggle All Markers On //need to make sure this doesn't deactivate kml - if called during nationalmaptoggle (after the ajax fetch) //if McNeil - then we don't want to add the facility layers... //Should this recenter the map??? function InitLayers (fLatitude, fLongitude) { if ((fLatitude!='') && (fLongitude!='')) map.setCenter (new google.maps.LatLng (fLatitude, fLongitude)); if (substr_count(window.location.href.toUpperCase(), 'MCNEIL' , 0, 300)==0) { for (keyVar2 in facilities) { var iLayer=0; //gets the iLayervisible value from the first element stored in the aiLayer array for (keyfactype in facilities[keyVar2]['aiLayer']) { iLayer=keyfactype; break; } //if we have all layers selected, then only show a marker if it isn't already being shown - eg. iLayervisible==0 //so checked and visible==0, or not checked if (keyVar2!=0) { createMarker_shell(facilities[keyVar2], keyVar2, iLayer); } } //works for national map if (facilities[0]!=undefined) { $("span#iCount").html("Total Results: "+facilities[0]['iCount']+"
Mapped Results: "+facilities[0]['iMapcount']); } else { //for local map - count number of facilities with iLayervisible>=1 and fLatitude and fLongitude non-zero //count number of markers //note: for local map, only geocoded facilities will show up in results as we use long/lat to see if they are local. //Thus we don't need to do the "total results" vs "mapped results" distinction var iCount_local=0; var iCount_localmapped=0; for (keyvar_count in facilities) { if (keyvar_count!=0) { if (facilities[keyvar_count]['iLayervisible']!=0) iCount_local++; if ((facilities[keyvar_count]['iLayervisible']!=0) && (facilities[keyvar_count]['fLatitude']!='')) iCount_localmapped++; } } $("span#iCount").html("Total Results: "+iCount_local); } } } //Internal function for ToggleMarkers - turns a single layer/status combination off //For "other" (98) - turn off all the markers with "other" in their factype string. function ToggleMarkersOff (iLayerid, iStatus) { layerstatus[iStatus][iLayerid]=0; //loop through facilitie array for (keyVar in facilities) { if ((keyVar!=0) && (keyVar!="0")) { //if this layer is visible and matches the layer to remove, or if there is no layer visible AND status matches //Why would there be no layer visible? that's weird! //either the layervisible fields matches iLayerid, or it is 98, and "other_" is in iLayervisible string var sFactype=facilities[keyVar]['iLayervisible'].toString(); //if (((facilities[keyVar]['iLayervisible']==iLayerid) || ((iLayerid==98) && (sFactype.indexOf('other_')!=-1)) // || (facilities[keyVar]['iLayervisible']==0)) // && (facilities[keyVar]['iTempstatus']==iStatus)) //removed part of if statement, because the other layer now uses a iLayerid==98 if (((facilities[keyVar]['iLayervisible']==iLayerid) || (facilities[keyVar]['iLayervisible']==0)) && (facilities[keyVar]['iTempstatus']==iStatus)) { //check all the layers in layerstatus - see if there is another layer that exists for this facility //if so, show it //make sure to show the layer that is on top, this is possible if you do a foreach on facilities[keyVar] //and exit when you find the first one that matches layerstatus //for it to be found it has to be a layer that is turned on var iFoundlayer=0; for (key in facilities[keyVar]['aiLayer']) { //we should be testing not iStatus, but the status of the newly found layer... //which might be in facilities[keyVar]['aiUnitstatus_factype'][key] //weird some facilities have layers associated with them that don't have a status - so this ignores them if (facilities[keyVar]['aiUnitstatus_factype'][key]!=undefined) { //the status that we are testing, comparing to the list of layers that are on display var iStatustest=facilities[keyVar]['aiUnitstatus_factype'][key]; //if Layerid=98 and we find an "other_" in the key - the we haven't found a layer - it's another other layer //if (((facilities[keyVar]['aiLayer'][key]['iLayer']!=undefined) && (layerstatus[iStatustest][key]==1)) // && (!((iLayerid==98) && (key.indexOf('other_')!=-1)))) //removed the other check since we now use ilayerid==98 if ((facilities[keyVar]['aiLayer'][key]['iLayer']!=undefined) && (layerstatus[iStatustest][key]==1)) { //get the iLayerid and the layer-rank and store in variables iFoundlayer=key; facilities[keyVar]['iLayervisible']=key; break; } } } //whether a replacement layer was found or not, remove the existing point from the overlay //would it be faster to do a bulk remove of markers? Maybe, but I do not see any supported api functions that //do this. //if (gMarkers[keyVar]!=null) map.removeOverlay(gMarkers[keyVar]); //weird this isn't removing icons from the state map (locally), but it works remotely if (gMarkers[keyVar]!=null) { gMarkers[keyVar].setMap(null); gMarkers[keyVar]=null; } //if Found - then move new icon to the front - by creating a new marker if (iFoundlayer>0) { createMarker_shell(facilities[keyVar], keyVar, iFoundlayer); } //stores in facilities array that there is nothing showing //it looks like this could be happening, when we fail to remove the marker - thus leaving markers on //the screen else { facilities[keyVar]['iLayervisible']=0; } } } } //set the checkbox to off - in case this was part of a "toggle all" task var sCheckname='giLayer_'+iLayerid+'_'+iStatus; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=false; //turns off 99,99 var sCheckname='giLayer_99_99'; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=false; //turns off anything that is iLayerid, 99 var sCheckname='giLayer_'+iLayerid+'_99'; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=false; //turns off anything that is 99, iStatus var sCheckname='giLayer_99_'+iStatus; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=false; } //toggles all the markers off - for use with the layer system, to get at the other layers that aren't in the 20 //basic facility types function ToggleAllMarkersOff () { //loop through facilities array and remove markers one at a time for (keyVar in facilities) { { if (gMarkers[keyVar]!=null) { gMarkers[keyVar].setMap(null) gMarkers[keyVar]=null; } facilities[keyVar]['iLayervisible']=0; } } //previously used to set the gMarkers length to zero, but was giving me an error for biomassoperating - says gMarkers was undefined and only doing //this if it !=undefined didn't work. //gMarkers.length=0; } //Internal function for ToggleMarkers - turns a single layer/status combination on function ToggleMarkersOn (iLayerid, iStatus) { layerstatus[iStatus][iLayerid]=1; //alert("layer: "+iLayerid+" status: "+iStatus); var prevKey=0; //loop through facilities array for (keyVar in facilities) { prevKey=keyVar; //skips element #0 which is just used for a center point if ((keyVar!=0) && (keyVar!="0")) { //if there is no layer currently displayed - then if this facility matches facilitytype and status - then add it //alert ("layervisible:"+facilities[keyVar]['iTempstatus']); if ((facilities[keyVar]['iLayervisible']==0) && (facilities[keyVar]['iTempstatus']==iStatus)) { //now we only check the aiLayer[iLayerid] if it is defined if (facilities[keyVar]['aiLayer']!=undefined) { if (facilities[keyVar]['aiLayer'][iLayerid]!=undefined) { if (facilities[keyVar]['aiLayer'][iLayerid]['iLayer']!=0) { createMarker_shell(facilities[keyVar], keyVar, iLayerid); } } //or we could be adding a "other_" layer in which case we need to do a for loop thorugh aiLayer //and add the first matching one that has "other_" in the key slot [aiLayer][key] //else if (iLayerid==98) //{ // for (iOtherfactype in facilities[keyVar]['aiLayer']) // { // if (iOtherfactype.indexOf('other_')!=-1) // { // //hopefully iOtherfactype works ok as the iLayerid - it's actually a string - like Other_22 // createMarker_shell(facilities[keyVar], keyVar, iOtherfactype); // //hopefully this breaks us out of the for loop // break; // } // } // } } } //else if there is currently a layer, check to see if this one get precedence //if so - remove the icon, add the new one else if ((facilities[keyVar]['iLayervisible']!=0) && (facilities[keyVar]['iTempstatus']==iStatus)) { if ((facilities[keyVar]['aiLayer']!=undefined) && (facilities[keyVar]['aiLayer'][iLayerid]!=undefined)) { if (facilities[keyVar]['aiLayer'][iLayerid]['iLayer'] > facilities[keyVar]['iLayervisible']) { if (gMarkers[keyVar]==null) { alert ("error with gMarkers"); } else { //map.removeOverlay(gMarkers[keyVar]); gMarkers[keyVar].setMap(null); createMarker_shell(facilities[keyVar], keyVar, iLayerid); } } } } //we're adding the "other" layer - need to check the priority for each "other" layer to see if //we should bring that layer to the front. //else if (iLayerid==98) //{ // var iOtherfactype=''; // for (iOtherfactype in facilities[keyVar]['aiLayer']) // { // // //this seems to execute even when it is false... // if (iOtherfactype.indexOf('other_')!=-1) // { // if ((facilities[keyVar]['aiLayer'][iOtherfactype]['iLayer']>facilities[keyVar]['iLayervisible']) && (facilities[keyVar]['iLayervisible']!=0)) // { // if (gMarkers[keyVar]==null) // { // alert ("error"); // } // map.removeOverlay(gMarkers[keyVar]); //we don't need to set gMarkers[keyVar]==undefined because that spot is filled in the next line // createMarker_shell(facilities[keyVar], keyVar, iOtherfactype); // } // } // } // } } } var sCheckname='giLayer_'+iLayerid+'_'+iStatus; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=true; //Check to see if we need to turn on 99,99 - if all layers/statuses are on var iAll=1; for (var iStatus_i=1; iStatus_i<=4; iStatus_i++) { for (var iLayer_i=1; iLayer_i<=iMaplayers; iLayer_i++) { if (layerstatus[iStatus_i][iLayer_i]==0) iAll=0; } if (layerstatus[iStatus_i][98]==0) iAll=0; } if (iAll==1) { var sCheckname='giLayer_99_99'; document.forms['faclayerform'][sCheckname].checked=true; } //Test for turning on iLayerid, 99 var iAll=1; for (var iStatus_i=1; iStatus_i<=4; iStatus_i++) { if (layerstatus[iStatus_i][iLayerid]==0) iAll=0; } if (iAll==1) { var sCheckname='giLayer_'+iLayerid+'_99'; if (document.forms['faclayerform'][sCheckname]!=undefined) document.forms['faclayerform'][sCheckname].checked=true; } //Test for turning on 99, iStatus var iAll=1; for (var iLayer_i=1; iLayer_i<=iMaplayers; iLayer_i++) { if (layerstatus[iStatus][iLayer_i]==0) iAll=0; } if (layerstatus[iStatus][98]==0) iAll=0; if (iAll==1) { var sCheckname='giLayer_99_'+iStatus; if (document.forms['faclayerform'][sCheckname]!=undefined) document.forms['faclayerform'][sCheckname].checked=true; } } //Toggle a Layer on/off //iOn - 1 is turn on, 0 is turn off //iLayerid - facility id of the layer to toggle - if 99 then toggle on/off all of them //iStatus - unitstatus of the layer to toggle - if 99 that toggle on/off all of them //Note: this does not handle having multiple unit statuses - eg when you hide one unit status, to check to for others //that should be displayed. I have one main unit status assigned to each facility-type, and only display that. //This means if you search for closed facilities - it will only show them if all of the units are closed. //for 99,99 - don't toggle - instead set them all to on or off! - same might be true for other 99 statuses function ToggleMarkers (iOn, iLayerid, iStatus) { if (iOn==0) { //turning off layers - could be written to turn them on or off, and reused as a function //turns off all layers if ((iLayerid==99) && (iStatus==99)) { for (var ikey2=1; ikey2<=4; ikey2++) { for (var isubkey=1; isubkey<=iMaplayers; isubkey++) { ToggleMarkersOff (isubkey, ikey2); } //toggles off the other layer ToggleMarkersOff (98, ikey2); } //also need to togglemarkersoff that are not in the regular 20 layers - all the other_nn ones ToggleAllMarkersOff (); for (var iI=1; iI<=4; iI++) { var sCheckname='giLayer_99_'+iI; if (document.forms['faclayerform'][sCheckname]!=undefined) document.forms['faclayerform'][sCheckname].checked=false; } for (var iI=1; iI<=iMaplayers; iI++) { var sCheckname='giLayer_'+iI+'_99'; if (document.forms['faclayerform'][sCheckname]!=undefined) document.forms['faclayerform'][sCheckname].checked=false; } var sCheckname='giLayer_98_99'; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=false; } //turns off all layers that have the same single status else if (iLayerid==99) { for (var ilayer=1; ilayer<=iMaplayers; ilayer++) { ToggleMarkersOff (ilayer, iStatus); } ToggleMarkersOff (98, iStatus); } //turn off all unitstatuses for a single layer else if (iStatus==99) { for (var istatus=1; istatus<=4; istatus++) { ToggleMarkersOff (iLayerid, istatus); } } //turn off a single status for one layer else { ToggleMarkersOff (iLayerid, iStatus); } } //turn layer on else if (iOn==1) { //if the user turns on proposed (iStatus:2) then turn on expanding (iStatus:4) - except for all layers (99) if ((iStatus==2) && (iLayerid!=99)) { var sCheckname_expanding='giLayer_'+iLayerid+'_4'; document.forms['faclayerform'][sCheckname_expanding].checked=true; } //turn all layers on if ((iLayerid==99) && (iStatus==99)) { //why don't i just use turnmarkerson - I could turn on all the layers that weren't on yet using togglemarkerson, then set the appropriate values for //layerstatus - or will that mess up togglemarkerson? for (var ilayer=1; ilayer<=iMaplayers; ilayer++) { for (var istatus=1; istatus<=4; istatus++) { ToggleMarkersOn (ilayer, istatus); } } //InitLayers(); for (var ikey=1; ikey<=4; ikey++) { for (var isubkey=1; isubkey<=iMaplayers; isubkey++) { layerstatus[ikey][isubkey]=1; var sCheckname='giLayer_'+isubkey+'_'+ikey; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=true; } layerstatus[ikey][98]=1; var sCheckname='giLayer_98_'+ikey; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=true; } //also need to togglemarkers-on that are not in the regular 20 layers - all the other_nn ones //instead of iSubkey - we have other_nn for (var iI=1; iI<=4; iI++) { var sCheckname='giLayer_99_'+iI; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=true; } for (var iI=1; iI<=iMaplayers; iI++) { var sCheckname='giLayer_'+iI+'_99'; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=true; } var sCheckname='giLayer_98_99'; if (document.forms['faclayerform'][sCheckname]) document.forms['faclayerform'][sCheckname].checked=true; } //turns On all layers that have the same single status else if (iLayerid==99) { for (var ilayer=1; ilayer<=iMaplayers; ilayer++) { ToggleMarkersOn (ilayer, iStatus); } ToggleMarkersOn (98, iStatus); } //turn On all unitstatuses for a single layer else if (iStatus==99) { for (var istatus=1; istatus<=4; istatus++) { ToggleMarkersOn (iLayerid, istatus); } } //turn On a single status for one layer else { ToggleMarkersOn (iLayerid, iStatus); } } //count number of markers //parses document.images to actually count number of images with 'marker' in their file name. //test how fast this is //ignore the markers for the layers - eg. http://www.energyjustice.net/map-test/images/whitemarker-gas.png //var iCount=0; //var iLength=document.images.length; //for (var n=0; n<=iLength; n++) //{ // if (document.images[n]!=undefined) // { // if ((document.images[n].src.indexOf('marker')!=-1) && (document.images[n].src.indexOf('whitemarker')==-1)) iCount++; //} //} //$("span#iCount").html("Total Results: "+iCount); var iCount_local=0; for (keyvar_count in facilities) { if (keyvar_count!=0) { if (facilities[keyvar_count]['iLayervisible']!=0) iCount_local++; } } $("span#iCount").html("Total Results: "+iCount_local); } //For local map - when the user changes the radius to 25, 50, 100 //This calls the webservice with maCheck (requested set of facility layers), lat, long, and radius //Resets the facilities array, removes all the markers, and loads a new set of markers from the webservice request //It preserves any other tile or kml layers (ex. justice map). //Should I use the original long/lat (from the geocoded sAddress_facility) OR the map center? Probably the map center as //it is possible that the user has panned the map intentionally. function SetRadius (iRadius) { //call webservice //turn all the markers off //turn on the new markers //FacilityLayerToggle does all three! FacilityLayerToggle (1, 99, 99, 'themap', iRadius); //set the CSS background color to '' for the unselected, and selected use: $sCss='background-color:#D455FF;'; //radius-one, radius-two, radius-three $("#radius-one").css("background-color", ""); $("#radius-two").css("background-color", ""); $("#radius-three").css("background-color", ""); if (iRadius==25) $("#radius-one").css("background-color", "#D455FF"); else if (iRadius==50) $("#radius-two").css("background-color", "#D455FF"); else if (iRadius==100) $("#radius-three").css("background-color", "#D455FF"); //stores the radius in a hidden div - so it can be used by save map $("#map_radius").html(iRadius); } //I put counties array in its own js file - so it won't cause zend studio to freeze by being a very long line //addcounties3 is for editview - people, for populating the counties drop down //differs from addcounties2 in that there is no "all" option function AddCounties3 (iStatevar, iCountyvar) { ClearOptions(document.forms[0].giCounty); AddToOptionList(document.forms[0].giCounty, 0, '--Select--'); for (i=1; i<100000; i++) { if (counties[i]!=undefined) { if (counties[i]['iStateid']==iStatevar) { AddToOptionList(document.forms[0].giCounty, i, counties[i]['sName']); } //mark as selected if (i==iCountyvar) { document.forms[0].giCounty[document.forms[0].giCounty.length-1].selected=1; } } } } //addcounties2 is for populating using the values from the last search function AddCounties2 (iStatevar, iCountyvar) { ClearOptions(document.forms[0].giCounty); AddToOptionList(document.forms[0].giCounty, 0, '-All-'); for (i=1; i<100000; i++) { if (counties[i]!=undefined) { if (counties[i]['iStateid']==iStatevar) { AddToOptionList(document.forms[0].giCounty, i, counties[i]['sName']); } //mark as selected if (i==iCountyvar) { document.forms[0].giCounty[document.forms[0].giCounty.length-1].selected=1; } } } } //When the user chooses a state - populate the county dropdown //Also use this when initializing the form - for EditView where a state may already be selected //note: looping through counties is slightly slow - 90ms according to firebug profiler function AddCounties () { var StateTypeList = document.forms[0].giState; //hmm, this seems to not always work... basic fac search - if you choose one state, then another - get counties for both... ClearOptions(document.forms[0].giCounty); //loop through counties - doing a foreach would be better (eg checking 32,000 comparisons, instead of 100,000)... //maybe start off by clearing all the options AddToOptionList(document.forms[0].giCounty, 0, '-All-'); for (i=1; i<100000; i++) { if (counties[i]!=undefined) { if (counties[i]['iStateid']==StateTypeList[StateTypeList.selectedIndex].value) { AddToOptionList(document.forms[0].giCounty, i, counties[i]['sName']); } } } } /* Based on AddCounties Populates the fuels dropdown based on the selected facility type - for Add a Facility also: create a javascript variable that holds the contents of this "add a fuel" dropdown - so we can use it to make a "add another fuel" dropdown */ //possible added fuels - for proposed facilities (based on factype) var gasAdd_fuels_list = new Array(); //selected fuels - are actually added fuels - for add a facility var iAddedfuel; //var gasSelected_units_list = new Array(); var iAddedunit; var gasAdd_units_list = new Array(); //not sure what this is used for var gasSelected_fuels_list = new Array(); //list of fuels to populate the options list var gasSelected_fuels_selectlist = new Array(); function AddFuels () { //empties these arrays - in the case the user has selected a basic factype and then chosen another one - to start the list of possible fuels from scratch gasAdd_fuels_list = []; gasSelected_fuels_list = []; //hmm I don't think FacTypeList is actually used? var FacTypeList = document.forms[0].giBfactype; ClearOptions(document.forms[0].giFacility_fueltype); //default option - urges them to select a fuel - though this isn't required AddToOptionList(document.forms[0].giFacility_fueltype, 0, '--Select--'); //selected factype (user entered this in a previous step) var iFactype=document.forms[0].giBfactype.value; var ij=0; for (i=0; i < ftype_fuel[iFactype].length; i++) { //need to have the last item be a string - the name of the fuel - for this I need a javascript array of fuelproduct to name AddToOptionList(document.forms[0].giFacility_fueltype, ftype_fuel[iFactype][i], fuelname[ftype_fuel[iFactype][i]]); //store the options list in a JS variable (needs to be a global variable) gasAdd_fuels_list[ij]=new Array(); gasAdd_fuels_list[ij]['name']=fuelname[ftype_fuel[iFactype][i]]; gasAdd_fuels_list[ij]['iFuelproductid']=ftype_fuel[iFactype][i]; ij=ij+1; } //it would be nice to sort gasAdd_fuels_list by name - it is currently sorted by fuelproductid var FuelTemp= new Array(); var ik=0; //for each element in the array - compare its 'name' value to that of the one before it for (ij=0; ij < gasAdd_fuels_list.length; ij++) { for (ik=ij; ik < gasAdd_fuels_list.length; ik++) { if (gasAdd_fuels_list[ik]['name'] < gasAdd_fuels_list[ij]['name']) { FuelTemp=gasAdd_fuels_list[ik]; gasAdd_fuels_list[ik]=gasAdd_fuels_list[ij]; gasAdd_fuels_list[ij]=FuelTemp; } } } //first we need to remove any existing options from this - happens if the user chooses one factype, then selects another $("select[name=fuel0]").find("option").remove(); //add options to the NEW fuels dropdown (copied code from displayfieldinc.php) //add first option - --Select-- - value 0 $("select[name=fuel0]") .append($("
" + "Email" + ""); } //I don't think this is in use, except for some test html files like ri.html function toggleMyKml() { if (toggleState == 1) { geoXml.setMap(null); toggleState = 0; } else { geoXml.setMap(map); toggleState = 1; } } //Initialize KML layers - based on GET //If it finds the key in GET, then it calls the toggle function and turns the layer on //if (substr_count(window.location.href , 'energyjustice.net' , 0, 200)) function kml_init() { //could replace window.location.href with another variable and then call this from PHP and use the GET variables that come from the tinyurl var sSerial=''; if (sGet!='') sSerial=sGet; else sSerial=window.location.href; if (substr_count(sSerial , 'giIncome' , 0, 5000)) { KmlToggle ('income'); } if (substr_count(sSerial , 'giPoverty' , 0, 5000)) { KmlToggle ('poverty'); } if (substr_count(sSerial , 'giBlack' , 0, 5000)) { KmlToggle ('black'); } if (substr_count(sSerial , 'giHispanic' , 0, 5000)) { KmlToggle ('hispanic'); } if (substr_count(sSerial , 'giAsian' , 0, 5000)) { KmlToggle ('asian'); } if (substr_count(sSerial , 'giNative' , 0, 5000)) { KmlToggle ('native'); } if (substr_count(sSerial , 'giWhite' , 0, 5000)) { KmlToggle ('white'); } if (substr_count(sSerial , 'giElection2008' , 0, 5000)) { KmlToggle ('election2008'); } if (substr_count(sSerial , 'giCounty_boundaries' , 0, 5000)) { KmlToggle ('county');; } if (substr_count(sSerial , 'giCd' , 0, 5000)) { KmlToggle ('cd'); } if (substr_count(sSerial , 'giCoaldeath' , 0, 5000)) { KmlToggle ('coaldeath'); } if (substr_count(sSerial , 'giCoalwaste' , 0, 5000)) { KmlToggle ('coalimpound'); } if (substr_count(sSerial , 'giCoalimpoundhazard' , 0, 5000)) { KmlToggle ('coalimpoundhazard'); } if (substr_count(sSerial , 'giCoalimpoundrivers' , 0, 5000)) { KmlToggle ('coalimpoundrivers'); } if (substr_count(sSerial , 'giEastwindcapacity' , 0, 5000)) { KmlToggle ('eastwindcapacity'); } if (substr_count(sSerial , 'giEastwindpower' , 0, 5000)) { KmlToggle ('eastwindpower'); } if (substr_count(sSerial , 'giEastwindoffshort' , 0, 5000)) { KmlToggle ('eastwindoffshore'); } if (substr_count(sSerial , 'giWestwindpotential' , 0, 5000)) { KmlToggle ('westwind'); } if (substr_count(sSerial , 'giSolartilted' , 0, 5000)) { toggleSolarPotential(); } if (substr_count(sSerial , 'giMarcellus' , 0, 5000)) { KmlToggle ('padrilledwells'); } //18 biomass layers... var aField=new Array(9); aField[0]='Forest'; aField[1]='PrimMill'; aField[2]='CropRes'; aField[3]='Wastewater'; aField[4]='Landfill'; aField[5]='ManureMgmt'; aField[6]='UrbanWood'; aField[7]='SecMillRes'; aField[8]='Total'; for (var i=0; i<9; i++) { //use the afield variables with a leading 'gi' and afield+'_sqmile' //test for gi+afield if (substr_count(sSerial , 'gi'+aField[i] , 0, 5000)) { toggleBiomassLayer(aField[i], i, 0) } //test for gi+afield+sqmile if (substr_count(sSerial , 'gi'+aField[i]+'_sqmile' , 0, 5000)) { toggleBiomassLayer(aField[i], i, 1) } } //=array (0=>'Forest', 1=>'PrimMill', 2=>'CropRes', 3=>'Wastewater', 4=>'Landfill', 5=>'ManureMgmt', 6=>'UrbanWood', 7=>'SecMillRes', 8=>'Total'); //vulcan co2 layers var aField=new Array(9); aField[0]='Total'; aField[1]='Commercial'; aField[2]='Industrial'; aField[3]='Residential'; aField[4]='ElectricityProd'; aField[5]='Onroad'; aField[6]='Cement'; aField[7]='Aircraft'; aField[8]='Nonroad'; for (var i=0; i<9; i++) { //use the afield variables with a leading 'gi' and afield+'_percapita' //test for gi+afield if (substr_count(sSerial , 'gi'+aField[i] , 0, 5000)) { toggleCarbonLayer(aField[i], i, 0) } //test for gi+afield+sqmile if (substr_count(sSerial , 'gi'+aField[i]+'_percapita' , 0, 5000)) { toggleCarbonLayer(aField[i], i, 1) } } } //general load kml layer function //creates the layer, and returns it (so it can be added or removed). //turning this off as it conflicts with jmap-lib loadkml! function loadkml_old (sUrl) { var layer = new google.maps.KmlLayer(sUrl, {preserveViewport: true}); return layer; } //general remove kml layer function might not be nessary can just do kmllayer.setMap(null). //kml layer array //kml toggle array //kml url array //then I only need the sName var aKml= new Array(); var aKml_toggle = new Array(); var aKml_url=new Array(); aKml_url['income']='ecounties-income.kmz'; aKml_url['coaldeath']='Toll_from_Coal-Existing_Plants.kmz'; aKml_url['coalimpound']='coal-ash/coalplant_waste_in_tons_out22.kmz'; aKml_url['coalimpoundhazard']='coal-ash/coalimpound-hazard-out.kmz'; aKml_url['coalimpoundrivers']='coal-ash/coalimpound-rivers-out.kmz'; aKml_url['election2008']='2008election.kmz'; aKml_url['county']='county_boundaries.kmz'; aKml_url['cd']='cd.kmz'; aKml_url['eastwindcapacity']='wind-east/blobs_capf15.kmz'; aKml_url['eastwindpower']='wind-east/blobs_pout15.kmz'; aKml_url['eastwindoffshore']='wind-east/ewits_offshore_sites.kmz'; aKml_url['westwind']='wind-west/site-meta-out18.kmz'; aKml_url['poverty']='ecounties-poverty.kmz'; aKml_url['black']='ecounties-black.kmz'; aKml_url['white']='ecounties-white.kmz'; aKml_url['hispanic']='ecounties-hispanic.kmz'; aKml_url['native']='ecounties-native.kmz'; aKml_url['asian']='ecounties-asian.kmz'; aKml_url['padrilledwells']='fracking/pa_drill3.kmz'; aKml_url['mcneil']='mcn/essex-barre-all-out-2010d.kmz'; function KmlToggle (sName) { if (!aKml[sName]) { aKml[sName]=loadkml_old (sServer+'kml/'+aKml_url[sName]); } if (aKml_toggle[sName] == 1) { aKml[sName].setMap(null) aKml_toggle[sName] = 0; } else { aKml[sName].setMap(map); aKml_toggle[sName] = 1; } } //disabled - the layers aren't there! /* var toggleStateZCTA=0; var sStateid=0; function toggleZCTA(sStateid) { var geoXmlZCTA= loadkml_old(sServer+"kml/"+sStateid+".kmz"); if (toggleStateZCTA == 1) { geoXmlZCTA.setMap(null); toggleStateZCTA = 0; } else { geoXmlZCTA.setMap(map); toggleStateZCTA = 1; } } */ var toggleStateSolarPotential=0; var geoXmlSolarPotential_part1; var geoXmlSolarPotential_part2; var geoXmlSolarPotential_part3; var geoXmlSolarPotential_part4; var geoXmlSolarPotential_part5; function toggleSolarPotential() { if (!geoXmlSolarPotential_part1) { geoXmlSolarPotential_part1=loadkml_old(sServer+"kml/solar/tilt-out-part1b.kmz"); geoXmlSolarPotential_part2=loadkml_old(sServer+"kml/solar/tilt-out-part2.kmz"); geoXmlSolarPotential_part3=loadkml_old(sServer+"kml/solar/tilt-out-part3.kmz"); geoXmlSolarPotential_part4=loadkml_old(sServer+"kml/solar/tilt-out-part4.kmz"); geoXmlSolarPotential_part5=loadkml_old(sServer+"kml/solar/tilt-out-part5.kmz"); } if (toggleStateSolarPotential == 1) { geoXmlSolarPotential_part1.setMap(null); geoXmlSolarPotential_part2.setMap(null); geoXmlSolarPotential_part3.setMap(null); geoXmlSolarPotential_part4.setMap(null); geoXmlSolarPotential_part5.setMap(null); toggleStateSolarPotential = 0; } else { geoXmlSolarPotential_part1.setMap(map); geoXmlSolarPotential_part2.setMap(map); geoXmlSolarPotential_part3.setMap(map); geoXmlSolarPotential_part4.setMap(map); geoXmlSolarPotential_part5.setMap(map); toggleStateSolarPotential = 1; } } //biomass layers - handles all 18 of them //define the layers as a [9][2] array - 9 possible types of layers by 2 types (total vs sqmile) var toggleBiomassArray = new Array(9); //can I get away just having this be a regular variable? Probably not. Probably needs to be an array so it can be persistent var geoXmlBiomassArray = new Array(9); for (i=0; i<9; i++) { toggleBiomassArray[i] = new Array(2); toggleBiomassArray[i][0]=0; toggleBiomassArray[i][1]=0; geoXmlBiomassArray[i] = new Array(2); geoXmlBiomassArray[i][0]=0; geoXmlBiomassArray[i][1]=0; } var sBiomasslayer; var j; var k; //j is the biomass layer - 1..9, and k is 0 for total tons per county or 1 for per square mile function toggleBiomassLayer(sBiomasslayer, j, k) { if (!geoXmlBiomassArray[j][k]) { if (k==0) geoXmlBiomassArray[j][k]=loadkml_old(sServer+"kml/biomass-"+sBiomasslayer+".kmz"); else if (k==1) geoXmlBiomassArray[j][k]=loadkml_old(sServer+"kml/biomass-"+sBiomasslayer+"-persqmile.kmz"); } if (toggleBiomassArray[j][k] == 1) { geoXmlBiomassArray[j][k].setMap(null); toggleBiomassArray[j][k] = 0; } else { geoXmlBiomassArray[j][k].setMap(map); toggleBiomassArray[j][k] = 1; } } var toggleCarbonArray = new Array(9); //can I get away just having this be a regular variable? Probably not. Probably needs to be an array so it can be persistent var geoXmlCarbonArray = new Array(9); for (i=0; i<9; i++) { toggleCarbonArray[i] = new Array(2); toggleCarbonArray[i][0]=0; toggleCarbonArray[i][1]=0; geoXmlCarbonArray[i] = new Array(2); geoXmlCarbonArray[i][0]=0; geoXmlCarbonArray[i][1]=0; } var sCarbonlayer; var j; var k; //j is the carbon layer - 1..9, and k is 0 for total tons per county or 1 for per square mile function toggleCarbonLayer(sCarbonlayer, j, k) { if (!geoXmlCarbonArray[j][k]) { if (k==0) geoXmlCarbonArray[j][k]=loadkml_old(sServer+"kml/carbon-"+sCarbonlayer+".kmz"); else if (k==1) geoXmlCarbonArray[j][k]=loadkml_old(sServer+"kml/carbon-"+sCarbonlayer+"-percapita.kmz"); } if (toggleCarbonArray[j][k] == 1) { geoXmlCarbonArray[j][k].setMap(null); toggleCarbonArray[j][k] = 0; } else { geoXmlCarbonArray[j][k].setMap(map); toggleCarbonArray[j][k] = 1; } } //uses jquery to do an embedded video popup function VideoShow(sYoutubekey) { //need to set the html embed tag for the video $( "#dialog-modal" ).html(""); $( "#dialog:ui-dialog" ).dialog( "destroy" ); $( "#dialog-modal" ).dialog({ height: 600, width: 800, modal: true }); } //Displays the photo gallery for McNeil, and jumps to the location function DisplayGallery (sGallery) { //hide all divs of class=slideclass $('div.slideclass').hide(); //show the div we want to see $("#"+sGallery).show(); var asGallery = new Array ("Moretown", "Lincoln", "Bristol", "Worcester", "Williston", "Richmond", "Trees"); /* for (var i=0; i < asGallery.length; i++) { //set all the play values to 0 //$('#slides_'+asGallery[i]).slides({ play: 0 }); $("#slides_"+asGallery[i]).slides({ preload: false, play: 0, pause: 2500, hoverPause: true }); } //set the play value of this gallery to 3500 //$('#slides_'+sGallery).slides({ play: 3500 }); $("#slides_"+sGallery).slides({ preload: false, play: 3500, pause: 2500, hoverPause: true }); */ } //Hides the next and previous page links - for displayview, where there is only one page of info being displayed. //also hides the number of rows /* * jQuery UI Tooltip 1.9m2 * * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * http://docs.jquery.com/UI/Tooltip * * Depends: * jquery.ui.core.js * jquery.ui.widget.js * jquery.ui.position.js */ (function($) { // role=application on body required for screenreaders to correctly interpret aria attributes if( !$(document.body).is('[role]') ){ $(document.body).attr('role','application'); } var increments = 0; $.widget("ui.tooltip", { options: { tooltipClass: "ui-widget-content", content: function() { return $(this).attr("title"); }, position: { my: "left center", at: "right center", offset: "15 0" } }, _init: function() { var self = this; this.tooltip = $("
") .attr("id", "ui-tooltip-" + increments++) .attr("role", "tooltip") .attr("aria-hidden", "true") .addClass("ui-tooltip ui-widget ui-corner-all") .addClass(this.options.tooltipClass) .appendTo(document.body) .hide(); this.tooltipContent = $("
") .addClass("ui-tooltip-content") .appendTo(this.tooltip); this.opacity = this.tooltip.css("opacity"); this.element .bind("focus.tooltip mouseenter.tooltip", function(event) { self.open( event ); }) .bind("blur.tooltip mouseleave.tooltip", function(event) { self.close( event ); }); }, enable: function() { this.options.disabled = false; }, disable: function() { this.options.disabled = true; }, destroy: function() { this.tooltip.remove(); $.Widget.prototype.destroy.apply(this, arguments); }, widget: function() { return this.tooltip; }, open: function(event) { var target = this.element; // already visible? possible when both focus and mouseover events occur if (this.current && this.current[0] == target[0]) return; var self = this; this.current = target; this.currentTitle = target.attr("title"); var content = this.options.content.call(target[0], function(response) { // ignore async responses that come in after the tooltip is already hidden if (self.current == target) self._show(event, target, response); }); if (content) { self._show(event, target, content); } }, _show: function(event, target, content) { if (!content) return; target.attr("title", ""); if (this.options.disabled) return; this.tooltipContent.html(content); this.tooltip.css({ top: 0, left: 0 }).show().position($.extend(this.options.position, { of: target })).hide(); this.tooltip.attr("aria-hidden", "false"); target.attr("aria-describedby", this.tooltip.attr("id")); if (this.tooltip.is(":animated")) this.tooltip.stop().show().fadeTo("normal", this.opacity); else this.tooltip.is(':visible') ? this.tooltip.fadeTo("normal", this.opacity) : this.tooltip.fadeIn(); this._trigger( "open", event ); }, close: function(event) { if (!this.current) return; var current = this.current.attr("title", this.currentTitle); this.current = null; if (this.options.disabled) return; current.removeAttr("aria-describedby"); this.tooltip.attr("aria-hidden", "true"); if (this.tooltip.is(':animated')) this.tooltip.stop().fadeTo("normal", 0, function() { $(this).hide().css("opacity", ""); }); else this.tooltip.stop().fadeOut(); this._trigger( "close", event ); } }); })(jQuery); $("[title]").tooltip(); function ResetSearchForm() { $(':input','#searchform') .not(':button, :submit, :reset, :hidden') .val('') .removeAttr('checked') .removeAttr('selected'); document.forms[0].gfUnitmwmaxrange.disabled=0; document.forms[0].gfUnitmwminrange.disabled=0; document.forms[0].gfUnitmwmaxrange.style.backgroundColor="#ffffff"; document.forms[0].gfUnitmwminrange.style.backgroundColor="#ffffff"; } //Deletes a fuel - for adding a facility, also removes the div, and reorders the remaining fuels //iRank is 0...n - so 1+iRank is the actual rank var iRank; var iSelectedfuelcount=0; //gasSelected_fuels_selectlist - stores the selected fuels (for the facility) with [iRank][iFuelproductid/sName] //gasSelected_fuels_list - stores the fuels that the users selects for the facility by iFuelproductid function DeleteFuel (iRank) { var sFuel_select_name='fuel'+iRank; var iFuelproductid=$("select[name="+sFuel_select_name+"]").val(); iSelectedfuelcount=0; for (var key in gasSelected_fuels_list) { if (gasSelected_fuels_list[key]!=undefined) iSelectedfuelcount++; } //remove the fuel from the list of selected fuels - gasSelected_fuels_list - so you'd have gasSelected_fuels_list[iFuelproductid]=undefined; gasSelected_fuels_list[iFuelproductid]=undefined; //remove from list of options //need to find the slot that it is in, and possibly move the other options up one slot? //need to STOP using .length since it doesn't work... //this first iJ loop is to find the rank of the fuel which is iJ, and then to reorder the fuels after it for (var iJ=0; iJ< iSelectedfuelcount; iJ++) { if (gasSelected_fuels_selectlist[iJ]!=undefined) { if (gasSelected_fuels_selectlist[iJ]['iFuelproductid']==iFuelproductid) { //shift all the elements up one, this also overwrites the deleted element for (var iK=iJ; iK < iSelectedfuelcount; iK++) { gasSelected_fuels_selectlist[iK]=gasSelected_fuels_selectlist[iK+1]; } //removes last element - or sets it to undefined... might be uncessary as the iK=iK+1 sets the last element to undefined... //this might not be working that well... //gasSelected_fuels_selectlist.splice(iSelectedfuelcount,1); } } } //remove the div - completely delete it from the dom - remove() should do this $("#fueldiv"+iRank).remove(); //reorder the remaining fuels - for all the divs with a greater rank numerically (eg less used fuels) (change the div id, the select name, the deletefuel(iRank) parameter //do i<=iSelectefuelcount to handle the options list at the end where the user hasn't chosen a fuel, but we still need to reorder the var i; for (i=(iRank+1); i <= iSelectedfuelcount; i++) { //change div id $("#fueldiv"+i).attr("id","fueldiv"+(i-1)); //change select name (seems to not work) - might work now $("select[name=fuel"+i+"]").attr("name","fuel"+(i-1)); //change text prompt (fuel #x) / aka the label -- hmm the id isn't set to +i instead it is 0 $("#fuellabel"+i).html("Fuel #"+i); //change DeleteFuel(iRank) js function call -- hmm the id isn't set to +i instead it is 0 $("#removefuel"+i).attr("onclick", "DeleteFuel(" + (i-1)+ ");"); //need to change the id for the remove fuel image $("#removefuel"+i).attr("id","removefuel"+(i-1)); //change the label id $("#fuellabel"+i).attr("id","fuellabel"+(i-1)); $("#addfuel"+i).attr("id","addfuel"+(i-1)); } //repopulate the list of possible fuels - to include the fuel that was just deleted - so remove all options, then add them back based on the possible fuels name2="fuel"+(iSelectedfuelcount-1); $("select[name="+name2+"]").find("option").remove(); // adding option: // http://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-select-from-an-array-with-jquery // selectValues = {"1":"test 1","2":"test 2"}; //in my case selectValues = gasFuels_list[0][iFuelproductid]/[name] - so I do not want to use the key - I want to use the value[iFuelproductid] or value[name] //add first option - --Select-- - value 0 $("select[name="+name2+"]") .append($("