﻿// JScript File

var selectedObject = "";
var afterKeyPad = null;

// post back with an additional parameter
function __pbx(eventTarget, eventArgument, ArgEx) {
    var theForm = document.forms['aspnetForm'];
    theForm.__ArgEx.value = ArgEx;
    __doPostBack(eventTarget, eventArgument);
}

function sendToClipboard(s)
{ if (window.clipboardData && clipboardData.setData) clipboardData.setData("Text", s); }

function getRC(type, loc, rac) {
    newWindow('RaceSelection.aspx?t=' + type + '&l=' + loc + '&r=' + rac, '_sel', 600, 500);
    return false;
}

function newWindow(mypage, myname, w, h) {
    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
    settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=1,resizable=1,menubar=1';
    return window.open(mypage, myname, settings);
}

function findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function changeProp(objName, x, theProp, theValue) {
    var obj = findObj(objName);
    if (obj && (theProp.indexOf("style.") == -1 || obj.style)) {
        if (theValue == true || theValue == false)
            eval("obj." + theProp + "=" + theValue);
        else eval("obj." + theProp + "='" + theValue + "'");
    } 
}

function callJS(jsStr)
{ return eval(jsStr); }

function getoffset(e) {
    var t = e.offsetTop, l = e.offsetLeft, rec = new Array(1);
    while (e = e.offsetParent) { t += e.offsetTop; l += e.offsetLeft; }
    rec[0] = l; rec[1] = t; return rec;
}

function getKeypad(ObjectName) {
    if (ObjectName != "") { findObj('LayerKeypad').style.visibility = "visible"; findObj('LayerKeypad').style.left = getoffset(findObj(ObjectName))[0]; findObj('LayerKeypad').style.top = getoffset(findObj(ObjectName))[1] + 20; }
    selectedObject = ObjectName; afterKeyPad = null;
}

function getKeypadEx(ObjectName, AfterProc) {
    if (ObjectName != "") { findObj('LayerKeypad').style.visibility = "visible"; findObj('LayerKeypad').style.left = getoffset(findObj(ObjectName))[0]; findObj('LayerKeypad').style.top = getoffset(findObj(ObjectName))[1] + 20; }
    selectedObject = ObjectName; afterKeyPad = AfterProc;
}

function hideKeypad()
{ findObj('LayerKeypad').style.visibility = "hidden"; selectedObject = ""; return false; }

function showObject(oObject, bShow) {
    oObject.style.display = (bShow) ? "block" : "none";
}

function visibility(oObject, bShow) {
    oObject.style.visibility = (bShow) ? "visible" : "hidden";
}

function disabled(oObject, bShow) {
    oObject.disabled = bShow;
}

function getObject(sID) {
    return (document.getElementById(sID));
}

function resetTextValue(srcObj) {
    srcObj.value = '';
}

function ParseDate(str1) {
    // Parse the string in DD/MM/YYYY format
    re = /(\d{2})\/(\d{2})\/(\d{4})/
    var arr = re.exec(str1);
    return new Date(parseInt(arr[3]), parseInt(arr[2], 10) - 1, parseInt(arr[1], 10));
}


function calendarPicker(thisform, thisControl) {
    //    alert(thisform.id + " " + thisControl.id);
    var myRef = window.open('DatePicker.aspx?fn=' + thisform.id + '&tn=' + thisControl.id, 'calendarPopup', ' width=220,height=230,top=' + event.screenY + ',left=' + event.screenX + ', resizable=no');
    myRef.focus();
}

function foldObj(objName, fldBtn, XpndBtn) {
    findObj(fldBtn).style.visibility = "hidden";
    findObj(XpndBtn).style.visibility = "visible";
    findObj(objName).style.visibility = "hidden";
    findObj(objName).style.display = "none";
    findObj(objName).style.height = "0px";
    findObj(objName).style.overflow = "hidden";
    return false;
}

function expandObj(objName, fldBtn, XpndBtn) {
    findObj(fldBtn).style.visibility = "visible";
    findObj(XpndBtn).style.visibility = "hidden";
    findObj(objName).style.visibility = "visible";
    findObj(objName).style.display = "inline";
    findObj(objName).style.height = "auto";
    findObj(objName).style.overflow = "hidden";
    return false;
}

function BookmarkMe() {
    var url = location.href;
    var title = AppConfig.WhiteLabel.CompanyName + " - Online Horse Racing and Sports Betting"

    if (window.sidebar) window.sidebar.addPanel(title, url, "");
    else if (window.external) window.external.AddFavorite(url, title);

    return false;
}

function set_focus(elementId) {
    var element = document.getElementById(elementId);
    if (element != null) {
        element.focus();
    }
}

//no post back
function nopb() {
    return false;
}

function openExternal(lnk, newWindow, w, h) {
   
    if (newWindow) {
        if (w && h) {
            newWindow = window.open(lnk, "consoleWindow", "width=" + w + ",height=" + h + ",resizable=yes,status=yes,toolbar=yes,menubar=yes,location=yes");
        }
        else {
            newWindow = window.open(lnk, "newWindow", "menubar=1,toolbar=1,location=1,directories=1,status=1,scrollbars=1,resizable=1");
        }
    }
    else {
        document.location.href = lnk;
    }
}
