var server = 'www.theadvertiser.com';
var strTestServer = 'theadvertiser.newsweaver.net';
var strRedirectionURL = 'http:\/\/www.theadvertiser.com/customerservice/html/01650E9C-777F-4146-91EC-BAB8D3EFE114.shtml';
gnsSite = 'theadvertiser';
var Site='LALAFELN';
var USATAffilCode= 'tda';
function jStech (elink)  {
	document.location = document.affils.cgiurl.value + "techwrapper.pl?URL=http://www.gannettonline.com/e/" + elink + "&AFFIL=" + document.affils.affil.value;
}

var y=1;	//used to count through available stories
var printedstories_array=new Array;
var printedrelatedlinks_array=new Array;

//Get the current file name so that we don't use it in the story list
arrayOfpath = document.location.pathname.split("/");
arrayOffile = arrayOfpath[arrayOfpath.length-1].split(".");
printedstories_array[0]=(arrayOffile[0]);

function PrintPrimaryIntroduction(story_array,quantity){
  var x=0;	//used to count through printed stories
  //Check for Server Location
  //If the links are displaying on a site other than www.publicationdamain.com, link to www.publicationdamain.com
  if (location.href.indexOf(strTestServer) != -1){
    serverurl='http://'+strTestServer+'/'+story_array[story_array.length-1][0];
  }
  else {
    serverurl='http://'+server+'/'+story_array[story_array.length-1][0];
  }

  //Set default quantity if not passed
  if (!quantity>0){
    quantity = story_array.length;
  }

  //Go through the array and display the necessary stories
  for (var i=0; i<(story_array.length-1); i++){
    storyprinted=false
    for (var z=0; z<printedstories_array.length; z++){
      if (printedstories_array[z]==story_array[i][3]){
        storyprinted=true;
      }
    }
    if (storyprinted==false){
      if ((x<=quantity-1) && (!story_array[i][1]=='') && (story_array[i][4])){
        document.write('  <div class=introductionheadline><a href="'+serverurl+'/html/'+story_array[i][3]+'.shtml">'+story_array[i][0]+'</a></div>');
        document.write('  <div class=introductioncontent>');
        if (!story_array[i][5]==""){
          document.write('<img src="/newsweaverincludes/photos/introductions/'+story_array[i][5]+'.jpg" &  border="0" align="right" alt="">');
        }
        document.write(story_array[i][4]+'<a class="fullstorylink" href="'+serverurl+'/html/'+story_array[i][3]+'.shtml"> ... Full Story</a><br clear=all><hr>');
        document.write('  </div>');
        x++;
        printedstories_array[y]=(story_array[i][3]);
        y++;
      }
    }
  }
}



function PrintSecondaryIntroduction(story_array,quantity){
  var x=0;	//used to count through printed stories
  //Check for Server Location
  //If the links are displaying on a site other than www.publicationdamain.com, link to www.publicationdamain.com
  if (location.href.indexOf(strTestServer) != -1){
    serverurl='http://'+strTestServer+'/'+story_array[story_array.length-1][0];
  }
  else {
    serverurl='http://'+server+'/'+story_array[story_array.length-1][0];
  }

  //Set default quantity if not passed
  if (!quantity>0){
    quantity = story_array.length;
  }

  //Go through the array and display the necessary stories
  for (var i=0; i<(story_array.length-1); i++){
    storyprinted=false
    for (var z=0; z<printedstories_array.length; z++){
      if (printedstories_array[z]==story_array[i][3]){
        storyprinted=true;
      }
    }
    if (storyprinted==false){
      if ((x<=quantity-1) && (!story_array[i][1]=='') && (story_array[i][4])){
        document.write('  <div class=introductionheadlineS><a href="'+serverurl+'/html/'+story_array[i][3]+'.shtml">'+story_array[i][0]+'</a></div>');
        document.write('  <div class=introductioncontentS>');
        if (!story_array[i][5]==""){
          document.write('<img src="/newsweaverincludes/photos/specialintroductions/'+story_array[i][5]+'.gif" &  border="0" align="right" alt="">');
        }
        document.write(story_array[i][4]+'<a class="fullstorylink" href="'+serverurl+'/html/'+story_array[i][3]+'.shtml"> ... Full Story</a><br clear=all><hr>');
        document.write('  </div>');
        x++;
        printedstories_array[y]=(story_array[i][3]);
        y++;
      }
    }
  }
}


function PrintStoryList(story_array,quantity,startingposition,showdates,displayarchive,sortorder,header,footer){
  if (story_array.length>1){
    var x=0;	//used to count through printed stories
    var printedheader=false;
	var displayarchivedate;
    //Check for Server Location
    //If the links are displaying on a site other than www.publicationdamain.com and publicationdomain.newsweaver.net
    if (location.href.indexOf(strTestServer) != -1){
      serverurl='http://'+strTestServer+'/'+story_array[story_array.length-1][0];
    }
    else {
      serverurl='http://'+server+'/'+story_array[story_array.length-1][0];
    }

    //Set defaults if not passed
    if (!quantity>0){
      quantity = story_array.length;
    }
    if (!startingposition>0){
      startingposition = 1;
    }
    if ((displayarchive=='false') || (displayarchive==false) && (!displayarchive=='')){
      displayarchivedate=story_array[0][1];
      displayarchive=false;
     }
    else {
      displayarchivedate=story_array[story_array.length-2][1];
      displayarchive=true;
    }
    if (sortorder=='rank'){
      SortArray(story_array,story_array.length-1,2)
    }
    if (sortorder=='alpha'){
      SortArray(story_array,story_array.length-1,0)
    }
    
    //Go through the array and display the necessary stories
    for (var i=0; i<(story_array.length-1); i++){
      if (i>=startingposition-1){

      storyprinted=false
      for (var z=0; z<printedstories_array.length; z++){
        if (printedstories_array[z]==story_array[i][3]){
          storyprinted=true;
        }
      }
      if (storyprinted==false){
        if ((x<=quantity-1) && (Math.abs(story_array[i][1])>=Math.abs(displayarchivedate)) && (!story_array[i][2]=="")){
          //Print the header if so requested
          if (!printedheader==true){
            if ((header=="") || (header=="true") || (!header)){
              document.write('<br><b>More '+story_array[story_array.length-1][1]+' Headlines</b><br>');
              printedheader=true;
            }
            else if (header=="false"){
              //We do nothing
            }
            else{
              document.write('<br><b>'+header+'</b><br>');
              printedheader=true;
            }
          }
          document.write('<b class="bullet">'+PublicationBullet+' </b><a href="'+serverurl+'/html/'+story_array[i][3]+'.shtml">'+story_array[i][0]+'</a>');
          if ((showdates==true) || (showdates=='true')) {
            document.write('&nbsp;<span class=publicationdate>'+story_array[i][1].substr(4,2)+'/'+story_array[i][1].substr(6,2)+'/'+story_array[i][1].substr(0,4)+'</span>');
          }
          document.write('<br>');
          printedstories_array[y]=(story_array[i][3]);
          x++;
          y++;
        }
      }
      }
    }

    //Print the footer if so requested
    if (x>0){
      if ((footer=="") || (footer=="true") || (!footer)){
        document.write('<b class="bullet">'+PublicationBullet+'<a href="'+serverurl+'/archive.shtml"> '+story_array[story_array.length-1][1]+' Archive</b></a><br>');
        printedheader=true;
      }
      else if (footer=="false"){
        //We do nothing
      }
      else{
        document.write('<b class="bullet">'+PublicationBullet+'<a href="'+serverurl+'/archive.shtml"> '+footer+'</b></a>');
        printedheader=true;
      }
    }
  }
}

function PrintRelatedLinks(storyrelatedlinks_array,sectionrelatedlinks_array,header){
  var x=0;	//used to count through printed links
  var printedheader=false;

  if (storyrelatedlinks_array.length>=0){
    //Go through the array and display the necessary links
    for (var i=0; i<(storyrelatedlinks_array.length); i++){
      linkprinted=false
      for (var z=0; z<printedrelatedlinks_array.length; z++){
        if (printedrelatedlinks_array[z]==storyrelatedlinks_array[i][1]){
          linkprinted=true;
        }
      }
      if (linkprinted==false){
        //Print the header if so requested
        if (!printedheader==true){
          if ((header=="") || (!header)){
            document.write('<b>'+sectionrelatedlinksheader+'</b><br>');
            printedheader=true;
          }
          else{
            document.write('<b>'+header+'</b><br>');
            printedheader=true;
          }
        }
        document.write('<b class="bullet">'+PublicationBullet+' </b><a href="'+storyrelatedlinks_array[i][1]+'" target=blank>'+storyrelatedlinks_array[i][0]+'</a><br>');
        printedrelatedlinks_array[y]=(storyrelatedlinks_array[i][1]);
        x++;
        y++;
      }
    }
  }
  if (sectionrelatedlinks_array.length>=0){
    //Go through the array and display the necessary links
    for (var i=0; i<(sectionrelatedlinks_array.length); i++){
      linkprinted=false
      for (var z=0; z<printedrelatedlinks_array.length; z++){
        if (printedrelatedlinks_array[z]==sectionrelatedlinks_array[i][1]){
          linkprinted=true;
        }
      }
      if (linkprinted==false){
        //Print the header if so requested
        if (!printedheader==true){
          if ((header=="") || (!header)){
            document.write('<b>'+sectionrelatedlinksheader+'</b><br>');
            printedheader=true;
          }
          else{
            document.write('<b>'+header+'</b><br>');
            printedheader=true;
          }
        }
        document.write('<b class="bullet">'+PublicationBullet+' </b><a href="'+sectionrelatedlinks_array[i][1]+'" target=blank>'+sectionrelatedlinks_array[i][0]+'</a><br>');
        printedrelatedlinks_array[y]=(sectionrelatedlinks_array[i][1]);
        x++;
        y++;
      }
    }
  }
  if (z>0){
    document.write('<br>')
  }
}


function isDigit (c) {
  return ((c >= "0") && (c <= "9"))
}

function SortArray(arrayName,length,element) {
  for (var h=0; h<(length-1); h++){
    for (var j=h+1; j<length; j++){
      if (arrayName[j][element] < arrayName[h][element]) {
        var dummy = arrayName[h];
        arrayName[h] = arrayName[j];
        arrayName[j] = dummy;
      }
    }
  }
}

