//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 if (substr_count(window.location.href , 'energyjustice.net' , 0, 200)) { var sServer="http://www.energyjustice.net/map/"; var sClienturl="http://www.energyjustice.net/map/"; var sBaseurl="http://www.energyjustice.net/"; } else { var sServer="http://localhost/ejm/"; var sClienturl="http://localhost/ejm/"; var sBaseurl="http://localhost/ejm/"; } 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"; 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_tag=""; var sub_phile=""; var sub_control=""; var sub_unit=""; var sub_unitstatus=""; //might want to be seperated into sub_fuel and sub_product var sub_fuelproduct=""; var datatable_search_facility=""; var datatable_search_groups=""; var datatable_search_people=""; var datatable_search_resource=""; var datatable_search_corporation=""; //For editing people/group to facility level of involvement function EditInvolvement (iLevel, iSubid, sSubidname, iMainid, sMainidname, sRelatedtable) { var sLevel=$("#"+iSubid+"_level").html(); if (sLevel=='Interested') iLevel=1; else if (sLevel=='Active') iLevel=0; //if (iLevel==0) iLevel=1; // else if (iLevel==1) 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) $("#"+iSubid+"_level").html("Interested"); else $("#"+iSubid+"_level").html("Active"); } } ); //need to disable the regular form action... this works! return false; } //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) { //creates rest of editarray object (some of it is created earlier in php) //this repeats code from SaveDate - could be a function... aEditarray['sUsername']=''; aEditarray['sPassword']=''; aEditarray['sAdd']=''; aEditarray['sEdit']=''; aEditarray['sDelete']=''; aEditarray['iAddRel']='1'; aEditarray['iAddRelid']=iAddid; aEditarray['iAddRelTable']=sAddtable; 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(); //I set it to empty because I don't think we need it here //aEditarray['sPost']=''; aEditarray['sGet']=''; aEditarray['sFiles']=''; aEditarray['aiCurpage']=new Array(); aEditarray['iDownloadid']=0; aEditarray['sIp']=0; aEditarray['iTraffic']=0; aEditarray['sSitedir']=''; aEditarray['sState']=''; //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_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(); //var position=oDatatable.fnGetPosition( $("#"+sDeleteidname+"_"+iDeleteid)[0]) //oDatatable.fnDeleteRow(position); //adds an extra row, in case we have the delete button... //note: I need to find out number of columns, sometimes there won't be a delete button! // var iColumns = oTable.fnSettings().aoColumns.length; //for adding this to editview - need the delete button sometimes, for adding it to displayview, no delete button //could store 1) presence of a delete button and 2) number of columns as javascript globals - //oDatatable.fnAddData(myObject['aRow']); var oSettings = oDatatable.fnSettings(); //var aiNew = oTable.fnAddData[ 1, 2, 3 ]; 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(''); } } ); //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"} //function AddRelation(sAddtable, iAddid, oDatatable, sAddidname) //set input fields to empty, once the AJAX has executed function AddLink() { var sAddtable='link'; var iAddid=''; var sAddidname='iLinkid'; var oDatatable_addlink=sub_link; //creates rest of editarray object (some of it is created earlier in php) //this repeats code from SaveDate - could be a function... aEditarray['sUsername']=''; aEditarray['sPassword']=''; aEditarray['sAdd']=''; aEditarray['sEdit']=''; aEditarray['sDelete']=''; aEditarray['iAddRel']=''; 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(); //I set it to empty because I don't think we need it here //aEditarray['sPost']=''; aEditarray['sGet']=''; aEditarray['sFiles']=''; aEditarray['aiCurpage']=new Array(); aEditarray['iDownloadid']=0; aEditarray['sIp']=0; aEditarray['iTraffic']=0; aEditarray['sSitedir']=''; aEditarray['sState']=''; //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(); 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(); //id=autocomplete_$sSubtable - hopefully sets the value of the input text box to '' //$('#autocomplete_'+aEditarray['iAddRelTable']).val(''); } //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 //doesn't use datatable - just a list of tags - bulleted style function AddTag(iDeletebutton) { //only executes if the add tag input box is non-null if ($('#gsTag').val()!='') { var sAddtable='tag'; var iAddid=''; var sAddidname='iTagid'; var oDatatable_addlink=sub_tag; //creates rest of editarray object (some of it is created earlier in php) //this repeats code from SaveDate - could be a function... aEditarray['sUsername']=''; aEditarray['sPassword']=''; aEditarray['sAdd']=''; aEditarray['sEdit']=''; aEditarray['sDelete']=''; aEditarray['iAddRel']=''; 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(); //I set it to empty because I don't think we need it here //aEditarray['sPost']=''; aEditarray['sGet']=''; aEditarray['sFiles']=''; aEditarray['aiCurpage']=new Array(); aEditarray['iDownloadid']=0; aEditarray['sIp']=0; aEditarray['iTraffic']=0; aEditarray['sSitedir']=''; aEditarray['sState']=''; //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(); 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(); //id=autocomplete_$sSubtable - hopefully sets the value of the input text box to '' //$('#autocomplete_'+aEditarray['iAddRelTable']).val(''); } } ); } //need to disable the regular form action... unsure if this works... return false; } //based on addtag function AddUnitStatus() { var sAddtable='unitstatus'; var iAddid=''; var sAddidname='iUsid'; var oDatatable_addlink=sub_unitstatus; //creates rest of editarray object (some of it is created earlier in php) //this repeats code from SaveDate - could be a function... aEditarray['sUsername']=''; aEditarray['sPassword']=''; aEditarray['sAdd']=''; aEditarray['sEdit']=''; aEditarray['sDelete']=''; aEditarray['iAddRel']=''; aEditarray['iAddRelid']=''; aEditarray['iAddRelTable']='unitstatus'; 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(); //I set it to empty because I don't think we need it here //aEditarray['sPost']=''; aEditarray['sGet']=''; aEditarray['sFiles']=''; aEditarray['aiCurpage']=new Array(); aEditarray['iDownloadid']=0; aEditarray['sIp']=0; aEditarray['iTraffic']=0; aEditarray['sSitedir']=''; aEditarray['sState']=''; //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(); //id=autocomplete_$sSubtable - hopefully sets the value of the input text box to '' //$('#autocomplete_'+aEditarray['iAddRelTable']).val(''); } } ); //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() { var sAddtable='control'; var iAddid=''; var sAddidname=''; var oDatatable_addadmin=sub_control; //creates rest of editarray object (some of it is created earlier in php) //this repeats code from SaveDate - could be a function... aEditarray['sUsername']=''; aEditarray['sPassword']=''; aEditarray['sAdd']=''; aEditarray['sEdit']=''; aEditarray['sDelete']=''; aEditarray['iAddRel']=''; 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... //this adds gsEmail_addadmin into POST 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']=''; //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(); } } ); //need to disable the regular form action... unsure if this works... 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(); } } ); //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) { //creates rest of editarray object (some of it is created earlier in php) //this repeats code from SaveDate - could be a function... aEditarray['sUsername']=''; aEditarray['sPassword']=''; aEditarray['sAdd']=''; aEditarray['sEdit']=''; //trying out null aEditarray['sDelete']=''; aEditarray['iAddRel']=''; aEditarray['iAddRelid']=''; aEditarray['iAddRelTable']=''; aEditarray['iDeleteRel']='1'; aEditarray['iUnsubscribe']=''; aEditarray['sAddstate']=''; aEditarray['iDeleteid']=iDeleteid; aEditarray['sDeletetable']=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(); //I set it to empty because I don't think we need it here aEditarray['sPost']=''; aEditarray['sGet']=''; aEditarray['sFiles']=''; aEditarray['aiCurpage']=new Array(); aEditarray['iDownloadid']=0; aEditarray['sIp']=0; aEditarray['iTraffic']=0; aEditarray['sSitedir']=''; aEditarray['sState']=''; //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) { $('#'+sDeletetable+'_message').hide(); 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) { //create editarray object //create the object earlier - do it using php so we can write out the session variables for iUid, iId, sLoginhash, sMaintable, sMainidname, iMainid //var aEditarray=new Array(); sHtml_id=sHtml_id_new; aEditarray['sUsername']=''; aEditarray['sPassword']=''; aEditarray['sAdd']=''; aEditarray['sEdit']='1'; aEditarray['sDelete']=''; aEditarray['iAddRel']=''; aEditarray['iAddRelid']=''; aEditarray['iAddRelTable']=''; aEditarray['iDeleteRel']=''; aEditarray['iUnsubscribe']=''; aEditarray['sAddstate']=''; //done with php, in signup.php step 5 //aEditarray['iUid']=0; //get from session //aEditarray['iSuperuser']=0; //get from session at a later date //aEditarray['iId']=0; //get from url, or session //aEditarray['sLoginhash']=''; //get from session //aEditarray['sMaintable']='people'; //aEditarray['sMainidname']='iPid'; //aEditarray['iMainid']=0; //get from url, or session aEditarray['iDeleteid']=0; 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... //it also has trouble with other characters like :// from http:// - turns into %3A%2F%2F (html entities?) 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']=''; //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); 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").show(); $("#clientmessage_wide").html('Saved').show(); //hmm, not sure what we need to do here... if successful, we could write out a "Privacy Settings Changed" message in clientmessage, and give them a back button to //return to their profile - eg displayperson-xx.htm (not signup) } } ); } 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' $("#clientmessage_wide").hide(); $(".main_smalltopmargin").removeClass('main_smalltopmargin').addClass('main'); $("#"+sHtml_id).html(myObject['sHtml']); //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" + ""); } } } ); } //need to disable the regular form action... this works! return false; } //turns edit mode on, display mode off //by setting style='display:none' or '' function EditMode(sHtml_id) { $("#"+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) { $("#"+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?
"); else if (data==0) $("#duplicate_username").html(""); else $("duplicate_username").html("That email already has an account.
Verify your email
"); /* if (data==1) $("td#duplicate_username").html("That email already has an account.
Forgot your password?
"); else if (data==0) $("td#duplicate_username").html(""); else $("td#duplicate_username").html("That email already has an account.
Verify your email
"); */ } ); } //unsure if this is in use... intended for use with a progressbar, which I'm not doing. //function pausecomp(millis) //{ // var date = new Date(); // var curDate = null; // // do { curDate = new Date(); } // while(curDate-date < millis); //} //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 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) { //old method - didn't work. //AddCounties3 (document.forms[0].value, document.forms[0].giCounty.value); 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) { $("#canada_state").show(); $("#canada_state_prompt").show(); $("#us_state").hide(); $("#us_state_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(); $("#canada_state").hide(); $("#canada_state_prompt").hide(); $("#us_state").hide(); $("#us_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].giProvince!=undefined) document.forms[0].giProvince.value=0; if (document.forms[0].giCounty!=undefined) document.forms[0].giCounty.value=0; } //US else { $("#us_state").show(); $("#us_state_prompt").show(); $("#county_search").show(); $("#county_search_prompt").show(); $("#canada_state").hide(); $("#canada_state_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=''; } } } } //http://www.internetdoc.info/1internetdoc/javascript-php-equivalent/substr_count.htm 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'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, "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null] }); } else { sub_corporation=$("#sub-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] }); } //4 columns - first name, last name, image, delete sub_people=$("#sub-people").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":false}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null, null] }); sub_groups=$("#sub-groups").dataTable({"iDisplayLength":20, "bLengthChange":false,"bFilter":false, "bAutoWidth":false, "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, "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null] }); sub_resource=$("#sub-resource").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null] }); sub_link=$("#sub-link").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null] }); sub_tag=$("#sub-tag").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null] }); sub_phile=$("#sub-phile").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "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, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [null, null, null] }); sub_unit=$("#sub-unit").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null] }); } //search mode //var datatable_search_facility=""; else if (substr_count(window.location.href , 'search' , 0, 200)) { TableToolsInit.sSwfPath = "js/TableTools/media/swf/ZeroClipboard.swf"; datatable_search_facility=$("#datatable-search-facility").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": 'T<"clear">lfrtip'}); 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": 'T<"clear">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":false}], "aoColumns": [{"sType":"html"}, 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... 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() { 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() { RemovePagination('corporation'); } }); } //4 columns - first name, last name, image, delete sub_people=$("#sub-people").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}, {"bSortable":true}, {"bSortable":false}], "aoColumns": [{"sType":"html"}, null, null], "fnDrawCallback": function() { RemovePagination('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() { RemovePagination('groups'); } }); sub_school=$("#sub-school").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { RemovePagination('school'); } }); sub_resource=$("#sub-resource").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { RemovePagination('resource'); } }); sub_link=$("#sub-link").dataTable({"iDisplayLength":20, "bLengthChange":false, "bFilter":false, "bAutoWidth":false, "aoColumns": [{"bSortable":true}], "aoColumns": [{"sType":"html"}], "fnDrawCallback": function() { RemovePagination('link'); } }); 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() { 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() { 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() { RemovePagination('unit'); } }); } //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)) { 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_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(); } }); //adding a facility - hide some of the steps until they are needed if ((substr_count(window.location.href , 'addfacility' , 0, 200)) || ((substr_count(window.location.href , 'addobject' , 0, 200)) && (substr_count(window.location.href , 'facility' , 0, 200)) )) { /*step 2 hide*/ $('#giBfactype').hide(); $('#giFacility_status').hide(); $('#Step2').hide(); /* step 3 hide*/ $('#giFacility_fueltype').hide(); $('#giFacility_producttype').hide(); $('#Step3').hide(); /*step 4 hide*/ $('#msWebsite').hide(); $('#facility_msNotes_public').hide(); $('#msPhone_addfacility').hide(); $('#Step4').hide(); //$('#gsAdd').hide(); //attach js function to #gsSubmit $('#gsAdd_control').click(function () { if (iFacilitystep==1) { //fuzzy name match //serializes form data - really I just need sName, but I might want other fields in the future //var aEdittarray = array(); //aEditarray['sPost']=$("form").serialize(); //var encoded = $.toJSON(aEditarray); var sFacilityname=$("input[name=gsName]").val(); $.post(sServer+"server-test/webservice/ajax_facilitymatch.php", { 'giAjax': "1", 'gsFacilityname': sFacilityname }, function (data) { var myObject = eval('(' + data + ')'); //match found - show request control link if (myObject['iFacilityid']>=1) { //requestcontrol.php?g".$this->GetIDName()."=".$this->GetID() $('#fuzzymatch').html("
If you are adding "+myObject['sName']+" - then you should " + "Request Control of that Facility").show(); } else { $('#fuzzymatch').hide(); } } ); $('#giBfactype').show(); $('#giFacility_status').show(); $('#Step2').show(); } else if (iFacilitystep==2) { //generate a list of fuels based on $GLOBALS['gasFacilitytypetofuelproduct'] $('#giFacility_fueltype').show(); $('#giFacility_producttype').show(); $('#Step3').show(); } else if (iFacilitystep==3) { $('#Step4').show(); $('#msWebsite').show(); $('#facility_msNotes_public').show(); $('#msPhone_addfacility').show(); } //call the webservice... using nusoap else if (iFacilitystep==4) { } //alert ("Hi"); //show iFacilitystep++; //will this cause the form to submit on step 4? if (iFacilitystep!=5) return false; else return true; } ); } //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});; } //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) { $("#canada_state").show(); $("#canada_state_prompt").show(); $("#us_state").hide(); $("#us_state_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(); $("#canada_state").hide(); $("#canada_state_prompt").hide(); $("#us_state").hide(); $("#us_state_prompt").hide(); $("#county_search").hide(); $("#county_search_prompt").hide(); document.forms[0].giState.value=0; document.forms[0].giProvince.value=0; } //USA else { $("#us_state").show(); $("#us_state_prompt").show(); $("#county_search").show(); $("#county_search_prompt").show(); $("#canada_state").hide(); $("#canada_state_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() { 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<=20; k++) { for (var j=1; j<=4; j++) { var sCheckname='giLayer_'+k+'_'+j; document.forms[0][sCheckname].checked=false; //layerstatus is only used for local map - i think if (layerstatus!=undefined) layerstatus[j][k]=0; } var sCheckname='giLayer_'+k+'_'+99; document.forms[0][sCheckname].checked=false; } for (var j=1; j<4; j++) { if (document.forms[0]['giLayer_98_'+j]!=undefined) { document.forms[0]['giLayer_98_'+j].checked=false; } } for (var j=1; j<=4; j++) //for (var j=2; j<=4; j++) { var sCheckname='giLayer_'+99+'_'+j; document.forms[0][sCheckname].checked=false; var sCheckname='giLayer_'+98+'_'+j; document.forms[0][sCheckname].checked=false; } document.forms[0]['giLayer_98_99'].checked=false; document.forms[0]['giLayer_99_99'].checked=false; map.clearOverlays(); //sets iLayervisible to 0, also reset gmarkers - unsure if that is needed. 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<=20; ik++) { for (var ij=1; ij<=4; ij++) { var sCheckname10='giLayer_'+ik+'_'+ij; if (document.forms[0][sCheckname10]!=undefined) { document.forms[0][sCheckname10].disabled=disable; } } var sCheckname10='giLayer_'+ik+'_99'; if (document.forms[0][sCheckname10]!=undefined) { document.forms[0][sCheckname10].disabled=disable; } } //all of the same status - only exists for statuses other than "operating", hmm, unsure what this really does... document.forms[0]['giLayer_99_2'].disabled=disable; document.forms[0]['giLayer_99_3'].disabled=disable; document.forms[0]['giLayer_99_4'].disabled=disable; if (document.forms[0]['giLayer_99_1']!=undefined) { document.forms[0]['giLayer_99_1'].disabled=disable; } if (document.forms[0]['giLayer_99_99']!=undefined) { document.forms[0]['giLayer_99_99'].disabled=disable; } if (document.forms[0]['giLayer_98_99']!=undefined) { document.forms[0]['giLayer_98_99'].disabled=disable; } for (var ij=1; ij<=4; ij++) { var sCheckname10='giLayer_98_'+ij; if (document.forms[0][sCheckname10]!=undefined) { document.forms[0][sCheckname10].disabled=disable; } } } //event - onchange - will the dom be changed then? so then i can use the dom's values for the checkboxes? //creates layer checkbox array - sends to server //gets list of facilities //runs initlayers to display them //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) //added iOn, iLayerid, iStatus parameters function NationalMapToggle(iOn, iLayerid, iStatus) { //creates layer checkbox array - sends to server //for every unit status - //it'd be nice if I could get the number of layers dynamically, instead of using the 20 constant //If we are going to display too many markers - toggle off high marker layers. //these include: hydro/oil/gas/coal - operating/all //only do this for the US - eg do not do it for national-xx if (substr_count(window.location.href , 'national-' , 0, 200)==0) { var aStatus=new Array (2, 3, 4, 17); if ( ((iLayerid==2) || (iLayerid==3) || (iLayerid==4) || (iLayerid==17)) && ((iStatus==1) || (iStatus==99))) { for (key in aStatus) { if (aStatus[key]!=iLayerid) { var sCheckname5='giLayer_'+aStatus[key]+'_'; document.forms[0][sCheckname5+'1'].checked=false; document.forms[0][sCheckname5+'99'].checked=false; } } } } //handle turning on/off all layers/statuses first (does this placement matter?) if ((iLayerid==99) && (iStatus==99)) { for (var ikey=1; ikey<=4; ikey++) { for (var isubkey=1; isubkey<=20; isubkey++) { var sCheckname5='giLayer_'+isubkey+'_'+ikey; if (document.forms[0][sCheckname5]!=undefined) { document.forms[0][sCheckname5].checked=iOn; } } var sCheckname5='giLayer_99_'+ikey; if (document.forms[0][sCheckname5]!=undefined) { document.forms[0][sCheckname5].checked=iOn; } } } //user is turning off a layer if (iOn==false) { //test for the user turning off a layer that breaks an "all" - so the all should be unchecked //look at the iLayerid - does that break an all? //instead of testing for it - I just set it to false //all/all does not exist if (iLayerid!=99) { var sCheckname5='giLayer_'+iLayerid+'_99'; document.forms[0][sCheckname5].checked=false; } //look at the iStatus -- does that break an all? //instead of testing for it - I just set it to false //exceptions are operating and all status - which do not exist in nationalmap //if ((iStatus!=99) && (iStatus!=1)) //{ //now changed, as all operating status is possible for nonUS var sCheckname5='giLayer_99_'+iStatus; if (document.forms[0][sCheckname5]!=undefined) { document.forms[0][sCheckname5].checked=false; } //} } //user is turning on a layer 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'; document.forms[0][sCheckname_expanding].checked=true; } //test for the user turning on a layer that causes all to be selected - so the all should be checked //look at the iLayerid - does that create an all? var iAll=true; var iStart=0; //starts at "2" for iStatus=1, operating, as there is no select all for that status. if (iStatus==1) iStart=2; else iStart=1; for (var n=iStart; n<=4; n++) { var sCheckname5='giLayer_'+iLayerid+'_'+n; if (document.forms[0][sCheckname5]!=undefined) { if (document.forms[0][sCheckname5].checked==false) iAll=false; } } if (iAll==true) { var sCheckname5='giLayer_'+iLayerid+'_99'; if (document.forms[0][sCheckname5]!=undefined) document.forms[0][sCheckname5].checked=true; } //look at the iStatus -- does that create an all? var iAll=true; for (var n=1; n<=20; n++) { var sCheckname5='giLayer_'+n+'_'+iStatus; if (document.forms[0][sCheckname5].checked!=undefined) { if (document.forms[0][sCheckname5].checked==false) iAll=false; } } if (iAll==true) { var sCheckname5='giLayer_99_'+iStatus; if (document.forms[0][sCheckname5].checked!=undefined) { document.forms[0][sCheckname5].checked=true; } } } var aCheck = new Array(); //parses to build the checkbox array to send to the server for (var m=1; m<=20; m++) { 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[0][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[0][sCheckname+'1'].checked=true; document.forms[0][sCheckname+'2'].checked=true; document.forms[0][sCheckname+'3'].checked=true; document.forms[0][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[0][sCheckname+'1'].checked=false; document.forms[0][sCheckname+'2'].checked=false; document.forms[0][sCheckname+'3'].checked=false; document.forms[0][sCheckname+'4'].checked=false; } aCheck[m][1]=document.forms[0][sCheckname+'1'].checked; aCheck[m][2]=document.forms[0][sCheckname+'2'].checked; aCheck[m][3]=document.forms[0][sCheckname+'3'].checked; aCheck[m][4]=document.forms[0][sCheckname+'4'].checked; aCheck[m][99]=document.forms[0][sCheckname+'99'].checked; } } aCheck[99]=new Array(); var sCheckname3='giLayer_99_'; //if the user just toggled the all factypes of one status if (iLayerid==99) { for (var k=1; k<=20; k++) { var sCheckname2='giLayer_'+k+'_'+iStatus; document.forms[0][sCheckname2].checked=iOn; } if (document.forms[0]['giLayer_'+98+'_'+iStatus]!=undefined) { document.forms[0]['giLayer_'+98+'_'+iStatus].checked=iOn; } } //aCheck[99][1]=document.forms[0][sCheckname3+'1'].checked; aCheck[99][1]=false; aCheck[99][2]=document.forms[0][sCheckname3+'2'].checked; aCheck[99][3]=document.forms[0][sCheckname3+'3'].checked; aCheck[99][4]=document.forms[0][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 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 map.clearOverlays(); //gets list of facilities //using post because I cannot use GET and send aCheck - as it is too long. //note: I might need to change my handling of giAjax //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 var str = $("form").serialize(); 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"); } else { //first disable all checkboxes CheckboxDisable (true); //alert("test"); var sSearchtype=''; if (substr_count(window.location.href , 'globalmap' , 0, 200)) { sSearchtype="globalmap"; } else sSearchtype="nationalmap"; //alert (str); //exit; $.post(sServer+"server-test/webservice/searchserver-new.php?"+str, { giAjax: "1", gsSearchtype: sSearchtype }, function (data) { var tempfacilities = eval('(' + data + ')'); facilities=tempfacilities.facilities; //Enable all the checkboxes CheckboxDisable (false); //runs initlayers to display them -- runs this only after the data is fetched. InitLayers(); $("span#iCount").html("Total Results: "+facilities[0]['iCount']+"
Mapped Results: "+facilities[0]['iMapcount']); if (facilities[0]['fLat']!=undefined) { map.setCenter(new GLatLng(facilities[0]['fLat'],facilities[0]['fLong']), parseInt(facilities[0]['iZoom']), G_NORMAL_MAP); } } ); } } //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 function GetTinyUrl (iFormdata) { var formstr=''; //for national and localmap - fetches form results - and adds to the string 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 GLatLng(0,0); point=map.getCenter(); //getsize unfortunately returns the original map size - if you use jquery resize, it won't be updated var size=new GSize(0,0); size=map.getSize(); //mapwidth=map.width(); //mapheight=map.height(); //alert ("size: "+size+" "+mapwidth+" "+mapheight); //only difference is miCountry=0 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.getCurrentMapType().getName()+"&giWidth="+size.width+"&giHeight="+size.height; 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) { $("span#tinyurl").html(""); $("#tinyurl-text").focus(); } ); } //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'+ title + ''; if (aFacility['sCity']!='') sTexturl+='
'+aFacility['sCity']; if (aFacility['sCity']!='' && aFacility['sState']!='') sTexturl+=', '; if (aFacility['sCity']=='' && aFacility['sState']!='') sTexturl+='
'; if (aFacility['sState']!='') sTexturl+=aFacility['sState']; //add power plant type if (sFactype!='other') sTexturl+='
'+sFacname; sTexturl+=''; createMarker_themap(point, sTexturl, title, aicon[sMarkercolor][sFactype], iFacilityid); //setTimeout ("createMarker_themap(point, sTexturl, title, aicon[sMarkercolor][sFactype], iFacilityid)", 1); } //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 function InitLayers () { //var iMarkercount=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]['iCount']!=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); //$("span#iCount").html("Total Results: "+iCount_local+"
Mapped Results: "+iCount_localmapped); } } //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) { //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]); 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; document.forms[0][sCheckname].checked=false; //turns off 99,99 var sCheckname='giLayer_99_99'; document.forms[0][sCheckname].checked=false; //turns off anything that is iLayerid, 99 var sCheckname='giLayer_'+iLayerid+'_99'; document.forms[0][sCheckname].checked=false; //turns off anything that is 99, iStatus var sCheckname='giLayer_99_'+iStatus; document.forms[0][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 for (keyVar in facilities) { if (keyVar!=0) { if (gMarkers[keyVar]!=null) map.removeOverlay(gMarkers[keyVar]); gMarkers[keyVar]=null; facilities[keyVar]['iLayervisible']=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) { //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"); } 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, 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; document.forms[0][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<=20; 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[0][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'; document.forms[0][sCheckname].checked=true; } //Test for turning on 99, iStatus var iAll=1; for (var iLayer_i=1; iLayer_i<=20; 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; document.forms[0][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. 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 ikey=1; ikey<=4; ikey++) { for (var isubkey=1; isubkey<=20; isubkey++) { ToggleMarkersOff (isubkey, ikey); } //toggles off the other layer ToggleMarkersOff (98, ikey); } //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; document.forms[0][sCheckname].checked=false; } for (var iI=1; iI<=20; iI++) { var sCheckname='giLayer_'+iI+'_99'; document.forms[0][sCheckname].checked=false; } var sCheckname='giLayer_98_99'; document.forms[0][sCheckname].checked=false; } //turns off all layers that have the same single status else if (iLayerid==99) { for (var ilayer=1; ilayer<=20; 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[0][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<=20; ilayer++) { for (var istatus=1; istatus<=4; istatus++) { ToggleMarkersOn (ilayer, istatus); } } //InitLayers(); for (var ikey=1; ikey<=4; ikey++) { for (var isubkey=1; isubkey<=20; isubkey++) { layerstatus[ikey][isubkey]=1; var sCheckname='giLayer_'+isubkey+'_'+ikey; document.forms[0][sCheckname].checked=true; } layerstatus[ikey][98]=1; var sCheckname='giLayer_98_'+ikey; document.forms[0][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; document.forms[0][sCheckname].checked=true; } for (var iI=1; iI<=20; iI++) { var sCheckname='giLayer_'+iI+'_99'; document.forms[0][sCheckname].checked=true; } var sCheckname='giLayer_98_99'; document.forms[0][sCheckname].checked=true; } //turns On all layers that have the same single status else if (iLayerid==99) { for (var ilayer=1; ilayer<=20; 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); } //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; 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 */ function AddFuels () { //hmm I don't think FacTypeList is actually used? var FacTypeList = document.forms[0].giBfactype; ClearOptions(document.forms[0].giFacility_fueltype); //could say "select", but they don't have to select one - so this is the less pushy version AddToOptionList(document.forms[0].giFacility_fueltype, 0, '--Select--'); //selected factype var iFactype=document.forms[0].giBfactype.value; for (i=0; iC)'); AddToOptionList(document.forms[0].FuelProduct, '38', 'High-Level Radioactive Waste'); AddToOptionList(document.forms[0].FuelProduct, '39', 'Mixed Waste'); AddToOptionList(document.forms[0].FuelProduct, '40', 'Trans-Uranic Waste'); AddToOptionList(document.forms[0].FuelProduct, '41', 'Depleted Uranium'); AddToOptionList(document.forms[0].FuelProduct, '42', 'NORM/NARM'); document.forms[0].FuelProduct.style.visibility='visible'; } else if (FacTypeList[FacTypeList.selectedIndex].value == "14") { AddToOptionList(document.forms[0].FuelProduct, '0', 'All'); AddToOptionList(document.forms[0].FuelProduct, '3', 'Blast Furnace Gas'); AddToOptionList(document.forms[0].FuelProduct, '5', 'Jet Fuel'); AddToOptionList(document.forms[0].FuelProduct, '6', 'Kerosene'); AddToOptionList(document.forms[0].FuelProduct, '15', 'Petroleum Coke'); AddToOptionList(document.forms[0].FuelProduct, '16', 'Propane'); AddToOptionList(document.forms[0].FuelProduct, '17', 'Residual Fuel Oil'); AddToOptionList(document.forms[0].FuelProduct, '25', 'Waste Oil'); AddToOptionList(document.forms[0].FuelProduct, '33', 'Oil'); AddToOptionList(document.forms[0].FuelProduct, '59', 'Diesel Fuel'); AddToOptionList(document.forms[0].FuelProduct, '65', 'Heavy Oil'); document.forms[0].FuelProduct.style.visibility='visible'; } else if (FacTypeList[FacTypeList.selectedIndex].value == "15") { AddToOptionList(document.forms[0].FuelProduct, '1', 'Natural Gas'); document.forms[0].FuelProduct.style.visibility='visible'; } else { document.forms[0].FuelProduct.style.visibility='hidden'; } } function PopulateDropDownUnitType() { var FacTypeList = document.forms[0].giPpmap_type; // Clear out the list of giPrimaryfacilitytype ClearOptions(document.forms[0].giPrimaryfacilitytype); //based on the chosen value - run a php script that writes out javascript (addtopoptionlist) to add the relevant //fuel products - whether coal, nuke, gas or other if (FacTypeList[FacTypeList.selectedIndex].value == "13" || FacTypeList[FacTypeList.selectedIndex].value == "14" || FacTypeList[FacTypeList.selectedIndex].value == "15" || FacTypeList[FacTypeList.selectedIndex].value == "18") { AddToOptionList(document.forms[0].giPrimaryfacilitytype, '0', 'All'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '6', 'Boiler'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '7', 'Circulating Fluidized Bed'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '9', 'Gasification'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '8', 'Inclined Fluidized Bed'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '5', 'Internal Combustion Engine - Combined Cycle'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '4', 'Internal Combustion Engine - Simple Cycle'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '2', 'Mass Burn'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '44', 'Organic Rankine Cycle'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '10', 'Plasma Arc'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '56', 'Pressurized Fluidized Bed'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '45', 'Reciprocating Engine'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '46', 'Supercritical'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '55', 'Supercritical'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '48', 'Thermal Depolymerization'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '3', 'Turbine'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '11', 'Unknown Type'); AddToOptionList(document.forms[0].giPrimaryfacilitytype, '47', 'Utility Boiler'); document.forms[0].giPrimaryfacilitytype.style.visibility='visible'; } else { document.forms[0].giPrimaryfacilitytype.style.visibility='hidden'; } } function ClearOptions(OptionList) { // Always clear an option list from the last entry to the first for (x = OptionList.length; x >= 0; x = x - 1) { OptionList[x] = null; } } function AddToOptionList(OptionList, OptionValue, OptionText) { // Add option to the bottom of the list OptionList[OptionList.length] = new Option(OptionText, OptionValue); } //array of basic20factypes to possible fuels - based on fuel-to-unit-types-new.xls //coal products: 8, 18, 20, 22, 32 //only doing the "must include" part - as the user can only add one fuel when they add a facility, in edit facility view they can add other fuels //not in use /* var basicfactypes_to_fuel= {'1' :(26, 27), '2' : (8, 18, 20, 22, 32), '3' : (3,5,6,15,16,17,25,33,59,65), '4' : (1), //oil refinery - notes say oilpetro =-1 which are the fields below '5' : (3, 5, 6, 15, 16, 17, 25, 33, 59, 65), '6' : (2,8,9,15,20,21,22,24,32,56), '7' : (1), '8' : (63), '9' : (2,9,12,19,23,24,46,47,48,51,52,53,54,56,57,61,62), '10' : (9), '11' : (2,4,12,23,24,46,51,52,53,54,56,57), '12': (47), '13': (21), //cement kiln - has no fuel '14': (0), //landfills - I skipped adding a bunch of nuclear wastes - emailed Mike about them. '15': (10, 19, 21, 24, 49, 51, 52, 53, 66, 67), '16': (7), '17': (29)}; */ //populate the fuel type drop down based on the value in giBfactype function Populate_Fuels() { ClearOptions(document.forms[0].giFacility_fueltype); //add options var iType=$("giBfactype").value; //AddToOptionList(document.forms[0].giPrimaryfacilitytype, '0', 'All'); } function mainSites(x) { if (x != '') { self.location=x; } } function s_show(){return false} function s_hide(){return false} if(window.event+''=='undefined')event=0 function DeleteInfo(sLocation, iUser) { if (iUser='1') document.write (""); else document.write (""); } function MassDeleteConfirm() { document.write (""); } function jereverselink(x, y) { document.write("" + "Email" + ""); } function toggleMyKml() { if (toggleState == 1) { map.removeOverlay(geoXml); toggleState = 0; } else { map.addOverlay(geoXml); toggleState = 1; } } //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