﻿function highlight (ctrl, bOn)
{
    
    if (bOn)
        ctrl.style.background='#ccc';
    else
        ctrl.style.background='#eee';
    
}

function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	
	
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	
	
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
	
	// bos...
	popUpDiv.style.top = '100px';
}
function popup_modal(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}



function fadeIn(domId)
{
    obj = document.getElementById(domId);
    
    if(obj.style.display != "none") return false; 

    obj.style.display = ''; 

    var alpha = 1; 

    function fade() {  
        alpha++;  

        obj.style.opacity = alpha;
        obj.style.MozOpacity = alpha;
        obj.style.KhtmlOpacity = alpha;
        obj.style.filter = "alpha(opacity=" + alpha * 10 + ")"; 
        if (alpha < 10) setTimeout(fade, 30);
    }
    fade();
}

function fadeOut(domId)
{
    obj = document.getElementById(domId);

    if(obj.style.display != "") return false; 

    var alpha = 10; 

    function fade() {  

        alpha--;  

        obj.style.opacity = alpha;
        obj.style.MozOpacity = alpha;
        obj.style.KhtmlOpacity = alpha;
        obj.style.filter = "alpha(opacity=" + alpha * 10 + ")"; 

        if(alpha > 0) 
            setTimeout(fade, 30);
        else
            obj.style.display = 'none';
    }

    fade();
}

function expandIn(domId, height)
{
    obj = document.getElementById(domId); 
    if(obj.style.display != "none") return false;
    
    obj.style.height = '0px';
    obj.style.display = '';
    
    var expandHeight = 0;
    
    function expand()
    {
        expandHeight++;  

        obj.style.height = expandHeight + 'px';

        if(expandHeight<height)setTimeout(expand, 1);

    }

    setTimeout(expand, 50);
}

function minimiseOut(domId)
{
    obj = document.getElementById(domId); 
    if(obj.style.display != "") return false;
    
    var expandedHeight = obj.style.height.substring(0, obj.style.height.length - 2);
                
    function minimise()
    {
        expandedHeight--;  

        obj.style.height = expandedHeight + 'px';

        if(expandedHeight>0)
            setTimeout(minimise, 1);
        else
            obj.style.display = 'none';
    }

    setTimeout(minimise, 50);
}       

function changeTab(tabToShowId, tabToHideID)
{
    tabToShow = document.getElementById(tabToShowId);
    tabToHide = document.getElementById(tabToHideID);
    
    tabToShow.style.display = 'block';
    tabToHide.style.display = 'none';
    
}

function addToDelete(id)
{
    document.getElementById('ctl00_ContentPlaceHolder1_txtPhotoToDelete').value += ',' + id;
}

function removeFromDelete(id)
{
    document.getElementById('ctl00_ContentPlaceHolder1_txtPhotoToDelete').value.replace(',' + id, '');
}

function removeAllFromDelete()
{
    document.getElementById('ctl00_ContentPlaceHolder1_txtPhotoToDelete').value = '';
}

function changeAdminTab(tabToShowId)
{
    //hide all week tabs
    document.getElementById('week1').style.display = 'none';
    document.getElementById('week2').style.display = 'none';
    document.getElementById('week3').style.display = 'none';
    document.getElementById('week4').style.display = 'none';
    
    //show the requested week tab
    
    document.getElementById('week'+tabToShowId).style.display = 'block';
    
    var sPre = 'ctl00_ContentPlaceHolder1_';
    
    document.getElementById(sPre + 'tabbox1').className = "tab";
    
    if (document.getElementById(sPre + 'tabbox2') != null)
        document.getElementById(sPre + 'tabbox2').className = "tab";
        
    if (document.getElementById(sPre + 'tabbox3') != null)
        document.getElementById(sPre + 'tabbox3').className = "tab";
        
    if (document.getElementById(sPre + 'tabbox4') != null)    
        document.getElementById(sPre + 'tabbox4').className = "tab";
    
    
    document.getElementById(sPre + 'tabbox' + tabToShowId).className = "tab selected";
    
    
}

function updateTotals(idPrefix, totalNumRooms, totalCost, totalSaving)
{
    document.getElementById(idPrefix + '_lblTotalNumRooms').innerHTML = '<span class="emphasis">No. of rooms selected:</span> ' + totalNumRooms + '<br/><br/>';
    document.getElementById(idPrefix + '_lblTotalCost').innerHTML = '<span class="emphasis">Total Cost:</span> <div class="priceblock">' + totalCost + '</div>';
    document.getElementById(idPrefix + '_lblTotalSaving').innerHTML = '<span class="emphasis">Total Saving:</span> <div class="priceblock">' + totalSaving + '</div>';
}