
var THOUSANDS_SEPARATOR = ',';
//****New Added on 01/09/08
var OriginalColTblHeader,OriginalColCalFlight,OriginalCol_txtAutoComplete,OriginalCol_txtPassengers;

function formatNumber(num, dec)
{
    if (typeof(dec) == 'undefined') {
        dec = 2;
    }
    if (dec) {
        var result = decRound(num, dec);
        var right = String(result).match(/\d+(\.\d+)?/)[1];
        if (!right) {
            right = '.';
        }
        while (right.length - 1 < dec) {
            right += '0';
        }
        result = String(result).replace(/(\.\d+)?$/, right);
    }
    else {
        var result = Math.round(num);
    }
    // Thousands
    if (THOUSANDS_SEPARATOR) {
        var left = String(result).match(/(\d+)(\.\d+)?/)[1];
        var newLeft = '';
        var s = left.length - 1;
        for (var i = s, k = 0; i >= 0; i--) {
            if (k++ % 3 == 0 && i < s) {
                newLeft = THOUSANDS_SEPARATOR + newLeft;
            }
            newLeft = left.charAt(i) + newLeft;
        }
        result = String(result).replace(/^(\d+)/, newLeft);
    }
    
    return result;
}

function decRound(num, dec)
{
    return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
}
var lastClickedTextboxObj_ac = null;
function doAfterAutoCompleteDivHide()
{
	 if(lastClickedTextboxObj_ac) {
		lastClickedTextboxObj_ac.parentNode.style.position = "";
		lastClickedTextboxObj_ac = null;
	}
}
function OnCalulatorChange(calculationID,calculateButton,calculateButtonValue,objTxtbox)
{
    if(objTxtbox) {
		lastClickedTextboxObj_ac = objTxtbox;
		//objTxtbox.parentNode.style.position = "relative";
	}
    var id = document.getElementById(calculationID);
    if (id.value>0)
    {
        id.value = 0;
        document.getElementById(calculateButton).className = "mmcr_calculate";
        document.getElementById(calculateButton).value = calculateButtonValue;
    }
}

function ClearValue(obj)
{    
    var textOfficeEnergyCalculate = obj;
    if((textOfficeEnergyCalculate.value == '0.00')||(textOfficeEnergyCalculate.value == '0.0')||(textOfficeEnergyCalculate.value == '0'))
    {
        textOfficeEnergyCalculate.value = '';
    }
}

function RepopulateValue(obj)
{
    var textOfficeEnergyCalculate = obj;
    if(textOfficeEnergyCalculate.value.length <= 0)
    { 
        textOfficeEnergyCalculate.value = '0';
    }
}

//-------------------------------Info Popup Function --------------------------------------
//function to call popup & background grey layer
function ShowInfoPopUpDiv1(centerDiv){
    DivSetVisible(true, centerDiv);
}

//function to close popup & background grey layer
function CloseInfoPopUpDiv1(centerDiv) {
    var itempopUp = document.getElementById(centerDiv);
    itempopUp.style.display="none";
    DivSetVisible(false, centerDiv); 
} 

//function to create background grey layer
//------only for safari-----------
    function mua(s) {
      var ua = navigator.userAgent.toLowerCase();
      return (ua.indexOf(s.toLowerCase()) > -1);
    }
    // get user agent version with a regexp only for safari browser
    function regv(r) {
      var _rx = new RegExp(r);
      _rx.test(navigator.userAgent);
      return parseFloat(RegExp["$1"]);
    } 
//-------------------------------------  
function DivSetVisible(state, centerDiv) 
{ 
    if(state == undefined || state == null) 
    { 
        state = true; 
        /*if(layerDisplay == true) 
        { 
        state = true; 
        }*/ 
    } 
    /*if( window.innerHeight && window.scrollMaxY ) // Firefox 
    { 
        pageWidth = window.innerWidth + window.scrollMaxX; 
        pageHeight = window.innerHeight + window.scrollMaxY; 
    } 
    else */if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac 
    { 
        pageWidth = document.body.scrollWidth; 
        pageHeight = document.body.scrollHeight; 
    } 
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari 
    { 
        pageWidth = document.body.offsetWidth + document.body.offsetLeft;
        pageHeight = document.body.offsetHeight + document.body.offsetTop; 
    }
    
    var DivRef = document.getElementById('divShim'); 
    var IfrRef = document.getElementById('iframeShim');
    var objPopupItems = document.getElementsByName(centerDiv);
    var objPopupItem = null;
    
    //Append 'divShim', 'iframeShim' and 'DivPopup' at end of the body tag
    if(DivRef == null) {
        DivRef = document.createElement("DIV");
        DivRef.setAttribute("id", "divShim");
        DivRef.className = "viewTransDiv";
        document.body.appendChild(DivRef);
    }
    if(IfrRef == null) {
        IfrRef = document.createElement("IFRAME");
        IfrRef.setAttribute("id", "iframeShim");
        IfrRef.setAttribute("src", "");
        IfrRef.setAttribute("scrolling", "no");
        IfrRef.setAttribute("frameborder", "3");
        IfrRef.className = "viewTransIframe";
        document.body.appendChild(IfrRef);
    }
    if(objPopupItems.length > 1) {
        if(objPopupItems[1] && objPopupItems[1].parentNode.tagName.toLowerCase() == "body") document.body.removeChild(objPopupItems[1]);
        if(objPopupItems[0] && objPopupItems[0].parentNode.tagName.toLowerCase() != "body") document.body.appendChild(objPopupItems[0]);
        objPopupItem = objPopupItems[0];
    }
    else {
        objPopupItem = document.getElementById(centerDiv);
        if(objPopupItem && objPopupItem.parentNode.tagName.toLowerCase() != "body") document.body.appendChild(objPopupItem);
    }
    
    if(state) { 
        DivRef.style.display = "block";
        DivRef.style.height = pageHeight+"px";
        DivRef.style.width = pageWidth+"px";
        IfrRef.style.width = DivRef.offsetWidth+"px"; 
        IfrRef.style.height = DivRef.offsetHeight+"px"; 
        IfrRef.style.display = "block"; 
        IfrRef.style.top = DivRef.style.top; 
        IfrRef.style.left = DivRef.style.left; 
        
        
         //for ie 6, 7 & firefox    
         var scrlTop=document.documentElement.scrollTop;
         
         //for safari
         isSafari = mua("AppleWebKit"); // Konq & Safari
         if (isSafari){
                var scrlTop=document.body.scrollTop;
         }
       
        if(centerDiv) {            
            window.scroll(0,(scrlTop+1));
            objPopupItem.style.position = "absolute";
            objPopupItem.style.left = "0px";
            objPopupItem.style.top = scrlTop+"px";            
            objPopupItem.style.display = 'block';//Show Popup Div
            objPopupItem.style.left = ((screen.width/2)-(objPopupItem.offsetWidth/2))+"px";
            if (document.documentElement && document.documentElement.scrollTop) {                
                window.oldScrollTop = document.documentElement.scrollTop; 
                             
                    //objPopupItem.style.top = (document.documentElement.scrollTop+((screen.height/2)-objPopupItem.offsetHeight))+50+"px";
                    objPopupItem.style.top = window.oldScrollTop + 80 + 'px';
                    window.onscroll = (!state)?"":function() {
                    objPopupItem.style.top = window.oldScrollTop + 80 + 'px';
                    //objPopupItem.style.top=(objPopupItem.offsetTop+(document.documentElement.scrollTop-window.oldScrollTop))+"px";
                    window.oldScrollTop = document.documentElement.scrollTop;
                };
            }
            else {                
                window.oldScrollTop = document.body.scrollTop;                
                objPopupItem.style.top = (document.body.scrollTop+((screen.height/2)-objPopupItem.offsetHeight))+50+"px";
                window.onscroll = (!state)?"":function() {
                    objPopupItem.style.top=(objPopupItem.offsetTop+(document.body.scrollTop-window.oldScrollTop))+"px";
                    window.oldScrollTop = document.body.scrollTop;
                };
            }
            //window.scroll(0,1);
        }
                
    }         
    else { 
        objPopupItem.style.display = 'none';//Hide Popup Div
        DivRef.style.display = "none"; 
        IfrRef.style.display = "none"; 
        document.body.scroll = ""; 
        document.body.style.overflow = ""; 
    }
} 
//------------------------- End Info Popup Function --------------------------

function ShowInfoPopUpDiv(divID,divID2) {

//divID--col2---divID2--col3
var outer_div=document.getElementById("douter" + divID + "1"); 
outer_div.style.display=""; 
    var itempopUp = document.getElementById(divID);  
    var itempopUp2 = document.getElementById(divID2);
    itempopUp.style.display=""; 
    itempopUp2.style.display=""; 
    var itempopUp1 = itempopUp.innerHTML;
    //****New Added on 01/09/08 for background colour    
    //document.body.bgColor="graytext";
    //OriginalColTblHeader=document.getElementById("tblHeader").style.backgroundColor;
    //document.getElementById("tblHeader").style.backgroundColor="graytext"; 
    //OriginalColCalFlight =document.getElementById("tblCalFlight").style.backgroundColor;
    //document.getElementById("tblCalFlight").style.backgroundColor="graytext"; 
    //document.getElementById("tblCalFlightChild").className="main_calculator_child_table_Popup";    
    //document.getElementById("tblCalFlight_Inner").className="main_calculator_child_table_Popup";
    //OriginalCol_txtAutoComplete=document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtFlyingfrom_txtAutoComplete").style.backgroundColor;
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtFlyingfrom_txtAutoComplete").style.backgroundColor="graytext";
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtGoingto_txtAutoComplete").style.backgroundColor="graytext";
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtVia_txtAutoComplete").style.backgroundColor="graytext";   
    //OriginalCol_txtPassengers=document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtPassengers").style.backgroundColor;     
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtPassengers").style.backgroundColor="graytext";     
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_ibtnFlight").ImageUrl="~/Images/Clear_For_Popup.GIF";     
    
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_btnFlightCalculate").className="busCalc_Cancel_btn";
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_btnFlightBuyoffset").className="busCalc_Cancel_btn";
    


    
    return false;
  }
function CloseInfoPopUpDiv(divID) {
    var itempopUp = document.getElementById(divID);
    itempopUp.style.display="none";     
    var outer_div=document.getElementById("douter" + divID); 
outer_div.style.display="none"; 
    //****New Added on 01/09/08   for original background colour    
    //document.body.bgColor="white"; 
    //document.getElementById("tblHeader").style.backgroundColor=OriginalColTblHeader; 
    //document.getElementById("tblCalFlight").style.backgroundColor=OriginalColCalFlight;  
    //document.getElementById("tblCalFlightChild").className="main_calculator_child_table";
    //document.getElementById("tblCalFlight_Inner").className="mmcr_table";
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtFlyingfrom_txtAutoComplete").style.backgroundColor=OriginalCol_txtAutoComplete;
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtGoingto_txtAutoComplete").style.backgroundColor=OriginalCol_txtAutoComplete;
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtVia_txtAutoComplete").style.backgroundColor=OriginalCol_txtAutoComplete;
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_txtPassengers").style.backgroundColor=OriginalCol_txtPassengers;
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_ibtnFlight").ImageUrl="~/Images/Clear3.GIF";     
     
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_btnFlightCalculate").className="mmcr_calculate";
    //document.getElementById("ctl00_ContentPlaceHolder1_cal12_flight_btnFlightBuyoffset").className="mmcr_buyOffset";
     
  }



    


