
function openNewsLetterSubscription() 
{
	popupWin = window.open('NewsletterSubscription.aspx?EmailAddress=', 'open_window', 'width=650, height=300');
}


function openNewsLetterSubscriptionForStaticHotelProfilePage() 
{
	popupWin = window.open('../NewsletterSubscription.aspx?EmailAddress=', 'open_window', 'width=650, height=300');
}

function openNewsLetterSubscriptionByAgent() 
{
	var objNewsletterWindow;
	objNewsletterWindow = window.open('NewsletterSubscription.aspx?EmailAddress=&Action=UnSubscribe','Newsletter_Subscription','width=650,height=300,,,resizable=no,scrollbars=yes');
}

function openNewsLetterUnSubscription(strEmail) 
{
	var objNewsletterWindow;
	objNewsletterWindow = window.open('NewsletterSubscription.aspx?EmailAddress=' + strEmail + '&Action=UnSubscribe','Newsletter_Subscription','width=650,height=300,,,resizable=no,scrollbars=yes');
}


function openCustomerVoucher(strOurReference) 
{
	var objNewsletterWindow;
	objNewsletterWindow = window.open('./Voucher/CustomerVoucher.aspx?OR=' + strOurReference,'Newsletter_Subscription','width=800,height=700,,,resizable=no,scrollbars=yes');
	//objNewsletterWindow = window.showModalDialog('./Voucher/CustomerVoucher.aspx?OurReference=' + strOurReference ,'','dialogHeight:800px;;;dialogWidth:800px;center:yes;;;;resizable:no;scroll:yes;status:no');
}

function OpenAffiliateTermsConditions()
{
  var objAffiliateTermsConditionsWindow;
  objAffiliateTermsConditionsWindow = window.open('PopupAffiliateTermsOfUse.aspx','AffiliateTermsAndConditions','width=800,height=600,,,resizable=no,scrollbars=yes,top=110,left=180');
}

// Function Name: CheckEmail
// Description: This function validates the Email field
function CheckEmail(strEmail)
{

    var checkAlpha="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    var checkOther="_.-'"
    var emailValid=true;
    var checkAtDot=false;  
    var i,j,ch;
    
	//Removing white spaces from strName
	while(strEmail.charAt(0)==' ')
	       strEmail=strEmail.substring(1,strEmail.length); 

    //checking for first character is alpha numeric or not
    for(i=0; i<checkAlpha.length; i++)
     {
       if(strEmail.charAt(0)==checkAlpha.charAt(i))
       {
         emailValid=true;   
         break;
       }
       else
         emailValid=false;
     }

     //Returning false if the first character was not alphabet 
     if(emailValid==false) return false;
   
    //checking the characters before '@' character
    for(i=1; i<strEmail.length; i++)
	{
	    ch=strEmail.charAt(i);	     	    
	    //if '@' is found then break from the loop
	    if(ch=='@')
             {
                checkAtDot=true;
                emailValid=true; 
	        break;
             } 
	    for(j=0; j<(checkAlpha.length + checkOther.length); j++)
	    {
	       if(ch==checkAlpha.charAt(j))
	       {               
	        emailValid=true;
	        break;
	       } 
	       else if(ch==checkOther.charAt(j))
           {
	        emailValid=true;
	        break;
           }                      
 	        emailValid=false;	           
	    } 
	    if(emailValid==false) 
	       break;
	}
	
	 //Returning false if the Email Id is Invalid  
     if(checkAtDot==false || emailValid==false) return false;
    
     //checking the characters after '@' characters
     //checking for first character after '@' character is alphabet or not
     //incrementing i to move to next character
 
     i++;
     ch=strEmail.charAt(i);
       for(j=0; j<checkAlpha.length; j++)
       { 
        if(ch==checkAlpha.charAt(j))
        {

         emailValid=true; 
         break;
        }   
       else
         emailValid=false;
      }
        
     //Returning false if the Email Id is Invalid  
     if(emailValid==false) return false;

     checkAtDot=false;
     
	//checking the characters before '.' character
     for(i=i+1;i<strEmail.length; i++)
	{
	    ch=strEmail.charAt(i);	     
	    
	    //if '.' is found then break from the loop
	    if(ch=='.')
            {  
               checkAtDot=true;
               emailValid=true;
	       break;
            }
        //check characters of Email ID in checkAlpha and checkOther     
	    for(j=0; j<(checkAlpha.length + checkOther.length); j++)
	    {
	       if(ch==checkAlpha.charAt(j))
	       {
	        emailValid=true;
	        break;
	       } 
	       else if(ch==checkOther.charAt(j))
	       {
	        emailValid=true;
	        break;
	       } 
               else 
	        emailValid=false;	           
	    } 
	    if(emailValid==false) 
	       break;
	}

    //returning false if character '.' or Email Id is false
    if(checkAtDot==false || emailValid==false) return false;
	
	//Checking if after '.' Email has non-alpha numeric characters
    //if no characters are there after '.' then return false
    emailValid=false;	           
    checkAtDot=false;
        
	for(i=i+1; i<strEmail.length; i++)
	{
	    ch=strEmail.charAt(i);   
	    for(j=0; j<checkAlpha.length; j++)
	    {
	       if(ch==checkAlpha.charAt(j))
	       {
	        emailValid=true;
	        break;
	       } 
	       else if(ch=='.')
	       { 
	        
	         //if email id has multiple '.' characters
	         checkAtDot=true; 
	         emailValid=false;
	         break;
	       }       
	       else
	        emailValid=false;	           
	    } 
	    if(checkAtDot==false && emailValid==false) 
	       break;
	    checkAtDot=false;    
	}	
	
   return(emailValid);	
}               


/*
  Code below was added for Affiliate Future
  This code hides the HotelHippo telephone numbers if the user is deep linked 
  from Affiliate Future network
*/

var searchString = window.location.search.substring(1);
var Parameters = new Object();
var nameValuePairs = searchString.split(/&/);
var nameValuePair;
var name;
var value;
 
for (var i = 0; i < nameValuePairs.length; i++) 
{
    nameValuePair = nameValuePairs[i].split(/=/);
    name = nameValuePair[0];    
    value = nameValuePair[1];
  
    name = name.toLowerCase();  
       
    if (name == "adnetwork")
    {
      if (typeof(value)!="undefined")
      {
           value = value.toLowerCase();
           if (value =="af")
           {
  
				///////////////set cookie///////////////
				pathname = location.pathname;
				myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
				// set expiry date to 30 days from now.
				var largeExpDate = new Date ();
				largeExpDate.setTime(largeExpDate.getTime() + (30 * 24 * 3600 * 1000));
				SetCookie(name,value,largeExpDate,myDomain);
				///////////////set cookie///////////////
             }
		}       
	}
}


if (GetCookie("adnetwork") == "af")
 //setImage("IMAGE_TEL_NAME","IMAGE_NO_TEL_URL")
 RemovePhoneNumbers(true, "tdPhoneUK", "tdPhoneOther");
else
 RemovePhoneNumbers(false, "tdPhoneUK", "tdPhoneOther");
 

//////////////////functions////////////////////////////////////////////////
function SetCookie (name, value) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;       
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
                ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}
 
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
 
function GetCookie (name) {  

        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
      
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal(j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
   return null;
}
 
function setImage(imgName,newImgSrc){
 var temp;
 temp = "document.images."+imgName+".src = '"+newImgSrc+"'";
 eval(temp);
}

function RemovePhoneNumbers(bHidePhoneNumbers, strPhoneUK, strPhoneOther)
{
	var objPhone = document.getElementById(strPhoneUK);
	var objPhoneOther = document.getElementById(strPhoneOther);
	
	if(bHidePhoneNumbers)
	{
		if(objPhone != null && objPhoneOther != null)
		{
			objPhone.innerText = "";
			objPhoneOther.innerText = "";
		}	
	}
	else
	{	
		if(objPhone != null && objPhoneOther != null)
		{
			objPhone.innerText = "UK: 0870 949 5000";
			objPhoneOther.innerText = "Other: 0044 1442 200 674";
		}
	}
	
} 

function load(Latitude, Longitude) {
			if (GBrowserIsCompatible()) {
				var map = new GMap2(document.getElementById("divMap"));
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				map.setCenter(new GLatLng(Latitude, Longitude), 13);
				
				var point = new GLatLng(Latitude, Longitude);
				map.addOverlay(new GMarker(point));
				var points = [];
				points.push(new GLatLng(Latitude, Longitude));
				map.addOverlay(new GPolyline(points));

				}
			}
			
	function loadGoogleMap(Latitude, Longitude, isLoad)
				{
					if(Latitude==0 || Longitude==0)
					 return false;
					else 
					{
					  if(isLoad)
					     load(Latitude, Longitude);
					  else
					     GUnload();
					} 
				}
				
				
	function LoadMapURL(URLString, PageTitleString, iWidth, iHeight, iResizable, iScrollbar)
				{
					var WindowParamterString = 'width=' + iWidth + ',height=' + iHeight + ',resizable=' + iResizable + ',scrollbars=' + iScrollbar;
					window.open(URLString , PageTitleString, WindowParamterString ); 
					return false; 
				}	

	function LoadMultipleLoactions()
	{
		if (GBrowserIsCompatible()) 
		{
				var map = new GMap2(document.getElementById("divMap"));
				var points = [];
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				
				if (HotelLatLngArray.length != 0)
				{
					map.setCenter(new GLatLng(HotelLatLngArray[0][0], HotelLatLngArray[0][1]), 13);
					
					for (var i=0; i<HotelLatLngArray.length; i=i+2) 
					{
						var point = new GLatLng(HotelLatLngArray[i][0], HotelLatLngArray[i][1]);
						map.addOverlay(new GMarker(point));
					}
				}
		}
	}
	
	var tooltip;
	var map;
		
	function LoadMultipleMapsWithIcons()
	{
		map = new GMap2(document.getElementById("divMap"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		//map.setCenter(new GLatLng(37.4419, -122.1419), 13);

		// ====== set up marker mouseover tooltip div ======
		tooltip = document.createElement("div");
		document.getElementById("divMap").appendChild(tooltip);
		tooltip.style.visibility="hidden";

		// Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		var baseIcon = new GIcon();
        baseIcon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
        baseIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
        baseIcon.iconSize = new GSize(12, 20);
        baseIcon.shadowSize = new GSize(22, 20);
        baseIcon.iconAnchor = new GPoint(6, 20);
        baseIcon.infoWindowAnchor = new GPoint(5, 1);      

        //iconblue = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_blue.png"); 
        //icongreen = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_green.png"); 
        //iconyellow = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_yellow.png"); 

		// Creates a marker whose info window displays the letter corresponding
		// to the given index.
		function createMarker(point, index) 
		{
			// Create a lettered icon for this point using our icon class
			var letter = String.fromCharCode("A".charCodeAt(0) + index);
			var letteredIcon = new GIcon(baseIcon);

			// Set up our GMarkerOptions object
			markerOptions = { icon:letteredIcon };
			var marker = new GMarker(point, markerOptions);
	        // === store the name so that the tooltip function can use it ===
		    marker.tooltip = '<div class="MapTooltip">'+HotelNameArray[index]+'<\/div>';

			//GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('<div id="MapInfoWindowDiv" class="MapInfoWindow"><div id="MapHotelDetails" class="MapHotelDetails"><div id="MapHotelName" class="MapHotelName"><span>' + HotelNameArray[index] + '<\/span><\/div><div id="MapHotelStarRating" class="MapHotelStarRating">' + HotelStarArray[index] + '<\/div><div id="MapHotelViewDetails" class="MapHotelViewDetails"><a href=hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '><span>[view details...]<\/span><\/a><\/div><div id="MapHotelAddress" class="MapHotelAddress">' + HotelAddressArray[index] + '<\/div><div id="MapHotelPrice" class="MapHotelPrice"><span class="MapHotelPricesFromText">Prices from <\/span><span>' + HotelPriceArray[index] + '<\/span><\/div><div id="MapHotelBook" class="MapHotelBook"><a href=hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '><img src="image/Buttons/book.gif" border="0"><\/img><\/a><\/div><\/div><div id="MapHotelThumbnail" class="MapHotelThumbnail"><img height="70" width="70" src=' + HotelThumbnailArray[index] + '><\/div><\/div>');});
			//GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('<div id="MapInfoWindowDiv" class="MapInfoWindow"><div id="MapHotelDetails" class="MapHotelDetails"><div id="MapHotelName" class="MapHotelName"><span>' + HotelNameArray[index] + '<\/span><\/div><div id="MapHotelStarRating" class="MapHotelStarRating">' + HotelStarArray[index] + '<\/div><div id="MapHotelViewDetails" class="MapHotelViewDetails"><a href=hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '><span>[view details...]<\/span><\/a><\/div><div id="MapHotelAddress" class="MapHotelAddress">' + HotelAddressArray[index] + '<\/div><div id="MapHotelPrice" class="MapHotelPrice"><span class="MapHotelPricesFromText">Prices from <\/span><span>' + HotelPriceArray[index] + '<\/span><\/div><div id="MapHotelBook" class="MapHotelBook"><a href="hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '&TB_iframe=true&modal=false&height=100&width=500" title="Status" class="thickbox" onclick=show_thickbox("hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '&TB_iframe=true&modal=false&height=100&width=500")><img src="image/Buttons/book.gif" border="0"><\/img><\/a><\/div><\/div><div id="MapHotelThumbnail" class="MapHotelThumbnail"><img height="70" width="70" src=' + HotelThumbnailArray[index] + '><\/div><\/div>');});
			
			//Commented by Manoj as contract type is added in hotelprofile url
			//GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('<div id="MapInfoWindowDiv" class="MapInfoWindow"><div id="MapHotelDetails" class="MapHotelDetails"><div id="MapHotelName" class="MapHotelName"><span>' + HotelNameArray[index] + '<\/span><\/div><div id="MapHotelStarRating" class="MapHotelStarRating">' + HotelStarArray[index] + '<\/div><div id="MapHotelViewDetails" class="MapHotelViewDetails"><a href="#" onclick=show_thickbox("hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '&TB_iframe=true&modal=false&height=450&width=750")><span>[view details...]<\/span><\/a><\/div><div id="MapHotelAddress" class="MapHotelAddress">' + HotelAddressArray[index] + '<\/div><div id="MapHotelPrice" class="MapHotelPrice"><span class="MapHotelPricesFromText">Prices from <\/span><span>' + HotelPriceArray[index] + '<\/span><\/div><div id="MapHotelBook" class="MapHotelBook"><a href="#" title="Status" class="thickbox" onclick=show_thickbox("hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '&TB_iframe=true&modal=false&height=450&width=750")><img src="image/Buttons/book.gif" border="0"><\/img><\/a><\/div><\/div><div id="MapHotelThumbnail" class="MapHotelThumbnail"><img height="70" width="70" src=' + HotelThumbnailArray[index] + '><\/div><\/div>');});
			//Added by Manoj Contract type is added in hotelprofile URL
			
			if (HotelIDSupplierIDArray[index][1] == "4" )
			{
				GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('<div id="MapInfoWindowDiv" class="MapInfoWindow"><div id="MapHotelDetails" class="MapHotelDetails"><div id="MapHotelName" class="MapHotelName"><span>' + HotelNameArray[index] + '<\/span><\/div><div id="MapHotelStarRating" class="MapHotelStarRating">' + HotelStarArray[index] + '<\/div><div id="MapHotelViewDetails" class="MapHotelViewDetails"><a href="#" onclick=show_thickbox("hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '&Contract=' + HotelIDSupplierIDArray[index][2] + '&TB_iframe=true&modal=false&height=450&width=750")><span>[view details...]<\/span><\/a><\/div><div id="MapHotelAddress" class="MapHotelAddress">' + HotelAddressArray[index] + '<\/div><div id="MapHotelPrice" class="MapHotelPrice"><span class="MapHotelPricesFromText">Prices from <\/span><span>' + HotelPriceArray[index] + '<\/span><\/div><div id="MapHotelBook" class="MapHotelBook"><a href="#" onclick=show_thickbox("hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '&Contract=' + HotelIDSupplierIDArray[index][2] + '&TB_iframe=true&modal=false&height=450&width=750")><img src="image/Buttons/book.gif" border="0"><\/img><\/a><\/div><\/div><div id="MapHotelThumbnail" class="MapHotelThumbnail"><img height="70" width="70" src=' + HotelThumbnailArray[index] + '><\/div><\/div>');});
			}
			else
			{
			GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('<div id="MapInfoWindowDiv" class="MapInfoWindow"><div id="MapHotelDetails" class="MapHotelDetails"><div id="MapHotelName" class="MapHotelName"><span>' + HotelNameArray[index] + '<\/span><\/div><div id="MapHotelStarRating" class="MapHotelStarRating">' + HotelStarArray[index] + '<\/div><div id="MapHotelViewDetails" class="MapHotelViewDetails"><a href="#" onclick=show_thickbox("hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '&TB_iframe=true&modal=false&height=450&width=750")><span>[view details...]<\/span><\/a><\/div><div id="MapHotelAddress" class="MapHotelAddress">' + HotelAddressArray[index] + '<\/div><div id="MapHotelPrice" class="MapHotelPrice"><span class="MapHotelPricesFromText">Prices from <\/span><span>' + HotelPriceArray[index] + '<\/span><\/div><div id="MapHotelBook" class="MapHotelBook"><a href="#" title="Status" class="thickbox" onclick=show_thickbox("hotelProfile.aspx?hotelID=' + HotelIDSupplierIDArray[index][0] + '&supplierID=' + HotelIDSupplierIDArray[index][1] + '&TB_iframe=true&modal=false&height=450&width=750")><img src="image/Buttons/book.gif" border="0"><\/img><\/a><\/div><\/div><div id="MapHotelThumbnail" class="MapHotelThumbnail"><img height="70" width="70" src=' + HotelThumbnailArray[index] + '><\/div><\/div>');});
			}
	        //  ======  The new marker "mouseover" and "mouseout" listeners  ======
			GEvent.addListener(marker,"mouseover", function() { showTooltip(marker); });        
			GEvent.addListener(marker,"mouseout", function() { tooltip.style.visibility="hidden" });        
			return marker;
		}

        var gmarkersA = [];      
        var gmarkersB = [];      
        var gmarkersC = [];      
        var gmarkersD = [];      

		var bSetMapCenter = false;
		
		if (HotelLatLngArray.length != 0)
		{
			for (var i=0; i<HotelLatLngArray.length; i++) 
			{
				var point = new GLatLng(HotelLatLngArray[i][0], HotelLatLngArray[i][1]);
				//map.addOverlay(createMarker(point,i));
				var marker = createMarker(point,i);
				gmarkersA.push(marker);
	
				if (bSetMapCenter == false)
				{
					if (HotelLatLngArray[i][0] != 0 && HotelLatLngArray[i][1] != 0)
					{
						map.setCenter(new GLatLng(HotelLatLngArray[i][0], HotelLatLngArray[i][1]), 11);
						bSetMapCenter = true;
					}
				}
			}
			//map.setCenter(new GLatLng(HotelLatLngArray[0][0], HotelLatLngArray[0][1]), 11);
	        var mm = new GMarkerManager(map, {borderPadding:1});
	        mm.addMarkers(gmarkersA,0,17);
		    mm.refresh();
		}
	}
	
	  // ====== This function displays the tooltip ======
      function showTooltip(marker) 
      {
		tooltip.innerHTML = marker.tooltip;
		var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
		var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
		var anchor=marker.getIcon().iconAnchor;
		var width=marker.getIcon().iconSize.width;
		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
		pos.apply(tooltip);
		tooltip.style.visibility="visible";
      }



