maha4india / Totcner_1.5_New_sanjay

// ==UserScript==
// @name         Totcner_1.5_New_sanjay
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @license      MIT
// @match        *://*.totalcorner.com/*
// @grant        none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// ==/UserScript==
(function() {
    'use strict';
    var $ = window.jQuery;
    var abc, vntTempTime, inplayRow;

    // Delete divs
    //HideDIV('navbar');
    HideDIV('carousel-banner-container');
    HideDIV('carousel-banner');
    HideDIV('navbar-right.btn-group.pull-right');
    var tbl = document.getElementById('inplay_match_table')

    //  set row number
    for( abc =3 ; abc < parseInt(tbl.rows.length); abc++ )
    {
        tbl.rows[ abc ].cells[ 0 ].innerText = abc;

        vntTempTime = tbl.rows[ abc ].cells[ 3 ].innerText.trim();
        vntTempTime = vntTempTime.replace( /\D+$/, '');

        if (vntTempTime > 0 )
        {
            inplayRow = abc;
        }
    }


    var test = $('<button>Run Me</button>').click(function () {
        Main();
    });

    var test1 = $('<button>HTFT Scr</button>').click(function () {
        HTFT();
    });
    var tableTest;
    tableTest = "<table ID = 'tblParam' bgcolor='#00FF00' border='3'><TR>" +
        "<TD>From<input type='text' ID = 'txtFrom' value='2' size='8'></TD>" +
        "<TD>To<input type='text' ID = 'txtTo' value='" + inplayRow + "' size='8'> <label id='lblMax' for='maxText'>" + (parseInt(tbl.rows.length) - 3) + "</label></TD>" +
        "<TD>Time<input type='text' ID = 'txtTime' value='105' size='8'>. Goals <input type='text' ID = 'txtGoals' value='9' size='8'>.  GetOdds<input type='checkbox' ID = 'chkGetScore'>. GetStats<input type='checkbox' ID = 'chkStats'></TD>" +
        "<TD>1.5 Only<input type='checkbox' ID = 'get15' checked>.  OnlyResult<input type='checkbox' ID = 'chkOnlyResult' checked></TD>" +
        "<TD>Check WHat<select id='sltCheckWhat'><option value='15'>1.5</option><option value='25'>2.5</option><option value='BTTS'>BTTS</option><option value='BTTS25'>BTTS25</option></select></TD>" +
        "<TD>Greater<select id='sltgreater'><option value='greater'>></option><option value='lesser'><</option></select></TD>" +
        "<TD>start<input type='text' ID = 'txtstart' value='2' size='8'>.   End<input type='text' ID = 'txtEnd' value='5' size='8'>    .HomeVal<input type='text' ID = 'txtHCheckVal' value='0' size='8'>.  AwayVal<input type='text' ID = 'txtACheckVal' value='0' size='8'>.  H2HVal<input type='text' ID = 'txtH2hCheckVal' value='0' size='8'></TD>" +
        "</TR><TR><TD><label id='lblStatus'></label></TD>" +
        "</TR></table>"
    //      $(".navbar").append("<input type='text' ID = 'txtFrom' value='2'>')
    //     $(".navbar").append('<input type="text" ID = "txtTo" value="' + inplayRow + '">')
    //     $(".navbar").append('<input type="text" ID = "txtTime" value="80">')
    //     $(".navbar").append('<input type="text" ID = "txtGoals" value="0">')
    //     $(".navbar").append('<input type="checkbox" ID = "chkGetScore">Get scr')
    //     $(".navbar").append('<input type="checkbox" ID = "chkStats" checked>Get Stat<br />')
    $(".navbar").append(tableTest).append(test).append(test1);

    $('#tblParam').css("background-color", "#FFFFFF");

    function HTFT()
    {
        tbl = document.getElementById('inplay_match_table');
        var vntCornerLink, vntMatchLink, i;

        //parseInt(tbl.rows.length)
        for( i = 3; i < parseInt(tbl.rows.length) ; i++ )
        {
            vntCornerLink = tbl.rows[ i ].cells[ 14 ]
            vntMatchLink = vntCornerLink.getElementsByTagName('a')[0];
            var LiveScor = 'https://www.totalcorner.com' + $(vntMatchLink).attr('href').replace("corner-stats", "odds-handicap");
            //               alert(LiveScor);
            //             div.load(LiveScor + ' #goal_div tbody tr:nth-child(2)', function(){handle1(div);});
            var currentRow = $('#inplay_match_table tr')[i];
            var cellu = $(currentRow).find('td')[5];
            var $celll = $(cellu);
            GetValue1($celll, LiveScor, '#goals_full tbody');

        }
        function GetValue1(strWheretoWrite, strReadLink, strReadAttribute)
        {
            var $ = window.jQuery;
            var temp;
            var strConcat;
            //         alert('inside getvalue');

            strConcat = strReadLink + "  " + strReadAttribute;

            var div = $('<Table width="60%" border="1" cellpadding="4"/>');
            div.load(strReadLink + ' ' + strReadAttribute, function(){handle(div);});
            //        alert(strWheretoWrite.find('table').length);

            function handle(element)
            {
                try
                {
                    var ht, ft, final, loop;

                    ft = $($(element).find('tr:nth-child(2) td:eq(1)')).html();
                    var html = $.parseHTML($(element).html());
                    //alert($(html).children('tr').length);

                    for( loop =2 ; loop < parseInt($(html).children('tr').length); loop++ )
                    {
                        var trHTML;
                        var time;
                        trHTML = ($($(html).find('tr')[loop]).html());
                        time = $($(element).find('tr:nth-child(' + loop + ') td:eq(0)')).html();
                        time = time.replace(/[^0-9]/g, '');
                        if ((trHTML.indexOf('half') > 1) || (time > 43 && time < 47))
                        {
                            ht = $($(element).find('tr:nth-child(' + loop + ') td:eq(1)')).html();
                            break;
                        }
                    }
                    final = ft + ' : ' + ht;

                    //                                         if (($(element).find("td:eq(1)").html().indexOf('half') > 1))
                    //                                         {
                    //                                             //$(element).find("td:eq(0)").html('Full');
                    //                                             alert($(element).find("td:eq(0)").html());
                    //                                         }
                }catch(ex){}
                //element.appendTo(strWheretoWrite);

                $(strWheretoWrite).empty();
                $(strWheretoWrite).css("width", "100px");
                $(strWheretoWrite).append(final);

                //                  var temp1 = $(strWheretoWrite).html();
                //                  element.html = temp1 + element.html();
                //                  $(strWheretoWrite).html (element);
            }
        }
    }

    function Main()
    {
        var isDelete;
        var deletedRows = 0;
        var vntTime;

        $('.container').empty();
        tbl = document.getElementById('inplay_match_table');
        var i;

        //('#container').append('<table width="320" border="3"><tr><td colspan="2" rowspan="1">' + " wdw" + '</td></tr><tr><td width="118">' + "sxs" + '</td><td width="186">' + "xs" + '</td></tr></table>');

        //for (i = tbl.rows.length - 1; i >= 3; i--)

        //     $('.container').load('https://www.totalcorner.com/match/corner-stats/83037923/ #place_bet_div');
        //     //$('#inplay_match_table').load('https://www.totalcorner.com/match/corner-stats/83037923/ #home_history_table');

        //     var temps = $('.container').children('table').first().empty();
        //     alert($(".container").find('table').length);
        //     temps.empty();
        //     return false;

        $('.col-xs-12.col-sm-9').empty();
        //$('.col-xs-12').empty();
        $('.col-xs-12.col-sm-9').append('<table border="3" width="100%" ID="MyTable" align="left"/>' );
        $('.col-xs-12.col-sm-9 table').append($('#inplay_match_table tr')[0]);
        //$('.col-xs-12.col-sm-9').append('<div>Result:</div>');

        var from, to;
        from = document.getElementById('txtFrom').value;
        to = document.getElementById('txtTo').value;

        if (from == "" )
        {
            from = 3;
        }

        if (to == "" )
        {
            to = tbl.rows.length;
        }

        for( i = parseInt(from); i < parseInt(to); i++ )
            //for( i = 2; i < 20; i++ )
        {

            var vntAttack;
            var vntShots;
            var vntCornerLink;
            var vntScore;
            var vntHome;
            var vntAway;
            var vntLeague;
            var vntLeagueTime;
            var vntTotalScore;
            //             alert(i);
            vntTime = tbl.rows[ i ].cells[ 3 ].innerText.trim();
            vntTime = vntTime.replace( /\D+$/, '');

            vntLeague = tbl.rows[ i ].cells[ 1 ].innerText.trim();
            vntLeagueTime = tbl.rows[ i ].cells[ 2 ].innerText.trim();

            if (vntTime.substring(0, 2) == "Ha")
            {
                //tbl.rows[ i ].cells[ 3 ].innerText = '45';
                tbl.rows[ i ].cells[ 3 ].getElementsByClassName('match_status_minutes')[0].textContent = '45';
                vntTime = 45;
            }
            vntTime = vntTime.replace( /\D+$/, '');
            vntAttack = tbl.rows[ i ].cells[ 10 ].getElementsByClassName('match_dangerous_attacks_div')[0].textContent;
            vntShots = tbl.rows[ i ].cells[ 11 ].getElementsByClassName('match_shoot_div')[0].textContent;
            vntCornerLink = tbl.rows[ i ].cells[ 13 ]
            vntScore = tbl.rows[ i ].cells[ 4 ].innerText.trim()
            vntHome = tbl.rows[ i ].cells[ 4 ].innerText.trim()
            vntAway = tbl.rows[ i ].cells[ 6 ].innerText.trim()
            //alert(vntAttack + '.' + vntShots + '.' + vntCornerLink + '.' + vntScore + '.' + vntHome + '.' + vntAway);

            try
            {
                var fieldsScore = vntScore.split('-');
                var HomeScore = fieldsScore[0].trim();
                var AwayScore = fieldsScore[1].trim();
            }catch(ex){HomeScore = AwayScore = 0;}

            var vntMatchLink = vntCornerLink.getElementsByTagName('a')[0];

            //alert('before call');

            isDelete = "False";
            //         if (vntTime > 79)
            //         {
            //             isDelete = "True";
            //         }

            if (isDelete == "False")
            {
                try
                {
                    var fieldsAttack = vntAttack.split('-');
                    var fieldsShots= vntShots.split('-');

                    //alert(fields);
                    var HomeAttack = fieldsAttack[0].trim();
                    var AwayAttack = fieldsAttack[1].trim();
                    var HomeShots = fieldsShots[0].trim();
                    var AwayShots = fieldsShots[1].trim();

                }
                catch(ex){HomeAttack = AwayAttack = HomeShots = AwayShots = 0;}

                var blnWrite = 'False';
                if (HomeAttack>0 && AwayAttack>0)
                {
                    //alert('yes');
                    var diff;
                    var diffShot;
                    var existScore;
                    diff = parseInt(HomeAttack) - parseInt(AwayAttack);

                    try{diffShot = (parseInt(HomeShots) - parseInt(AwayShots)).toFixed(0)}catch(ex){diffShot = 0};

                    existScore = tbl.rows[ i ].cells[ 5 ].innerText;
                    HomeScore = parseInt(HomeScore);
                    AwayScore = parseInt(AwayScore);
                    //alert(diffShot);
                    //alert(existScore);
                    tbl.rows[ i ].cells[ 2 ].innerText = existScore + '   (  ' + diff + ' ) ( ' + diffShot + ' )';

                    diff = parseInt(diff);

                    var vntColor;
                    if (diff > 7)
                    {
                        if (HomeScore > AwayScore)
                        {
                            vntColor = "Black"
                            tbl.rows[ i ].cells[ 2 ].innerText = "H Adv  = " + tbl.rows[ i ].cells[ 2 ].innerText;
                        }
                        if (HomeScore == AwayScore)
                        {
                            vntColor = "MediumSeaGreen"
                            tbl.rows[ i ].cells[ 2 ].innerText = "H EQ  = " + tbl.rows[ i ].cells[ 2 ].innerText + vntHome;
                            tbl.rows[ i ].cells[ 2 ].style.fontWeight = "900";
                            blnWrite = 'True';
                        }
                        if (HomeScore < AwayScore)
                        {
                            vntColor = "Orange"
                            tbl.rows[ i ].cells[ 2 ].innerText = "H Beh  = " + tbl.rows[ i ].cells[ 2 ].innerText + vntHome;
                            tbl.rows[ i ].cells[ 2 ].style.fontWeight = "900";
                            blnWrite = 'True';
                        }
                        tbl.rows[ i ].cells[ 2 ].style.color = vntColor;
                        tbl.rows[ i ].cells[ 1 ].style.color = "MediumSeaGreen";

                        if (diff > 12)
                        {
                            tbl.rows[ i ].cells[ 2 ].innerText = "SS " + tbl.rows[ i ].cells[ 2 ].innerText;
                        }
                    }
                    else if (diff < -7)
                    {
                        if (HomeScore > AwayScore)
                        {
                            vntColor = "Orange"
                            tbl.rows[ i ].cells[ 2 ].innerText = "A Beh  = " + tbl.rows[ i ].cells[ 2 ].innerText + vntHome;
                            tbl.rows[ i ].cells[ 2 ].style.fontWeight = "900";
                            blnWrite = 'True';
                        }
                        if (HomeScore == AwayScore)
                        {
                            vntColor = "MediumSeaGreen"
                            tbl.rows[ i ].cells[ 2 ].innerText = "A EQ  = " + tbl.rows[ i ].cells[ 2 ].innerText + vntHome;
                            tbl.rows[ i ].cells[ 2 ].style.fontWeight = "900";
                            blnWrite = 'True';
                        }
                        if (HomeScore < AwayScore)
                        {
                            vntColor = "Black"
                            tbl.rows[ i ].cells[ 2 ].innerText = "A Adv  = " + tbl.rows[ i ].cells[ 2 ].innerText;
                        }
                        tbl.rows[ i ].cells[ 2 ].style.color = vntColor;
                        $(tbl.rows[ i ].cells[ 1 ]).css("background-color", "red");

                        if (diff < -12)
                        {
                            tbl.rows[ i ].cells[ 2 ].innerText = "SS " + tbl.rows[ i ].cells[ 2 ].innerText;
                        }
                    }
                    else {
                    }
                }
            }


            var firstLink = document.getElementsByClassName('text-center th_start_time')[0];
            firstLink.style.width = "300px";
            firstLink.style.fontWeight = "900";

            firstLink = document.getElementsByClassName('text-center td_league')[0];
            firstLink.style.width = "300px";

            // Read individual odds
            //             if (HomeAttack == 0 && AwayAttack == 0)
            //             {
            var div = $('<div/>');
            //             div.load(vntMatchLink + ' #place_bet_div', function(){handle(div);});
            var currentRow = $('#inplay_match_table tr')[i];
            var cellu = $(currentRow).find('td')[1];
            var $celll = $(cellu);

            $($(currentRow).find('td')[4]).css("font-size", "20px");
            $($(currentRow).find('td')[3]).css("font-size", "15px");
            $($(currentRow).find('td')[2]).css("font-size", "15px");
            $($(currentRow).find('td')[1]).css("font-size", "15px");

            //                 $($(currentRow).find('.btn.btn-default.btn-sm.btn-favrite.star_btn')).trigger("click");

            $($(currentRow).find('td')[2]).css("width", "200px");
            var LiveScor = 'https://www.totalcorner.com' + $(vntMatchLink).attr('href').replace("corner-stats", "odds-handicap");

            var getodds = "No";
            var getscore = "No";
            var getTime, getScore, livescore;

            getTime = document.getElementById('txtFrom').value;
            livescore = document.getElementById('txtGoals').value;
            vntTotalScore = parseInt(HomeScore) + parseInt(AwayScore);

            if ($('#chkGetScore').is(":checked"))
            {
                getodds = "Yes";
            }
            if ($('#chkStats').is(":checked"))
            {
                getscore = "Yes";
            }

            try
            {
                if(vntTotalScore <= livescore)
                {
                    //                     alert(i + ':' + vntTime);
                    //                     alert(i + ':' + vntTotalScore);
                    //                     alert(i );
                    if ( getodds == "Yes")
                    {
                        GetValue($celll,vntMatchLink ,".table-bordered.table-condensed-2:first-child tr:nth-child(2)");
                        GetValue($celll,LiveScor ,"#odds_full tbody tr:nth-child(2)");
                    }
                    if ( getscore == "Yes")
                    {
                        GetValueHistory($celll,vntMatchLink ,"#content_container", "Home", vntHome, vntAway, vntLeague, vntLeagueTime, (HomeScore + "-" + AwayScore));
                    }
                    $("#lblStatus").text("Processing " + i + ' \ ' + parseInt(to));
                }
            }catch(ex){}

            if (blnWrite == 'True' && vntTime < 80)
            {
                var templateClone = $(tbl.rows[ i ]).clone();
                $('.col-xs-12.col-sm-9 table').append(templateClone);
            }
            //             }
        }

        function GetValue(strWheretoWrite, strReadLink, strReadAttribute)
        {
            var $ = window.jQuery;
            var temp;
            var strConcat;
            //         alert('inside getvalue');

            strConcat = strReadLink + "  " + strReadAttribute;

            var div = $('<Table width="60%" border="1" cellpadding="4"/>');
            div.load(strReadLink + ' ' + strReadAttribute, function(){handle(div);});
            //        alert(strWheretoWrite.find('table').length);

            function handle(element)
            {
                try
                {
                    $(element).find("td:eq(6)").remove()
                    $(element).find("td:eq(5)").remove()
                    if (($(element).find("td:eq(1)").html().indexOf('-') <1))
                    {
                        $(element).find("td:eq(0)").html('Full');
                        //   alert($(element).find("td:eq(0)").html());
                    }
                }catch(ex){}
                $(element).css('border', '1px solid black');
                //element.appendTo(strWheretoWrite);

                $(strWheretoWrite).append(element);

                //                  var temp1 = $(strWheretoWrite).html();
                //                  element.html = temp1 + element.html();
                //                  $(strWheretoWrite).html (element);
            }
        }

        function GetValueHistory(strWheretoWrite, strReadLink, strReadAttribute, strAppendText, strHome, strAway, vntLeague, vntLeagueTime, vntscre)
        {
            var $ = window.jQuery;
            var temp;
            var strConcat;
            //         alert('inside getvalue');

            strConcat = strReadLink + "  " + strReadAttribute;

            var div = $('<Body/>');
            try
            {
                //div.load(strReadLink + ' ' + strReadAttribute, function(){handle(div);});
                //        alert(strWheretoWrite.find('table').length);
                div.load(strReadLink + ' ' + strReadAttribute, function(){handle(div);});
            }catch(ex){}

            var tbl;
            var tblH2H;

            tbl = '<Table width="100%" border="3"><tr><td></td><td>Tt</td><td>O1</td><td>O2</td><td>BS</td><td>1.5%</td><td>2.5%</td><td>BT%</td></tr>';
            function handle(element)
            {
                var html;
                var incrementor, Over1, Over2, BTTS, incrementorH2H, ResultHistory;
                var Over1H2H, Over2H2H, BTTSH2H;
                incrementor = Over1 = Over2 = BTTS = 0;
                incrementorH2H = Over1H2H = Over2H2H = BTTSH2H = 0;
                var finalVal = "";
                var strOdds = "";

                var blnIsH2H;
                var H2HString= "";
                var HString= "";
                var AString= "";
                html = $.parseHTML($(element).html());
                //                 alert($(element).html());
                //                 console.log($(element).html());

                //                 var start = new Date().getTime();
                var table1 = $(html).find('#head_to_head_history_table').html();
                var table2 = $(html).find('#home_history_table').html();
                var table3 = $(html).find('#away_history_table').html();
                var table4 = $(html).find('.table-bordered.table-condensed-2:first-child tr:nth-child(2)').html();

                //                 var end = new Date().getTime();
                //                 var time = end - start;
                //                 alert('Execution time: ' + time);

                html = '';


                // call generic sub
                // H
                var o1;
                var o2;
                var bt;
                var bgColorgreen = "#98FB98";
                var bgColorWhite = "#F0F8FF";
                var tempStartCntr, tempMaxCntr;
                var start,end;
                start = document.getElementById('txtstart').value;
                end = document.getElementById('txtEnd').value;
                tempStartCntr = parseInt(start);
                tempMaxCntr =parseInt(end);
                try
                {
                    ResultHistory = '';
                    Generic(table2, "H");
                    var HomeIncr, Home01, HomeO2, HomeBTTS, HomeO1, ResultHome;
                    HomeIncr = incrementorH2H;
                    Home01 = Over1H2H;
                    HomeO2 = Over2H2H;
                    HomeBTTS = BTTSH2H;
                    ResultHome = ResultHistory;

                    table2 = ""
                    o1=0;
                    o2=0;
                    bt=0;
                    try{o1 = ((parseInt(Home01)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    try{o2 = ((parseInt(HomeO2)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    try{bt = ((parseInt(HomeBTTS)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    HomeO1 = o1;
                    HString = "<TR bgcolor=XX><td>H</td><td style='font-weight: bold'>" + incrementorH2H + "</td><td>" + Over1H2H + "</td><td>" + Over2H2H + "</td><td>" + BTTSH2H + "</td><td>" + o1 + "</td><td>" + o2 + "</td><td>" + bt + "</td></TR>";
                    if (o1 > 60){HString = HString.replace("XX", bgColorgreen);}else{HString = HString.replace("XX", bgColorWhite);}
                }catch(ex){}
                // A
                try
                {
                    ResultHistory = '';
                    Generic(table3, "A");
                    var AwayIncr, Away01, AwayO2, AwayBTTS, AwayO1, ResultAway;
                    AwayIncr = incrementorH2H;
                    Away01 = Over1H2H;
                    AwayO2 = Over2H2H;
                    AwayBTTS = BTTSH2H;
                    ResultAway = ResultHistory;
                    table3 = "";
                    o1=0;
                    o2=0;
                    bt=0;
                    try{o1 = ((parseInt(Away01)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    try{o2 = ((parseInt(AwayO2)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    try{bt = ((parseInt(AwayBTTS)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    AwayO1 = o1;
                    AString = "<TR bgcolor=XX><td>A</td><td style='font-weight: bold'>" + incrementorH2H + "</td><td>" + Over1H2H + "</td><td>" + Over2H2H + "</td><td>" + BTTSH2H + "</td><td>" + o1 + "</td><td>" + o2 + "</td><td>" + bt + "</td></TR>";
                    if (o1 > 60){AString = AString.replace("XX", bgColorgreen);}else{AString = AString.replace("XX", bgColorWhite);}
                }catch(ex){}
                // H2H

                try
                {
                    ResultHistory = '';
                    Generic(table1, "H2H");
                    var H2HIncr, H2H01, H2HO2, H2HBTTS, ResultHH;
                    H2HIncr = incrementorH2H;
                    H2H01 = Over1H2H;
                    H2HO2 = Over2H2H;
                    H2HBTTS = BTTSH2H;
                    ResultHH = ResultHistory;
                    table1 = "";
                    o1=0;
                    o2=0;
                    bt=0;
                    try{o1 = ((parseInt(H2H01)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    try{o2 = ((parseInt(H2HO2)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    try{bt = ((parseInt(H2HBTTS)/parseInt(incrementorH2H))* 100).toFixed(0)}catch(ex){};
                    //                 alert(incrementorH2H + " " + Over1H2H + " " + Over2H2H + " " + BTTSH2H);
                    H2HString = "<TR bgcolor=XX><td>H2</td><td style='font-weight: bold'>" + incrementorH2H + "</td><td>" + Over1H2H + "</td><td>" + Over2H2H + "</td><td>" + BTTSH2H + "</td><td>" + o1 + "</td><td>" + o2 + "</td><td>" + bt + "</td></TR>";
                    if (o1 > 60){H2HString = H2HString.replace("XX", bgColorgreen);}else{H2HString = H2HString.replace("XX", bgColorWhite);}
                }catch(ex){}

                html = ""
                $($(currentRow).find('td')[4]).css("font-size", "20px");

                finalVal = finalVal + HString + AString + H2HString ;
                finalVal = finalVal.replace(" - ", "-");
                finalVal = tbl + finalVal + '</table>';
                //                alert(finalVal);
                $(finalVal).css('border', '1px solid black');
                $(finalVal).css("background-color", "#000000");
                //                 $(strWheretoWrite).css('border', '1px solid black');
                //                 alert('olo');
                //                 alert($(finalVal).html());

                // alert(o1);
                var shouldProcess, checkWhat, hval, aval, h2hval, whatCheckH, whatCheckA, whatCheckH2h, greater;
                shouldProcess = checkWhat = hval = aval = h2hval = whatCheckH = whatCheckA = whatCheckH2h = greater = '';

                checkWhat = $("#sltCheckWhat option:selected").text();
                greater = $("#sltgreater option:selected").text();
                hval = parseInt(document.getElementById('txtHCheckVal').value);
                aval = parseInt(document.getElementById('txtACheckVal').value);
                h2hval = parseInt(document.getElementById('txtH2hCheckVal').value);

                //                 alert(checkWhat);
                //                 alert('testME ' + Home01);
                //                 alert('testME 1 ' + HomeIncr);
                //                 alert("After testME");

                switch (checkWhat)
                {
                    case '1.5':
                        try{whatCheckH = ((parseInt(Home01)/parseInt(HomeIncr))* 100).toFixed(0)}catch(ex){whatCheckH = 0};
                        try{whatCheckA = ((parseInt(Away01)/parseInt(AwayIncr))* 100).toFixed(0)}catch(ex){whatCheckA = 0};
                        try{whatCheckH2h = ((parseInt(H2H01)/parseInt(H2HIncr))* 100).toFixed(0)}catch(ex){whatCheckH2h = 0};
                        break;
                    case '2.5':
                        try{whatCheckH = ((parseInt(HomeO2)/parseInt(HomeIncr))* 100).toFixed(0)}catch(ex){whatCheckH = 0};
                        try{whatCheckA = ((parseInt(AwayO2)/parseInt(AwayIncr))* 100).toFixed(0)}catch(ex){whatCheckA = 0};
                        try{whatCheckH2h = ((parseInt(H2HO2)/parseInt(H2HIncr))* 100).toFixed(0)}catch(ex){whatCheckH2h = 0};
                        break;
                    case 'BTTS':
                        try{whatCheckH = ((parseInt(HomeBTTS)/parseInt(HomeIncr))* 100).toFixed(0)}catch(ex){whatCheckH = 0};
                        try{whatCheckA = ((parseInt(AwayBTTS)/parseInt(AwayIncr))* 100).toFixed(0)}catch(ex){whatCheckA = 0};
                        try{whatCheckH2h = ((parseInt(H2HBTTS)/parseInt(H2HIncr))* 100).toFixed(0)}catch(ex){whatCheckH2h = 0};
                        break;
                    case 'BTTS25':
                        var h25,a25,hh25,hbtts,abbts,hhbtts;
                        h25 = a25 = hh25 = hbtts = abbts = hhbtts = 0
                        try{h25 = ((parseInt(HomeO2)/parseInt(AwayIncr))* 100).toFixed(0)}catch(ex){h25 = 0};
                        try{a25 = ((parseInt(AwayO2)/parseInt(AwayIncr))* 100).toFixed(0)}catch(ex){a25 = 0};
                        try{hh25 = ((parseInt(H2HO2)/parseInt(H2HIncr))* 100).toFixed(0)}catch(ex){hh25 = 0};
                        try{hbtts = ((parseInt(HomeBTTS)/parseInt(HomeIncr))* 100).toFixed(0)}catch(ex){hbtts = 0};
                        try{abbts = ((parseInt(AwayBTTS)/parseInt(AwayIncr))* 100).toFixed(0)}catch(ex){abbts = 0};
                        try{hhbtts = ((parseInt(H2HBTTS)/parseInt(HomeIncr))* 100).toFixed(0)}catch(ex){hhbtts = 0};

                        whatCheckH = ((parseInt(h25)+parseInt(hbtts))/2);
                        whatCheckA = ((parseInt(a25)+parseInt(abbts))/2);
                        whatCheckH2h = ((parseInt(hh25)+parseInt(hhbtts))/2);
                        break;
                }

                //                 alert(checkWhat);
                //                 alert(whatCheckH);
                //                 alert(whatCheckA);
                //                 alert(whatCheckH2h);

                //shouldProcess = "False";
                if ($('#get15').is(":checked"))
                {
                    //alert(whatCheckH2h + ' - ' + h2hval + ' : ' + whatCheckH + ' - ' + hval + ' : ' + whatCheckA + ' - ' + aval );
                    if (greater == ">")
                    {
                        // shouldProcess = ((parseInt(whatCheckH2h) >= h2hval) && (parseInt(whatCheckH) >= hval) && (parseInt(whatCheckA) >= aval));
                        shouldProcess = (parseInt(whatCheckH) >= hval) && (parseInt(whatCheckA) >= aval);
                    }
                    else
                    {
                        // shouldProcess = ((parseInt(whatCheckH2h) <= h2hval) && (parseInt(whatCheckH) <= hval) && (parseInt(whatCheckA) <= aval));
                        shouldProcess = (parseInt(whatCheckH) <= hval) && (parseInt(whatCheckA) <= aval);
                    }
                }
                else
                {
                    if (greater == ">")
                    {
                        shouldProcess = ((whatCheckH2h >= h2hval) || ((whatCheckH >= hval) && (whatCheckA >= aval)));
                    }
                    else
                    {
                        shouldProcess = ((whatCheckH2h <= h2hval) || ((whatCheckH <= hval) && (whatCheckA <= aval)));
                    }
                }

                // get odds
                strOdds = "";
                ///GetOdds(strOdds,strReadLink ,".table-bordered.table-condensed-2:first-child tr:nth-child(2)");
                // append output to top
                //                 alert(strOdds);
                //if ((o1 > 50) || ((HomeO1 > 60) && (AwayO1 > 60)))
                strOdds = table4;
                var Teaminfo = "";

                Teaminfo = "<DIV>[" + vntLeague + "] - [" + vntLeagueTime + "] - [" + strHome + "] - [" + strAway + "] - [" + HomeIncr + "] - [" + AwayIncr + "] - [" + H2HIncr + "] - [" + whatCheckH + "] - [" + whatCheckA + "] - [" + whatCheckH2h + "] - [" + vntscre + "] - [" + ResultHome + "] - [" + ResultAway + "] - [" + strOdds + "]</DIV>";

                //   shouldProcess = "true";

                if (shouldProcess == true)
                {
                    // alert('Yes mate');
                    //                     var start = new Date().getTime();
                    //                 var fragment = document.createDocumentFragment();
                    //                 var el = document.createElement(finalVal);
                    //                 fragment.appendChild(el);

                    //                 alert('ebfore');
                    //$(finalVal).appendTo(strWheretoWrite);
                    //                 $(finalVal).appendChild(fragment)
                    var temp = $(strWheretoWrite).html();

                    finalVal = temp + finalVal;
                    //$(strWheretoWrite).append(finalVal);

                    if ($('#chkOnlyResult').is(":checked"))
                    {
                        $('.col-xs-12.col-sm-9').append(Teaminfo);
                    }
                    else
                    {
                        $(strWheretoWrite).html (finalVal);
                        // append output to top
                        $('.col-xs-12.col-sm-9').append(Teaminfo);
                    }


                    //$(strWheretoWrite).appendChild(createFragment(finalVal));
                    //                 alert('after');
                    //                     var end = new Date().getTime();
                    //                     var time = end - start;
                    //                     alert('Execution time: ' + time);
                }
                finalVal = '';

                function GetOdds(strOddsVariable, strReadLink, strReadAttribute)
                {
                    var $ = window.jQuery;
                    var temp;
                    var strConcat;
                    //         alert('inside getvalue');

                    strConcat = strReadLink + "  " + strReadAttribute;

                    var div = $('<Table width="60%" border="1" cellpadding="4"/>');
                    div.load(strReadLink + ' ' + strReadAttribute, function(){handle(div);});
                    //        alert(strWheretoWrite.find('table').length);

                    function handle(element)
                    {
                        try
                        {
                            $(element).find("td:eq(6)").remove()
                            $(element).find("td:eq(5)").remove()
                            if (($(element).find("td:eq(1)").html().indexOf('-') <1))
                            {
                                $(element).find("td:eq(0)").html('Full');
                                //   alert($(element).find("td:eq(0)").html());
                            }
                        }catch(ex){}
                        //                         alert($(element).text().trim());
                        //    alert($(element).html());

                        strOdds = $(element).text().trim();
                        strOddsVariable = $(element).text().trim();
                        //                  var temp1 = $(strWheretoWrite).html();
                        //                  element.html = temp1 + element.html();
                        //                  $(strWheretoWrite).html (element);
                    }
                }

                function Generic(vnttable, strWho)
                {
                    incrementorH2H = Over1H2H = Over2H2H = BTTSH2H = 0;
                    //alert(tempStartCntr);
                    //                     alert('hello ' + strHome + '  :: ' + $(vnttable).children('tr').length);
                    //                     alert('hello22 ' + strHome + '  :: ' + $(vnttable).children('tr').size());
                    //                     alert('ads233 ' + strHome + $('tr', $(vnttable).find('tbody')).length);

                    for(i = tempStartCntr; i < $(vnttable).children('tr').length -2; i++ )
                    {
                        if (incrementorH2H === tempMaxCntr) { break; }

                        var time;
                        var htmltbl = "";
                        //                     alert('insideloop');
                        htmltbl = (vnttable);
                        //                     console.log(htmltbl);
                        //                     console.log(htmltbl.html());
                        var currentRow = $(htmltbl).find('tr')[i];
                        //alert($($(html).find('tr')[1]).html());
                        var cellu = $(currentRow).find('td')[3];
                        //                      alert($(cellu).html());
                        var HomeTeam, AwayTeam;

                        HomeTeam = $($(currentRow).find('td')[2]).text().trim();
                        AwayTeam = $($(currentRow).find('td')[4]).text().trim();
                        HomeTeam = HomeTeam.replace(/\d+/, '').trim();
                        AwayTeam = AwayTeam.replace(/\d+/, '').trim();
                        strHome = strHome.replace(/\d+/,'').trim();
                        strAway = strAway.replace(/\d+/,'').trim();

                        //                         alert(HomeTeam + ',' + AwayTeam + ',' + strHome + ',' + strAway);

                        var score = "";
                        score = $(cellu).text().replace(/(\r\n|\n|\r)/gm, "/").trim();
                        score = score.substr(score.length - 7);
                        score = score.split("/").join("").trim();
                        //alert(score);

                        // H2H
                        if (incrementorH2H < tempMaxCntr)
                        {
                            var fieldScoreH2H = score.split('-');
                            var HomeScoreH2H = fieldScoreH2H[0].trim();
                            var AwayScoreH2H = fieldScoreH2H[1].trim();

                            HomeScoreH2H = parseInt(HomeScoreH2H);
                            AwayScoreH2H = parseInt(AwayScoreH2H)
                            incrementorH2H = parseInt(incrementorH2H) +1;

                            //                             alert(i);
                            //                             alert(HomeScoreH2H + ' ' + AwayScoreH2H + ' ' + incrementorH2H);

                            // check 1.5
                            if ((parseInt(HomeScoreH2H) + parseInt(AwayScoreH2H)) > 1)
                            {
                                Over1H2H = parseInt(Over1H2H) + 1; //+ '( ' + HomeScoreH2H + '-' + AwayScoreH2H;
                            }

                            // check 2.5
                            if ((parseInt(HomeScoreH2H) + parseInt(AwayScoreH2H)) > 2)
                            {
                                Over2H2H = parseInt(Over2H2H) + 1; //+ '( ' + HomeScoreH2H + '-' + AwayScoreH2H;
                            }

                            // check BTTS
                            if ((parseInt(HomeScoreH2H) >0) && (parseInt(AwayScoreH2H)>0))
                            {
                                BTTSH2H = parseInt(BTTSH2H) + 1; //+ '( ' + HomeScoreH2H + '-' + AwayScoreH2H;
                            }
                            // get results
                            var tempHomScr, tempAscr;
                            if (strWho == "H")
                            {
                                if (strHome == HomeTeam)
                                {
                                    tempHomScr = HomeScoreH2H;
                                    tempAscr = AwayScoreH2H;
                                }
                                else
                                {
                                    tempHomScr = AwayScoreH2H;
                                    tempAscr = HomeScoreH2H;
                                }
                                //                                 alert("H" + tempHomScr + ' - ' + tempAscr);
                            }
                            else if (strWho == "A")
                            {
                                if (strAway == AwayTeam)
                                {
                                    tempHomScr = AwayScoreH2H;
                                    tempAscr = HomeScoreH2H;
                                }
                                else
                                {
                                    tempHomScr = HomeScoreH2H;
                                    tempAscr = AwayScoreH2H;
                                }
                                //                                 alert("A" + tempHomScr + ' - ' + tempAscr);
                            }

                            //                             alert(strWho);
                            //                             alert(strHome);
                            //                             alert(HomeTeam);
                            //                             alert(tempHomScr);
                            //                             alert(tempAscr);

                            if (tempHomScr == tempAscr)
                            {
                                ResultHistory = ResultHistory + "D";
                            }
                            else if(tempHomScr > tempAscr)
                            {
                                ResultHistory = ResultHistory + "W";
                            }
                            else
                            {
                                ResultHistory = ResultHistory + "L";
                            }
                        }
                    }
                }
            }
        }

        function createFragment(htmlStr) {

            var frag = document.createDocumentFragment(),
                temp = document.createElement('div');

            temp.innerHTML = htmlStr;

            while(temp.firstChild) {
                frag.appendChild(temp.firstChild);
            }

            alert(frag);
            return frag;
        }

        //         // remove unwanted cols
        //         $('.col-xs-12.col-sm-9 table tr').each(function(){

        //             //$(this).children('td').eq(14).remove();
        //             $(this).children('td').eq(13).remove();
        //             $(this).children('td').eq(10).remove();
        //             $(this).children('td').eq(9).remove();
        //             $(this).children('td').eq(7).remove();
        //             $(this).children('td').eq(0).remove();

        //             $(this).children('th').eq(13).remove();
        //             $(this).children('th').eq(10).remove();
        //             $(this).children('th').eq(9).remove();
        //             $(this).children('th').eq(7).remove();
        //             $(this).children('th').eq(0).remove();

        //         });

        //         $('#inplay_match_table tr').each(function(){

        //             //$(this).children('td').eq(14).remove();
        //             $(this).children('td').eq(13).remove();
        //             $(this).children('td').eq(10).remove();
        //             $(this).children('td').eq(9).remove();
        //             $(this).children('td').eq(7).remove();
        //             $(this).children('td').eq(0).remove();

        //             //$(this).children('th').eq(14).remove();
        //             $(this).children('th').eq(13).remove();
        //             $(this).children('th').eq(10).remove();
        //             $(this).children('th').eq(9).remove();
        //             $(this).children('th').eq(7).remove();
        //             $(this).children('th').eq(0).remove();
        //         });

        //     $("th").click(function(){
        //       var theLink = $(this).text();
        // //       alert(theLink);
        // //         sortTable(1);
        // });

    }

    function HideDIV(strName)
    {
        var adSidebar = document.getElementById(strName);
        if (adSidebar) {
            adSidebar.parentNode.removeChild(adSidebar);
        }
    }


})();