// JavaScript Document

function download() {
document.write("<a href='/poker/download' class='bigDownload'>");
document.write("<img src='/images/poker/download/download-button.jpg' alt='Download Now' border='0'/>");
document.write("</a>");
}


//open 'play in browser' window (url is passed from the link)

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=795,height=532,left =200,top =200');");
}


//Sets a Cookie with the given name and value.

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

 // Gets the value of the specified cookie.

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}



//Deletes the specified cookie.


function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


$(document).ready(function() {
			
	var myurl = window.location.href;
	var expireTime = new Date();
	var oneMonth = 30 * 24 * 60 * 60 * 1000;
	expireTime.setTime( expireTime.getTime() + oneMonth);
	
	
	//creates the site and language cookies for the portal page
	var posLang = myurl.indexOf('/vcpoker/');
		var startLang = posLang + 9;
		if (posLang == -1) {
		posLang = myurl.indexOf('/bb-poker/');
		var startLang = posLang + 10;
		}
		
		var endLang = myurl.indexOf('/', startLang);
		var currentLanguage = myurl.substring(startLang,endLang);
		setCookie('vc_site', 'vcpoker', expireTime, '/', '', false);
		setCookie('language', currentLanguage, expireTime, '/', '', false);

	// Checks for btagid in the BTAGTracker cookie and btagid in the url (which will override the BTAGTracker)
	var pos = myurl.indexOf('btagid=');
	if (pos != -1) { 
		var start = pos + 7;
    	var end = myurl.indexOf(";", start);
		if (end == -1) end = myurl.length;
		var passCookie =  myurl.substring(start, end);
    	document.cookie = "BTAGTracker=" + passCookie + ";" + ";path=/" + ";expires=" + expireTime.toGMTString() + ";"	
	}
	//it then sends the btagid into the cashier iframe to stamp the cookie in the cashier
	var btag = getCookie("BTAGTracker");
		if (btag) {
			// add vc cashier cookie
			var aiFrame = '<iframe src="http://cashier.vcbet.com/webcashier/affiliate.jsp?btagid='+btag + '" width="0px" height="0px;" style="display:none;"></iframe>';
			// add hebrew cashier cookie
			aiFrame += '<iframe src="https://pokercashier.betvictor.com/webcashier/affiliate.jsp?btagid='+btag + '" width="0px" height="0px" style="display:none;"></iframe>';
		
			$('#wrapper').append(aiFrame);
		}


});


//function to get individual tournament details

function getTournamentData(tournament){
		
			   
		// get the JSON and create the table	   
	
		$.getJSON('/poker/tournaments/entraction', function(data) {
			$('#schedule').empty();
			var html = '<table class="table1 tourney"><thead><tr><th width="20%">Type</th><th>Details</th><th  width="20%">Buy-in</th><th width="20%">Start Date</th></thead><tbody>';
	
			$.each(data, function(entryIndex, entry) {
				if(entry['tournament_name'].match((tournament))  && entry['state'] == '0') {			  
					html += '<tr>';
					html += '<td>' + entry['game'] + '</td>';
					html += '<td>' + entry['tournament_name'] + ' - ' + entry['limit'] + '</td>';
					html += '<td>' + entry['buy_in'] + '</td>';
					html += '<td>' + entry['starttime'] + '</td>';
					html += '</tr>';
				}
				
			});
			html += '</tbody></table>';
			$('#tournament').append(html);
			$('.tourney tbody tr:odd').addClass('dark');
			$('.tourney tbody tr:even').addClass('light');
		
	});
		

}

function pokerGodFatherBTAG() {
//	var expireTime = new Date();
//	var oneMonth = 30 * 24 * 60 * 60 * 1000;
//	expireTime.setTime( expireTime.getTime() + oneMonth);
	
//	document.cookie = "banner_tag=13994;" + ";path=/" + ";expires=" + expireTime.toGMTString() + ";";
//  document.cookie = "BTAGTracker=13994;" + ";path=/" + ";expires=" + expireTime.toGMTString() + ";";	
	
//	var aiFrame = '<iframe src="http://cashier.vcbet.com/webcashier/affiliate.jsp?btagid=13994" width="0px" height="0px;" style="display:none;"></iframe>';
//	$('#wrapper').append(aiFrame);
}
         
