// 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);
  if(command=="click") {
    if(args=="offer" || args=="suo") {
      location.href="/welcome.html";
    }
    if(args=="download") {
      startDownloadWithTutor();
    }
    if(args=="instant") {
      InstantPlay();
    }
    if(args=="promo") {
      startDownloadWithTutor();
    }
    if(args=="playmobile") {
      location.href="/mobile";
    }
  }
}

function FlashMobile_DoFSCommand(command, args) {
  if (command == 'click') {
    if (args == 'mobile') {
      location.href="/mobile";
    }
  }
}

function FlashMovieNewGames_DoFSCommand(command, args) {
//  alert(command + "  " + args);
  bTag = Get_Cookie('bTag');
  if(bTag == null) bTag = '';
  
  if(command=="click") {
    if(args=="promo") {
      location.href="/freetournamentnew.html";
    }
    if(args=="offer" || args=="suo") {
      location.href="/welcome.html";
    }
    if(args=="instant" || args=="promo") {
    	guid = Get_Cookie('PCMGUID');
    	var new_url = "https://allslots.gameassists.co.uk/allslots/t3start.asp?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 as_mob_splash01_DoFSCommand(command, args) {
	 if(command=="click") {
		 if(args=="play1") {
			location.href="/mobile-casino.html";
		 }
		 if(args=="play2") {
			location.href="/iphone-casino.html";
		 }
	 }
}

function f( 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 '';
	}
}

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");
  }
}
