var coa_s_pagecount = 0; var coa_s_searchcount = 0; var coa_s_dursecs = 0; var coa_s_peight = ''; var coa_s_mobileflag = -1; function coa_s_ismobile() { if ( coa_s_mobileflag > -1 ) { return coa_s_mobileflag; } var linkarr = document.getElementsByTagName("script"); var i = 0; coa_s_mobileflag = 0; while (i < linkarr.length ) { var lo = linkarr[i]; var loh = lo.getAttribute('src'); if ( loh != null ) { if ( loh.indexOf("/mobile") > -1 ) { // mobile coa_s_mobileflag = 1; } } ++i; } return coa_s_mobileflag; } function coa_s_count_dept() { var dval = coa_s_getdept(); if (dval == null) { return; } var cname = "surveydepts"; var dcountstring = coa_surveyreadcookie(cname); if ( dcountstring == null ) { dcountstring = ''; } var ds = dcountstring.split(':'); var i = 0; var found = 0; var newdstr = ''; while ( i < ds.length ) { var pair = ds[i].split('/'); var d = unescape(pair[0]); var v = parseInt(pair[1]); if ( d != '' ) { coa_s_pagecount += v; if ( d == 'SEARCH' ) { coa_s_searchcount = v; } if ( d == dval ) { var ncount = 1.0 + v; newdstr = newdstr.concat(escape(dval),'/',ncount,':'); found = 1; } else { newdstr = newdstr.concat(ds[i],':'); } } ++i; } if ( found < 1 ) { newdstr = newdstr.concat(escape(dval),'/',1,':'); } ++coa_s_pagecount; if ( dval == 'SEARCH' ) { ++coa_s_searchcount; } var nv = newdstr.substring(0,(newdstr.length - 1)); coa_surveymakecookie(cname,nv,null); } function coa_s_getdept() { // search results if ( document.getElementById('cse-search-box') != null ) { return 'SEARCH'; } // departmental RSS var linkarr = document.getElementsByTagName("link"); var i = 0; var ddir = null; while (i < linkarr.length ) { var lo = linkarr[i]; var loh = lo.getAttribute('href'); if ( loh != null ) { // home page if ( loh == '/RSS.aspx' ) { return 'HOME'; } var rpos = loh.lastIndexOf('/RSS.aspx'); if ( rpos > 1 ) { var ss = loh.substring(0,(rpos - 0)); var spos = ss.lastIndexOf('/'); if ( spos > -1 ) { return ss.substring((spos + 1),(ss.length + 1)); } } } ++i; } return ddir; } // http://www.webreference.com/programming/javascript/onloads/ function coa_s_addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } function coa_surveymakecookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else expires = ""; document.cookie = name+"="+value+expires+"; path=/; domain=.alexandriava.gov;"; } function coa_surveyreadcookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); var retval = null; for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) { retval = c.substring(nameEQ.length,c.length); } } return retval; } function coa_w3survey_showdiv() { coa_w3survey_showtab(); var hobj = document.getElementById("coa_s_header"); if ( hobj != null ) { //coa_surveymakecookie("surveyclosed","1",null); coa_s_toggle(); } } function coa_w3survey_showtab() { var tobj = document.getElementById("coa_s_outer"); if ( tobj == null ) { coa_s_makediv(); } } function coa_s_toggle() { var pobj = document.getElementById("coa_s_panel"); //if ( pobj.style.width == '1px' ) { //alert('toggle running'); if ( pobj.style.display == 'none' ) { //alert('toggle opening'); //pobj.style.width = coa_s_pwidth + 'px'; pobj.style.display = ''; coa_surveymakecookie("surveyclosed","0",90); var oobj = document.getElementById("coa_s_outer"); if ( coa_s_peight == '' ) { coa_s_peight = oobj.style.height; } oobj.style.height = ''; } else { //alert('toggle closing'); //pobj.style.width = '1px'; pobj.style.display = 'none'; coa_surveymakecookie("surveyclosed","1",90); var oobj = document.getElementById("coa_s_outer"); oobj.style.height = coa_s_peight; } } function coa_s_makediv() { var mbody = document.getElementById("coa_pageheader"); var ishome = 0; if ( mbody == null ) { mbody = document.getElementById("HomepageTabs").parentNode; ishome = 1; } if ( mbody == null ) { return; } // TODO: if mobile, do somthing else! // desktop page var clickcode = "coa_s_toggle();"; var headerhtml = "How can we improve our website? Take a survey and let us know."; if (navigator.appVersion.indexOf("MSIE 7.") != -1) { clickcode = ''; headerhtml = "" + headerhtml + ""; } // outer div var odiv = document.createElement('div'); odiv.setAttribute('id','coa_s_outer'); odiv.setAttribute('class','coa_s_outer_c'); var t2pheight = (coa_s_pheight + 43); ///odiv.style.height = t2pheight + 'px'; ///odiv.style.top = '25%'; ///odiv.style.left = '-5px'; ///odiv.style.width = '32px'; // make and add header div var hdiv = document.createElement('div'); hdiv.setAttribute('id','coa_s_header'); hdiv.setAttribute('class','coa_s_header_c'); if ( clickcode != '' ) { hdiv.setAttribute('onClick',clickcode); } //hdiv.style.left = "0px"; //hdiv.style.width = coa_s_hwidth + "px"; ///var tpheight = (coa_s_pheight - 5); ///hdiv.style.height = tpheight + "px"; //hdiv.style.top = coa_s_ptop + "px"; hdiv.innerHTML = headerhtml; odiv.appendChild(hdiv); // make and add panel div var pdiv = document.createElement('div'); pdiv.setAttribute('id','coa_s_panel'); pdiv.setAttribute('class','coa_s_panel_c'); //pdiv.style.left = coa_s_pleft + "px"; //pdiv.style.width = "1px"; // default collapsed pdiv.style.display = 'none'; //pdiv.style.height = coa_s_pheight + "px"; //pdiv.style.top = coa_s_ptop + "px"; odiv.appendChild(pdiv); // populate panel div var p1 = document.createElement('p'); p1.innerHTML = coa_s_p1; pdiv.appendChild(p1); var p2 = document.createElement('p'); p2.innerHTML = coa_s_p2; pdiv.appendChild(p2); // move the text over in the main well // insert in main page var fc = mbody.firstChild; if ( fc != null ) { mbody.insertBefore(odiv,fc); return; } mbody.appendChild(odiv); } function coa_s_set_stime() { var stimeName = "surveystime"; var stime = coa_surveyreadcookie(stimeName); var nobj = new Date(); var tt = parseInt(nobj.getTime() / 1000); if ( stime == null ) { coa_surveymakecookie(stimeName,tt,null); return; } // how long they've been here coa_s_dursecs = tt - parseInt(stime); } function coa_s_makelink() { // recalculate time spent on our site coa_s_set_stime(); var cname = "surveydepts"; var dcountstring = coa_surveyreadcookie(cname); var ism = coa_s_ismobile(); if ( dcountstring == null ) { dcountstring = ''; } var rguid = Math.floor(Math.random()*100000000000000001); var sglink = coa_s_sgurl + '?ckey=' + rguid + '&pagecount=' + coa_s_pagecount + '&searchcount=' + coa_s_searchcount + '×pent=' + coa_s_dursecs + '&dlist=' + escape(dcountstring) + '&ismob=' + ism; return sglink; } function coa_s_opensurvey() { var destpage = coa_s_makelink(); var sgwin = window.open(destpage,"SG_COA","width=950,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,copyhistory=no"); } function coa_w3survey() { // start time cookie coa_s_set_stime(); // dept count coa_s_count_dept(); // if persistent cookie says already taken survey, bail var alldone = coa_surveyreadcookie("surveytaken"); if ( alldone != null ) { return; } var chosenPhrase = "surveyoffered"; var chosen = coa_surveyreadcookie(chosenPhrase); // if cookie says has been chosen if ( chosen != null ) { // show tab var sclosed = coa_surveyreadcookie("surveyclosed"); if ( (sclosed != null) && (sclosed == '1') ) { coa_w3survey_showtab(); return; } coa_w3survey_showdiv(); // return return; } // roll the dice var rper = Math.random()*100; //alert(rper); if ( rper < coa_surveyPercentage ) { // if less than threshhold // set has been chosen cookie coa_surveymakecookie(chosenPhrase,"1",null); // show div coa_w3survey_showdiv(); } } coa_s_addLoadEvent(function() { coa_w3survey(); });