// JavaScript Document

// Hide / Show Account
function hideAccountbar() {
    document.getElementById('balance').style.display = "none";
    document.getElementById('balancehide').style.display = "block";
    document.cookie = "IASBetBalance=hide;path=/"; 
}
    
function showAccountbar() {
    document.getElementById("balance").style.display = "block";
    document.getElementById('balancehide').style.display = "none";
    document.cookie = "IASBetBalance=show;path=/";
}

function SetAccountBarMode() {
   
		var show;
		var pos = document.cookie.indexOf("IASBetBalance=");
		if (pos == -1)
		    show = true;
		else {
		    pos = document.cookie.indexOf("IASBetBalance=show", pos)
		    if (pos == -1)
		        show = false;
		    else
		        show = true;
		}

		if (show) {
		    showAccountbar();
		}
		else {
		    hideAccountbar();
    }
}

function CheckLoggedInlnk(){
   
	var balanceElement = document.getElementById("balance_switch");
	
	if (balanceElement != null)
	{
		return true;		
	}else{
		LoginRequired();
		return false;
	}
}


function CheckLoggedInDownloadLnk(){

	var balanceElement = document.getElementById("balance_switch");
	
	if (balanceElement != null)
	{
		return true;		
	}else{
		LoginRegisterRequired();
		return false;
	}
}



// Jockey / Fluc / Trainers
function hideRaceInfo()
{
    var RaceInfo = document.getElementById('race');
    RaceInfo.style.display = "none";    
}

function showRaceInfo()
{
    var RaceInfo = document.getElementById("race");
    RaceInfo.style.display = "block";
}
    

//function for href jump using drop-down list box.
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//function is for the feedback popup off the left hand menu.
function OpenFeedBack()
{
	newWindow = window.open("/site/help/Feedback.htm","Feedback","height=305,width=350,scrollbars=no");
	newWindow.focus()
}

function PopupCasinoFlash()
{
	newWindow = window.open("/site/casino/instant-play-popup.aspx","Casino","height=570,width=440,scrollbars=no");
	newWindow.focus()
}

function PopupPreviewMsg()
{
	newWindow = window.open("/images/en/misc/popups/preview-popup.gif","Preview","height=564,width=458,scrollbars=no");
	newWindow.focus()
}


function OpenLiveChat()
{
  newWindow = window.open('http://server.iad.liveperson.net/hc/83179417/?cmd=file&file=visitorWantsToChat&site=83179417&referrer='+document.location,'chat83179417','width=472,height=320');
  return false;
}

//call this function and passing a Static HTML Resource name to have
//a little pop-up help screen
function OpenPopup( Key )
{
	newWindow = window.open("/site/help/helppopup.aspx?ContentKey=" + Key,"Info","height=172,width=290,scrollbars=yes");
	newWindow.focus()
}

//call this function and passing a Static HTML Resource name to have
//a size defined pop-up help screen
function OpenPopupBigger( Key, Height, Width )
{
	newWindow = window.open("/site/help/helppopup.aspx?ContentKey=" + Key,"Info","height=" + Height + ",width=" + Width + ",scrollbars=yes");
	newWindow.focus()
}

function OpenExternalPopup(url, height, width)
{
	newWindow = window.open(url,"Info","height=" + height + ",width=" + width + ",scrollbars=yes");
	newWindow.focus()
}

//call this function and passing a Static HTML Resource name to have
//a little pop-up help screen
function OpenDemo( Key )
{
	newWindow = window.open("/Demo/" + Key,"IASTutorial","scrollbars=yes,resizable=yes,width=656,height=480");
	newWindow.focus()
}

function OpenPopUpWindow(theURL, winName, features)
{
  newWindow = window.open(theURL, winName, features);
  newWindow.focus();
}


function OpenTutorial()
{
	newWindow = window.open("/demo/horse_tutorial.htm","IASTutorial","scrollbars=yes,width=656,height=480");
	newWindow.focus()
}

function OpenCanbetTutorial()
{
	newWindow = window.open("/demo/canbet_demo.htm","Tutorial","scrollbars=yes,width=656,height=480;resizable=yes;");
	newWindow.focus()
}

function ensurePayIn(curr)
{
 	newWindow = window.open("/MyAccount/ensurePay/PayIn.aspx?currency=" + curr,"EnsurePay","height=480,width=520,scrollbars=yes");
	newWindow.focus()
}

function NoBetAllowed() {
  //alert(GENERAL_Script.Global_MustLogin);
  ShowLoginPopup();
  return false;
} 


function LoginRequired() {
    //alert(GENERAL_Script.Global_LoginBeforeAccessing);
    ShowLoginPopup();
  return false;
}

function LoginRegisterRequired() {
  alert(GENERAL_Script.Global_LoginRegisterBeforeAccessing);
  return false;
}

function PreviewOnly() {
  alert(GENERAL_Script.Global_FunctionNotActivated);
  return false;
} 



function NoEnter() {
  return !(window.event && window.event.keyCode == 13);
}


// image rollovers

function changeImages(img_name,img_src) {
	document[img_name].src=img_src;
}


function IsInArray(sString, aArray) {
  var iLoop;
  var bRet = false;
  for (iLoop = 0; iLoop < aArray.length; iLoop++) {
    if (aArray[iLoop] == sString) {
      bRet = true;
      break;
    }
  }
  return bRet;
}

function SafeSetValue(NodeId, Value) {
  var node = document.getElementById(NodeId);
  if (node != null) {
    node.value = Value;
  }
}

function SafeSetAttr(NodeId, Class) {
  var node = document.getElementById(NodeId);
  if (node != null) {
    node.setAttribute('class', Class);
    node.setAttribute('className', Class);
  }
}

function openMiniFormWindow(nID) {
 newWindow = window.open("../form/HorseMiniForm.aspx?nID=" + nID + "","Mini","height=370,width=724,scrollbars=yes,resizable=yes");
 newWindow.focus()
}

function play_game(gameId,inPopup,gameType, width, height) {
      var u = "demo";
      var p = "demo";

    if (gameType=="realplay") { u = ""; p = ""; }

    OpenCasinoGameWindow("https://canbet.gameassists.co.uk/canbet/t3start.asp?gameID="+gameId+"&sEXT1="+u+"&sEXT2="+p+"",width,height);

    return false;
}

function OpenCasinoGameWindow(url,width,height)
{
	newWindow = window.open(url,"","width="+width+",height="+height+",scrollbars=no,resizable");
	newWindow.focus()
}

function openCancelWithdrawalWindow(purse, servername) {
 newWindow = window.open("/MyAccount/Banking/CancelWithdrawal.aspx","CancelWithdrawal","height=480,width=540,scrollbars=yes,resizable=yes");
 newWindow.focus();
}

function onlyAlphaNumeric(objEvent) {
  ikeyCode = objEvent.keyCode;
  if (ikeyCode ==46 || ikeyCode >= 48 && ikeyCode <= 57 || ikeyCode >= 64 && ikeyCode <= 90 || ikeyCode >= 97 && ikeyCode <= 122) { return true; }
  { 
	alert(GENERAL_Script.Global_AlphNumericMessage);
	return false;	
  }
}

function ValidateInput(target)
{
	// 12 Mar 2008. Pravesh Tanwar 
	var InitialValue = target.value;  
	var FilteredValue = target.value.replace(/([^0-9A-Za-z .])/g,"");
	        
	if (InitialValue != FilteredValue)
	{
		target.value = FilteredValue; 
		alert(GENERAL_Script.Global_AlphNumericMessage);
	}
}

function IsAlphaNumeric(strString)
{
	var strValidChars = "abcdefghijklmnopqrstuvwxyz0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;
	// test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function ShowLoginPopup() {
    $.fancybox($("#loginPopup"), { 'speedIn': 50, 'speedOut': 50, 'scrolling': 'no', 'padding': 0 });
}
var oldPasswordbox;
var currestPasswordbox;


function ResetTextFields(obj, defaultValue, passwordfld) {
    
    if (obj.value != defaultValue) {
        return;
    }

    if (passwordfld == true) {
        if (obj.getAttribute('type') == 'password') {
            return;
        }

        oldPasswordbox = obj;
        //var newO = $(obj).clone(); //document.createElement('input');
        var newO = document.createElement('input');
        var onblur = obj.onblur;
        var onfocus = obj.onfocus;
        if (newO) {
         
            newO.setAttribute('type', 'password');


            if (obj.getAttribute('class') != null) {
                newO.setAttribute('class', obj.getAttribute('class'));
            } else {
                newO.setAttribute('className', obj.getAttribute('className'));
            }

            newO.setAttribute('name', obj.getAttribute('name'));
            newO.setAttribute('tabindex', obj.getAttribute('tabindex'));

            newO.tabindex = 1;
            obj.parentNode.replaceChild(newO, obj);
            newO.tabindex = 1;
            newO.value = "";
            newO.style.color = "#000000";
            newO.style.fontStyle = 'normal';
            newO.onblur = onblur;
            newO.onfocus = onfocus;
            currestPasswordbox = newO;
            setTimeout('currestPasswordbox.focus();', 10);
       
        }
    } else {

        obj.value = "";
        obj.style.color = "#000000";
        obj.style.fontStyle = 'normal';
        //obj.focus();
    }
}

function ResetTextFields2(obj, defaultValue, passwordfld) {
   
    if (passwordfld) {
        if (obj.value == '') {
            obj.parentNode.replaceChild(oldPasswordbox, obj);
        }
    } else {
        if (obj.value == '') {
            obj.value = defaultValue;
            obj.style.color = "#666666";
            obj.style.fontStyle = 'italic';
        } 
    }
    return;


   
}