/**
* Allows new functions to be added to existing 'onload' events
*/
//Enquisite tagging for flash
//loc is the location that you'd like to record
//ref is the referrer. (optional)
function enq_flash(loc, ref)
{	
	var newLoc = window.location.protocol + "//" + window.location.host + "/flash/" + loc;
		
	//Deprecated on client request - gA.
	/*
    var enq_id = enquisiteid;
    
    if(enq_id == null)
    {
    	enq_id = "";
    }
    
    var enq_param=new Array();
        
    enq_param.push('location='+escape(newLoc));
    if(ref)
    {
    	enq_param.push('referrer='+escape(ref));
    }
    else
    {
        enq_param.push('referrer='+escape(document.referrer));
    }
    enq_param.push('ua='+escape(navigator.userAgent));
        
    enq_param.push('pc='+escape(enqp ? enqp : enq_rc('enqp')));
    enq_param.push('sc='+escape(enqs ? enqs : enq_rc('enqs')));
        
    enq_param.push('r='+Math.random());
    var i=new Image();
    var p=enq_param.join('&');
    var enq_url=(document.location.href.substring(0,5)=='https')?'https://logssl.enquisite.com':'http://log.enquisite.com';
    var s=enq_url+'/d.js?id='+enq_id+'&'+p;
    var i=new Image();
    i.src=s;
    */
        
    //insightgrit tag
    var ins_url = "http"+(document.URL.indexOf('https:')==0?'s':'')+"://app.insightgrit.com/1/nat?id=" + insightid  + "&ref="+window.document.referrer.replace(/&/g, '|@@|')+"&z="+Math.floor(Math.random()*999999)+"&purl="+newLoc.replace(/&/g, '|@@|');
    var j=new Image();
    j.src = ins_url;
}

/**
 * @param cookieName A String value of the cookie name to return data from.
 */
function enq_cookie(cookieName) 
{
	//Enquisite tags have been deprecated upon client request. - gA
	/*
 	var theCookie = "" + document.cookie;
	var ind = theCookie.indexOf(cookieName);
	
	//alert('ind = ' + ind + ' | ' + 'name = ' + cookieName);	
	
 	if(ind == -1 || cookieName == "") 
 		return "";
 		
 	var ind1 = theCookie.indexOf(';',ind);
 	
 	if(ind1 == -1) 
 		ind1=theCookie.length;
 		
 	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
 	*/
}

/**
 * 
 */
function googleAdPageConversion(imageSrc)
{			 	
	var img = new Image();
	img.src = imageSrc;
}	

/**
 * Function used to write images from flash
 */
function pixelTag(imageSrc)
{			 	
	var img = new Image();
	img.src = imageSrc;
}

/**
 * pageUrl does nothing but is there in case we need it
 */
function steelhouseTag(pageUrl, siteName){
	
	// tracking pixel
	var aid='9236',
	site = (siteName || "unknown");
	
	document.getElementById('steelhouseFrame').contentWindow.steelhouseTag(pageUrl, siteName);

//	var additional = "&"+ site +"=1"; // add additional arguments here. please start off with '&'
//	(function(){steelhouse={add:function(a,b,c,d){d=d||false;if(a.addEventListener){a.addEventListener(b,c,d)}else if(a.attachEvent){a.attachEvent("on"+b,c)}},load:function(){var a;if(typeof a=='undefined'){a=Math.random()*10000000000000000}var b=document.createElement('script');var c='px.steelhousemedia.com/st?aid='+aid+'&cb='+a+additional;b.type='text/javascript';b.src=('https:'==document.location.protocol?'https://':'http://')+c;var d=document.getElementsByTagName('script');var e=Number(d.length)-1;var f=document.getElementsByTagName('script')[e];f.parentNode.insertBefore(b,f)}};steelhouse.load();})();

}

function mediaplexTag(url){
	//console.log("mediaplex track ", url);
	document.getElementById("mediaplexFrame").src = url;
}


/**
 * This methods started as a way to fire off insight tags at the end of the IBE confirmation process.
 * MHG added the need to fire off a Spotlight tag at the same time so we have combined both processes
 * into one combined method for ibe order confirmation event handling.
 * @param	total		- Insigth Param
 * @param	currency	- Insigth Param
 * @param	hotelId		- Insigth Param
 * @param	orderId		- Insigth Param
 * @param	checkIn		- Insigth Param
 * @param	nightsBooked	- Insigth Param
 * @param	email		- Insigth Param
 * 
 * @param	hotelName	- Spotlight Param
 */
function ibeConfirmationTracking(total,currency,hotelId,orderId,checkIn,nightsBooked,email,hotelName)
{
	var r = total;
	var oc = currency;
	var p1 = orderId;
	var p2 = hotelId;
	var p3 = checkIn;
	var p4 = nightsBooked;
	var p5 = (email != null & email != "") ? email : "unknown";
	var s = "http"+(document.URL.indexOf('https:')==0?'s':'')+"://app.insightgrit.com/1/ct?id=49984187&z="+Math.floor(Math.random()*999999)+"&r="+r+"&p1="+p1+"&p2="+p2+"&p3="+p3+"&p4="+p4+"&p5="+p5+"&oc="+oc+"&purl="+document.URL;
	var j=new Image();
	j.src = s;
	
	//Doubleclick tags deprecated on client request - gA
	/*
	var t = "";
	if(hotelId == 18)
	{
		t = "https://ad.doubleclick.net/activity;src=2456088;type=mondr732;cat=mondr466;u1=" + hotelName +  ";qty=1;cost=" + total + ";ord="+ orderId + "?";
	}
	else
	{
		t = "https://ad.doubleclick.net/activity;src=2456088;type=morga326;cat=morga495;u1=" + hotelName +  ";qty=1;cost=" + total + ";ord="+ orderId + "?";	
	}
	var k = new Image();
	k.src = t;
	*/
	
	var u = "https://trvlnet.adbureau.net/TrackAction/ADVID=692";
	var l = new Image();
	l.src = u;
}

/**
 *
 */


function onResizeHome()
{
	if (swfobject.hasFlashPlayerVersion("7.0.0"))
    {
	
		var browserHeight = $(window).height();
		var browserWidth = $(window).width();
		var minFlashHeight = 558;
		var minFlashWidth = 990;
		//need to subtract out spacing for html header and footer
		var navHeight = 50;
		
		var container = document.getElementById("container");
		container.style.marginLeft = 0;
		container.style.marginRight = 0;
		container.style.width = "auto";
		
		try 
		{
			var flashDiv = document.getElementById("morgans_home_flash");
			flashDiv.height = (browserHeight >= minFlashHeight) ? browserHeight-navHeight : minFlashHeight;
			flashDiv.width = (browserWidth >= minFlashWidth) ? browserWidth : minFlashWidth;
		}
		catch(e)
		{
			//flash must be enabled and written to the page for the resize functionality to work
		}
    }
}

/**
 *
 */
function onBrowserResize()
{
	var browserHeight = $(window).height();
	var browserWidth = $(window).width();
	var minFlashHeight = 600;
	var minFlashWidth = 990;
	
	try{
	
		var flashDiv = document.getElementById("morgans_flash");
		flashDiv.height = (browserHeight >= minFlashHeight) ? browserHeight : minFlashHeight;
		flashDiv.width = (browserWidth >= minFlashWidth) ? browserWidth : minFlashWidth;
		
	}
	catch(e)
	{
		//flash must be enabled and written to the page for the resize functionality to work
	}
}

/**
 *
 */
function getBrowserObjects()
{
    // Create an array to hold each of the browser's items.
    var tempArr = new Array();

    // Loop over each item in the browser's navigator object.
    for(var name in navigator)
    {
        var value = navigator[name];

        // If the current value is a string or Boolean object, add it to the
        // array, otherwise ignore the item.
        switch (typeof(value))
        {
            case "string":
            case "boolean":

                // Create a temporary string which will be added to the array.
                // Make sure that we URL-encode the values using JavaScript's
                // escape() function.
                var tempStr = "navigator." + name + "=" + escape(value);
                // Push the URL-encoded name/value pair onto the array.
                tempArr.push(tempStr);
                break;
        }
    }
    // Loop over each item in the browser's screen object.
    for(var name in screen)
    {
        var value = screen[name];

        // If the current value is a number, add it to the array, otherwise
        // ignore the item.
        switch (typeof(value))
        {
            case "number":
                var tempStr = "screen." + name + "=" + escape(value);
                tempArr.push(tempStr);
                break;
        }
    }
    // Return the array as a URL-encoded string of name-value pairs.
    return tempArr.join("&");
}

/**
 *
 */
function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}
