// AFC library functions
// Written by Richard Shea and Lee Tindell for Millini (www.millini.co.uk)

// Quick browser mouseover detection.
var MouseOv=0
if (navigator.appName.indexOf("Netscape") != -1 && parseFloat(navigator.appVersion) >= 3.00){MouseOv=1;}
if (navigator.appName.indexOf("Microsoft") != -1 && parseFloat(navigator.appVersion) >= 4.00){MouseOv=1;}

// Variable names required: Iloc = Image Location (i.e. 'images/nav/'), Ext = Extension (i.e. '.gif')
Rloc=''; Iloc='images/'; Ext='.gif'; Numx='x'; Stateon='_on'; Stateoff='_off';

/////////////// RELATIVE LOCATION OF IMAGES FOLDER ////////////////
Rloc = '/'
if (self.document.location.href.indexOf('/cgi-bin/')!=-1){Rloc = '../../../'}
Iloc = Rloc+Iloc;


// popup function.
function OpenWin(URL,x,y,width,height){
	setTimeout("window.open('"+URL+"','Kiln','height="+height+",width="+width+",top="+y+",left="+x+",screenY="+y+",screenX="+x+",alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=0,status=0,titlebar=0,toolbar=0,z-lock=0')",1);
}

// This function opens up windows in the centre of the screen using function above.
function MidWin(URL,width,height){
	var x = 400, y = 300;
	if (document.all || document.layers) {
        x= (screen.width - width) / 2;
        y= (screen.height - height) / 2;
	}
	OpenWin(URL,x,y,width,height)
}
////////////////// GENERAL MOUSEOVER FUNCTIONS ///////////////////
i = "0"
function MouseON(Num,Srs){
	if (MouseOv){document.images[Num].src = Iloc+document.images[Num].name+Stateon+Ext;}
	if (Srs == null){Srs = document.images[Num].alt}
	window.status=Srs;
}
function MouseOFF(Num){
	if (MouseOv){
		if (Num != Numx){document.images[Num].src = Iloc+document.images[Num].name+Stateoff+Ext;}
		}
	window.status="";
}
function ImageOn(){
	MouseCLICK(ImgOn)
}
function MouseStick(Num){
	if (MouseOv){document.images[Num].src = Iloc+document.images[Num].name+'_on'+Ext; Numx = Num}
	window.status="";
}


function makeArray0() {
     for (i = 0; i<makeArray0.arguments.length; i++)
          this[i] = makeArray0.arguments[i];
}

var days = new makeArray0("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var months = new makeArray0('Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sept','Oct','Nov','Dec');
function nths(day) {
     if (day == 1 || day == 21 || day == 31)
          return 'st';
     else
          if (day == 2 || day == 22)
               return 'nd';
               if (day == 3 || day == 23)
                    return 'rd';
               else return 'th';
}
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

var date = new Date();
var today = days[date.getDay()] + ' ' +
    date.getDate() + nths(date.getDate()) + " " +
    months[date.getMonth()] + " " + (y2k(date.getYear()));
var BasicDate = date.getDate()+nths(date.getDate())+" " +months[date.getMonth()]+" "+(y2k(date.getYear()))

// sldate variable is of dd/mm/yyyy format with preceding zeros if <10
slMon=date.getMonth()+1*1
if (slMon <10){slMon="0"+(date.getMonth()+1*1)}
slDat=date.getDate()
if (slDat <10){slDat="0"+date.getDate()}
var sldate = slDat+"/"+slMon+"/"+y2k(date.getYear())

// Replaces text with by in string //////////////////////////////////////
function Replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += Replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
} // End Replace function
/////////////////////////////////////////////////////////////
function CompanyEmail(Dept){
	for (i=0; i<dept.length; i++){
		if (dept[i][01] == Dept){
			Pic = '';
			MailName = dept[i][02]
			MailTo = dept[i][03]
			Title = ''; Dept = ''; Box = '';
			Action = 'Company';
		}
	}
	EmailWindow('../loading.html');
} // end Email function
function GetBod(Bod){
	// Now call the user in question which gets the info...
	for (i=0; i<user.length; i++){
		if (user[i][01] == Bod){
			Pic = user[i][01]
			MailName = user[i][02]
			MailTo = user[i][03]
			Title = user[i][04]
			Dept = user[i][05]
			Box = user[i][06]
			Action = '';
		}
	}
} // end Email function
function Email(Bod){
	GetBod(Bod);
	EmailWindow('../loading.html');
} // end Email function
function EmailWindow(URL){
	Point=1;
	if (top.screen) {
		if (screen.width >=800){var Point=20;}
		if (screen.width >=1024){var Point=40;}
	}
	setTimeout("window.open('"+URL+"','Emailer','height=440,width=415,top="+Point+",left="+Point+",screenY="+Point+",screenX="+Point+",alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,z-lock=0')",1);
} // end EmailWindow function

function LivePopUp(Laction, player_id, fixture_id){
	URL = "liveaction.php?Laction=" + Laction + "&player_id=" + player_id + "&fixture_id=" + fixture_id;;
	
	Point=1;
	if (top.screen) {
		if (screen.width >=800){var Point=20;}
		if (screen.width >=1024){var Point=40;}
	}
	setTimeout("window.open('"+URL+"','LiveAction','height=200,width=200,top="+Point+",left="+Point+",screenY="+Point+",screenX="+Point+",alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,z-lock=0')",1);
} // end EmailWindow function


/////////////////////////////////////////////////////////////
// Function to higlight text boxes, uses obj=Ojbect name, bg=#BackGround Colour, bc=#BorderColour
function MarkMe(obj,bg,bc) {
	blurred=false;
    if (obj.style.backgroundColor == "")
	{
	   if (obj.value == "(optional)"){obj.value=''}
	   obj.style.backgroundColor = bg;
	   obj.style.borderColor = bc;
	}
    else {
    	obj.style.backgroundColor = "";
		obj.style.borderColor = "";
	}
}
function Disable()
{
	// for IE 4.0+
	if (document.all)
	{
		document.all.Submit.setAttribute("disabled", true);
		document.all.Submit.value="Submitting...";
		document.all.Submit.style.borderColor = "#FF0000";
		document.all.Submit.style.backgroundColor = "#FFFFFF";
		//document.all.login.submit();
	}
}
/////////////////////////////////////////////////////////////
function SearchValidate(){
validated = false;
if (document.Search.terms.value == ''){
	alert('Please enter a keyword to search');
	return false;}
	else {validated = true}
if (validated){return true};
}
/////////////////////////////////////////////////////////////
// Print page function - does not work in Netscape (what does!)
function PrintPage(){
if (navigator.appName.indexOf("Netscape") != -1){alert("Sorry, Netscape does not offer the option to print this way,\nplease use your printer option from the browser itself.")}
bg=document.body.background
bgc=document.body.bgColor
document.body.background='';
document.bgColor='#FFFFFF';
window.print();
document.body.background=bg;
document.bgColor=bgc
}

function BookMark(){
if ((navigator.appVersion.indexOf("MSIE") > 0)&& (parseInt(navigator.appVersion) >= 4)){window.external.AddFavorite(self.document.location.href, document.title);}
else {alert('why not bookmark this web site?')}
}


/////////////////////////////////////////////////////////////
function rnd() {
		rnd.today=new Date();
		rnd.seed=rnd.today.getTime();
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};
function rand(number) {
        return Math.ceil(rnd()*number);
};
/////////////////////////////////////////////////////////////




function setCaretToEnd (el) {
  if (el.createTextRange) {
    var v = el.value;
    var r = el.createTextRange();
    r.moveStart('character', v.length);
    r.select();
  }
}

function markSelection ( txtObj ) {
 if ( txtObj.createTextRange ) {
   txtObj.caretPos = document.selection.createRange().duplicate();
   isSelected = true;
 }
}
function insertTag ( txtName, tag, enclose ) {
 var closeTag = tag;
 if ( enclose ) {
   var attribSplit = tag.indexOf ( ' ' );
   if ( tag.indexOf ( ' ' ) > -1 )
     closeTag = tag.substring ( 0, attribSplit );
 }
 if ( isSelected ) {
   var txtObj = eval ( "document.AFCnews." + txtName );
   if (txtObj.createTextRange && txtObj.caretPos) {
     var caretPos = txtObj.caretPos;
     if (caretPos.text.indexOf(tag) != -1){
     	Rtext = Replace(caretPos.text,"</"+tag+">",'<null>');
     	Rtext = Replace(Rtext,"<"+tag+">",'<null>');
     	Rtext = Replace(Rtext,"<null>",'');
     	caretPos.text = Rtext
     	return true;
     	}
     caretPos.text = ( ( enclose ) ? "<"+tag+">"+caretPos.text+"</"+closeTag+">" : "<"+tag+">"+caretPos.text );
     markSelection ( txtObj );
     if ( txtObj.caretPos.text=='' ) {
       isSelected=false;
    txtObj.focus();
     }
   }
 } else {
   // placeholder for loss of focus handler
 }
}

