﻿
function cacheBurst() { var cb = cb + 1;var s = Math.round(Math.random()*100000,0);return s;}

//Clock
var clockId = 0;
var serverDate = new Date();
function CreateClock(y, m, d, h, M, S) {serverDate = new Date(y, m, d, h, M, S);DisplayTime();clockID = setTimeout("UpdateClock()", 1000);}
function DisplayTime() {var hours = Number(serverDate.getHours());var mins = Number(serverDate.getMinutes());var sec = Number(serverDate.getSeconds());if (hours < 10) hours = "0" + hours;if (mins < 10) mins = "0" + mins;if (sec < 10) sec = "0" + sec;var serverClock = document.getElementById("serverClock");serverClock.innerHTML = "" + hours + ":" + mins + ":" + sec;}
function UpdateClock() {if(clockId) {clearTimeout(clockId);clockId=0;}serverDate.setTime(serverDate.getTime() + 1000);DisplayTime();clockId = setTimeout("UpdateClock()", 1000);}
function KillClock() {if(clockId) {clearTimeout(clockId);clockId = 0;}}

//Windows
function liveResults(){var resultsPopup;var tmp;if (resultsPopup){tmp=resultsPopup;resultsPopup=null;}resultsPopup=window.open('live-results.aspx', 'LiveResults','height=580,location=0,menubar=0,personalbar=0,scrollbars=1,status=0,toolbar=0,width=720,resizable=1,screenx=0,screeny=0,left=0,top=0');}

function openFlashPoker() {
            var poker_link = 'https://mppv2flash3.valueactive.eu/Betshop/lobby/index.aspx';
            openFlashPokerPopup('poker_lobby', poker_link,790,571)
          }

           function openFlashPokerPopup(name, url, width, height) {
               //alert("The Instant Flash Poker is currently unavailable due to maintainance work. It will back online shortly.  Please make use of our Download version.");
               alert("Για να παίξετε θα πρέπει να είστε  χρήστης της Betshop. Δώστε το username και το password όταν σας ζητηθούν.");
               var new_win = window.open(url, name,'width=' + width + ',height=' + height + ',directories=no,toolbar=no,resizable=no,location=no,menubar=no,status=no,scrollbars=no');
            }


function help(url){
    var resultsPopup;
    var tmp;
    if (resultsPopup)
    {
        tmp=resultsPopup;
        resultsPopup=null;
    }
    resultsPopup = window.open(url, 'helpwin','height=600,location=0,menubar=0,personalbar=0,scrollbars=1,status=0,toolbar=0,width=800,resizable=1,screenx=0,screeny=0,left=0,top=0');
    resultsPopup.focus();
}

function bethelp(){    
    window.open('/bet-help.aspx', 'bethelp','height=600,location=0,menubar=0,personalbar=0,scrollbars=1,status=0,toolbar=0,width=800,resizable=1,screenx=0,screeny=0,left=0,top=0');
}

function liveChat(){window.open('http://server.iad.liveperson.net/hc/47173528/?cmd=file&file=visitorWantsToChat&site=47173528&SESSIONVAR!window_look=GrBetshop&referrer='+escape(document.location),'chat47173528','width=475,height=400,resizable=yes');return false;}

function MonthDays(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	} 
	return this;
}

function Feb (year){return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );}

function DateCheck(dday, mmonth, yyear){
    var daysInMonth = MonthDays(12);
	
	var month=parseInt(mmonth);
	var day=parseInt(dday);
	var year=parseInt(yyear);
	
	if ((year == -1) || (day == -1) || (month == -1)) {
		return false;
    }else {
    	if (dday.length<1 || day<1 || day>31 || (month==2 && day>Feb(year)) || day > daysInMonth[month]){
            return false;
        }
    }
   return true; 
}

function BirthDateCheck(dday, mmonth, yyear){
    if (DateCheck(dday, mmonth, yyear)){
	    
	    var x = new Date();
	    var yeardiff = x.getFullYear() - parseInt(yyear);
	    var monthdiff = x.getMonth() - parseInt(mmonth) + 1;
	    var daydiff = x.getDate() - parseInt(dday);
	    
	    if (yeardiff > 18){ return true; }
	    
	    if (yeardiff == 18 ){
	        if (monthdiff > 0){ return true; }
	        if (monthdiff == 0 && daydiff >= 0  ){ return true; }
	    }
    }
    
    return false;
}

function EmailCheck(field) {
	var good = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	if (good){return true} else {return false}
}

function UrlEncode(str) {
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    ret = encodeURIComponent(ret);
    for (search in histogram) {
        replace = histogram[search];
        tmp_arr = ret.split(search); // Custom replace
        ret = tmp_arr.join(replace); 
    }
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    return ret;
}


//Ajax
function updateBalance(updown)
{
    var textColor = "black";
    if (updown=="up") textColor = "green";
    else if (updown=="down") textColor = "red";
    else textColor = "black";
    var url = "/handlers/ajaxfunctions.ashx?command=getbalance&cb=" + cacheBurst();     
    $j.get(url, function(result){
        $j("#ctl00_HeaderUI1_loginUI___lblBalance").fadeOut("slow").css("color",textColor).fadeIn("slow").html(result);
    },"text");
}

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (dblValue + '.' + strCents);
}