//// The Sky Blue Superplex //////
//////////////////////////////////
// Javascript Functions Library //
//////////////////////////////////


// Headline Maker //

function Init()
{
ScrollColor();
Linker();
}

function Linker()
{

// make sure ConstDomain is set in an ASP header somewhere //

if ((document.getElementsByTagName))
{
	for(i=0; (as = document.getElementsByTagName("a")[i]); i++) 
		{
			//host = as.getAttribute("hostname");
			host = as.hostname;
			if (!host.match(ConstDomain))
				{
					as.setAttribute("target","_blank");
				}
		}
}

}


function headline(cellid, tx)
{

if (document.getElementById(cellid) && navigator.appName == "Microsoft Internet Explorer")

  {
  text = ('<marquee width="376">' + tx + '</marquee>');
  }
else
  {
  text = (' ' + tx);
  }

eval ("document.getElementById('" + cellid + "').innerHTML = text");

}

//color scrollbars//
function ScrollColor()
{

if (document.getElementById)
 {
  document.body.style.scrollbarArrowColor = "#000080";
  document.body.style.scrollbarBaseColor = "#87CEEB";
 }
}

// Featured Link //

function RandomLink()
{

fl = new Array() 

fl[0] = '<a href="#news">Latest Headlines</a> - Keep up with recent news, rumours and results.'
fl[1] = '<a href="databank_stats.asp">Stats & Facts</a> - the most comprehensive CCFC statistics pages on the web.'
fl[2] = '<a href="archive_index.asp">The Sky Blue Superplex Archive</a> - news and features going back to 1997.'
fl[3] = '<a href="who_squad.asp">Who\'s Who</a> - check out the CCFC squad.'
fl[4] = '<a href="extra_songs.asp">The Hymn Sheet</a> - what we"re all singing on the terraces.'
fl[5] = '<a href="extra_vote.asp">Vote Results</a> - your take on the issues that matter.'
fl[6] = '<a href="databank_wait.asp">The Waiting Game</a> - our unique countdown clock.'
fl[7] = '<a href="databank_lockerroom.asp">The Locker Room</a> - Cov strips from days of yore.'
fl[8] = '<a href="cc-feat1.asp">A Tip from Bobby Moore</a> - Prizewinning novellist Graham Joyce writes for us.'
fl[9] = '<a href="databank_records.asp">Club Records</a> - more stats than you\'d care to shake a shit at.'

today = new Date(); 
v = Math.round((today.getSeconds() / 60) * (fl.length - 1)); 
document.write (fl[v]); 

}


// Image Randomiser //

function RandomAd() 

{
j = new Array() 

j[0] = 'cc-joke1.gif' 
j[1] = 'cc-joke2.gif' 
j[2] = 'cc-joke3.gif' 
j[3] = 'cc-joke4.gif' 
j[4] = 'cc-joke5.gif' 
j[5] = 'cc-joke1.gif'  

today = new Date(); 
v = Math.round((today.getSeconds() / 60) * (j.length - 1)); 
document.write("<img src="+(j[v])+" alt='A spoof advertisment'>"); 
} 


// pull page into frameset and redirect to news anchor if required //

function redirect(frame,anc)

{

return true;

//realpage = location.href; 
//notin = ((top.location.href.indexOf("index") == -1) && (top.location.href != "http://sbs.depro.co.uk/"))
//latest = (top.location.href.indexOf(anc) != -1)

//if (notin)
// {
  //eval ("top.location.href = 'index.asp?" + realpage + "&" + frame + "'");
// }
//else
// {
//  if (latest)
//   {
//    location.href='#news';
//   }
// }
}


//browser sniffer - popup//

function sniffer()
{
if (document.getElementById?0:1)
 {
  open("w3c.html", "error", "target=_blank,width=380,height=440,screenX=40,screenY=40"); 
 }
}

// Generic PopUp //

function OpenWnd(a) 
{ 
   wnd=window.open(a,"pic","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,title=yes,width=590,height=410,location=no"); 
} 

// Table writer and closer  //

function TableO(cls)

{
document.write ('<table class="' + cls + '">');
}

function TableC()

{
document.write ('</table>');
}


// Results by Opposition //

function WriteH(Header)
 {
  document.write 
  (
   '<tr></tr>',
   '<tr>',
    '<td colspan="26" class="statsh" style="border-top: 1px black solid; border-bottom: 1px black solid;">', Header, '</td>',  
   '</tr>',
   '<tr></tr>'  
  );
 }

function WriteT(TN, BN, PW, PD, PL, FW, FD, FL, OW, OD, OL, CW, CD, CL)
 {
  t = (Number(0).toFixed?1:0);

  PP = (PW + PD + PL);
  FP = (FW + FD + FL);
  OP = (OW + OD + OL);
  CP = (CW + CD + CL);
  TW = (PW + FW + OW);
  TD = (PD + FD + OD);
  TL = (PL + FL + OL);
  TP = (TW + TD + TL);

  if (!t) 
   {
    XW = (Math.round((TW / TP) * 100));
    XD = (Math.round((TD / TP) * 100));
    XL = (Math.round((TL / TP) * 100));
   }
  else
   {
    XW = (((TW / TP) * 100).toFixed(0));
    XD = (((TD / TP) * 100).toFixed(0));
    XL = (((TL / TP) * 100).toFixed(0));
   }

  if (PP >= 1)
   {
    if (!t)
     {
      PA = ((Math.round((((PW * 3) + PD) / PP)*100))/100);
     } 
    else
     {
      PA = ((((PW * 3) + PD) / PP).toFixed(2));
     }
   }
  else
   {
    PA = "0.00";
   }  
 
  if (FP >= 1)
   {
    if (!t)
     {
      FA = ((Math.round((((FW * 3) + FD) / FP)*100))/100);
     } 
    else
     {
      FA = ((((FW * 3) + FD) / FP).toFixed(2));
     }
    }
   else
    {
     FA = "0.00";
    }  

  if (OP >= 1)
   {
    if (!t)
     {
      OA = ((Math.round((((OW * 3) + OD) / OP)*100))/100);
     } 
    else
     {
      OA = ((((OW * 3) + OD) / OP).toFixed(2));
     }
   }
  else
   {
    OA = "0.00";
   }   

  if (TP >= 1)
   {
    if (!t)
     {
      TA = ((Math.round((((TW * 3) + TD) / TP)*100))/100);
     } 
    else
     {
      TA = ((((TW * 3) + TD) / TP).toFixed(2));
     }
   }
  else
   {
    TA = "0.00";
   }   


document.write (
'<tr align="right">',
  '<td><img width="45" height="45" class="bdr" src="images/badges/', BN, '.gif" alt="', TN, '" /></td>',
  '<td class="bold" align="center">', TN, '</td>',
  '<td style="color: navy;">', PP, '</td><td>', PW, '</td><td>', PD, '</td><td>', PL, '</td><td>', PA, '</td>',
  '<td class="bold" style="color: navy;">', FP, '</td><td class="bold">', FW, '</td><td class="bold">', FD, '</td><td class="bold">', FL, '</td><td class="bold">', FA, '</td>',
  '<td style="color: navy;">', OP, '</td><td>', OW, '</td><td>', OD, '</td><td>', OL, '</td><td>', OA, '</td>',  
  '<td class="bold" style="color: navy;">', TP, '</td><td><strong>', TW, '</strong><br />', XW, '%</td><td><strong>', TD, '</strong><br />', XD, '%</td><td><strong>', TL, '</strong><br />', XL, '%</td><td class="bold">', TA, '</td>',    
  '<td style="color: navy;">', CP, '</td><td>', CW, '</td><td>', CD, '</td><td>', CL, '</td>',  
'</tr>'  
);

}


// The Waiting Game //

function WGwriteH(header)
 {
  document.write ('<tr><td colspan="2" align="center">' + header + '</td></tr>');
 }

function WGwriteD(date, feat)
 { 
  diff = getDifference(date);
  if (totalDays >= 50)
   {
    document.write ('<tr><td nowrap="nowrap" align="right" class="c1">' + diff + '</td><td class="c2">' + feat + ' <span>(' + date + ')</span></td></tr>');
   }
 }

function getDifference(workDate)

{ 
var date1 = new Date(workDate);  // create date object with workDate
var date2 = new Date();          // create date object with todays date
var dateDiff = new Date();      // create date object
var sReturn = "";            // string to be returned
var milliDay = 86400000;         // 24 hours * 60 minutes * 60 seconds * 1000 milliseconds
date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate(), 0, 0, 0, 0); // force the hours, minutes, seconds, and milliseconds to 0
date2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate(), 0, 0, 0, 0); // force the hours, minutes, seconds, and milliseconds to 0
workDiff = Math.abs(date1.getTime() - date2.getTime()); 
totalDays = Math.floor(workDiff / milliDay);  // total number of days in range
workDays = totalDays;
workYears = Math.floor(totalDays / 365.25);   // count years, 1 year = 365.25 days
workDays -= Math.round(workYears * 365.25);  // remainder days left

if (workDays==365)
 { 
  workYears++;
  workDays = 0;
 }
if (workYears>0)
 {
  sReturn += workYears + " YEAR";
  sReturn += (workYears>1)?"S":"";
  sReturn += (workDays==0)?" EXACTLY":", ";
 }
if (workDays>0)
 {
  sReturn += workDays + " DAY";
  sReturn += (workDays>1)?"S":"";
 }
return sReturn;
}


function FrameMaker()

{

var str = location.search;
var pos = str.indexOf("&");

 if (pos != -1) 
  {
   var num = str.substring(pos + 1, str.length);
   window["ar" + num] = str.substring(1, pos);
  }

document.write(
'<frameset rows="76,*" cols="100%" border="0" frameborder="0" framespacing="0">',
  '<frame name="top" src="', ar0, '"  marginheight="0" marginwidth="0" scrolling="no" noresize="noresize" />',
    '<frameset rows="100%" cols="124,*" border="0" frameborder="0" framespacing="0">',
      '<frame name="lh" src="', ar1, '"  marginheight="0" marginwidth="0" scrolling="no" noresize="noresize" />',
      '<frame name="sbs" src="', ar2, '"  marginheight="0" marginwidth="0" scrolling="auto" noresize="noresize" />',
    '</frameset>',
'</frameset>'
);

}

// League Table //

function WriteL(tm, po, w, d, l, f, a, pt)
{

if (tm != 'header')
 {
  p = (w + d + l);
  gdu = (f - a);
  if (gdu == 0)
   {
    gd = '=';
   }
  else if (gdu > 0)
   {
    gd = '+' + gdu;
   }
  else
   {
    gd = gdu;
   }
  if (tm == 'Coventry City')
   {
    document.write ('<tr class="bold">')
   } 
  else
   {
    document.write ('<tr>'); 
   }
 
  document.write (
  '<td class="pos">', po, '</td><td class="tm">', tm, '</td><td>', p, '</td><td>', w, '</td><td>', d, '</td><td>', l, '</td><td>', f, '</td><td>', a, '</td><td>', gd, '</td><td>', pt, '</td></tr>');

 }
else
 {
  document.write (
  '<tr class="hd"><td> </td><td class="tm">Team</td><td>Pld</td><td>W</td><td>D</td><td>L</td><td>F</td><td>A</td><td>+/-</td><td>Pts</td></tr>');
 }  

}

// Vote Results //

function WriteV(da, tx, r1, n1, r2, n2, r3, n3, r4, n4, r5, n5)
{

b1 = (Math.floor(n1));
b2 = (Math.floor(n2));
b3 = (Math.floor(n3));
b4 = (Math.floor(n4));
b5 = (Math.floor(n5));

document.write ('<div class="voteresults">');

document.write (
'<div>' + da + '</div>',
'<div><strong>' + tx + '</strong></div>'
);

if (n1 == "")
{
document.write (
'<div>',
' (Poll still open for voting) ',
'</div>'
);
}

else

{

document.write (
'<table>',
      '<tr><td class="bold">', r1, '</td>',    
         '<td><div class="pollbar" style="background-color: red; width: ', b1, 'px"></div> </td><td> ', n1, '&nbsp;%</td></tr>'
  );      

if (n2 != "")
{
  document.write ( 
      '<tr><td class="bold">', r2, '</td>',    
         '<td><div class="pollbar" style="background-color: orange; width: ', b2, 'px"></div> </td><td> ', n2, '&nbsp;%</td></tr>'
  );      
}

if (n3 != "")
{
  document.write ( 
      '<tr><td class="bold">', r3, '</td>',    
         '<td><div class="pollbar" style="background-color: yellow; width: ', b3, 'px"></div> </td><td> ', n3, '&nbsp;%</td></tr>'
  );      
}


if (n4 != "")
{
  document.write ( 
       '<tr><td class="bold">', r4, '</td>',    
         '<td><div class="pollbar" style="background-color: green; width: ', b4, 'px"></div> </td><td> ', n4, ' %</td></tr>'
    );      
}


if (n5 != "")
{
  document.write ( 
      '<tr><td class="bold">', r5, '</td>',    
        '<td><div class="pollbar" style="background-color: blue; width: ', b5, 'px"></div> </td><td> ', n5, ' %</td></tr>'
   );      
}

document.write ('</table>');

}


document.write ('</div>');


}



// Who's Who //

function WriteProfile(no, im, nm, po, nk, an, db, sd, sc, sf, dd, dc, df, ht, wt, nt, is, bi, li)
{

if (dd != "")
{
ifgone = 
'<strong>DEPARTED: </strong> ' + dd + '<br />' + '<strong>MOVED TO: </strong> ' + dc + ' <strong><em> for</em></strong> ' + df + '<br />';
no = "EX";
}
else
{
ifgone = "";
}

document.write(

'<div class="ww">',
'<span class="wwno">', no, '</span>',
'<span class="wwname">', nm, '</span>',
'<div class="wwpro" style="width: 360px;">',
'<div>',
'<span style="color: navy">',
bi,
'</span>',
'<br /><br /><br /><strong>* LITTLE-KNOWN PLAYER FACT: </strong>', li,
'</div></div>',
'<div class="wwf">&nbsp;</div>',
'<div class="wwpro" style="width: 274px;">',
'<div>',
'<img align="right" src="cc-sq-', im, '.jpg" alt="', nm, '" />',
'<strong>POSITION:</strong> ', po, '<br />',
'<strong>NICKNAMES: </strong> ', nk, '<br />',
'<strong>ANAGRAM: </strong> ', an, '<br />',
'<strong>DATE OF BIRTH: </strong> ', db, '<br />',
'<strong>DATE SIGNED: </strong> ', sd, '<br />',
'<strong>SIGNED FROM: </strong> ', sc, ' <strong><em> for</em></strong> ', sf, '<br />', ifgone,
'<strong>HEIGHT: </strong> ', ht, '<br />',
'<strong>WEIGHT: </strong> ', wt, '<br />',
'<strong>COUNTRY: </strong> ', nt, ' (', is, ')<br />',
'</div></div>',
'</div>'

); 

}

// Links //

function lnk(url, tit, txt, img, rat)
{
document.write ('<table align="center" width="97%" border="0" cellpadding="2" cellspacing="0" class="simple">');
document.write ('<tr><td><a href="http:/' + '/' + url + '" class="link2">' + tit + '</a></td>');

if (img != "null")
 {
  document.write ('<td rowspan="3"><img src="' + img + '" alt="' + tit + '" /></td>');
 }
document.write ('</tr>');
document.write ('<tr><td>' + txt + '</td></tr>');

if (rat != "null")
 {
  document.write ('<tr><td class="bold">SBS STAR RATING: ' + rat + '</td></tr>');
 }
document.write ('</table>');
document.write ('<br />');
}

function sh(header)
{
document.write ('<br />');
document.write ('<a name="' + header + '"></a><span style="vertical-align: top;" class="big"><img src="links.gif" alt="links"> <strong>' + header + '</strong></span>');
document.write ('<br /><br />');
}

// Image Preloader //

function IMGpreload(IMG) 

{ 
var a=new Image(); 
a.src=IMG; 
return a; 
}


// Image Swappers //

function IMGon(nm)

{
eval ("document['" + nm + "'].src=" + nm + "_on.src");
document.getElementById('lnavmenu').style.backgroundColor='#eeeeee';
}

function IMGoff(nm)
{
eval ("document['" + nm + "'].src=" + nm + "_off.src");
document.getElementById('lnavmenu').style.backgroundColor='#ffffff';
}



function lockerchange(number,season,strip)
{
if (number == "seasonall")
{
	for (i=1;i<=display;i++)
	{
	eval("document.forms.lockerroom.season" + i + ".selectedIndex = (document.forms.lockerroom.seasonall.selectedIndex)");
eval("document.forms.lockerroom.season" + i + ".focus()");
	}
document.body.focus();	
}

else if (number == "stripall")
{
	for (i=1;i<=display;i++)
	{
	eval("document.forms.lockerroom.strip" + i + ".selectedIndex = (document.forms.lockerroom.stripall.selectedIndex)");
eval("document.forms.lockerroom.strip" + i + ".focus()");
	}
document.body.focus();	
}

else
{
	filestring = "viewstrip.asp?strip=" + strip + "&season=" + season;
	stripstring = eval("'kit" + number + "'");
	document.getElementById(stripstring).setAttribute("src",filestring);
}


			
}

