function show(id_on,id_off) {
  if (document.getElementById) {
    var returnOnVar = document.getElementById(id_on); 
    var returnOffVar = document.getElementById(id_off); 
  } else if (document.all) {
    var returnOnVar = document.all[id_on]; 
    var returnOffVar = document.all[id_on]; 
  } else if (document.layers) {
    var returnOnVar = document.layers[id_on]; 
    var returnOffVar = document.layers[id_on]; 
  }
  returnOnVar.style.visibility = 'visible';
  returnOnVar.style.display = 'block';
  returnOffVar.style.visibility = 'hidden';
  returnOffVar.style.display = 'none';
}

// Change Frame
function ChangeFrame(frameName,url) {
  if (parent.parent.document.getElementById(frameName)) {
	var x = WEB_HOME; //"??";
	var tt = '['+parent.parent.document.getElementById(frameName).src+']';
	if (tt != '[]') {
	   var test = parent.parent.document.getElementById(frameName).src;
   	   test = test.replace(x,"");
    } else {
	   var test = "[]";
	}

	if (frameName == 'hf_bs_pref' || frameName == 'hf_bs_help' || frameName == 'hf_accounts') {
	  if (test != url || test == "[]") {
	    parent.parent.document.getElementById(frameName).src = url;
      }
    } else {
	  parent.parent.document.getElementById(frameName).src = url;
    }
  }
  
  /*if (frameName == "bs_main") {
	if (url.indexOf("/horses/card") != -1) parent.show_options('panel_notepad','panel_notepad_off');
	else parent.show_options('panel_notepad_off','panel_notepad');
  }*/
  return;
}

function ChangeLock(inForm) {
  var Status = document.forms[inForm]["status"].value;
  var Img = document.images[inForm].src;
  if (Status == "open") {
	 document.forms[inForm]["status"].value = "closed";
	 Img = Img.replace('open','closed');
	 document.images[inForm].src = Img;
  } else {
	 document.forms[inForm]["status"].value = "open";
	 Img = Img.replace('closed','open');
	 document.images[inForm].src = Img;
  }
}

function ChangeTipCom(RaceID) {
  //ChangeMyNotepad(RaceID);

  if (eval(parent.parent.frames['hf_bs_tip'].document.forms[0])) {
    var PanelTipStatus = parent.parent.frames['hf_bs_tip'].document.forms["tip_lock"]["status"].value;
    if (PanelTipStatus != 'closed') {
      CurrentUrl = parent.parent.document.getElementById('hf_bs_tip').src;
      TipUrl = WEB_HOME+'/horses/tipping_update.sd?race_id='+RaceID;
      if (CurrentUrl != TipUrl) ChangeFrame('hf_bs_tip',TipUrl);
    }
  }
	
  if (eval(parent.parent.frames['hf_bs_tip'].document.forms[0])) {
    var PanelCommStatus = parent.parent.frames['hf_bs_text'].document.forms["comm_lock"]["status"].value;
    if (PanelCommStatus != 'closed') {
	  CurrentUrl = parent.parent.document.getElementById('hf_bs_text').src;
      CommUrl = WEB_HOME+'/horses/race_commentary.sd?race_id='+RaceID+'&size=small';
      if (CurrentUrl != CommUrl) ChangeFrame('hf_bs_text',CommUrl);
    }
  }
}

function ChangeMyNotepad(RaceID) {
	//alert('ChangeMyNotepad: '+RaceID);
	//parent.parent.frames['my_notepad'].NewPad(RaceID);
	NewPad(RaceID);
}

function NewPad(RaceID) {
	// Runs from Notepad Panel
	//alert('NewPad');
	
	parent.show_options('panel_notepad','panel_notepad_off');
	
	//if (typeof parent.parent.frames['my_notepad'].document.forms[0]!= 'undefined') alert('1');
	//else alert('2');
	if (eval(parent.parent.frames['my_notepad'].document.forms[0])) CurrentRaceID = parent.parent.frames['my_notepad'].document.forms[0]["notes_race_id"].value;
	else CurrentRaceID = -1;
	//alert('CurrentRaceID= '+CurrentRaceID);
	
	// Check to see if we have any unsaved changes if so save them
	if (CurrentRaceID != -1) {
      //alert('CheckForChanges');
  
      //alert('No. of forms = '+parent.parent.frames['my_notepad'].document.forms.length);
      //alert(parent.parent.frames['my_notepad'].document.forms[0].modified_yn.value);
	  var NotesModified = parent.parent.frames['my_notepad'].document.forms[0]["modified_yn"].value;
	  if (NotesModified == 'Y') {
	    // Save unsaved changes
	    parent.parent.frames['my_notepad'].document.forms[0]["race_id"].value = RaceID;
	    parent.parent.frames['my_notepad'].document.forms[0].submit();
	    return;
      }
	}
	//return;
	
	if (eval(parent.parent.frames['bs_main'].document.race)) CardRaceID = parent.parent.frames['bs_main'].document.race.race_id.value;
	else CardRaceID = -1;
	//alert('fred');
	//alert(CardRaceID);
	// Show My Notepad Panel
	if (CardRaceID != -1) parent.show_options('panel_notepad','panel_notepad_off');

	//alert('(1) CurrentRaceID='+CurrentRaceID+'\nCardRaceID='+CardRaceID);
	CurrentUrl = parent.parent.document.getElementById('my_notepad').src;
	NewUrl = WEB_RP_HOME+'/horses/my_notepad_panel.sd?source=TBS&race_id='+CardRaceID;
	//alert('(2) CurrentUrl:'+CurrentUrl+'\n'+CurrentRaceID+'\n'+CardRaceID);
	if (CurrentRaceID != -1) {
	  //alert('(3) CardRaceID='+CardRaceID+'\nNewUrl'+NewUrl);
      if (CardRaceID == -1) parent.parent.frames['my_notepad'].location = WEB_RP_HOME+'/horses/my_notepad_panel.sd';
	  else if (CurrentRaceID != CardRaceID) parent.parent.frames['my_notepad'].location = NewUrl;
      /* Check to see if Main frame is a card, if so use race_id */
    } else {
	  //alert('(4) RaceID='+RaceID+'\nCurrentRaceID='+CurrentRaceID);
	  if (RaceID == 0 || (CurrentRaceID == -1 && RaceID > 0) )  parent.parent.frames['my_notepad'].location = NewUrl;
    }
}

function OWSize(window_name,NewLink,width,height,menubar,resize,scroll) {
  var myWindow = window.open(NewLink, window_name, "menubar="+menubar+",location=no,toolbar=no,resizable="+resize+",scrollbars="+scroll+",status=0,width="+width+",height="+height);
}

function OSWSize(window_name,NewLink,width,height,menubar,resize,scroll) {
  var myWindow = window.open(NewLink, window_name, "menubar="+menubar+",location=yes,toolbar=yes,resizable="+resize+",scrollbars="+scroll+",status=1,width="+width+",height="+height);
}

function OWPrint(window_name,NewLink,width,height,menubar,resize,scroll) {
  var myWindow = window.open(NewLink, window_name, "menubar="+menubar+",location=no,toolbar=no,resizable="+resize+",scrollbars="+scroll+",status=0,width=5,height=5");
  myWindow.blur(); 
  myWindow.moveTo(screen.width,screen.height);
}

function mo(msg) {
   window.status=msg;
   return true;	
}

// Void
function linkvoid() {
	return;
}

var clockID = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var tDate = new Date();
   var m = tDate.getMinutes();
   if (m < 10) m = '0'+m;

   document.getElementById('curr_time').innerHTML = "" 
                                   + tDate.getHours() + ":" 
                                   + m ;
   
   clockID = setTimeout("UpdateClock()", 30000);
}
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

function showCol(ReqCol,ReqPB_id,ReqOutcome_id,ReqHorseArray) {
  //alert(ReqCol+","+ReqPB_id+","+ReqOutcome_id);
  var UserCol = MN_req_cols[(ReqCol+1)];
  var ColType = MN_cols_id[UserCol];
  //document.write("<font color='#00FF00'>["+UserCol+"]["+ColType+"]</font><BR>");
  
  if (ColType == "b") {
	//alert(UserCol);
    var ReqSpan = 'p_'+ReqPB_id+'_'+ReqOutcome_id;
    //alert(ReqSpan);
    //var NewSpan = "p_"+ReqPB_id+"_"+ReqOutcome_id+"_"+MN_bookmaker_ids[UserCol];
    var NewSpan = "p_"+ReqPB_id+"_"+ReqOutcome_id+"_"+MN_bookmaker_ids[UserCol];
    document.write("<span id='"+NewSpan+"'></span>");
    //document.getElementById(ReqSpan).id=NewSpan;
    //document.write("<font color='#FF0000'>["+ReqCol+"]["+MN_bookmaker_ids[UserCol]+"]["+NewSpan+"]</font><BR>");
    //document.write("<font color='#FF0000'>["+MN_bookmaker_ids[UserCol]+"]</font><BR>");
  } else {
    //ReqSpan = 'MN_'+ReqRaceId+'_'+ReqHorseId;
    //alert(ReqSpan);
    //alert(MN_cols[UserCol]);
    if (MN_cols[UserCol]=="My Odds") {
	  if (typeof ReqHorseArray[2] != 'undefined' && ReqHorseArray != 'null') document.write(ReqHorseArray[2]+"X");
    } else { 
      document.write("<font color='#0000FF'>["+ReqSpan+"]</font><BR>");
    }
  }
}

// Change Frame
function ChangeCard(f_column,f_value) {
	//var x = "<?=$GLOBALS["WEB_HOME"]?>";
	//alert('TBS BETA');
  if (top.frames['bs_main']) {
	var x = WEB_HOME; //"??";
	var tt = new String('['+top.frames['bs_main'].location+']');

	var MainUrl = new String(top.frames['bs_main'].location.href);
	var OldUrl = MainUrl;
	if (OldUrl.indexOf("card") == -1) var OldUrl = new String(top.frames['bs_pref'].location.href);
	
   	NewUrl = new String(OldUrl); //.replace(x,"");

	if (f_column == "view") {
	   if (NewUrl.indexOf("card_choice") != -1) {
	     NewUrl = NewUrl.replace("card_choice=customised","card_choice=").replace("card_choice=odds","card_choice=");
	     NewUrl = NewUrl.replace("card_choice=","card_choice="+f_value);
       } else { 
         NewUrl = NewUrl+"&card_choice="+f_value;
       }
	} else if (f_column == "ratings") {
	   if (NewUrl.indexOf("ratings") != -1) {
	     NewUrl = NewUrl.replace("ratings=mono","ratings=").replace("ratings=rpr","ratings=").replace("ratings=ts","ratings=");
	     NewUrl = NewUrl.replace("ratings=","ratings="+f_value);
       } else { 
         NewUrl = NewUrl+"&ratings="+f_value;
       }
	} else if (f_column == "odds") {
	   if (NewUrl.indexOf("odds") != -1) {
	     NewUrl = NewUrl.replace("odds=Decs","odds=").replace("odds=Frac","odds=");
	     NewUrl = NewUrl.replace("odds=","odds="+f_value);
       } else { 
         NewUrl = NewUrl+"&odds="+f_value;
       }
	} else if (f_column == "bookmakers") {
	  NewUrl = NewUrl.replace("card_choice=customised","card_choice=").replace("card_choice=odds","card_choice=");
	  NewUrl = NewUrl.replace("ratings=mono","ratings=").replace("ratings=rpr","ratings=").replace("ratings=ts","ratings=");
	  NewUrl = NewUrl.replace("odds=Decs","odds=").replace("odds=Frac","odds=");
	  OldUrl = ""; // Force refresh of card
	}

	
	// Change tick box
 	ButtonClicked(f_column,f_value);  
	
 	// If not displaying a card return
	if (MainUrl.indexOf("card") == -1) {
	  if (NewUrl.indexOf("card_preferences") == -1) {
		NewUrl = NewUrl.replace(".sd&",".sd?");
		this.location.href = NewUrl;
	  }
	} else if (NewUrl != OldUrl || NewUrl == "[]") top.frames['bs_main'].location.href = NewUrl;
    	
  }
  return;
}

function ButtonClicked(prefix,button_on) {
    var tabOff = "0";
    var tabOn = "1";
	
	// Change start and end images
    for (i=0; i<document.getElementsByTagName('img').length; i++) {
      var theImg = (document.getElementsByTagName('img')[i]);
      //alert(theImg.id+", "+theImg.id.length);
	  if (theImg.id.length > 3) {
	    if (theImg.id.substring(0,prefix.length) == prefix) {
		  TestPos = theImg.id.indexOf(button_on);
		  if (TestPos > -1) {
			  theImg.src = theImg.src.replace(tabOff,tabOn);
	      } else if (theImg.src.indexOf(tabOn) > -1) {
			  theImg.src = theImg.src.replace(tabOn,tabOff);
		  }
        }
      }
    }
    
    return;
}

//var panel_settings=[];

function show_options(id_on,id_off) {
  if (document.getElementById) {
    var returnOnVar = document.getElementById(id_on); 
    var returnOffVar = document.getElementById(id_off); 
  } else if (document.all) {
    var returnOnVar = document.all[id_on]; 
    var returnOffVar = document.all[id_off]; 
  } else if (document.layers) {
    var returnOnVar = document.layers[id_on]; 
    var returnOffVar = document.layers[id_off]; 
  }
  
  if (typeof returnOnVar != 'undefined' && returnOnVar != null) {
    returnOnVar.style.visibility = 'visible';
    returnOnVar.style.display = 'block';
    returnOffVar.style.visibility = 'hidden';
    returnOffVar.style.display = 'none';
  }
/*
   // P Cos: 
   // Figure out whether a user's panel preferences need to be updated in the cust_info DB 
   var x;
   
   if(typeof getCookie == 'function') { 
      x = getCookie("RP_UID"); 
   } else {
	  x==null;
   }

   if (x!=null) {
      var curVal;
      var ignoreChange = 'N';
   
      //insert into (or update value in) panel_settings array
      if (id_on.indexOf('_selection') > -1) {
	     var panel_name;
	     panel_name = id_on.substring(0,id_on.indexOf('_selection'));
	  
	     curVal = panel_settings[panel_name];
	  
	     if (curVal==null || curVal=='close') {
	        panel_settings[panel_name] = 'open';
         } else {
	        //already has value of 'open' so don't modify DB
	        ignoreChange='Y';
         }
      } else {
	     curVal = panel_settings[id_on];
	  
   	     if (curVal==null || curVal=='open') {
	        panel_settings[id_on] = 'close';
         } else {
	        //already has value of 'close' so don't modify DB
	        ignoreChange='Y';
         }
      }

      // This "if clause" avoids the db being updated when the panels
      // are first adjusted after the user logs in
      if (ignoreChange != 'Y' && id_on != 'video_free_selection' && id_on != 'video_free' && id_on != 'vid_avail' && id_on != 'vid_not_avail') {
  	     requestSave();
      }
   }*/
}

// ChangeLink
function ChangeLink(link_id) {
	for (i=0; i<document.getElementsByTagName('a').length; i++) {
		var theLink = (document.getElementsByTagName('a')[i]);
		if (theLink.id.substring(0,link_id.length) == link_id) {
     	  theLink.style.color = "#FF0000";
          theLink.style.fontWeight = "bold";
        } else if (theLink.id.substring(0,4) == "LID_") {
          theLink.style.color = "#041B5D";
          theLink.style.fontWeight = "normal";
        }
	}
	return;
}

function sendClick(priceboxID, bookieID, outcomeID, price, sport, pageRef, userID, userName) {
	var req;
	var URL = priceboxID + "&" +
	bookieID + "&" + 
	outcomeID + "&" +
	price + "&" +
	sport + "&" +
	screen.availWidth + "&" +	// screen W
	screen.availHeight + "&" +	// screen H
	pageRef + "&" +
	"A&" +
	"JavaScript" + "&" +	// Technology is JavaScript
	navigator.userAgent + "&" +
	"1.0&" +
	userID + "&" +
	userName;
	//alert (URL);

	URL = URL.replace(/ /g, "%20");
	URL = "/applet?9," + URL.length + "," + URL;
	
	try { req = new XMLHttpRequest();}
	catch (e)
	{
		try { req = new ActiveXObject('MSXML2.XMLHTTP'); }
		catch (e)
		{
			try { req = new ActiveXObject('Microsoft.XMLHTTP'); }
			catch (e) {	}
		}
	}
	req.open("POST", URL, false);
	req.onreadystatechange = function() {}; 
	req.send("");
}

function removeBG(obj) {
	obj.style.backgroundImage="url('/images/furniture/blank.gif')";
}
function hideHL(obj) {
	obj.style.background="#FFFFFF";
}
function showHL(obj) {
	obj.style.background="#D9E8F3";
}

function show_welcome() {
  var winW = 630, winH = 460;

  if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    winW = window.innerWidth;
    winH = window.innerHeight;
   }
   if (navigator.appName.indexOf("Microsoft")!=-1) {
    winW = document.body.offsetWidth;
    winH = document.body.offsetHeight;
   }
  }
  
  if (document.getElementById) {
    var returnOnVar = document.getElementById('weclome'); 
  } else if (document.all) {
    var returnOnVar = document.all['weclome']; 
  } else if (document.layers) {
    var returnOnVar = document.layers['weclome']; 
  }
  returnOnVar.style.display = 'block';
  returnOnVar.style.left = ((winW-540)/2);
  returnOnVar.style.top = ((winH-310)/2);

}

function hide_welcome(){
  if (document.getElementById) {
    var returnOnVar = document.getElementById('weclome'); 
  } else if (document.all) {
    var returnOnVar = document.all['weclome']; 
  } else if (document.layers) {
    var returnOnVar = document.layers['weclome']; 
  }
  returnOnVar.style.display = 'none';
}
