﻿var CounterID;

GetPageName();

var PartnerId = GetValue("PartnerId");
if (PartnerId == "")
{
    PartnerId = "t4u";
}

if ((document.location.href.toLowerCase().search("summarypagenew.aspx") > -1) || (document.location.href.toLowerCase().search("default.aspx") > -1))
{
    sitestat("https://uk.sitestat.com/hotels4u/hotels4u/s?T4U." + PartnerId + "." + CounterID);
}
else
{
	sitestat("http://uk.sitestat.com/hotels4u/hotels4u/s?T4U." + PartnerId + "." + CounterID);
}
	
//Debugging Code
//alert(CounterID);
//document.write("<font color=white>" + CounterID + "</font>");


//GetSearchParam();

function GetPageName()
{
	var Page;
	var Pos;
	var Pos2;

	Page = document.location.href;

	Pos = Page.lastIndexOf('/');
	Pos2 = Page.indexOf('?');

	if (Pos2>-1)		//Remove any QueryString
	{
		var tmp;

		tmp = Page.substring(0,Pos2);
		Pos = tmp.lastIndexOf('/');

		CounterID = tmp.substring(Pos+1);
	}
	else
	{
		if (Page.length-1 == Pos)	//no page name, its Default.aspx
			CounterID = "default.aspx";	
		else
			CounterID = Page.substring(Pos+1);
	}
}

function sitestat(ns_l)
{
	
	ns_l+='&amp;ns__t='+(new Date()).getTime();
	ns_pixelUrl=ns_l;
	ns_0=document.referrer;
	ns_0=(ns_0.lastIndexOf('/')==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf('/'),0):ns_0;
	
	if(ns_0.length>0)
		ns_l+='&amp;ns_referrer='+escape(ns_0);
	
	if(document.images)
	{
		ns_1=new Image();
		ns_1.src=ns_l;
	}
	else
		document.write('<img src="'+ns_l+'" width="1" height="1" alt="">');
}


/*
This function is to retive the SearchParameter Values from the Querystring
This can be used to set the CounterID to PageName + Search Parameters to 
further analyse the Search Trafic.
*/
function GetSearchParam()
{
    var URL = document.location.href;
    var Param = "";
    
    if (URL.toLowerCase().indexOf('searchresults.aspx')>-1)
    {
        var AirportCode;
        var GatewayCode;
        var ResortID;
        var BuildingID;
        var BuildingName;
        var CheckInDate;
        var Duration;
        var Occu;
        
        AirportCode = GetValue("AirportCode");
        GatewayCode = GetValue("GatewayCode");
        ResortID = GetValue("ResortID");
        BuildingID  = GetValue("BuildingID");
        BuildingName  = GetValue("BuildingName");
        CheckInDate  = GetValue("CheckInDate");
        Duration  = GetValue("Duration");
        Occu  = GetValue("Occu");
        
        //alert('AirportCode:' + AirportCode + ' GatewayCode:' + GatewayCode + ' ResortID:' + ResortID + ' BuildingID: ' + BuildingID + ' BuildingName:' + BuildingName + ' CheckInDate:' + CheckInDate + ' Duration: ' + Duration + ' Occu: ' + Occu);
        
        /*
        Param+= CheckInDate;
        Param+= "," + Duration;
        Param+= "," + Occu;
        
        
        if (AirportCode != 0 && AirportCode != "")
            Param+= "," + AirportCode;
 
        if (GatewayCode != 0 && GatewayCode != "")
            Param+= "," + GatewayCode;
            
        if (ResortID != 0 && ResortID != "")
            Param+= "," + ResortID;
            
        if (BuildingID != 0 && BuildingID != "")
            Param+= "," + BuildingID;    
        
        if (BuildingName != "")
            Param+= "," + BuildingName;    
        */
        
        
        
    }
        
}

function GetValue(key)
{
    var URL = document.location.href.toLowerCase();
    var arrValue;
    var value = "";
    
    key = key.toLowerCase();
    arrValue= URL.split('&');
    
    for (i=0;i<arrValue.length;i++)
    {
        if (arrValue[i].indexOf(key)>-1)
        {
            var pos = arrValue[i].indexOf('=');
            
            if (pos>-1)
            {
           
                value=arrValue[i].substring(pos+1); 
               
            }
        }
    }
    
    
    return value;
}