<!--
function autoUnderlineLink(num){
/* *** Auto Select First Anchor Link *** */
var subMenu = document.getElementById("menuBar"); 
	if (subMenu!=null){
	var subLinkList = subMenu.getElementsByTagName("a"); 
		subLinkList[num].style.textDecoration = 'underline';
	}
}
/*********** Start Scroller Text Script ****************/
var delayb4scroll=3000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit=1 //Pause marquee onMousever (0=no. 1=yes)?
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''
function scrollmarquee(){
	if (parseInt(cross_marquee1.style.top)>(actualheight*(-1)+8)){
		cross_marquee1.style.top=parseInt(cross_marquee1.style.top)-copyspeed+"px";
	} else {
		cross_marquee1.style.top=parseInt(marqueeheight)+8+"px";
	}
/*
	if (parseInt(cross_marquee2.style.top)>(actualheight*(-1)+8)){
		cross_marquee2.style.top=parseInt(cross_marquee2.style.top)-copyspeed+"px";
	} else {
		cross_marquee2.style.top=parseInt(marqueeheight)+8+"px";
	}
*/
}
function initializemarquee(){
cross_marquee1=document.getElementById("vmarquee1");
cross_marquee1.style.top=0;
/*
cross_marquee2=document.getElementById("vmarquee2");
cross_marquee2.style.top=0;
*/
marqueeheight=document.getElementById("MarqueeContainer1").offsetHeight;
actualheight=cross_marquee1.offsetHeight;
/*
marqueeheight=document.getElementById("MarqueeContainer2").offsetHeight;
actualheight=cross_marquee2.offsetHeight;
*/
if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
cross_marquee1.style.height=marqueeheight+"px"
cross_marquee1.style.overflow="scroll"
/*
cross_marquee2.style.height=marqueeheight+"px"
cross_marquee2.style.overflow="scroll"
*/
return
}
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}
/***********  End Scroller Text ****************/
// Decode Popup Information
function decodeString(myStr){
	document.open();
	document.write(decodeURIComponent(myStr));
	document.close();
}
// Encode Popup Information
function encodeMyParms(id, p_ml, p_dt, p_hn, p_an, p_hmr, p_amr, p_hl, p_al){
	pParameters = "";
	pParameters += id + "&";
	pParameters += "p_ml=" + encodeURIComponent(p_ml) + "&";
	pParameters += "p_dt=" + p_dt + "&";
	pParameters += "p_hn=" + encodeURIComponent(p_hn) + "&";
	pParameters += "p_an=" + encodeURIComponent(p_an) + "&";
	pParameters += "p_hmr=" + p_hmr + "&";
	pParameters += "p_amr=" + p_amr + "&";
	pParameters += "p_hl=" + encodeURIComponent(p_hl) + "&";
	pParameters += "p_al=" + encodeURIComponent(p_al) + "";
	return  pParameters;
}
function G2W_login_submit(myLang){
	var detectCookies = navigator.cookieEnabled;
	if(myLang == 'tc'){
		document.loginForm.lang.value = 'tc';
		if (detectCookies != true){
			alert("阁下的要求不适合，因为您的浏览器Cookies设置为无效，请于您的浏览器设置上把Cookies设为有效");
		}
	} else if(myLang == 'sc'){
		document.loginForm.lang.value = 'sc';
		if (detectCookies != true){
			alert("阁下的要求不适合，因为您的浏览器Cookies设置为无效，请于您的浏览器设置上把Cookies设为有效");
		}
	}
	document.loginForm.encodedname.value=encodeURIComponent(document.loginForm.username.value);
	document.loginForm.submit();
}
function setBrowserLanguage(lang){
	var cookiesValue = getCookie('bfindexBrowserLan');
	var broswerLan = '';
	var bfindexsc = 'sc/';
	var bfindextc = 'tc/';
	if (cookiesValue==null){
		// if cookies not found, run below. Detect browser type & browser language then save to cookies.
		//alert("no cookies found, do auto detect now");
		if(navigator.appName == "Microsoft Internet Explorer"){
			var IELan = window.navigator.browserLanguage;
			if (IELan == "zh-tw" || lang =="tc"){ broswerLan = "tc"; window.location.href = bfindextc;
			}else if (IELan == "zh-cn" || lang =="sc"){ broswerLan = "sc"; window.location.href = bfindexsc;
			}else {	broswerLan = "sc"; window.location.href = bfindexsc;}
		}else if(navigator.appName == "Netscape"){
			var FFLan = window.navigator.language;
			if (FFLan == "zh-TW" || lang =="tc"){ broswerLan = "tc";window.location.href = bfindextc;
			}else if (FFLan == "zh-CN" || lang =="sc"){ broswerLan = "sc"; window.location.href = bfindexsc;
			}else {	broswerLan = "sc"; window.location.href = bfindexsc;}
		}else{ broswerLan = "sc"; window.location.href = bfindexsc}
		setCookie('bfindexBrowserLan', broswerLan, "999", "/", "bfindex.com"); // save cookies
	}else{
		broswerLan = lang;
		setCookie('bfindexBrowserLan', broswerLan, "999", "/", "bfindex.com"); // save cookies				
	}
}
function setBrowserLanguageRedirect(){
	var cookiesValue = getCookie('bfindexBrowserLan');
		if(cookiesValue== "tc"){
			window.location.href = bfindextc;
		}else if(cookiesValue== "sc"){
			window.location.href = bfindexsc;
		}
}
function ChangeLanguage(inlang){
	var inurl = self.location.href;
        var num;
        num = inurl.indexOf("#");
        if (num>-1) inurl = inurl.substr(0,num);

        if (inlang=='tc') inurl = inurl.replace("/sc/","/tc/");
        else if (inlang=='sc') inurl = inurl.replace("/tc/","/sc/");
        else inurl = inurl.replace("/sc/","/en/");
        self.location.href=inurl;
}
function openBrWindow(theURL,winName) { //v2.0
  window.open(theURL,winName,'scrollbars=yes,resizable=yes,width=794,height=560');
}

function myExtUrl(extUrl,  lang){
	var myContentWin = window.open('','','scrollbars=yes,resizable=yes,width=695,height=520');
	myContentWin.document.open();
	myContentWin.document.write('<html><HEAD><TITLE>bfindex.com</TITLE>');
	myContentWin.document.write('<META http-equiv=Content-Type content="text/html; charset={}"></head>');
	myContentWin.document.write('<LINK href="/templates/bfindex_cht/css/contentstyle.css" type=text/css rel=stylesheet>');
	myContentWin.document.write('<body>');
	myContentWin.document.write('<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" class="popupContent">');
	myContentWin.document.write('<tr><td><iframe src="' + extUrl + '" scrolling="auto" width="100%" height="504" marginwidth="0" marginheight="0" frameborder="0" align="default"></iframe></td></tr>');
	myContentWin.document.write('</table>');
	myContentWin.document.write('</body></html>');
	myContentWin.document.close();
}

/*
function betfairStUrl(url, homeSel, awaySel, drawSel){
        var myContentWin = window.open('','','scrollbars=yes,resizable=yes,width=695,height=520');
        myContentWin.document.open();
        myContentWin.document.write('<html><HEAD><TITLE>bfindex.com</TITLE>');
        myContentWin.document.write('<META http-equiv=Content-Type content="text/html; charset={}"></head>');
        myContentWin.document.write('<LINK href="/templates/bfindex_cht/css/contentstyle.css" type=text/css rel=stylesheet>');
        myContentWin.document.write('<body>');
        myContentWin.document.write('<a href="#">按上中下排列</a>|<a href="#">按左中右排列</a>');
        myContentWin.document.write('<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" class="popupContent">');
        myContentWin.document.write('<tr><td><iframe src="' + url + "&selectionId=" + homeSel + '" scrolling="auto" width="100%" height="504" marginwidth="0" marginheight="0" frameborder="0" align="default"></iframe></td></tr>');
        myContentWin.document.write('</table>');
	if(drawSel!=""){
	myContentWin.document.write('<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" class="popupContent">');
	myContentWin.document.write('<tr><td><iframe src="' + url + "&selectionId=" + drawSel + '" scrolling="auto" width="100%" height="504" marginwidth="0" marginheight="0" frameborder="0" align="default"></iframe></td></tr>');
	myContentWin.document.write('</table>');
	}

        myContentWin.document.write('<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" class="popupContent">');
        myContentWin.document.write('<tr><td><iframe src="' + url + "&selectionId=" + awaySel + '" scrolling="auto" width="100%" height="504" marginwidth="0" marginheight="0" frameborder="0" align="default"></iframe></td></tr>');
        myContentWin.document.write('</table>');

        myContentWin.document.write('</body></html>');
        myContentWin.document.close();
}
*/
function myContentPage(inUrl){
	var myContentWin = window.open(inUrl,"CONTENT",'scrollbars=yes,resizable=yes,width=669,height=640');
}
/*********** Functions for clear/fill text field handling ****************/
function clearUserName(){
	document.loginForm.username.value = "";
}
function fillUserName(){
 if(document.loginForm.username.value == ""){
 	document.loginForm.username.value = document.loginForm.username.title;
 }
}
function clearPassword(){
	document.getElementById('password').type = 'password';
	document.loginForm.password.value = "";
}
function fillPassword(){
 if(document.loginForm.password.value == ""){
	document.getElementById('password').type = 'text';
	document.loginForm.password.value = document.loginForm.password.title;
 }
}
/***********  Start Cookies below ****************/
var cookiescriptloaded = true;
function setCookie(name, value, days, path, domain, secure) {
if(days){
	var expires = new Date();
	expires.setTime(expires.getTime()+(days*24*60*60*1000)); 
} else {
	expires = null;
}
  var curCookie = name + "=" + value +
     ((expires) ? "; expires=" + expires.toGMTString() : "") +
     ((path) ? "; path=" + path : "") +
     ((domain) ? "; domain=" + domain : "") +
     ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
   begin = dc.indexOf(prefix);
   if (begin != 0) return null;
  } else
   begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
   end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
   document.cookie = name + "=" +
   ((path) ? "; path=" + path : "") +
   ((domain) ? "; domain=" + domain : "") +
   "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
/* Smooth scrolling */
var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
    ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },
  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;
    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;
    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }
    // Stop any current scrolling
    clearInterval(ss.INTERVAL);
    cypos = ss.getCurrentYPos();
    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },
  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      location.hash = anchor;
    }
  },
  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },
  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  } 
}
ss.STEPS = 25;
ss.addEvent(window,"load",ss.fixAllLinks);

function returnDomain(){
	// This is for changing the object into string, otherwise will failed in match()
        var str = " " + window.location + " ";
	// This is to remove http:// because the regex found the first . that won't work if no subdomain is use.
	str = str.substr(8,str.length);
        var regex = /[^.]*\.com/;
        var myDomain = str.match(regex);
	return myDomain;
}

