var geo_user_asked = 0;

var links = new Array();
links['en'] = new Array();
links['it'] = new Array();
links['fr'] = new Array();
links['de'] = new Array();
links['es'] = new Array();
links['pt-br'] = new Array();
links['nl'] = new Array();
links['ar'] = new Array();
links['cl'] = new Array();
links['mx'] = new Array();
links['at'] = new Array();
links['ch'] = new Array();

/* missing langauges*/
links['ro'] = new Array();
links['sv'] = new Array();
links['da'] = new Array();
links['ru'] = new Array();
links['bg'] = new Array();
links['el'] = new Array();



links['en']['game1'] = links['nl']['game1'] = links['pt-br']['game1'] =links['ro']['game1'] = links['sv']['game1'] = links['bg']['game1'] = links['ru']['game1'] = links['el']['game1'] = links['da']['game1']= '/slots.html';
links['en']['game2'] = links['nl']['game2'] = links['pt-br']['game2'] =links['ro']['game2'] = links['sv']['game2'] = links['bg']['game2'] = links['ru']['game2'] = links['el']['game2'] = links['da']['game2'] =  '/video-poker.html';
links['en']['game3'] = links['nl']['game3'] = links['pt-br']['game3'] =links['ro']['game3'] = links['sv']['game3'] = links['bg']['game3'] = links['ru']['game3'] = links['el']['game3'] = links['da']['game3'] =  '/blackjack.html';
links['en']['game4'] = links['nl']['game4'] = links['pt-br']['game4'] =links['ro']['game4'] = links['sv']['game4'] = links['bg']['game4'] = links['ru']['game4'] = links['el']['game4'] = links['da']['game4']=  '/roulette.html';
links['en']['game5'] = links['nl']['game5'] = links['pt-br']['game5'] =links['ro']['game5'] = links['sv']['game5'] = links['bg']['game5'] = links['ru']['game5'] = links['el']['game5'] = links['da']['game5']=  '/slots-tournaments.html';
links['en']['game6'] = links['nl']['game6'] = links['pt-br']['game6'] =links['ro']['game6'] = links['sv']['game6'] = links['bg']['game6'] = links['ru']['game6'] = links['el']['game6'] = links['da']['game6'] =  '/jackpots.html';



links['fr']['game1'] = 'machines-a-sous.html';
links['fr']['game2'] = links['it']['game2'] = links['de']['game2'] = links['es']['game2'] = 'video-poker.html';
links['fr']['game3'] = links['it']['game3'] = links['de']['game3'] = links['es']['game3'] = 'blackjack.html';
links['fr']['game4'] = links['it']['game4'] = links['de']['game4'] = links['es']['game4'] = 'roulette.html';
links['fr']['game5'] = links['es']['game5'] = 'slots-tournaments.html';
links['fr']['game6'] = links['de']['game6'] = 'jackpots.html';

links['it']['game1'] = links['de']['game1'] = links['es']['game1'] = 'slots.html';
links['it']['game5'] = links['de']['game5'] = 'tournaments_schedule.html';
links['it']['game6'] = 'slots-progressive.html';
links['es']['game6'] = 'progressive-slots.html';

links['ar']['game1'] = links['cl']['game1'] = links['mx']['game1'] = '/es/slots.html';
links['ar']['game2'] = links['cl']['game2'] = links['mx']['game2'] = '/es/video-poker.html';
links['ar']['game3'] = links['cl']['game3'] = links['mx']['game3'] = '/es/blackjack.html';
links['ar']['game4'] = links['cl']['game4'] = links['mx']['game4'] = '/es/roulette.html';
links['ar']['game5'] = links['cl']['game5'] = links['mx']['game5'] = '/es/slots-tournaments.html';
links['ar']['game6'] = links['cl']['game6'] = links['mx']['game6'] = '/es/progressive-slots.html';

links['at']['game1'] = links['ch']['game1'] = '/de/slots.html';
links['at']['game2'] = links['ch']['game2'] = '/de/video-poker.html';
links['at']['game3'] = links['ch']['game3'] = '/de/blackjack.html';
links['at']['game4'] = links['ch']['game4'] = '/de/roulette.html';
links['at']['game5'] = links['ch']['game5'] = '/de/tournaments_schedule.html';
links['at']['game6'] = links['ch']['game6'] = '/de/jackpots.html';

//alert(Drupal.settings.language+" "+seo_lang);
var suo_link="sub.html";
if(typeof seo_lang != "undefined")
{
  if(seo_lang==true)
	 suo_link="/sub.html";
	
}

//if(Get_Cookie('bTag').indexOf('ajaff03676_4400_1209') != -1 && Drupal.settings.language=='en') 
//	suo_link='moneybookers_welcome.html';
	
function createRequestObject() {
  var xmlhttp = null;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(f) {
      xmlhttp = null;
    }
  }
  if(!xmlhttp && typeof XMLHttpRequest != "undefined") {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.overrideMimeType('text/xml');
  }
  return  xmlhttp;
}
var httpObj = createRequestObject();

function handleResponse() {
  try {
    if((httpObj.readyState == 4) && (httpObj.status == 200)) {
      var response = httpObj.responseText;
      var newContent = document.createElement('div');
      newContent.style.zIndex = 1000;
      var dest = document.getElementById('FlashMovie');
      if(!dest) dest = document.getElementById('content');
      dest = document.body;
      if(dest) {
//       strresp = response.substring(response.search('<div class="content">')+21,response.search('<!--tutorial ends-->'));
       strresp = response.substring(response.search('<body class="mainPage">'+23),response.search('</body>'));
       dest.innerHTML = strresp;
      }
      dwnl();
    }
  }
  catch(e){ }
}

function sndReq() {
  dwnl();
  tutorial_win=window.open('getstarted.html');
  if (tutorial_win)
    tutorial_win.focus();
  return;

  httpObj.open('GET', 'getstarted.html');
  httpObj.onreadystatechange = handleResponse;
  httpObj.send(null);
}

function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function startDownloadWithTutor() {
  sndReq();
}

function startDownloadWithTutorInNewWin() {
  dwnl();
  window.open("/getstarted.html");
}

function location_submit(url) {
	location.href = url;
}

function ShowBtag() {
	var btg = ureadCookie('bTag');
	if(!btg) btg = 'default';
	return false;
}

function dwnl(source) { 
  
  if(typeof(source)=='undefined'){
    source = 'default';
  }
  // Wait for pcm.
  if (typeof(pcm)=='undefined' || pcm.ready == 0) {
    window.setTimeout('dwnl()',100);
    return;
  }
  data = pcm.data;
  bTag = pcm.data.btag;
  // Geo issue
  if (bTag.indexOf('ff1265') == -1) { // Cancel GEO redirect for affiliate with bTag aff1265
    if (typeof(data.geo) != 'undefined' && typeof(data.geo.country_code) != 'undefined') {
      if (data.geo.country_code == 'US') {
        geo_go();
        return false;
      }
      else if (data.geo.country_code == 'FR') {
        if(typeof(zeepzap.tracker._track_ga) != 'undefined') {
          zeepzap.tracker._track_ga({'virtual_pageview':'/fr_redirect'});
        }

        window.location.href = 'http://www.grandevegascasino.com/fr/alljackpotsredi.aspx';
        return false;
      }    
    }
  }

  if(typeof(data.tracking) != 'undefined') {
	if (typeof(data.tracking.download) != 'undefined' && parseInt(data.tracking.download) > 0) {
	  pcm.track(data.tracking.download);
	  setTimeout("start_dwnl()",1000);
	  return false;
	}
  }
  
  if(zeepzap.tracker._track_ga) {
	zeepzap.tracker._track_ga({'virtual_pageview':'/download_initiated'});
  }
  start_dwnl(source);
  return false;
}

function dwnl_m() {  
  // Wait for pcm.
  if (typeof(pcm)=='undefined' || pcm.ready == 0) {
    window.setTimeout('dwnl_m()',100);
    return;
  }
  data = pcm.data;
  bTag = pcm.data.btag;
  start_dwnl_m();
  return false;
}
function start_dwnl_m(source) {
 var tracked = '/AllJackpots-m.exe';
	  
 if (Drupal.settings.language && Drupal.settings.language != 'en') {
	var  prefix = Drupal.settings.language.substring(0,2);
	if (prefix == 'ja')
	  prefix = 'jp';
	 if(prefix == 'ar' || prefix == 'cl' || prefix == 'mx')
	   prefix == 'es';
	  tracked = '/' + prefix + tracked;
  }
  //  window.top.location.href="/dwnl.php?filename=alljackpotsviper.exe&bTag="+pcm.data.btag+'&ul='+Drupal.settings.language;
  var newloc="/dwnl.php?filename=AllJackpots-m.exe&bTag="+pcm.data.btag+'&ul='+Drupal.settings.language;
  if (pcm.data.btag5)
    newloc += "&bTag5=" + pcm.data.btag5
  if (pcm.data.btag4)
  	newloc += "&bTag4=" + pcm.data.btag4
  	
  if(source)
      newloc += "&bTag3=" + source;  	
      
  window.open(newloc,'dwnl');
}

function start_dwnl(source) {
 var tracked = '/AllJackpots.exe';
	  
 if (Drupal.settings.language && Drupal.settings.language != 'en') {
	var  prefix = Drupal.settings.language.substring(0,2);
	if (prefix == 'ja')
	  prefix = 'jp';
	 if(prefix == 'ar' || prefix == 'cl' || prefix == 'mx')
	   prefix == 'es';
	  tracked = '/' + prefix + tracked;
  }
//  window.top.location.href="/dwnl.php?filename=alljackpotsviper.exe&bTag="+pcm.data.btag+'&ul='+Drupal.settings.language;
  var newloc="/dwnl.php?filename=alljackpotsviper.exe&bTag="+pcm.data.btag+'&ul='+Drupal.settings.language;
  if (pcm.data.btag5)
    newloc += "&bTag5=" + pcm.data.btag5
  if (pcm.data.btag4)
  	newloc += "&bTag4=" + pcm.data.btag4
  	
  if(source)
      newloc += "&bTag3=" + source;  	
      
  window.open(newloc,'dwnl');
}

function openGame(game){
	window.open('demogame.html?gameid='+game+'&bTag='+Get_Cookie('bTag'),'game','width=665,height=680,resizable=yes,scrollbars=1,top=0,left=0');
}

// JS functions for FSCommands
function Download_DoFSCommand(command, args) {
  //alert(command + "  " + args);
  //alert(seo_lang);
  if (Drupal.settings.language) {
	 	 	 
	 if(Drupal.settings.language == 'en')
	   suo_link = '/sub.html';
	 if(Drupal.settings.language == 'ar' || Drupal.settings.language == 'mx' || Drupal.settings.language == 'cl')
	   suo_link = '/es/sub.html';
	 if(Drupal.settings.language == 'ch' || Drupal.settings.language == 'at')
		   suo_link = '/de/sub.html';
  }

  if(command == 'click'){
    if(args == 'suo'){
    	if(Get_Cookie('bTag').indexOf('ajaff03676_4400_1209') != -1 && Drupal.settings.language=='en') 
			suo_link='moneybookers_welcome.html';
     location.href=suo_link;
    }
    if(args == 'download')
      dwnl();
  }
}

function Games_DoFSCommand(command, args){
 // alert(command + "  " + args);
  if(command == 'click'){
    if(args == 'game1')
      location.href = links[Drupal.settings.language]['game1'];
    if(args == 'game2')
      location.href = links[Drupal.settings.language]['game2'];
    if(args == 'game3')
      location.href = links[Drupal.settings.language]['game3'];
    if(args == 'game4')
      location.href = links[Drupal.settings.language]['game4'];
    if(args == 'game5')
      location.href = links[Drupal.settings.language]['game5'];
    if(args == 'game6')
      location.href = links[Drupal.settings.language]['game6'];
  }
}

function Instant_DoFSCommand(command, args){
  if(command == 'click') {
     if(args == 'instant') {	 
    	instant_play();
    	return false;
     }
  }            
}

function live_dealer_DoFSCommand(command, args){
  if(command == 'click') {
     if(args == 'LD_Download') {	 
    	dwnl();
     }
  }            
}

function instant_play(source) {
	
  if(typeof(source)=='undefined'){
	    source = 'default_flash';
  }
// Wait for pcm.

  if (typeof(pcm)=='undefined' || pcm.ready == 0) {
    window.setTimeout('instant_play', 100);
	return;
  }
  data = pcm.data;
  bTag = pcm.data.btag;
  // Geo issue
  if (bTag.indexOf('ff1265') == -1) { // Cancel GEO redirect for affiliate with bTag aff1265
    var data = pcm.data;
    if (typeof(data.geo) != 'undefined' && typeof(data.geo.country_code) != 'undefined') {
      if (data.geo.country_code == 'US') {
        geo_go();
        return false;
      }
      else if (data.geo.country_code == 'FR') {
        if(typeof(zeepzap.tracker._track_ga) != 'undefined') {
          zeepzap.tracker._track_ga({'virtual_pageview':'/fr_redirect'});
        }

        window.location.href = 'http://www.grandevegascasino.com/fr/alljackpotsredi.aspx';
        return false;
      }    
    }
  }
    
  guid = Get_Cookie('PCMGUID');
    if(Drupal.settings.language == 'fr') {
      var new_url = "https://bigflash.gameassists.co.uk/french?bTag=" + Get_Cookie('bTag')+'&bTag3='+source;
    }else if(Drupal.settings.language == 'it'){
      var new_url = "https://bigflash.gameassists.co.uk/bigflash_italian/t3start.asp?bTag=" + Get_Cookie('bTag')+'&bTag3='+source;
    }else if(Drupal.settings.language == 'es' || Drupal.settings.language == 'ar' || Drupal.settings.language == 'mx' || Drupal.settings.language == 'cl'){
      var new_url = "https://bigflash.gameassists.co.uk/spanish?bTag=" + Get_Cookie('bTag')+'&bTag3='+source;
    } 
    /*else if(Drupal.settings.language == 'de' || Drupal.settings.language == 'at' || Drupal.settings.language == 'ch'){
        var new_url = "https://instant.allslotscasino.com/de?bTag=" + Get_Cookie('bTag')+'&bTag3='+source;
      }*/
    else {
      var new_url = "https://bigflash.gameassists.co.uk/bigflash/t3start.asp?bTag=" + Get_Cookie('bTag')+'&bTag3='+source;
    }
    if(guid!=null)
      new_url +="&trackingguid="+guid;
    if (pcm.data.btag5)
      new_url += "&bTag5=" + pcm.data.btag5;
    if (pcm.data.btag4)
  	  new_url += "&bTag4=" + pcm.data.btag4;
  	  
    if(typeof(zeepzap.tracker.track) != 'undefined') {
  	  zeepzap.tracker.track('virt', '/instant_initiated');
    }
  	
    if(Drupal.settings.language == 'de' || Drupal.settings.language == 'at' || Drupal.settings.language == 'ch'){
    	window.open(new_url);	
    	return false;
    }
    else{
    	window.open(new_url,'','width=770,height=535,toolbar=no,menubar=no,resizable,scrollbars=yes,location=no,status=1');
    	return false;
    }
}

function InnerDownload_DoFSCommand(command, args){
 // alert(command + "  " + args);
  if(command == 'click' &&  args == 'download')
    dwnl();
}

function do_redirect() {
	  if (geo_user_asked) {
	    return false;
	  }
	  geo_user_asked = true;
	  var data = pcm.data;
	  
    if (typeof(data.geo) != 'undefined' && typeof(data.geo.country_code) != 'undefined') {
      if (data.geo.country_code == 'US') {
        geo_go();
        return false;
      }
      else if (data.geo.country_code == 'FR') {
        if(typeof(zeepzap.tracker._track_ga) != 'undefined') {
          zeepzap.tracker._track_ga({'virtual_pageview':'/fr_redirect'});
        }

        window.location.href = 'http://www.grandevegascasino.com/fr/alljackpotsredi.aspx';
        return false;
      }    
    }
	  
	  if (!document.getElementById('geo_question')) {
	    var qdiv = document.createElement('div');
	    qdiv.id = 'geo_question';
	    $(document.body).append('<div id="geo_question"></div>');
	    $('#geo_question').load('/geo_popup.html');
	  }
	  else {
		$('#geo_question').show();
	  }
	  
	  return true;
	}

	function geo_go() {
	  data = pcm.data;
	  id = parseInt(data.id)
	  if (!id) {
		id = new Date().getTime();
	  }
	  newref = "http://downloads.jackpotcapital.com/affiliates/aiddownload.asp?casinoID=272&gAID=23874&subGid="+id+"&bannerID=6946";
	  var tracked = location.pathname;
	  if (location.search) {
	    tracked += location.search;
	  }
	  if (tracked.charAt(tracked.length-1)!='/') {
	    tracked += '/';
	  }
	  tracked += 'jackpotcapital';
			    
	  location.href = newref;
	  return false;
	}

	function geo_close() {
	  $('#geo_question').hide();
	  geo_user_asked = false;
	}
	
	
function dwnl_href(url){
  dwnl();
  if(url != '') 
  {
    tutorial_win=window.open(url);
    if (tutorial_win)
      tutorial_win.focus();
    return;
    
    httpObj.open('GET', url);
    httpObj.onreadystatechange = handleResponse;
    httpObj.send(null);
  }
}

function Lotr_DoFSCommand(command, args){
  dwnl();
}

