
// Alerts

var categoryConfirmDelete = "Are you sure you want to delete this entry?";
var categoryCannotDelete = "Cannot delete this category as it is assigned to landmark(s) !";
var categoryNameExists = "Category name already exists !";
var enterLocationName = "Enter Location Name !";
var enterAddress = "Enter Address !";
var enterLatitude = "Enter Latitude !"
var enterLongitude = "Enter Longitude !"
var enterCategoryName = "Enter Category Name !";
var enterCategoryDescription = "Enter Category Description !";
var selectCategoryImage = "Select image for upload !";
var locationNameAlert = 'Please enter location name !';
var locateMeError = 'Click on Locate Me button to view the Location !';
var radiusAlert = 'Please enter radius greater than 0 !';
var locationAlert = 'Please select the location !'
var LandmarkMax = 'Maximum number of Landmarks reached. Cannot create more Landmarks.'

// Set the alert messages from the Resource File
function SetAlertMessages(categoryConfirmDeleteAlert, categoryCannotDeleteAlert, categoryNameExistsAlert,
        enterLocationNameAlert, enterAddressAlert, enterLatitudeAlert, enterLongitudeAlert,
        enterCategoryNameAlert, enterCategoryDescriptionAlert, selectCategoryImageAlert, rlocationNameAlert, rradiusAlert, rlocateMeError, rLandmarkAlert, rlocationAlert) {
    categoryConfirmDelete = categoryConfirmDeleteAlert;
    categoryCannotDelete = categoryCannotDeleteAlert;
    categoryNameExists = categoryNameExistsAlert;
    enterLocationName = enterLocationNameAlert;
    enterAddress = enterAddressAlert;
    enterLatitude = enterLatitudeAlert;
    enterLongitude = enterLongitudeAlert;
    enterCategoryName = enterCategoryNameAlert;
    enterCategoryDescription = enterCategoryDescriptionAlert;
    selectCategoryImage = selectCategoryImageAlert;
    locationNameAlert = rlocationNameAlert;
    locateMeError = rlocateMeError;
    radiusAlert = rradiusAlert; locationAlert = rlocationAlert;
    LandmarkMax = rLandmarkAlert;
}

window.onresize = function(event) {
    loadForLandMark();
}

function DeleteCategory(elementName, isAssigned) {
    if (isAssigned == 0) {
        //confirm(categoryConfirmDelete); //Replaced with Custom alert. 
        return TrinetraConfirm(elementName, categoryConfirmDelete);
    }
    else {
        TrinetraCustomAlerts(categoryCannotDelete);
        CloseCategoryPopup();
        HidePopUp();
        ShowHideCategoryIcons();
        return false;
    }
}

// Included by Kumuthini. L on 02-Jan-2010
function pageLoad() {
    ShowHideCategoryIcons_Events();
}

// Included by Kumuthini. L on 02-Jan-2010
function ShowHideCategoryIcons_Events() {
    $('#ddlCategory').change(function() {
        ShowHideCategoryIcons()
    });

    $('#btnCancelPwd').click(function() {
        ShowHideCategoryIcons()
    });
}

// Included by Kumuthini. L on 02-Jan-2010
// Function to Show or Hide the Add & Edit Icons based on the Category Selection
function ShowHideCategoryIcons() {
    //var categoryId = $("#ddlCategory > option[selected]").attr("value");
    var categoryId = ""; 
    categoryId = ddlCategory.GetSelectedIndex();

    //if (categoryId == "- Select Category -" || categoryId == "- اختر الفئة -") {
    if (categoryId == 0) {
        $('#lnkAdd').show();
        $('#lnkEdit').hide();
        $('#btnDeleteCategory').hide();
    }
    //else if (categoryId != "") {
    else {
        $('#lnkEdit').show();
        $('#btnDeleteCategory').show();
        $('#lnkAdd').hide();
    }    
}

// Included by Kumuthini. L on 31-Dec-09
// Function to load the Land mark Category Popup
function LoadCategoryPopup(IsDuplicateCatName) {
    var isIE = CheckBrowser();
    var pnlCategory = document.getElementById("pnlAddEditLandmarkCategory");
    pnlCategory.style.display = "block";

    if (IsDuplicateCatName == "True") {
        TrinetraCustomAlerts(categoryNameExists);
        document.getElementById("txtCategoryName").focus();
        document.getElementById('txtCategoryName').style.backgroundColor = 'lightyellow';
    }
    else {
        document.getElementById('txtCategoryName').style.backgroundColor = 'white';
    }
}

// Included by Kumuthini. L on 31-Dec-09
// Function to close the Land mark Category Popup
function CloseCategoryPopup() {
    var pnlCategory = document.getElementById("pnlAddEditLandmarkCategory");
    var lnkadd = document.getElementById("lnkAdd");
    pnlCategory.style.display = "none";
    setFocusToControl('ddlCategory');
    lnkadd.style.display = "block";
    ShowHideCategoryIcons();
}



// Included by Kumuthini. L on 13-Feb-09
// Function to reset all the hidden values and load the map on clicking the Cancel Button
function CancelLandmark() {
    //document.getElementById("hdnIsCancel").value = 1;
    document.getElementById("hdnLatLong").value = "";
    document.getElementById("hdnMapZoomLevel").value = "";
    document.getElementById("hdnMapZoomLevelLatLong").value = "";
    document.getElementById("hdnIsLocateMe").value = "N";
    document.getElementById("hdnLandmarkImage").value = "";
    loadForLandMark();

    document.getElementById('ddlType').selectedIndex = 0;
}

function PlotAddress() {
    //    if (document.getElementById("txtLocationName").value == "" || document.getElementById("txtLocationName").value == "Name") {
    //        alert(enterLocationName);
    //        document.getElementById("txtLocationName").focus();
    //        return false;
    //    }
    var Restriction = document.getElementById('hdnRestriction').value;

    if (Restriction == '0') {
        TrinetraCustomAlerts(LandmarkMax);
        return false;
    }

    if (document.getElementById("ddlType").value == "addr") {
        if (document.getElementById("txtstreet").value == "" || document.getElementById("txtstreet").value == "Address") {
            TrinetraCustomAlerts(enterAddress);
            document.getElementById("txtstreet").focus();
            return false;
        }
    }
    else if (document.getElementById("ddlType").value = "ltlng") {
        if (document.getElementById("txtlat").value == "" || document.getElementById("txtlat").value == "Latitude") {
            TrinetraCustomAlerts(enterLatitude);
            document.getElementById("txtlat").focus();
            return false;
        }
        if (document.getElementById("txtlong").value == "" || document.getElementById("txtlong").value == "Longitude") {
            TrinetraCustomAlerts(enterLongitude);
            document.getElementById("txtlong").focus();
            return false;
        }
    }

    var image = null;
    var imageicn = ddlCategory.GetSelectedItem().imageUrl;
    if (imageicn != '')
        image = "../" + imageicn.substring(imageicn.indexOf('images'), imageicn.length);

    showAddress('', image, '');
    return true;
}

function AddCategory() {
    var isIE = CheckBrowser();
    ClearCategoryDetails();
    LoadCategoryPopup("False");

    document.getElementById("hdnCategoryOprType").value = 'Add';

    if (document.getElementById("lnkAdd") != null) {
        document.getElementById("lnkAdd").style.display = "block";
        document.getElementById('btnDeleteCategory').style.display = "none";
        document.getElementById('txtCategoryName').focus();
    }

    if (document.getElementById("lnkEdit") != null) {
        document.getElementById("lnkEdit").style.display = "none";
    }
    HidePopUp();
}

// Included by Kumuthini. L on 02-Jan-10
// Function to clear the Land mark Category Details
function ClearCategoryDetails() {
    document.getElementById("txtCategoryName").value = "";
    document.getElementById("txtDescription").value = "";

    if (document.getElementById("imgUploded") != null) {
        document.getElementById("imgUploded").style.display = "none";
    }
}

function ValidateCategory() {
    var isError = false;
    var alertMessage = '';
    var controlToBeFocussed = '';
    if (RemoveSpaces(document.getElementById("txtCategoryName")).length == 0) {
        isError = true; alertMessage = enterCategoryName;
        controlToBeFocussed = document.getElementById("txtCategoryName");
        document.getElementById("txtCategoryName").style.backgroundColor = 'lightyellow';
    }
    else {
        document.getElementById("txtCategoryName").style.backgroundColor = 'white';
    }
    if (RemoveSpaces(document.getElementById("txtDescription")).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + enterCategoryDescription;
        if (!isError) controlToBeFocussed = document.getElementById("txtDescription");
        document.getElementById("txtDescription").style.backgroundColor = 'lightyellow';
        isError = true;
    }
    else {
        document.getElementById("txtDescription").style.backgroundColor = 'white';
    }
    if (document.getElementById("imgUploded").style.display == 'none') {
        if (document.getElementById("lblFileName").innerHTML == "") {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + selectCategoryImage;
            if (!isError) controlToBeFocussed = document.getElementById("fuImageUpload");
            document.getElementById("fuImageUpload").style.backgroundColor = 'lightyellow';
            isError = true;
        }
        else {
            document.getElementById("fuImageUpload").style.backgroundColor = 'white';
        }
    }
    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        try {
            controlToBeFocussed.focus();
        }
        catch (Error) { }
    }
    return !isError;
}

function validateNotification() {
    try {
        var manageNotifiction = document.getElementById('btnAddNotifictions');
        var notify = document.getElementById('chkNotify');
        if (notify.checked) {
            manageNotifiction.style.display = "block";
        }
        else {
            if (manageNotifiction != null)
                manageNotifiction.style.display = "none";
        }
    }
    catch (ex) {

    }
}

function readFileName()
{
    var input = document.getElementById("fuImageUpload").value;
    document.getElementById("lblFileName").value = document.getElementById("lblFileName").innerHTML = input;
}