// JS functions for FSCommands

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', 'tutorial.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);
  var ext_btag = $.cookie('sp_medium');
  if(!ext_btag) ext_btag = '';
  else ext_btag = "_spv_" + ext_btag;
  if(command=="click") {
    if(args=="offer") {
       if((document.URL.indexOf('iphone-casino.html') != -1) || (document.URL.indexOf('mobile-casino.html') != -1) )
      location.href="welcome.html";
      else dwnl();
    }
    if(args=="suo") {
      dwnl();
    }
    if(args=="download") {
      dwnl();
    }
    if(args=="instant") {
      InstantPlay();
    }
    if(args=="read"){
       location.href="/welcome.html";
    }
    if(args=="promo") {
      startDownloadWithTutor();
    }
  }
}


function FlashMovieForBonus_DoFSCommand(command, args){
  if(command=="click") {
    if(args=="offer") {
      location.href="/welcome.html";
    }
  }
}
function FlashMovieMobile_DoFSCommand(command, args) {
  if(command=="click") {
    if(args=="offer" || args=="suo") {
      location.href="/mobile/cash_back.html";
    }
    if(args=="download") {
      location.href="/mobile";
    }
    if(args=="instant") {
      InstantPlay();
    }
    if(args=="promo") {
      location.href="/mobile/cash_back.html";
    }
    if(args=="playmobile") {
      location.href="/mobile";
    }
  }
}

function FlashMovieNewGames_DoFSCommand(command, args) {
//  alert(command + "  " + args);
  if(command=="click") {
    if(args=="promo") {
      location.href="freetournamentnew.html";
    }
    if(args=="offer" || args=="suo") {
      location.href="welcome.html";
    }
    if(args=="instant" || args=="promo") {
      InstantPlay();
    }
    if(args=="download") {
      startDownloadWithTutor();
    }
  }
}

function as_mob_splash01_DoFSCommand(command, args) {
 if(typeof bTag == 'undefined') {
  bTag = $.cookie('bTag');
 }
 if(bTag == null) {
  bTag = '';
 }
 if(bTag.indexOf('znpc')==0) {
   gdcp();
 }
 if(command=="click") {
  if(args=="play1") {
   location.href="http://www.allslotscasino.com/mobile/mobile-casino.html";
  }
  if(args=="play2") {
   location.href="http://www.allslotscasino.com/mobile/iphone-casino.html";
  }
 }
}

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() {
  dwnl();
  if (!as_geo.country || as_geo.country!='US') {
   tutorial_win=window.open('tutorial.html');
   if(tutorial_win) tutorial_win.focus();
  }
}
function startDownloadWithTutorInNewWin(){
 dwnl();
 if (!as_geo.country || as_geo.country!='US') {
  window.open("tutorial.html");
 }
}

function MySlot_DoFSCommand(command, args) {
  if(command=="click" && args=="download") {
    dwnl();
  }
}

function LuckySpin_DoFSCommand(command, args) {
  if(command=="click" && args=="download") {
      window.open("slots-bonus.html");
  }
}

function gotoGame(gameId) {
  guid = Get_Cookie('PCMGUID');
  var ext_btag = $.cookie('sp_medium');
  if(!ext_btag) ext_btag = '';
  else ext_btag = "_spv_" + ext_btag;

  bTag = Get_Cookie('bTag');
  if(bTag == null) bTag = '';
  
  var new_url = "https://allslots.gameassists.co.uk/allslots/t3start.asp?sEXT1=demo&sEXT2=demo&bTag="+ bTag + ext_btag;
  if(gameId.length>0)
    new_url += "&gameId="+gameId;
  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');
}
