function GenerateGetElement()
{
	if (document.getElementById) return function(id) { return document.getElementById(id); }
	else if (document.all) return function(id) { return document.all[id]; }
	else if (document.layers) return function(id) { document.layers[id]; }
}
var GetElement;
GetElement = GenerateGetElement();

function roll(element, type)
{
    if (element != null)
    {
        var old = element.src;

        var newsrc = ""; 
        if (type == "on")
            newsrc = old.replace("_off", "_on");
        else 
            newsrc = old.replace("_on", "_off");  

        element.src = newsrc;    
    }
}


function setDepartDate(endDate)
{
     
    
    //var arrival_date = $find("<%=rdpStartDate.ClientID %>");
    //var depart_date = $find("<%=rdpEndDate.ClientID %>");
}

function placeClientId(clientid)
{   
}

function checkRoomSelection()
{            
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}


function isUnique(arrRoomTypes)
{    
    var unique = "1";
    for(i = 0; i < arrRoomTypes.length; ++i)
    {
        var temp = arrRoomTypes[i];        
        for(j = 0; j < arrRoomTypes.length; ++j)
        {
            if(i != j && unique != "0")
            {                
                if(arrRoomTypes[i] == arrRoomTypes[j])
                    unique = "0";                                                
            }        
        }
        if(unique == "0")
            break;                
    }
    return unique;

}


// Change Text on the summary table based radio button input and tally the total cost of the reservation
function radioButtonClick(total, taxes, roomInfo, roomType, roomDescriptionID, roomCostID, roomTaxID, roomTotalID, roomTotalCostID, allroomTotalCostID, allroomTaxID, allroomTotalID, allroomInfoID, allroomTypeID, roomTypeID, allroomsSelectedID, roomTypesUnique, numRooms, roomCostIds, roomTaxIds, roomDescriptionIds, roomTypeIds)
{    
    
    
    // Get the labels for cost of room, tax for room, and total cost of all rooms       
    var lroomDescription = GetElement(roomDescriptionID);
    var lroomType = GetElement(roomTypeID);
    var lroomCost  = GetElement(roomCostID);
    var lroomTax   = GetElement(roomTaxID);
    var lroomTotal = GetElement(roomTotalID);
    var ltotal     = GetElement(roomTotalCostID);                    
	var lAllRoomCost  = GetElement(allroomTotalCostID); 
	var lAllRoomTax   = GetElement(allroomTaxID);
	var lAllTotal = GetElement(allroomTotalID);
	var lAllRoomInfo = GetElement(allroomInfoID);
	var lAllRoomType = GetElement(allroomTypeID);
	var lAllRoomsSelected = GetElement(allroomsSelectedID);
	var lRoomTypesUnique = GetElement(roomTypesUnique);
	                
    var x = new Number(total);
    var y = new Number(taxes);
            
    var temp = 0;
    var z = 0.0;
    z     = x + y;
                                                             
    lroomCost.innerHTML = "$" +  CurrencyFormatted(x.toFixed(2)) + "<br>";      
    lroomTax.innerHTML =  "$" + CurrencyFormatted(y.toFixed(2)) + "<br>";
    lroomTotal.innerHTML = "$" +  CurrencyFormatted(z.toFixed(2)) + "<br>";
    lroomDescription.innerHTML = roomInfo + "<br>";
    lroomType.innerHTML = roomType;
        
    // Calculate Total Cost, save room info in textboxes
    var count = new Number(0);
    var listRoomPrices;
    var listRoomTaxes;
    var listRoomInfo;
    var listRoomTypes;
    
    var cids = roomCostIds; // Client ID's for labels that store price for each room    
    var arrRoomCostIds = cids.split(",", numRooms); // List is delimited by ","
                           
    var cids2 = roomTaxIds // Client ID's for labels that store tax for each room
    var arrRoomTaxIds = cids2.split(",", numRooms);  // List is delimited by ","
    
    var cids3 = roomDescriptionIds // Client ID's for labels that store description for each room
    var arrRoomDescriptionIds = cids3.split(",", numRooms);  // List is delimited by ","
    
    var cids4 = roomTypeIds // Client ID's for labels that store type for each room
    var arrRoomTypeIds = cids4.split(",", numRooms);  // List is delimited by ","
    
    
    for(i = 0; i < numRooms; ++i)
    {       
        var lcost = GetElement(arrRoomCostIds[i]);
        var ltax  = GetElement(arrRoomTaxIds[i]);
        var lroomInfo = GetElement(arrRoomDescriptionIds[i]);
        var lroomtype = GetElement(arrRoomTypeIds[i]);
                  
        var str = lcost.innerHTML;
        var str3 = ltax.innerHTML;
        var str4 = lroomInfo.innerHTML;
               
        var j = str4.search("<br>");
        var str5 = str4.slice(0, j); // Slice out line break                
        
        var str6 = lroomtype.innerHTML;
        
        var num;
        var num2;
        
        if(str.length == 0)
        {
            num = new Number(0);                   
        }
        else
        {
            var str2 = str.substring(1); // Cut off the dollar sign                         
            var cost = str2.replace("<br>", "").replace("<BR>", "");            
            num = new Number(cost);            
        } 
        
        if(str3.length == 0)
        {
            num2 = new Number(0);
        }
        else
        {
            var str2 = str3.substring(1); // Cut off the dollar sign 
            var tax = str2.replace("<br>", "").replace("<BR>", "");           
            num2 = new Number(tax);    
        }
                                
        count += (num + num2); 
        
        if(i == 0) // This prevents the first value of a & b from being undefined
        {
            if(numRooms == 1)
            {
                listRoomPrices = num;
                listRoomTaxes  = num2;
                listRoomInfo = str5;
                listRoomTypes  = str6;
            }
            else
            {
               listRoomPrices  = num  + "|";
               listRoomTaxes  = num2 + "|";
                listRoomInfo  = str5 + "|";
                listRoomTypes  = str6 + "|";
            }
            
        }
        else if(i == numRooms - 1) 
        {
            listRoomPrices  += num;
            listRoomTaxes  += num2;
            listRoomInfo  += str5;
            listRoomTypes  += str6;
        }
        else
        {
            listRoomPrices += num  + "|";
            listRoomTaxes  += num2 + "|";
            listRoomInfo  += str5 + "|";
            listRoomTypes  += str6 + "|";
        }                                          
    }      
    ltotal.innerHTML = "$" + CurrencyFormatted(count.toFixed(2));
   
    // The table that holds all the the summary information is dynamic so it won't persist after a postback 
    lAllRoomCost.value = listRoomPrices; // A List of the prices for each selected room 
	lAllRoomTax.value  = listRoomTaxes; // A List of the taxes/fees for each selected room                       
    lAllRoomInfo.value = listRoomInfo; // A List of the room descriptions
    lAllRoomType.value = listRoomTypes; // A List of the room types
    lAllTotal.value = count;
    
    //Check if All Rooms have been Selected
    var s = new String(listRoomPrices);
    var arrCheck = s.split("|", numRooms);
    var flag = "0";
  
    for(i = 0; i < arrCheck.length; ++i)
    {
        if(arrCheck[i] == "0")
            flag = 0;
        else
            flag = "1";             
    }        
    if(flag == "1")
    {
        lAllRoomsSelected.value = "Yes"; 
        var strRoomTypes = new String(listRoomTypes);
        var arrRoomTypes = strRoomTypes.split("|", numRooms); 
        if(isUnique(arrRoomTypes) == "1")
            lRoomTypesUnique.value = "Yes";
         else
            lRoomTypesUnique.value = "No";
    }                  
            
    
}

function valCountry(source, arguments)
{
    alert("<%= ddlState.ClientID %>");
    //var stateddl = document.getElementById("<%= ddlState.ClientID %>");
    //alert(stateddl.Value);
    /*if(stateddl.value != "None" && arguments.Value != "US")
    {
       
        arguments.IsValid = "false";
    }
    else
        arguments.IsValid = "true";               */
}
/*
function ShowGalleryImage(strImageSource)
{
    GetElement("imgMainGalleryImage").src = strImageSource;
}
*/

function ShowGalleryImage(strMainImageElement, strMainImageSource)
{
    //Update Main Image
    GetElement(strMainImageElement).src = strMainImageSource;
}

//ShowGalleryImage
//e.g. Input: 'imgPrivateSuite', 'images/lgPrivate2.jpg', this, 'thPrivate2,thPrivate3,thXXXX0'
//Notes: Quick Configuration over Convention Implementation
function ShowGalleryImage(strMainImageElement, strMainImageSource, OnObject, Off_ID_List)
{
	//Update the Main Image
    GetElement(strMainImageElement).src = strMainImageSource;
	
	//Turn all thumbnails off
	TurnThumbnailsOff(Off_ID_List);
	
	//Turn the clicked thumbnail image on
	roll(OnObject, 'on');
}

function TurnThumbnailsOff(Off_ID_List)
{
	var OffArray = Off_ID_List.split(",");
	var Index = 0;
	var Element;
	
	for(Index=0; Index < OffArray.length; Index++)
	{
		Element = GetElement(OffArray[Index]);
		roll(Element, 'off');
	}
}

function ClearCommentBox(tb)  
{   
    if (tb.value=="Please write additional requests here.")
        tb.value="";
}
function RestoreCommentBox(tb) 
{
    if (tb.value=="")
        tb.value="Please write additional requests here.";
}

//function SetUniqueRadioButton(nameregex, current)
//{
//      re = new RegExp(nameregex);
//      for(i = 0; i < document.forms[0].elements.length; i++)
//      {
//            elm = document.forms[0].elements[i]
//            if (elm.type == 'radio')
//            {
//                  if (re.test(elm.name))
//                  {
//                          elm.checked = false;
//                  }
//             }
//      }
//      current.checked = true;
//}

function OpenPrivacy()
{
    var newwin = window.open('/privacy.html','Privacy','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=800,height=600,left=150,top=150,alwaysRaised=1')
    newwin.focus();
}




