// JS functions for FSCommands
var bTag = Get_Cookie('bTag');
if(bTag == null) bTag = '';

var links = new Array();
links['it'] = new Array();

if(bTag.indexOf('asCa495225_aff_466CT10_it') != -1)
     links['it']['welcome'] = '/it/casinotop10.html';
else if(bTag.indexOf('asCa495225_aff_466CTL_it') != -1)
     links['it']['welcome'] = '/it/casinoonline_welcome.html';
else if(bTag.indexOf('asaff2664_5600') != -1)
     links['it']['welcome'] = '/it/askgamblers_welcome.html';
else if(bTag.indexOf('asez_5600') != -1)
     links['it']['welcome']="/it/onlinekeno_welcome.html";
else if(bTag.indexOf('asaff04188_IT') != -1 || bTag.indexOf('asaff04188_it') != -1 || bTag.indexOf('asaff04188_TRFSD25') != -1)
     links['it']['welcome']="/it/gamblingplanet_welcome.html";
else if(bTag.indexOf('ca410835_aff_') != -1)
     links['it']['welcome']="/it/casinoweb_welcome.html";
else if(bTag.indexOf('asaff03548_TRFSD25') != -1)
     links['it']['welcome']="/it/welcome.html";
else if(bTag.indexOf('as_sj94') != -1)
     links['it']['welcome']="/it/giocacasino_welcome.html";
else
     links['it']['welcome'] = "/it/welcome.html";//"/it/benvenuto.html";


if(bTag.indexOf('asaff03548_TRFSD25') != -1 || bTag.indexOf('asaff04188_TRFSD25') != -1)
    links['it']['promo'] = '/it/25freespins.html';
else
    links['it']['promo'] = '';//'/it/thunderstruck2slot.html';
 
function createRequestObject() {
  var xmlhttp = null;
  try {
    xmlhttp = new XMLHttpRequest();
  } 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 sndReq() {
  httpObj.open('GET', 'guida.html');
  httpObj.onreadystatechange = handleResponse;
  httpObj.send(null);
}

function handleResponse() {
  try {
    if((httpObj.readyState == 4) && (httpObj.status == 200)) {
      var response = httpObj.responseText;
      strresp = response.substring(response.search('<div class="main">'),response.search('</body>'));
      document.getElementById('bodyelem').innerHTML = strresp;
      document.getElementById('innersuo').innerHTML = '<object width="220" height="140" id="FlashMovie" name="FlashMovie" type="application/x-shockwave-flash" data="http://www.allslotscasino.com/sites/default/themes/as/flash/as_inr_suo01.swf"><param name="allowScriptAccess" value="sameDomain" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="movie" value="http://www.allslotscasino.com/sites/default/themes/as/flash/as_inr_suo01.swf" /></object>';
    } else {
      try{}
      catch(e){
        alert("display div  undefined");
      }
    }
  }catch(e) {}
  finally{}
}

function FlashMovie_DoFSCommand(command, args) {
	//alert(command + ' ' + args);
  if(command=="click") {
    if(args=="offer" || args=="suo") {
      location.href="/it/benvenuto.html";
    }
    if(args=="download") {
      startDownloadWithTutor();
    }
    if(args=="instant") {
    	guid = Get_Cookie('PCMGUID');
    	var new_url = "https://allslots.gameassists.co.uk/italian/?bTag=" + bTag;
    	if(guid!=null)
    	 new_url +="&trackingguid="+guid;
      window.open(new_url,'game_window','width=810,height=670,resizable=yes,scrollbars=1,top=0,left=0');
    }
    if(args=="promo") {
      startDownloadWithTutor();
    }
    if(args=="playmobile") {
      location.href="http://www.allslotscasino.com/mobile.html";
    }
    if(args=="read") {
    	location.href="/it/welcome.html";
    }
  }
}

function FlashMobile_DoFSCommand(command, args) {
  if (command == 'click') {
    if (args == 'mobile') {
      location.href="http://www.allslotscasino.com/mobile.html";
    }
  }
}

function FlashMovieNewGames_DoFSCommand(command, args) {
//  alert(command + "  " + args);
  if(command=="click") {
    if(args=="promo") {
      location.href="/it/freetournamentnew.html";
    }
    if(args=="offer" || args=="suo") {
      location.href="/it/benvenuto.html";
    }
    if(args=="instant" || args=="promo") {
    	guid = Get_Cookie('PCMGUID');
    	var new_url = "https://allslots.gameassists.co.uk/italian/?bTag=" + bTag;
    	if(guid!=null)
    	 new_url +="&trackingguid="+guid;
      window.open(new_url,'game_window','width=810,height=670,resizable=yes,scrollbars=1,top=0,left=0');
    }
    if(args=="download") {
      startDownloadWithTutor();
    }
  }
}

function Flash2009_DoFSCommand(command, args) {
//alert(command+ ' '+ args)
  var gameId = "empty";
  var section = "empty";
  if(command=="click") {
    switch (args) {
     case "download":
//      location.href = "/download.html?download=1";
      dwnl();
     //dwnl_new_win();
     //tutorial_win=window.open('/it/scarica.html');tutorial_win.focus();

      break;
     case "download1":
     case "download2":
     case "download3":
      dwnl();
      break;
     case "suo":
        if(typeof(firstmovie) != "undefined")
		    {
	        if(firstmovie=='hp_it_5600')
	     		  location.href = '5600_welcome.html';
		    }
       else
          location.href = links['it']['welcome'];

      break;
     case "suo1":
     case "side":

        location.href = "/it/scarica.html";

      break;
     case "suo_main":
      if(firstmovie=='hp_it_5600')
     		location.href = '5600_welcome.html';
     	else if(bTag.indexOf('asCa495225_aff_466CT10_it') != -1)
          location.href = '/it/casinotop10.html';
       else if(bTag.indexOf('asCa495225_aff_466CTL_it') != -1)
          location.href = links['it']['welcome'];
      else
          location.href = "/it/benvenuto.html";
      break;
     case "win":

        location.href = "/it/tournaments.html";

      break;
     case "lucky_spin":

        location.href = "/it/slots-bonus.html";

      break;
     case "instant":
      gameId = "";
      break;
     case "game1":
      gameId = "RubyTombRaiderII";
      break;
     case "game2":
      gameId = "5ReelDrive";
      break;
     case "game3":
      gameId = "bj";
      break;
     case "game4":

        location.href = "/it/all-slots-casino.html";

      break;
     case "game5":
      location.href = "/it/all-slots-casino.html";
      break;
     case "game6":
      //gameId = "Thunderstruck";
      location.href = "/it/all-slots-casino.html";
      break;
     case "promo":
           if(links['it']['promo'] != '')
    	         location.href = links['it']['promo'];
    	     else dwnl();
    	 break;
    }
    if(gameId!="empty") {
      gotoGame(gameId);
    }
  }
}


function PlayNow2009_DoFSCommand(command, args) {
 var ext_btag = readCookie('sp_medium');
  if(!ext_btag) ext_btag = '';
  else ext_btag = "_spv_" + ext_btag;
  if(command=="click") {
    switch (args) {
     case "instant":
      gameId = "";
     /* if(urchinTracker) {
          urchinTracker('/launchflash');
      }*/
      InstantPlay();
      return;
      break;
     case "mobile":
        gameId="empty";
        location.href = "/mobile/iphone-casino.html";
      break;
    }
    if(gameId!="empty") {
      gotoGame(gameId);
    }
  }
}

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();
  dwnl();
  tutorial_win=window.open('/it/guida.html');tutorial_win.focus();
}
function startDownloadWithTutorInNewWin(){
	dwnl();
  	window.open("/it/guida.html");
}

function SplashCenter_DoFSCommand(command, args) {
//  alert(command + " " + args);
  if (command == 'click') {
    switch (args) {
      case "suo" :
        location.href="/it/benvenuto.html";
        break;
      case "download" :
        dwnl();
        break;
      case "instant" :
        guid = Get_Cookie('PCMGUID');
        var new_url = "https://allslots.gameassists.co.uk/italian/?bTag=" + bTag;
        if(guid!=null) {
          new_url +="&trackingguid="+guid;
        }
        window.open(new_url,'game_window','width=810,height=670,resizable=yes,scrollbars=1,top=0,left=0');
        break;
      case "playmobile" :
        location.href="http://www.allslotscasino.com/mobile.html";
        break;
    }
  }
}

function HowToPlay_DoFSCommand(command, args) {
  if (command=='click') {
    switch (args) {
      case "action1" :
        location.href = 'guida.html','game_window','width='+screen.availWidth+',height='+screen.availHeight+',resizable=yes,scrollbars=1,top=0,left=0';
        break;
      case "action2" :
        location.href = 'guida_crea_conto.html','game_window','width='+screen.availWidth+',height='+screen.availHeight+',resizable=yes,scrollbars=1,top=0,left=0';
        break;
      case "action3" :
        location.href = 'guida_deposito.html','game_window','width='+screen.availWidth+',height='+screen.availHeight+',resizable=yes,scrollbars=1,top=0,left=0';
        break;
    }
  }

}

function gotoGame(gameId) {

/*  if(gameId.length>0) {
    window.location.href = "/free_games.html?gameid="+gameId;
  }
  else {*/
    guid = Get_Cookie('PCMGUID');
    var ext_btag = readCookie('sp_medium');
    if(!ext_btag) ext_btag = '';
    else ext_btag = "_spv_" + ext_btag;
   	var new_url = "https://allslots.gameassists.co.uk/italian/?bTag=" + bTag + ext_btag;
    if(gameId.length>0)
      new_url += "&gameId="+gameId+"&sEXT1=demo&sEXT2=demo";
    if(guid!=null)
      new_url +="&trackingguid="+guid;
    window.open(new_url,'game_window','width=810,height=670,resizable=yes,scrollbars=1,top=0,left=0');
  //}
}

function dwnl_flash(){
  guid = Get_Cookie('PCMGUID');
  var new_url = "https://allslots.gameassists.co.uk/italian/?bTag=" + bTag;
  if(guid!=null) {
   new_url +="&trackingguid="+guid;
  }
  window.open(new_url,'game_window','width=810,height=670,resizable=yes,scrollbars=1,top=0,left=0');
}

function chLang(obj) {
 location.href=obj.value;
}
