//Includes some common JavaScript
//Put smth like this to link to this file:
//<script language="JavaScript" src="/common/jscommon.js" type="text/javascript"></script>


//Send the name of the CheckListControl to Check/Uncheck all checkboxes in it
//example: lnkCheckAll.Attributes.Add("onclick","CheckAllCheckBoxesInTable('" + chklstNbr.ClientID + "',true)");

function CheckAllCheckBoxesInTable(strCheckListControlID, chknm) {
    // Go through all items of a check list control
    var table = document.getElementById(strCheckListControlID);
    var cells = table.getElementsByTagName("td");
    var objControl;
    for (var i = 0; i < cells.length; i++) {
        objControl = cells[i].firstChild;
        if (objControl.type == 'checkbox')
            objControl.checked = chknm;
    }
}

//Returns true or false depending if user confirms the delete
function confirmDelete(sMessage) {
    if (sMessage == null || sMessage == "") {
        sMessage = 'Are you sure you want to delete this record?';
    }
    return confirm(sMessage);
}

//Returns true or false depending if user confirms the cancel
function confirmCancel(sMessage) {
    if (sMessage == null || sMessage == "") {
        sMessage = 'Are you sure you want to cancel all your changes?';
    }
    return confirm(sMessage);
}

//Opens an new window
function openwindow() {
    var fpwindow = null;
    fpwindow = window.open("", 'fpwindow', 'resizable=yes,menubar=no,toolbar=no,scrollbars=yes,width=640,height=600,location=no,copyhistory=no');
    fpwindow.focus()
    return true;
}

//Returns true or false depending if user confirms the remove
function confirmRemove(sMessage) {
    if (sMessage == null || sMessage == "") {
        sMessage = 'Are you sure you want to remove this item from the list?';
    }
    return confirm(sMessage);
}

//Removes a character from the value of a box
//Call sample: txtSqFt0.Attributes.Add("onkeyup","stripAChar(this,',')");
function stripAChar(oInputBox, cRemoveMe) {
    oInputBox.value = oInputBox.value.replace(cRemoveMe, "");
}

//Gets minimum zoom level for a bound
function getSmallestZoom(clientWidth, clientHeight, minX, minY, maxX, maxY) {
    var maxX = -180;
    var minX = 180;
    var maxY = -90;
    var minY = 90;
    var viewFactor = 0.9;

    // calculate center of marker bounds 
    var xCenter = (parseFloat((maxX + minX) / 2)).toFixed(6);
    var yCenter = (parseFloat((maxY + minY) / 2)).toFixed(6);


    // calculate pixels/degLon in each direction of slightly smaller viewport 
    var xZoom = Math.abs((clientWidth * viewFactor) / (maxX - minX));
    var yZoom = Math.abs((clientHeight * viewFactor) / ((maxY - minY)));

    // take the smaller value from the two directions 
    if (yZoom < xZoom) { xZoom = yZoom };


    // divide by pixelsPerLonDegree at zoomLevel=0 
    xZoom /= (32 / 45) * Math.pow(2, 17);
    alert(xZoom);

    var lastZoom;
    lastZoom = 0;
    for (var i = 0; i < 18; i++) {
        if (xZoom > 1) {
            lastZoom = i;
            break;           // minimum zoomLevel that dispays all markers 
        }; // if 
        xZoom *= 2;        // multiply by 2 to get next zoomlevel 	pixelsPerLonDegree 
    }; // for	
    return lastZoom;
}

if (window.jQuery) {
    $(function() {
        $("span.floorPlanAvail:contains('Avail')").append(" <a href='#lock' title='Buy to see this data'><IMG src='/images/lock.gif'></a>");
    });
}