// JavaScript Document
/*PLACE AT THE BOTTOM OF THE PAGE WHERE THE WHOLE PAGE NEEDS TO LOAD FIRST BEFORE TRIGGERING THE SCRIPTS*/

function RetrieveURLFlash()
{
	/*FUNCTION TO RETRIEVE ORIGIN AND TARGET URL*/
	var originURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;

	var StringSpliter = "?&";
	var targetURL = window.location.href;

	/*FUNCTION TO STRIP OUT TARGET URL*/
	targetURL = window.location.toString();
	
	var myArr = new Array();
	
	myArr = targetURL.split(StringSpliter);
	
	for(var i=0;i<myArr.length;i++)
	{
		//trace("URL " + i + " = " + myArr[i] + "<br />");
		if(i == 1)
		{
			/*FUNCTION LAUNCH MODAL WINDOW*/
			var myString = new String();
			myString = "#";
			targetURL = myString.replace(/#/,myArr[i] + "?TB_iframe=true&amp;height=490&amp;width=510");
			trace(targetURL);
			$(document).ready(function(){
				tb_show("",targetURL,"");
			});
		}
	}
}

function ReplaceAddBar(url)
{
	/* THEORY: THIS FUNCTION INSERTS THE HOSTS FULL URL + A BUTTONS LINK LOCATION THEN EXCHANGES THESE TO THE BROWSERS ADDRESS BAR */
	var originURL = window.location.protocol + "//" + window.location.host + window.location.pathname;

	/* Identify current domain url and the buttons link location */
	var targetURL = window.location.href;
	
	/* InsertHash  */
	var InsertHash = window.location.hash = "apps";
	
	/* Inject the string splitter */
	var StringSpliter = "?$";
	
	/* Merge targetURL + StringSpliter + buttonLinkLocation */
	var CaptureAndReplace = targetURL + StringSpliter + url;
	trace('CaptureAndReplace: ' + CaptureAndReplace);
	
	/*CLEAR THE BROWSERS ADDRESS BAR FIRST*/
		
	
	/* Replace the browser's current URL */
	window.location.href(CaptureAndReplace);
	
}

/*FUNCTION ADD LOAD EVENT HANDLER*/
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

addLoadEvent(function() {
	RetrieveURLFlash();
})

/*addLoadEvent(function() {
	ReplaceAddBar();
})*/

/*FUNCTION TO TRACE*/
function trace( msg ){
  if( typeof( jsTrace ) != 'undefined' ){
    jsTrace.send( msg );
  }
}