﻿/*
utils used for hunchers
*/

function togExt(id)
{
    var r = $(id);
    
    if(r == undefined) {
        return;
    }
    
    if((r.style.display == "inline") || (r.style.display == "table-row") || (r.style.display == ""))
    {
        r.style.display = "none";
    }
    else
    {
        //IE doesn't support table* display styles good
        if(navigator.appName == "Microsoft Internet Explorer") {
            r.style.display = "inline";
        }
        else {
            r.style.display = "table-row";
        }    
    }
}

function checkSubmit(keyCode,id)
{
    if (keyCode == 13)
    {
        __doPostBack(id);
        return false;
    }
}

function checkSubmitForm(keyCode,id)
{
    if (keyCode == 13)
    {
        __doPostBack(id);
        return false;
    }
}

//getElementbyid
function ebid(d){
	return document.getElementById(d);
}

//general function to show a prompt string by key
function prompt(keyValue) 
{
    var keyData = { "key": keyValue };
    var stream = JSON.stringify(keyData);
    
    $.post("/JsonApi/JsonGetString.ashx", { snjp: stream },
        function(data) {
            ebid('jqmsg').innerHTML = data.desc;
            $('#jqmalert').jqmShow();
        },"json"
        );
}

//prompts the given text/html to the prompt box
function promptHtml(html,c)
{
    ebid('jqmsg').innerHTML = html;
    if(!c) {
        $('#jqmcloser').hide();
    }
    $('#jqmalert').jqmShow();
}

//closes the prompt dialog
function promptClose()
{
    $('#jqmcloser').show();
    $('#jqmalert').jqmHide();
}

//check if the value is numeric
function isNumeric(val) 
{ 
    if (val.match(/^\d+$/) == null) 
        return false; 
    else 
        return true; 
} 

//returns the time as the number of ms since 1/1/1970 (for cache busting)
function getTimeStr()
{
    var t = new Date();
    return t.getTime();
}

//validate the prediction fields and returns true/false, will prompt the error if there is one
function validatePredictionFields(home,away)
{
    if(home == '')
    {
        prompt("JS_ERR_HOME_TEAM_MISSED");
        return false;
    }
    if(!isNumeric(home)) {
        prompt("JS_ERR_HOME_NUMERIC");
        return false;            
    }
    if(away == '')
    {
        prompt("JS_ERR_AWAY_TEAM_MISSED");
        return false;
    }
    if(!isNumeric(away)) {
        prompt("JS_ERR_AWAY_NUMERIC");
        return false;            
    }  
    return true;
}

//returns the serialized command for head to head
function serializeHeadToHead(cid,h,a)
{
    var reqData = { "cid": cid, "homes":h, "aways":a };
    return JSON.stringify(reqData);
}

//returns the serialized command for yes no
function serializeYesNo(cid,res)
{
    var reqData = { "cid": cid, "res":res };
    return JSON.stringify(reqData);
}
