var myphone;
var myfname;
var mylname;
var myaddress;
var mycity;
var mystate;
var transparentBackground;

function $a(id) {
    return document.getElementById(id);
}

function displayPopup(AuctionItemDescription, hasForm) {
    _alphaLayer = DrawBackground();
    transparentBackground = _alphaLayer;
    //document.body.appendChild(_alphaLayer);
    //use div in page instead, because before it was conflicting and showing div on top of popup because of the master page.
    $a('disableBG').style.display = 'block';

    Window2CenterScreen($a('PopupContentContainer'), _alphaLayer);

    $a('PopupContentContainer').style.display = 'block';
    $a('PopupContentContainer').style.zIndex = 10000000000;
    $a('PopupDataContainer').innerHTML = AuctionItemDescription;

    if (hasForm == 1)
        $a('PopupFormContainer').style.display = 'block';
    else
        $a('PopupFormContainer').style.display = 'none';


    //Position popup for smartphones.
    var iPadAgent = navigator.userAgent.match(/iPad/i) != null;
    var iPodAgent = navigator.userAgent.match(/iPhone/i) != null;
    var AndroidAgent = navigator.userAgent.match(/Android/i) != null;
    var webOSAgent = navigator.userAgent.match(/webOS/i) != null;

    //Only reposition the popup if on a computer.
    if (iPadAgent || iPodAgent || AndroidAgent || webOSAgent) {
//        $a('PopupFormContainer').style.top = "10px";
//        $a('PopupFormContainer').style.left = "10px";
//        alert('test');
    }
}

function displayPopupEvents(AuctionItemDescription) {
    _alphaLayer = DrawBackground();
    transparentBackground = _alphaLayer;
    //document.body.appendChild(_alphaLayer);
    //use div in page instead, because before it was conflicting and showing div on top of popup because of the master page.
    $a('disableBG').style.display = 'block';

    Window2CenterScreen($a('PopupContentContainer'), _alphaLayer);

    $a('PopupContentContainer').style.display = 'block';
    $a('PopupContentContainer').style.zIndex = 10000000000;
    $a('PopupDataContainer').innerHTML = AuctionItemDescription;
}

function displayPopup1()
{
	_alphaLayer = DrawBackground();
        transparentBackground = _alphaLayer;
        //document.body.appendChild(_alphaLayer);
	//use div in page instead, because before it was conflicting and showing div on top of popup because of the master page.
	$a('disableBG').style.display = 'block';
        
    Window2CenterScreen($a('PopupContentContainer'), _alphaLayer);

    $a('PopupContentContainer').style.display='block';
    $a('PopupContentContainer').style.zIndex = 10000000000;
}

function displayPopup2(Date, FromHour, FromMin, FromTT, ToHour, ToMin, ToTT, Attendant, AddInfo, EventDate, hasForm) {
    _alphaLayer = DrawBackground();
    transparentBackground = _alphaLayer;
    //document.body.appendChild(_alphaLayer);
    //use div in page instead, because before it was conflicting and showing div on top of popup because of the master page.
    $a('disableBG').style.display = 'block';

    Window2CenterScreen($a('PopupContentContainer'), _alphaLayer);

    $a('PopupContentContainer').style.display = 'block';
    $a('PopupContentContainer').style.zIndex = 10000000000;

    //Populate fields.
    $a('MainContent_lblDate').innerHTML = Date;
    $a('MainContent_ddlFromHours').value = FromHour.replace(' ', '');
    $a('MainContent_ddlFromMinutes').value = FromMin.replace(' ', '');
    $a('MainContent_ddlFromTT').value = FromTT.replace(' ', '');
    $a('MainContent_ddlToHours').value = ToHour.replace(' ', '');
    $a('MainContent_ddlToMinutes').value = ToMin.replace(' ', '');
    $a('MainContent_ddlToTT').value = ToTT.replace(' ', '');
    $a('MainContent_txtAttendant').value = Attendant;
    if (navigator.appName == 'Microsoft Internet Explorer')
        $a('MainContent_txtAdditionalInfo').innerText = AddInfo.replace(/<br\s*\/?>/ig, "\r\n");
    else
        $a('MainContent_txtAdditionalInfo').textContent = AddInfo.replace(/<br\s*\/?>/ig, "\r\n");
    $a('MainContent_hdnEventDate').value = EventDate;

    if (hasForm == 'True')
        $a('MainContent_chkForm').checked = true;
    else
        $a('MainContent_chkForm').checked = false;


}

function closePopupDiv()
{
    //DestroyTransparentBackground();
    //use div in page instead, because before it was conflicting and showing div on top of popup because of the master page.
    $a('disableBG').style.display = 'none';
    $a('PopupContentContainer').style.display='none';
}

function closePopupDivCalendar() {
    //DestroyTransparentBackground();
    //use div in page instead, because before it was conflicting and showing div on top of popup because of the master page.
    $a('disableBG').style.display = 'none';
    $a('PopupDataContainer').innerHTML = "";
    $a('result').innerHTML = "";
    $a('PopupContentContainer').style.display = 'none';
}

function GetScrollXY() {
    var scrOfX = 0;
    var scrOfY = 0;

    if (window.outterWidth != null) {
        //Netscape compliant
        scrOfY = (window.outerHeight - window.innerHeight);
        scrOfX = (window.outerWidth - window.innerWidth);
    } else if (document.documentElement != null && (document.documentElement.scrollWidth != null || document.documentElement.scrollHeight != null)) {
        //IE standards compliant mode
        if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
            scrOfY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
        }
        else {
            scrOfY = 0;
        }
        if (document.documentElement.scrollWidth > document.documentElement.clientWidth) {
            scrOfX = document.documentElement.scrollWidth - document.documentElement.clientWidth;
        }
        else {
            scrOfX = 0;
        }
    }
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    }

    return [scrOfX, scrOfY];
}

function ResizeCustomWindowBackground(who) {
    var myWidth = 0;
    var myHeight = 0;

    if (typeof (window.innerWidth) == 'number') {
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    if (who != null) {
        var scrolls = GetScrollXY();

        who.style.width = scrolls[0] + myWidth + "px";
        who.style.height = scrolls[1] + myHeight + "px";
    }

}

function Window2CenterScreen(wnd, wndShade) {
    var pageH = null;

    var wndH = 400;//wnd.style.Height;
    
    
    wnd.style.position = "absolute";

    if (window.innerHeight != null) {
        pageH = window.innerHeight;
    }
    else if (document.documentElement.clientHeight != null) {
        pageH = document.documentElement.clientHeight;
    }
    else if (document.body.clientHeight != null) {
        pageH = document.body.clientHeight;
    }

    if (pageH == 0 && pageW == 0) {
        pageH = document.body.clientHeight;
    }
    
    if (wndH > pageH) {
        wnd.style.top = document.documentElement.scrollTop + "px";
    }
    else {
        wnd.style.top = ((pageH - wndH) / 2) + document.documentElement.scrollTop + document.body.scrollTop + "px";
        //alert(document.documentElement.scrollTop + document.body.scrollTop);
    }  

    if (wndShade != null) {
        wndShade.style.position = "absolute";
        wndShade.style.top = "0px";
    }
}


function DrawBackground() {
    //var wndBg = document.createElement("DIV");
    //use div in page instead, because before it was conflicting and showing div on top of popup because of the master page.
    var wndBg = $a('disableBG');
    wndBg.style.zIndex = 100000000000;
    wndBg.className = "myTransparentBackground";
    ResizeCustomWindowBackground(wndBg);

    return wndBg;
}



function DestroyTransparentBackground() {
    document.body.removeChild(transparentBackground);
    transparentBackground = null;
}


// -------------- ISABELLE

 function FocusOnElement(ID)
    {
        elem = document.getElementById(ID);
        elem.scrollIntoView();
    }
    
    //Added by Isabelle on 11/20/2009: Indicate selected row.
    var gridViewCtlId = null;
    var gridViewCtl = null;
    var curSelRow = null;
    function getGridViewControl()
    {
        if (null == gridViewCtl)
        {
            gridViewCtl = document.getElementById(gridViewCtlId);
        }
    }
    
    function onGridViewRowSelected(rowIdx, gridViewCtlId1)
    {
        gridViewCtlId = gridViewCtlId1;
        var selRow = getSelectedRow(rowIdx);
        if (curSelRow != null)
        {
            curSelRow.style.backgroundColor = '#ffffff';
        }
        
        if (null != selRow)
        {
            curSelRow = selRow;
            curSelRow.style.backgroundColor = '#9EE6E8';
        }
    }
    
    function getSelectedRow(rowIdx)
    {
        getGridViewControl();        
        
        //If drop down was changed for cancellation then we want to change cancel column to true else we want to change it to false.
        var inputList = gridViewCtl.getElementsByTagName("tr"); 
        var inputTD = inputList[rowIdx].getElementsByTagName("td"); 
        for (var i=0;i<inputTD.length;i++) 
        { 
            var isCancel = inputTD[i].innerText;
            if(isCancel == "False" || isCancel == "True")
            {
                var selects = gridViewCtl.getElementsByTagName("select");
                var newRowInx = (rowIdx/2) + 0.5 - 1; //select is only there every 2 rows.
                var selectItem = selects[newRowInx].selectedIndex;
                var selection = selects[newRowInx].options[selectItem].text;
                //alert(selection);
                    
                if(selection == "Valid Lead" || selection == "Pending")
                    inputTD[i].innerText = "False";
                else
                    inputTD[i].innerText = "True";
            }
        } 
        
        if (null != gridViewCtl)
        {
            return gridViewCtl.rows[rowIdx];
        }
        return null;
    }
    
// --------------- ISABELLE    
