// Coyote's YourWay JS

var cookieflag,unitcode,warnflag ;

function updatepages() {
//Change mail addy to Juno and adds formmail link both with subject from title (&dash; replaced)
subj='Re: '+document.getElementsByTagName("title")[0].innerHTML.replace(/[\u2011-\u2015]/g,"-").replace(/-+/g,"-")+
      ' (ASSTR)' ;
mail='<a href="mailto:YLeeCoyote@juno.com?subject='+subj+'">YLeeCoyote@juno.com</a>' ;
form='&nbsp;&nbsp;&nbsp;&nbsp; <a href="Formmail.htm?'+subj+'">Anon Form Mail</a> ' ;
document.getElementById("yw").innerHTML=document.getElementById("yw").innerHTML.
  replace(/Your comments are appreciated.*?<\/a>/gi,'Your comments are appreciated.&nbsp; '+mail+form).
  replace(/<a href=.mailto.y.*?<\/a>/gi,mail ) ;  }

function yourwaysetup()  {
updatepages() ;
yourwaysetup1() ; }

// Extracts the 'your way' parameters from the cookie and loads them
function yourwaysetup1() {
var i,j,k,cnt,item,data,cookiedata,end,cookies,inx ;

cookies = new String(document.cookie) ;                    //get the cookie data
cookiestart=cookies.indexOf("CoyoteDenWay") ;
cookieflag=false ;
unitcode="English" ;                                       //defaults
document.getElementById("yw").style.marginLeft="5%" ;
document.getElementById("yw").style.marginRight="5%" ;
if (cookiestart>-1) {                                      //have a cookie - use it
end=cookies.indexOf(";",cookiestart) ;
if (end< 0) end=cookies.length ;
cookiedata=cookies.substring(cookiestart,end) ;                                 
cookieflag=true ;

j=cookiedata.indexOf('=',1) ; k=cookiedata.indexOf(',',j) ;
cookieVersion=cookiedata.substring(j+1,k) ;
warnflag=(cookieVersion==1)? true : false ;

i=cookiedata.indexOf('background') ;
if (i>-1) {j=cookiedata.indexOf('#',i) ; k=cookiedata.indexOf(',',j) ;
  document.getElementById("yw").style.backgroundColor=cookiedata.substring(j,k) ; }
i=cookiedata.indexOf('color') ;
if (i>-1) {j=cookiedata.indexOf('#',i) ; k=cookiedata.indexOf(',',j) ;
  document.getElementById("yw").style.color=cookiedata.substring(j,k); }
i=cookiedata.indexOf('side') ;
if (i>-1) {j=cookiedata.indexOf('#',i) ; k=cookiedata.indexOf(',',j) ;
  document.getElementById("body").style.backgroundColor=cookiedata.substring(j,k); }
i=cookiedata.indexOf('link') ; csflag1=false ;
if (i>-1) {j=cookiedata.indexOf('#',i) ; k=cookiedata.indexOf(',',j) ;
  cslink=cookiedata.substring(j,k) ; csflag1=true ;}
i=cookiedata.indexOf('linkbg') ; csflag2=false ;
if (i>-1) {j=cookiedata.indexOf('#',i) ; k=cookiedata.indexOf(',',j) ;
  cslinkbg=cookiedata.substring(j,k) ; csflag2=true ;}
i=cookiedata.indexOf('linkv') ; csflag3=false ;
if (i>-1) {j=cookiedata.indexOf('#',i) ; k=cookiedata.indexOf(',',j);
  cslinkv=cookiedata.substring(j,k) ; csflag3=true ;}
i=cookiedata.indexOf('linkvbg') ; csflag4=false;
if (i>-1) {j=cookiedata.indexOf('#',i) ; k=cookiedata.indexOf(',',j);
  cslinkvbg=cookiedata.substring(j,k) ; csflag4=true ;}
if (csflag1 || csflag2 || csflag3 || csflag4 ) modRule()  ;              //if any link's colors altered -- apply 'em
i=cookiedata.indexOf('margin');
if (i>-1) {j=cookiedata.indexOf('=',i) ; k=cookiedata.indexOf(',',j);
  document.getElementById("yw").style.marginLeft=cookiedata.substring(j+1,k);
  document.getElementById("yw").style.marginRight=cookiedata.substring(j+1,k);
  document.getElementById("yw").style.padding="1em" ;}
i=cookiedata.indexOf('width');
if (i>-1) {j=cookiedata.indexOf('=',i) ; k=cookiedata.indexOf(',',j);
  document.getElementById("yw").style.width=cookiedata.substring(j+1,k);
  document.getElementById("yw").style.margin="auto";
  document.getElementById("yw").style.padding="1em" ;}
i=cookiedata.indexOf('fontSize') ;
if (i>-1) {j=cookiedata.indexOf('=',i) ; k=cookiedata.indexOf(',',j) ;
  document.getElementById("body").style.fontSize=cookiedata.substring(j+1,k) ;}
i=cookiedata.indexOf('fontFamily') ;
if (i>-1) {j=cookiedata.indexOf('=',i) ; k=cookiedata.indexOf(',',j);
  document.getElementById("body").style.fontFamily=
    (warnflag)? cookiedata.substring(j+2,k-1) : cookiedata.substring(j+1,k) ;}
i=cookiedata.indexOf('unitcode') ;
if (i>-1) {j=cookiedata.indexOf('=',i) ; k=cookiedata.indexOf(',',j) ;
  unitcode=cookiedata.substring(j+1,k) ; } 
  }

//Insert hit counter
if (document.getElementById("body").innerHTML.indexOf("www.statcounter.com")===-1) {
  document.getElementById("body").innerHTML+='<img src="http://c.statcounter.com/7657356/0/02f0dfe5/1/" alt="">' ;}
 }

// Need this to change css for links
function modRule() {
  var thecss = new Array();
  cslinka=((csflag1)? "color:"+cslink+";" : "" ) + ((csflag2)? "background:"+cslinkbg : "") ;
  cslinkb=((csflag3)? "color:"+cslinkv+";" : "" ) + ((csflag4)?"background:"+cslinkvbg : "") ;
  thecss= (document.styleSheets[0].cssRules) ? document.styleSheets[0].cssRules : document.styleSheets[0].rules ; 
  for (i=0;i<thecss.length;i++) {
    if((csflag1 || csflag2)) {
      if (thecss[i].selectorText.toLowerCase()=='a:link') {thecss[i].style.cssText=cslinka ;}
      if (thecss[i].selectorText.toLowerCase()=='.a') {thecss[i].style.cssText="text-decoration:underline;"+cslinka ;}   }
    if((csflag3 || csflag4)) {if (thecss[i].selectorText.toLowerCase()=='a:visited') {thecss[i].style.cssText=cslinkb ;} }  } }

// Special entry from direct.htm to warn users about those still using version=1
var message="The YOUR WAY program has been enhanced with additional options that control link displays.  Please click OK to go to it now and update your selections.  (This message will appear each time you come to the this directory page until you rewrite your cookie.)" ;
function yourwaysetup2() {
yourwaysetup1()  ;                                       // the normal stuff first
if (warnflag) {if (window.confirm (message)) {window.location="yourway.htm" ; } } }

// Toggle between two sets of measurements
function unit(count,show,hide) {
 for (j=0;j<count;j++) {
  document.getElementById(show+j).style.display="inline" ;
  document.getElementById(hide+j).style.display="none"  ; }  }

// Used only to initial unit selection when yourway not used
function setunit(cnt) {
document.getElementById('unitsw').style.display='inline' ;
for (j=1;j<cnt;j++) {
 document.getElementById('fuj'+j).style.display='none' ;
 document.getElementById('nuj'+j).style.display='none' ; }
unit(cnt,'euj','muj') ; }


// Setup for unit selection
// display:id of span with button
// count: number of fields to deal with
// eng,met: english,metric unit id's (0-count)
// parl,parr: (,) used when both are displayed (1-count)
// #5 is #3 without doing the e-mail addy change
function yourwaysetup3(display,count,eng,met,parl,parr)    {
updatepages() ;
yourwaysetup5(display,count,eng,met,parl,parr) ;}

function yourwaysetup5(display,count,eng,met,parl,parr)  {
 yourwaysetup1() ;
 document.getElementById(display).style.display="inline"  ;     //show the control
 for (j=1;j<count;j++) {                                        //hide the ( )
  document.getElementById(parl+j).style.display="none" ;
  document.getElementById(parr+j).style.display="none" ;  }
 unitcode=="metric" ?  unit(count,met,eng) : unit(count,eng,met) ; } //show one

// Simpler version used for interactive pages
// #6 is #4 without doing the e-mail addy change
function yourwaysetup4(display,count,eng,met)    {
updatepages() ;
yourwaysetup6(display,count,eng,met); }

function yourwaysetup6(display,count,eng,met)  {
 yourwaysetup();
 document.getElementById(display).style.display="inline" ;      //show the control
 unitcode=="metric" ?  unit(count,met,eng) : unit(count,eng,met) ; } //show one

//Name changing routines (three)
function NameChangerShow() {
 document.getElementById("firstbutton").className="xhide" ;
 document.getElementById("formqw").className="" ;
 for (j=0;j<namecnt;j++){document.getElementById("name"+j).value=curname[j] ;} }

function NameChangeAct() {
for (j=0;j<namecnt;j++) {
  asd=document.getElementById("name"+j).value ;
  document.getElementById("story").innerHTML=
    document.getElementById("story").innerHTML.replace(RegExp("\\b"+curname[j]+"\\b","g"),asd) ;
  curname[j]=asd ;}
document.getElementById("formqw").className="xhide" ;
document.getElementById("firstbutton").className="litbut" ;}

function NameVerify(arg) {
asd=document.getElementById("name"+arg).value ;
if(asd!="") {
  asd=asd.replace(/\s+/g,"") ;                       //no white space
  if (asd==asd.replace(/\W|\d/g,"")) {              //no non-alpha
    asd=asd.substr(0,1).toUpperCase()+asd.substr(1).toLowerCase() ;
    if (curname[arg]==asd || document.getElementById("story").innerHTML.search((RegExp("\\b"+asd+"\\b","")))==-1 ) {   //in use ?
      document.getElementById("name"+arg).value=asd ;}
    else {
     window.alert ("Name already in use - input ignored") ;
     document.getElementById("name"+arg).value=curname[arg] ;} }
  else {
   window.alert ("Only alphabetical characters allowed - input ignored") ;
   document.getElementById("name"+arg).value=curname[arg] ;} }
 else {
  window.alert ("Input is null - input ignored") ;
  document.getElementById("name"+arg).value=curname[arg]; }   }
//End name changer routines

//Last modified 08:53:11 PM Mon, Feb 13 2012
//&copy; (c) Copyright A.I.L., 2008 - 2012



