<!-- Begin Javascript
// Location Injection Script
// Use this script if you want to inject location links to the Delaware.gov multimedia gallery
//Contact the Government Information Center if you need assistance.

//##################################################
//Non Application Link Prompt Instructions
//-----------------------------------------
//To Use:
//  1. Add a link to this file in the head section of ALL html pages that need this functionality.
//  Example: <script language="JavaScript" type="text/javascript" src="/rootfoldersitepath/js/nonApp.js"></script>
//
//  2. Add onload="setLocations()" to the body tag of ALL pages that need this functionality.
//
//  3. Update the Application Name variable strAppName to your application name. 
//     This name will be presented to the users in the popup.
//
//If you need the popup to show for additional urls follow the syntax below and increment the numurls variable appropriately.
//
//Notes:
//-The link array is 0 based so 0 counts as 1 link
//##################################################

//##################################################
//Set the total Number of locationss if needed
var numurls = 57; //0 counts as 1
//##################################################

//##################################################
//Default Link Array
//By default the link array contains the urls in the header, sidenav, and
//footer of the CLF frame. You may add addition urls to this array by 
//following the syntax below. If you do add additional urls be sure to update
//numurls variable appropriately.
var arrayLocs = new Array(numurls);
arrayLocs[0]=new Array(2);
arrayLocs[0]['Name']='Bethany Beach';
arrayLocs[0]['URL']='http://portal.delaware.gov/locations/bethany_beach.shtml';
arrayLocs[1]=new Array(2);
arrayLocs[1]['Name']='Bowers';
arrayLocs[1]['URL']='http://portal.delaware.gov/locations/bowers_beach.shtml';
arrayLocs[2]=new Array(2);
arrayLocs[2]['Name']='Bridgeville';
arrayLocs[2]['URL']='http://portal.delaware.gov/locations/bridgeville.shtml';
arrayLocs[3]=new Array(2);
arrayLocs[3]['Name']='Camden';
arrayLocs[3]['URL']='http://portal.delaware.gov/locations/camden.shtml';
arrayLocs[4]=new Array(2);
arrayLocs[4]['Name']='Cheswold';
arrayLocs[4]['URL']='http://portal.delaware.gov/locations/cheswold.shtml';
arrayLocs[5]=new Array(2);
arrayLocs[5]['Name']='Clayton';
arrayLocs[5]['URL']='http://portal.delaware.gov/locations/clayton.shtml';
arrayLocs[6]=new Array(2);
arrayLocs[6]['Name']='Dagsboro';
arrayLocs[6]['URL']='http://portal.delaware.gov/locations/dagsboro.shtml';
arrayLocs[7]=new Array(2);
arrayLocs[7]['Name']='Delaware City';
arrayLocs[7]['URL']='http://portal.delaware.gov/locations/delaware_city.shtml';
arrayLocs[8]=new Array(2);
arrayLocs[8]['Name']='Dewey';
arrayLocs[8]['URL']='http://portal.delaware.gov/locations/dewey_beach.shtml';
arrayLocs[9]=new Array(2);
arrayLocs[9]['Name']='Dover';
arrayLocs[9]['URL']='http://portal.delaware.gov/locations/dover.shtml';
arrayLocs[10]=new Array(2);
arrayLocs[10]['Name']='Felton';
arrayLocs[10]['URL']='http://portal.delaware.gov/locations/felton.shtml';
arrayLocs[11]=new Array(2);
arrayLocs[11]['Name']='Fenwick Island';
arrayLocs[11]['URL']='http://portal.delaware.gov/locations/fenwick_island.shtml';
arrayLocs[12]=new Array(2);
arrayLocs[12]['Name']='Frederica';
arrayLocs[12]['URL']='http://portal.delaware.gov/locations/frederica.shtml';
arrayLocs[13]=new Array(2);
arrayLocs[13]['Name']='Georgetown';
arrayLocs[13]['URL']='http://portal.delaware.gov/locations/georgetown.shtml';
arrayLocs[14]=new Array(2);
arrayLocs[14]['Name']='Harrington';
arrayLocs[14]['URL']='http://portal.delaware.gov/locations/harrington.shtml';
arrayLocs[15]=new Array(2);
arrayLocs[15]['Name']='Hartly';
arrayLocs[15]['URL']='http://portal.delaware.gov/locations/hartly.shtml';
arrayLocs[16]=new Array(2);
arrayLocs[16]['Name']='Laurel';
arrayLocs[16]['URL']='http://portal.delaware.gov/locations/laurel.shtml';
arrayLocs[17]=new Array(2);
arrayLocs[17]['Name']='Leipsic';
arrayLocs[17]['URL']='http://portal.delaware.gov/locations/leipsic.shtml';
arrayLocs[18]=new Array(2);
arrayLocs[18]['Name']='Lewes';
arrayLocs[18]['URL']='http://portal.delaware.gov/locations/lewes.shtml';
arrayLocs[19]=new Array(2);
arrayLocs[19]['Name']='Little Creek';
arrayLocs[19]['URL']='http://portal.delaware.gov/locations/little_creek.shtml';
arrayLocs[20]=new Array(2);
arrayLocs[20]['Name']='Middletown';
arrayLocs[20]['URL']='http://portal.delaware.gov/locations/middletown.shtml';
arrayLocs[21]=new Array(2);
arrayLocs[21]['Name']='Milford';
arrayLocs[21]['URL']='http://portal.delaware.gov/locations/milford.shtml';
arrayLocs[22]=new Array(2);
arrayLocs[22]['Name']='Millsboro';
arrayLocs[22]['URL']='http://portal.delaware.gov/locations/millsboro.shtml';
arrayLocs[23]=new Array(2);
arrayLocs[23]['Name']='Millville';
arrayLocs[23]['URL']='http://portal.delaware.gov/locations/millville.shtml';
arrayLocs[24]=new Array(2);
arrayLocs[24]['Name']='Milton';
arrayLocs[24]['URL']='http://portal.delaware.gov/locations/milton.shtml';
arrayLocs[25]=new Array(2);
arrayLocs[25]['Name']='New Castle';
arrayLocs[25]['URL']='http://portal.delaware.gov/locations/new_castle.shtml';
arrayLocs[26]=new Array(2);
arrayLocs[26]['Name']='Newark';
arrayLocs[26]['URL']='http://portal.delaware.gov/locations/newark.shtml';
arrayLocs[27]=new Array(2);
arrayLocs[27]['Name']='Odessa';
arrayLocs[27]['URL']='http://portal.delaware.gov/locations/odessa.shtml';
arrayLocs[28]=new Array(2);
arrayLocs[28]['Name']='Rehoboth Beach';
arrayLocs[28]['URL']='http://portal.delaware.gov/locations/rehoboth_beach.shtml';
arrayLocs[29]=new Array(2);
arrayLocs[29]['Name']='Seaford';
arrayLocs[29]['URL']='http://portal.delaware.gov/locations/seaford.shtml';
arrayLocs[30]=new Array(2);
arrayLocs[30]['Name']='Slaughter';
arrayLocs[30]['URL']='http://portal.delaware.gov/locations/slaughter_beach.shtml';
arrayLocs[31]=new Array(2);
arrayLocs[31]['Name']='Smyrna';
arrayLocs[31]['URL']='http://portal.delaware.gov/locations/smyrna.shtml';
arrayLocs[32]=new Array(2);
arrayLocs[32]['Name']='Townsend';
arrayLocs[32]['URL']='http://portal.delaware.gov/locations/townsend.shtml';
arrayLocs[33]=new Array(2);
arrayLocs[33]['Name']='Wilmington';
arrayLocs[33]['URL']='http://portal.delaware.gov/locations/wilmington.shtml';
arrayLocs[34]=new Array(2);
arrayLocs[34]['Name']='Wyoming';
arrayLocs[34]['URL']='http://portal.delaware.gov/locations/wyoming.shtml';
arrayLocs[35]=new Array(2);
arrayLocs[35]['Name']='Bellefonte';
arrayLocs[35]['URL']='http://portal.delaware.gov/locations/bellefonte.shtml';
arrayLocs[36]=new Array(2);
arrayLocs[36]['Name']='Bethel';
arrayLocs[36]['URL']='http://portal.delaware.gov/locations/bethel.shtml';
arrayLocs[37]=new Array(2);
arrayLocs[37]['Name']='Blades';
arrayLocs[37]['URL']='http://portal.delaware.gov/locations/blades.shtml';
arrayLocs[38]=new Array(2);
arrayLocs[38]['Name']='Ellendale';
arrayLocs[38]['URL']='http://portal.delaware.gov/locations/ellendale.shtml';
arrayLocs[39]=new Array(2);
arrayLocs[39]['Name']='Elsmere';
arrayLocs[39]['URL']='http://portal.delaware.gov/locations/elsmere.shtml';
arrayLocs[40]=new Array(2);
arrayLocs[40]['Name']='Farmington';
arrayLocs[40]['URL']='http://portal.delaware.gov/locations/farmington.shtml';
arrayLocs[41]=new Array(2);
arrayLocs[41]['Name']='Frankford';
arrayLocs[41]['URL']='http://portal.delaware.gov/locations/frankford.shtml';
arrayLocs[42]=new Array(2);
arrayLocs[42]['Name']='Greenwood';
arrayLocs[42]['URL']='http://portal.delaware.gov/locations/greenwood.shtml';
arrayLocs[43]=new Array(2);
arrayLocs[43]['Name']='Henlopen Acres';
arrayLocs[43]['URL']='http://portal.delaware.gov/locations/henlopen_acres.shtml';
arrayLocs[44]=new Array(2);
arrayLocs[44]['Name']='Houston';
arrayLocs[44]['URL']='http://portal.delaware.gov/locations/houston.shtml';
arrayLocs[45]=new Array(2);
arrayLocs[45]['Name']='Kenton';
arrayLocs[45]['URL']='http://portal.delaware.gov/locations/kenton.shtml';
arrayLocs[46]=new Array(2);
arrayLocs[46]['Name']='Magnolia';
arrayLocs[46]['URL']='http://portal.delaware.gov/locations/magnolia.shtml';
arrayLocs[47]=new Array(2);
arrayLocs[47]['Name']='Ocean View';
arrayLocs[47]['URL']='http://portal.delaware.gov/locations/ocean_view.shtml';
arrayLocs[48]=new Array(2);
arrayLocs[48]['Name']='Selbyville';
arrayLocs[48]['URL']='http://portal.delaware.gov/locations/selbyville.shtml';
arrayLocs[49]=new Array(2);
arrayLocs[49]['Name']='South Bethany';
arrayLocs[49]['URL']='http://portal.delaware.gov/locations/south_bethany.shtml';
arrayLocs[50]=new Array(2);
arrayLocs[50]['Name']='Woodside';
arrayLocs[50]['URL']='http://portal.delaware.gov/locations/woodside.shtml';
arrayLocs[51]=new Array(2);
arrayLocs[51]['Name']='Viola';
arrayLocs[51]['URL']='http://portal.delaware.gov/locations/viola.shtml';
arrayLocs[52]=new Array(2);
arrayLocs[52]['Name']='Arden';
arrayLocs[52]['URL']='http://portal.delaware.gov/locations/arden.shtml';
arrayLocs[53]=new Array(2);
arrayLocs[53]['Name']='Ardencroft';
arrayLocs[53]['URL']='http://portal.delaware.gov/locations/ardencroft.shtml';
arrayLocs[54]=new Array(2);
arrayLocs[54]['Name']='Ardentown';
arrayLocs[54]['URL']='http://portal.delaware.gov/locations/ardentown.shtml';
arrayLocs[55]=new Array(2);
arrayLocs[55]['Name']='Delmar';
arrayLocs[55]['URL']='http://portal.delaware.gov/locations/delmar.shtml';
arrayLocs[56]=new Array(2);
arrayLocs[56]['Name']='Newport';
arrayLocs[56]['URL']='http://portal.delaware.gov/locations/newport.shtml';
//##################################################

//##################################################
//setLocs Function
//This function aggregates through all of text as a string
//if text matches the array a link is injected.

function doScramble(str){
var strScram='';
for (var i=str.length; i>=0; i--) {
strScram=strScram+str.substr(i,1);
}
return strScram;
}

function doRegExReplace(str,strRe,strNew){
var strRep=str;
var re=new RegExp(strRe,'gim');
strRep=strRep.replace(re,strNew);
return strRep;
}



function setLocs(str){
var strChk=str;
var strLink;

//Replace a link search for a before</a
var myReA1=new RegExp('a</a>','gim');
strChk=strChk.replace(myReA1,'a~</a>');

//doRegExReplace(strChk,'a</a>','a~</a>');

//Scramble links to avoid inject
var myReLink1=new RegExp('<a [^</a].*?</a>','gim');
//alert(myReLink1.exec(strChk));
strChk=strChk.replace(myReLink1, function (str, p1, p2, offset, s) { return doScramble(str) });

//doRegExReplace(strChk,'<a [^</a].*?</a>','function (str, p1, p2, offset, s) { return doScramble(str) }');


//loop inject array
 for (x=0; x<numurls; x++) {
//compare current text to all link array

//build link
strLink='<a title="Learn about '+arrayLocs[x]['Name']+'" style="text-decoration:none;border-bottom:1px dashed blue;" href="'+arrayLocs[x]['URL']+'">'+arrayLocs[x]['Name']+'</a>';
//set word
strWord = new RegExp(arrayLocs[x]['Name'],'gm');
//inject
strChk=strChk.replace(strWord,strLink);


}

//DeScramble
var myReLink2=new RegExp('>a/<[^ a<].*? a<','gim');
strChk=strChk.replace(myReLink2, function (str, p1, p2, offset, s) { return doScramble(str) });

//Restore a link search for a before</a
var myReA2=new RegExp('a~</a>','gim');
strChk=strChk.replace(myReA2,'a</a>');


//alert(strChk);
return strChk;
}

//##################################################


//##################################################
//calling sub
function setLocations(str) {
 return setLocs(str);
}
//##################################################




// End Javascript -->