//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='