//
// global.js
// Paul Dragicevich, 28/11/2008
//
// Global page code.
//

var Global = Global ? Global : {};

// Flash parameters defined for every flash embed.
Global.FlashParameters = { wmode: 'transparent', quality: 'high' };

//
// document.ready
//
$(function(){
   //Global.SecureFormCheck();
   Global.ActivateFlashMarkup();
});


//
// Global.SecureFormCheck
// Check if we contain a frame that points to an SSL URL.
// If we are not SSL, make it so :)
//
Global.SecureFormCheck = function ()
{
   var windowUrl = window.location.href.toString();
   if ( windowUrl.length < 4 )
   {
      return;
   }
   var isSecure = (windowUrl.indexOf('https') === 0);
   var hasSecureForm = false;
   $('iframe').each(function()
   {
      var iframeSrc = $(this).attr('src').toLowerCase();
      if ( iframeSrc.indexOf('https://farcry.rac') === 0 )
      {
         hasSecureForm = true;
      }
   });
   if ( hasSecureForm && !isSecure )
   {
      var newUrl = 'https' + windowUrl.substr(4);
      window.location.replace(newUrl);
   }
}


//
// Global.SiteIntelligenceFormTaggingHookup
// Hook up Site Intelligence form tagging code to any form submit event.
//
Global.SiteIntelligenceFormTaggingHookup = function ()
{
   $('form#form1').submit(Global.SiteIntelligenceFormTracking);
}



//
// Global.SiteIntelligenceFormTracking
// Wrap SiteIntelligence form tracking call.
// Don't include hidden fields.
//
Global.SiteIntelligenceFormTracking = function ()
{
   var start = (new Date()).valueOf();
   var form1 = document.getElementById('form1');
   var fieldList = [];
   var name;
   $('input,select,textarea', form1).each(function(){
      name = $(this).attr('name');
      if ( name.substr(0,2) !== '__' )
      {
         fieldList[fieldList.length] = name;
      }
   });

   SiTrackFormData(form1, fieldList);
}




//
// Global.ActivateFlashMarkup
// Use SWFObject to activate markup as flash.
// Users create objects with css class SWFObject,
// and include the other neccessary parameters.
//
Global.ActivateFlashMarkup = function ()
{
   var id;
   var swfWidth;
   var swfHeight;
   var swfVersion;
   var swfUrl;

   $('.SWFObject').each(function(){
      id = $(this).attr('id');
      swfUrl = $(this).attr('swfurl');
      swfWidth = $(this).attr('swfwidth');
      swfHeight = $(this).attr('swfheight');
      swfVersion = $(this).attr('swfversion');
      if ( id && swfUrl && swfWidth && swfHeight && swfVersion )
      {
         swfobject.embedSWF(swfUrl, id, swfWidth, swfHeight, swfVersion, undefined, Global.FlashParameters);
      }
   });
}

//
// Global.GetRadioButtonListSelection
// Get the selected value of an ASP.NET generated radio button list.
//
Global.GetRadioButtonListSelection = function ( listId )
{
   var v = '';
   var radioIndex = 0;
   var radio = $('#'+listId+'_'+radioIndex);
   while ( radio.length == 1 )
   {
      if ( radio.attr('checked') )
      {
         v = radio.attr('value');
         break;
      }
      radioIndex++;
      radio = $('#'+listId+'_'+radioIndex);
   }
   return v;
}


