﻿// JScript File
var XmlHttp = null;
var glb_SaveSendNote = 0;
var currEmail = "anonymous";
var PopUpLoadingDiv = "popUpBody";
var currUserID = 0;

function trimAll(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}

function isValidEmail(str) {
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

/************************** Start:// Add Contacts Category **********************/
// My Changes -->
function validateEmail(str) {
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {

        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {

        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {

        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {

        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {

        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {

        return false
    }

    if (str.indexOf(" ") != -1) {

        return false
    }

    return true
}

function validateContacts(contacts) {
    //returns 0 Everything OK  ----  returns 1 not OK
    var arr;
    var isValid = 0;
    arr = contacts.split(',');
    for (i = 0; i < arr.length; i++) {
        if (!validateEmail(trimAll(arr[i]))) {
            isValid = 1;
            break;
        }
    }
    return isValid;
}



function checkit() {

    var content = trimAll(document.getElementById('txtAreaContacts').value);
    if (content != '') {
        if (validateContacts(content) == 0) {
            alert("Contacts are in Proper Format.\n Checking Successful...");
        } else {
            alert("Contacts are not in Proper Format.\n Checking Failed... \n Please Enter contacts as id1@domain.com,id2@domain.com,id3@domain.com and so on");
        }

    }
    else {
        alert('Please Enter Some Contacts To Check');
    }
}



function readTextFile() {
//    alert("11");
    var strContents;
    strContents = "";
    alert(document.getElementById('myContactsBrowse').value + '--' + document.getElementById('myContactsBrowse').innerText);
    strFileName = document.getElementById('myContactsBrowse').value;

    if (trimAll(strFileName) != '') {
        XmlHttp = null;
        CreateXmlHttp();
        if (XmlHttp != null)
            XmlHttp.open("GET", strFileName, true);
        XmlHttp.onreadystatechange = function () {
            //Remove the loading div as data has come.
            RemoveLoadingDiv(PopUpLoadingDiv);
            if (XmlHttp.readyState == 4) {
//                alert(trimAll(XmlHttp.responseText));
                document.getElementById('txtAreaContacts').innerText = trimAll(XmlHttp.responseText);
            }
        }
        sendRequest(null)

    }
    else {
        alert('Please select some text file to upload');
    }
} //end of function


function addCategoryContact(obj) {
    if (trimAll(document.getElementById('txtContactCategory').value) != '') {
        if (trimAll(document.getElementById('txtAreaContacts').value) != '') {
            if (validateContacts(trimAll(document.getElementById('txtAreaContacts').value)) == 1) {
                document.getElementById('txtAreaContacts').focus();
                alert("Contacts are not in Proper Format... \n Please Enter contacts as id1@domain.com,id2@domain.com,id3@domain.com and so on");
                return;
            }

            /*Check Added ::Rakesh Dated 28July 2008::START
            Desc::This check is for Restricting User to Add More Than 50 EmailIDs per Contact Category
            */

            var ContactMailIDArray = trimAll(document.getElementById('txtAreaContacts').value).split(',');

            if (ContactMailIDArray.length > 50) {
                alert('You cannot Add more than 50 Email Contacts to one Contact Category!!');
                return;
            }

            /*Check Added ::Rakesh Dated 28July 2008::END*/
        }



        var requestUrl = 'saveCategoryContacts.aspx?cat=' + trimAll(document.getElementById('txtContactCategory').value) + '&contacts=' + trimAll(document.getElementById('txtAreaContacts').value) + '&ActualCatName=' + _glbCatName + '&rand=' + Math.floor(Math.random() * 10000000);
        //alert(requestUrl);
        CreateXmlHttp();
        // If browser supports XMLHTTPRequest object
        if (XmlHttp) {
            //Setting the event handler for the response
            XmlHttp.onreadystatechange = HandleResponseContacts;

            //Initializes the request object with GET (METHOD of posting), 
            //Request URL and sets the request as asynchronous.
            //alert(requestUrl);
            XmlHttp.open("GET", requestUrl, true);

            //Sends the request to server
            sendRequest(null);
        }
    }
    else {
        alert('Please enter category name');
        document.getElementById('txtContactCategory').focus();
    }
}
function deleteCategoryContact(cat) {

    var ConfirmMsg = confirm('Are you sure you want to delete this Contact Category?');
    if (ConfirmMsg) {
        var requestUrl = 'DeleteCategoryContacts.aspx?cat=' + cat + '&rand=' + Math.floor(Math.random() * 10000000);
        CreateXmlHttp();
        // If browser supports XMLHTTPRequest object
        if (XmlHttp) {
            //Setting the event handler for the response
            XmlHttp.onreadystatechange = HandleResponseContacts;

            //Initializes the request object with GET (METHOD of posting), 
            //Request URL and sets the request as asynchronous.
            //alert(requestUrl);
            XmlHttp.open("GET", requestUrl, true);

            //Sends the request to server
            sendRequest(null);
        }
    }

}
function HandleResponseContacts() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            //alert(document.getElementById('Div21'));	
            //if(document.getElementById('Div21'))
           // alert(XmlHttp.responseText);
            document.getElementById('contactDiv').innerHTML = XmlHttp.responseText;
            //document.getElementById('hdnV').value="";
            //alert('This note details has been saved');
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

//New function is made so as to send request in different function
function sendRequest(params) {
    //Show the loading div before sending request.
    ShowLoadingDiv(PopUpLoadingDiv);
    //Sends the request to server
    XmlHttp.send(params);
}

function loadContacts() {

    var requestUrl = 'showCategoryContacts.aspx?rand=' + Math.floor(Math.random() * 10000000);
    //    
    CreateXmlHttp();
    //    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {
        //        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponseContacts;

        //        //Initializes the request object with GET (METHOD of posting), 
        //        //Request URL and sets the request as asynchronous.
        XmlHttp.open("GET", requestUrl, true);

        //        //Sends the request to server
        sendRequest(null);
    }
}
function ShowHideCategoryContacts() {
    //alert(arguments[0]);
    for (i = 0; i < arguments[1]; i++) {
        if (document.getElementById('contactId' + arguments[0] + i)) {
            //alert('contactId'+arguments[0]+i);
            if (document.getElementById('contactId' + arguments[0] + i).style.display == 'none') {
                document.getElementById('contactId' + arguments[0] + i).style.display = '';
            }
            else {
                document.getElementById('contactId' + arguments[0] + i).style.display = 'none';
            }
        }
    }
}

function ShowHideCategoryContactsNew(index) {

    if (document.getElementById('contactId' + index).style.display == 'none') {
        document.getElementById('contactId' + index).style.display = '';
    }
    else {
        document.getElementById('contactId' + index).style.display = 'none';
    }
}

function ShowHideCategoryContactsAA(index) {

    if (document.getElementById('contactIdAA' + index).style.display == 'none') {
        document.getElementById('contactIdAA' + index).style.display = '';
    }
    else {
        document.getElementById('contactIdAA' + index).style.display = 'none';
    }
}
function ShowHideCategoryContactsSN(index) {

    if (document.getElementById('contactIdSN' + index).style.display == 'none') {
        document.getElementById('contactIdSN' + index).style.display = '';
    }
    else {
        document.getElementById('contactIdSN' + index).style.display = 'none';
    }
}
function ShowHideCategoryContactsJN(index) {

    if (document.getElementById('contactIdJN' + index).style.display == 'none') {
        document.getElementById('contactIdJN' + index).style.display = '';
    }
    else {
        document.getElementById('contactIdJN' + index).style.display = 'none';
    }
}
// My Changes -->
/************************** Ends://Add Contacts Category **********************/

function HideMyPicsLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
function ShowMyPicsLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "inline";

}
function HideMyContactsLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
function ShowMyContactsLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "inline";

}
function HideAlertReminderLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
function ShowAlertReminderLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "inline";

}
function HideMyDailyDiaryLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
    //alert(document.getElementById('fc').style.display);

    // document.getElementById('fc').style.display="none";
}
function ShowMyNotesLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "inline";


}
function HideMyNotesLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
function ShowMyDailyDiaryLayer(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "inline";

}

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp() {
    //Creating object of XMLHTTP in IE
    try {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

        }
        catch (oc) {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if (!XmlHttp && typeof XMLHttpRequest != "undefined") {
        XmlHttp = new XMLHttpRequest();
    }
}

function saveNotes() {

    if (trimAll(document.getElementById('txtCategory').value) != '') {
        if ((trimAll(document.getElementById('txtNote').value) == '') && ((trimAll(InnerContentsTinyMCE('txtNoteDesc')) != '') || (trimAll(document.getElementById('txtLinkUrl').value) != '') || (trimAll(document.getElementById('txtLinkUrl').value) != ''))) {
            alert('Please enter note name before saving its details');
            //document.getElementById('txtNote').focus();
        }
        else {
            if ((trimAll(document.getElementById('txtLinkName').value) != '' && trimAll(document.getElementById('txtLinkUrl').value) != '') || (trimAll(document.getElementById('txtLinkName').value) == '' && trimAll(document.getElementById('txtLinkUrl').value) == '')) {
                // do work


                var NoteDescription = trimAll(InnerHtmlTinyMCE('txtNoteDesc'));
                NoteDescription = NoteDescription.replace(/</g, "&lt;");
                NoteDescription = NoteDescription.replace(/>/g, "&gt;");

                NoteDescription = NoteDescription.replace(/&/g, "^^^");


                //var requestUrl = 'saveNoteDetails.aspx';
                //var params = 'cat='+trimAll(document.getElementById('txtCategory').value)+'&note='+trimAll(document.getElementById('txtNote').value)+'&description='+NoteDescription+'&linkname='+trimAll(document.getElementById('txtLinkName').value)+'&linkurl='+trimAll(document.getElementById('txtLinkUrl').value)+'&userid='+document.getElementById('hdnusernameid').value+'&hdnF='+document.getElementById('hdnF').value+'&hdnV='+document.getElementById('hdnV').value+'&rand='+Math.floor(Math.random() * 10000000);

                var requestUrl = 'saveNoteDetails.aspx';
                var params = 'linkID=' + trimAll(document.getElementById('hdnLinkTrack').value) + '&noteID=' + trimAll(document.getElementById('hdnNotesTrack').value) + '&catID=' + trimAll(document.getElementById('hdnCategoryTrack').value) + '&cat=' + trimAll(document.getElementById('txtCategory').value) + '&note=' + trimAll(document.getElementById('txtNote').value) + '&description=' + NoteDescription + '&linkname=' + trimAll(document.getElementById('txtLinkName').value) + '&linkurl=' + trimAll(document.getElementById('txtLinkUrl').value) + '&userid=' + document.getElementById('hdnusernameid').value + '&hdnF=' + document.getElementById('hdnF').value + '&hdnV=' + document.getElementById('hdnV').value + '&rand=' + Math.floor(Math.random() * 10000000);


                CreateXmlHttp();
                // If browser supports XMLHTTPRequest object
                if (XmlHttp) {
                    //Setting the event handler for the response
                    XmlHttp.onreadystatechange = HandleResponse;

                    //Initializes the request object with GET (METHOD of posting), 
                    //Request URL and sets the request as asynchronous.
                    XmlHttp.open("POST", requestUrl, true);
                    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
                    XmlHttp.setRequestHeader("Content-Type", contentType);
                    XmlHttp.setRequestHeader("Content-length", params.length);
                    //Sends the request to server
                    sendRequest(params);
                }
            }
            else {
                if (trimAll(document.getElementById('txtLinkName').value) == '') {
                    alert('Please enter link name before saving its URL');
                    //document.getElementById('txtLinkName').focus();
                }
                else {
                    alert('Please enter link URL');
                    document.getElementById('txtLinkUrl').focus();
                }
            }

        }
    }
    else {
        alert('Please enter category name');
        //document.getElementById('txtCategory').focus();
    }
}

function HandleResponse() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            var resultSet = XmlHttp.responseText.split('^^^');
            if (resultSet[0] == "1")
                alert("Category with this name already belongs to the User.Please enter a different Category Name.");
            else if (resultSet[0] == "2")
                alert("Note with this name already belongs to the selected Category.Please enter a different Note Name.");
            else if (resultSet[0] == "3")
                alert("Link with this name already belongs to the selected Note.Please enter a different Link Name.");

            document.getElementById('noteLinkMainCell').innerHTML = resultSet[1];
            //document.getElementById('hdnV').value="";
            //alert('This note details has been saved');
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function saveDiary() {
    if (trimAll(document.getElementById('txtdiaryheading').value) != '') {

        // do work

        //alert(window.frames["calDiv"].document.getElementById('hdnDate').value);
        //return;
        var requestUrl = 'saveDiary.aspx?diaryheading=' + trimAll(document.getElementById('txtdiaryheading').value) + '&diarydesc=' + trimAll(document.getElementById('txtdiarydesc').value) + '&userid=' + document.getElementById('hdnusernameid').value + '&datediary=' + window.frames["calDiv"].document.getElementById('hdnDate').value + '&rand=' + Math.floor(Math.random() * 10000000);
        CreateXmlHttp();
        // If browser supports XMLHTTPRequest object
        if (XmlHttp) {
            //Setting the event handler for the response
            XmlHttp.onreadystatechange = HandleResponseDiary;

            //Initializes the request object with GET (METHOD of posting), 
            //Request URL and sets the request as asynchronous.
            XmlHttp.open("GET", requestUrl, true);

            //Sends the request to server
            sendRequest(null);
        }

    }
    else {
        alert('Please enter Diary note title');
        document.getElementById('txtdiaryheading').focus();
    }
}

function HandleResponseDiary() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == 'updated')
                alert('This Diary Note has been updated successfully');
            else if (XmlHttp.responseText == 'saved')
                alert('This Diary Note has been saved successfully');
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function retrievePass() {
    if (trimAll(document.getElementById('txtmoosid').value) != '') {
        //if(trimAll(document.getElementById('txtemailid').value) != '')
        //{
        //if(isValidEmail(document.getElementById('txtemailid').value))
        //{
        // do work

        var requestUrl = 'sendMail.aspx?moosid=' + trimAll(document.getElementById('txtmoosid').value) + '&emailid=' + trimAll(document.getElementById('txtemailid').value) + '&rand=' + Math.floor(Math.random() * 10000000);
        CreateXmlHttp();
        // If browser supports XMLHTTPRequest object
        if (XmlHttp) {
            //Setting the event handler for the response
            XmlHttp.onreadystatechange = HandleResponseForgotPass;

            //Initializes the request object with GET (METHOD of posting), 
            //Request URL and sets the request as asynchronous.
            XmlHttp.open("GET", requestUrl, true);

            //Sends the request to server
            sendRequest(null);
        }
        //}
        //else 
        //{
        //alert('Please enter a valid EmailID');
        //document.getElementById('txtemailid').focus();
        //}
        //}
        //else
        //{
        //alert('Please enter your EmailID');
        //document.getElementById('txtemailid').focus();
        //}
    }
    else {
        alert('Please enter your MoosID');
        document.getElementById('txtmoosid').focus();
    }
}

function HandleResponseForgotPass() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == '0') {
                alert('An E-mail regarding your password has been sent to you.');
            } else if (XmlHttp.responseText == '1') {
                alert('A Poblem Occured While Mailing you Password. Please Try Again');
            } else {
                alert('This Moos ID doesnot exists.');
                document.getElementById('txtmoosid').focus();
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function ShowHideNotesLinks() {
//    alert(arguments[0]);
    defaultDisable();
    document.getElementById('txtCategory').disabled = false;
    document.getElementById('txtCategory').value = arguments[0];
    document.getElementById('txtNote').value = '';
    //setInsertHtml('');
    document.getElementById('txtLinkName').value = '';
    document.getElementById('txtLinkUrl').value = '';
    document.getElementById('spanReplySentNoteID').innerText = "Just Send Note";
    document.getElementById('hdnV').value = arguments[0];
    if (document.getElementById('noteId' + arguments[0])) {
        if (document.getElementById('noteId' + arguments[0]).style.display == 'none')
            document.getElementById('noteId' + arguments[0]).style.display = '';
        else
            document.getElementById('noteId' + arguments[0]).style.display = 'none';
    }

}

function showHideLink() {
    document.getElementById('txtCategory').disabled = false;
    document.getElementById('txtNote').disabled = false;
    document.getElementById('txtLinkName').disabled = true;
    document.getElementById('txtLinkName').value = '';
    document.getElementById('txtLinkUrl').value = '';
    document.getElementById('spanReplySentNoteID').innerText = "Just Send Note";
    if (document.getElementById(arguments[0])) {
        if (document.getElementById(arguments[0]).style.display == 'none')
            document.getElementById(arguments[0]).style.display = '';
        else
            document.getElementById(arguments[0]).style.display = 'none'
    }
    document.getElementById('hdnF').value = "0";
}

function fillNoteData(catName, noteName) {
    document.getElementById('txtCategory').value = catName;
    document.getElementById('txtNote').value = noteName;
    document.getElementById('hdnV').value = catName + "^" + noteName;
    var requestUrl = 'showDesc.aspx?catname=' + catName + '&notename=' + noteName + '&rand=' + Math.floor(Math.random() * 10000000);
    CreateXmlHttp();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {
        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponseShowDesc;

        //Initializes the request object with GET (METHOD of posting), 
        //Request URL and sets the request as asynchronous.
        XmlHttp.open("GET", requestUrl, true);

        //Sends the request to server
        sendRequest(null);
    }
}

function HandleResponseShowDesc() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            setInsertHtml(XmlHttp.responseText);
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function popLinks(catname, notename, linkname, linkurl) {

    //document.getElementById('txtLinkName').disabled=false;
    //document.getElementById('txtLinkUrl').disabled=false;
    document.getElementById('txtCategory').disabled = false;
    document.getElementById('txtNote').disabled = false;
    document.getElementById('txtLinkName').disabled = false;
    document.getElementById('spanReplySentNoteID').innerText = "Just Send Note";
    document.getElementById('hdnV').value = catname + "^" + notename + "^" + linkname;
    document.getElementById('txtLinkName').value = linkname;
    document.getElementById('txtLinkUrl').value = linkurl;
}

function AddNewCat() {
    document.getElementById('txtCategory').disabled = false;
    document.getElementById('txtCategory').value = "";
    document.getElementById('txtNote').value = "";
    document.getElementById('txtLinkName').value = "";
    document.getElementById('txtLinkUrl').value = "";
    document.getElementById('hdnCategoryTrack').value = '0';
    document.getElementById('txtCategory').focus();
    document.getElementById('hdnF').value = '1';
    document.getElementById('spanReplySentNoteID').innerText = "Just Send Note";
}

function AddNewNote() {

    document.getElementById('txtNote').disabled = false;
    document.getElementById('txtNote').value = "";

    document.getElementById('txtLinkName').value = "";
    document.getElementById('txtLinkUrl').value = "";
    document.getElementById('hdnNotesTrack').value = '0';
    document.getElementById('txtNote').focus();
    document.getElementById('hdnF').value = '1';
    document.getElementById('spanReplySentNoteID').innerText = "Just Send Note";

}
function addNewLink() {

    document.getElementById('txtLinkName').disabled = false;
    document.getElementById('txtLinkName').value = "";
    document.getElementById('txtLinkUrl').value = "";
    document.getElementById('hdnLinkTrack').value = '0';
    document.getElementById('txtLinkName').focus();
    document.getElementById('spanReplySentNoteID').innerText = "Just Send Note";
    document.getElementById('hdnF').value = '1';

}



function deleteCat() {

    if (trimAll(document.getElementById('txtCategory').value) != '') {
        var confirmDelCat = confirm('Are you sure you Want to Delete this category?');

        if (confirmDelCat) {
            //deleteCat
            var requestUrl = 'deleteCat.aspx?catname=' + trimAll(document.getElementById('txtCategory').value) + '&rand=' + Math.floor(Math.random() * 10000000);
            CreateXmlHttp();
            // If browser supports XMLHTTPRequest object
            if (XmlHttp) {
                //Setting the event handler for the response
                XmlHttp.onreadystatechange = HandleResponseDeleteCat;

                //Initializes the request object with GET (METHOD of posting), 
                //Request URL and sets the request as asynchronous.
                XmlHttp.open("GET", requestUrl, true);

                //Sends the request to server
                sendRequest(null);
            }

        }
    } else {
        alert('Please select a Category to delete!!');
    }
}

function HandleResponseDeleteCat() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            document.getElementById('noteLinkMainCell').innerHTML = XmlHttp.responseText;
            document.getElementById('txtCategory').value = '';
            document.getElementById('txtNote').value = '';
            setInsertHtml('');
            document.getElementById('txtLinkName').value = '';
            document.getElementById('txtLinkUrl').value = '';
            document.getElementById('hdnF').value = '1';
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}


function deleteNote() {
    if (trimAll(document.getElementById('txtCategory').value) != '') {

        if (trimAll(document.getElementById('txtNote').value) != '') {
            var confirmDelNote = confirm('Are you sure you Want to Delete this Note?');

            if (confirmDelNote) {
                //deleteNote
                var requestUrl = 'deleteNote.aspx?catname=' + trimAll(document.getElementById('txtCategory').value) + '&notename=' + trimAll(document.getElementById('txtNote').value) + '&rand=' + Math.floor(Math.random() * 10000000);
                CreateXmlHttp();
                // If browser supports XMLHTTPRequest object
                if (XmlHttp) {
                    //Setting the event handler for the response
                    XmlHttp.onreadystatechange = HandleResponseDeleteNote;

                    //Initializes the request object with GET (METHOD of posting), 
                    //Request URL and sets the request as asynchronous.
                    XmlHttp.open("GET", requestUrl, true);

                    //Sends the request to server
                    sendRequest(null);
                }

            }
        } else {
            alert('Please select a Note to delete!!');
        }
    } else {
        alert('Please select a Valid Category whose note is to be deleted!!');
    }
}

function HandleResponseDeleteNote() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            document.getElementById('noteLinkMainCell').innerHTML = XmlHttp.responseText;
            document.getElementById('txtCategory').value = '';
            document.getElementById('txtNote').value = '';
            setInsertHtml('');
            document.getElementById('txtLinkName').value = '';
            document.getElementById('txtLinkUrl').value = '';
            document.getElementById('hdnF').value = '1';
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}


function deleteLink() {
    if (trimAll(document.getElementById('txtCategory').value) != '') {

        if (trimAll(document.getElementById('txtNote').value) != '') {

            if (trimAll(document.getElementById('txtLinkName').value) != '') {
                var confirmDelNote = confirm('Are you sure you Want to Delete this Link?');

                if (confirmDelNote) {
                    //deleteNote
                    var requestUrl = 'deleteLink.aspx?catname=' + trimAll(document.getElementById('txtCategory').value) + '&notename=' + trimAll(document.getElementById('txtNote').value) + '&linkname=' + trimAll(document.getElementById('txtLinkName').value) + '&rand=' + Math.floor(Math.random() * 10000000);
                    CreateXmlHttp();
                    // If browser supports XMLHTTPRequest object
                    if (XmlHttp) {
                        //Setting the event handler for the response
                        XmlHttp.onreadystatechange = HandleResponseDeletLink;

                        //Initializes the request object with GET (METHOD of posting), 
                        //Request URL and sets the request as asynchronous.
                        XmlHttp.open("GET", requestUrl, true);

                        //Sends the request to server
                        sendRequest(null);
                    }

                }
            } else {
                alert('Please select a Link to delete!!');
            }
        } else {
            alert('Please select a Valid Note whose Link is to be deleted!!');
        }
    } else {
        alert("Please select a Valid Category whose Note's Link is to be deleted!!");
    }
}

function HandleResponseDeletLink() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            document.getElementById('noteLinkMainCell').innerHTML = XmlHttp.responseText;
            document.getElementById('txtCategory').value = '';
            document.getElementById('txtNote').value = '';
            setInsertHtml('');
            document.getElementById('txtLinkName').value = '';
            document.getElementById('txtLinkUrl').value = '';
            document.getElementById('hdnF').value = '1';
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function imageClicked(imgScreenPos, imgDBId, imgPath) {
    mainImgDatabaseId = 0;
    mainImgSrcPath = "";
    if (typeof (imgDBId) != "undefined") {
        mainImgDatabaseId = imgDBId;
        mainImgSrcPath = imgPath
    }
    document.getElementById("mainPicdiv").innerHTML = getPathStr(imgScreenPos, imgDBId, imgPath);
}



function getPathStr(imgScreenPos, imgDBId, imgPath) {
    if (typeof (imgDBId) == "undefined")
        return "";
    return '<img id="MainImg_' + imgDBId + '" src="' + imgPath
    + '" style="width:300px;height:250px;" width="300" height="250" border="0" alt="'
    + imgPath + '" />';
}

function getPathStrA() {
    return '<img id="PutImg_'
   + mainImgDatabaseId + '" src="' + mainImgSrcPath
   + '" width="100" height="100"  border="0" alt="'
   + mainImgSrcPath + '" />';
}

function putHere(obj) {
    if (mainImgDatabaseId != 0) {
        obj.innerHTML = getPathStrA();
        obj.innerHTML = obj.innerHTML + "<span onclick=\"javascript:putHere(document.getElementById('" + obj.id + "'));\">Put Here</span>";
    }
    else
        obj.innerHTML = "<span onclick=\"javascript:putHere(document.getElementById('" + obj.id + "'));\">Put Here</span>";
}

/*Function to Return ImageID*/
function returnImageID(obj, ControlVar) {
    var ImageID = 0;
    var mainStr = obj.innerHTML;
    //alert(mainStr);
    if (trimAll(obj.innerHTML) != "") {
        if (ControlVar == 0) {
            //for three divs on Left ..PutImg_
            
            //alert(mainStr.indexOf("<img"));
            if(mainStr.toUpperCase().indexOf("<IMG") != -1)
            {
                tempStr = mainStr.substring(mainStr.indexOf('PutImg_') + 7, mainStr.length);
                //alert(tempStr);
                ImageID = tempStr.substring(0, tempStr.indexOf(" "));
                //alert(ImageID);
                
            }
            
        } else {
            //for div in center  ..MainImg_
            if(mainStr.toUpperCase().indexOf("<IMG") != -1)
            {
                tempStr = mainStr.substring(mainStr.indexOf('MainImg_') + 8, mainStr.length);
                ImageID = tempStr.substring(0, tempStr.indexOf(" "));
            }
        }
        //in Firefox/ FF ID is like 3" remove "
        if (ImageID != 0 && ImageID.indexOf('"') != -1)
            ImageID = ImageID.substring(0, ImageID.length - 1);
    }

    return ImageID;
}

function savePics() {
    var PutImageID1 = returnImageID(document.getElementById("putDiv1"), 0);

    var PutImageID2 = returnImageID(document.getElementById("putDiv2"), 0);
    var PutImageID3 = returnImageID(document.getElementById("putDiv3"), 0);
    var MainImageID = returnImageID(document.getElementById("mainPicdiv"), 1);
    var requestUrl = 'saveImages.aspx?PutImageID1=' + PutImageID1 + '&PutImageID2=' + PutImageID2 + '&PutImageID3=' + PutImageID3 + '&MainImageID=' + MainImageID + '&rand=' + Math.floor(Math.random() * 10000000);
    //alert(requestUrl);
    CreateXmlHttp();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {
        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponseSaveImages;

        //Initializes the request object with GET (METHOD of posting), 
        //Request URL and sets the request as asynchronous.
        XmlHttp.open("GET", requestUrl, true);

        //Sends the request to server
        sendRequest(null);
    }

}

function HandleResponseSaveImages() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            var imageStr = XmlHttp.responseText;

            var mySplitResult = imageStr.split("^^");
            //alert(imageStr);
           
            window.parent.document.getElementById("mainPicDivID1").innerHTML = mySplitResult[0];
            window.parent.document.getElementById("mainPicDivID2").innerHTML = mySplitResult[1];
            window.parent.document.getElementById("mainPicDivID3").innerHTML = mySplitResult[2];
            window.parent.HideMyPicsLayer('myPicsLayer');

        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}


/*Add Alert reminder Functionality::Start*/

//For Add Alert


var OpenModalWindow = function (modalUrl, modalTitle, modalWidth, modalHeight, SuccFnToExec) {
    showPopWin(modalUrl + 'rand=' + Math.floor(Math.random() * 100001), modalTitle, modalWidth, modalHeight, null, null, SuccFnToExec);
}

//Load Add alerts window
var LoadAddAlertsWindow = function () {
    var CatName = trimAll(document.getElementById('txtCategory').value);
    var NoteName = trimAll(document.getElementById('txtNote').value);
    OpenModalWindow("AddAlerts.aspx?CatName=" + CatName + "&NoteName=" + NoteName + "&", "MOOSTOOL :: Add Your Alerts", 557, 355, AddAlertSuccess);
}

//Load View alerts window
var LoadViewAlertsWindow = function () {
    OpenModalWindow("ShowAlerts.aspx?", "MOOSTOOL :: View Your Alerts", 800, 500);
}

//User Images
var LoadUserPicturesWindow = function (deleteImageID) {
    if (deleteImageID)
        OpenModalWindow("UserPictures.aspx?deleteImage=" + deleteImageID + "&", "MOOSTOOL :: Manage your Pics", 879, 497, UserPictureSuccess);
    else
        OpenModalWindow("UserPictures.aspx?", "MOOSTOOL :: Manage your Pics", 879, 497, UserPictureSuccess);
}

//Moos Diary
var LoadMoosDiaryWindow = function () {
    OpenModalWindow("MoosDiary.aspx?", "MOOSTOOL :: Manage your Diary", 650, 385, MoosDiarySuccess);
}

//Moos Print
var LoadMoosPrintWindow = function () {
    OpenModalWindow("MoosPrint.aspx?", "MOOSTOOL :: Print Details", 557, 285,InitializePrintPage);
}

var LoadCatContactsWindow = function (querystringParams) {
    if (querystringParams)
        OpenModalWindow("CategoryContacts.aspx?" + querystringParams + "&", "MOOSTOOL :: Your Contacts", 650, 400, CreateCatSuccess);
    else
        OpenModalWindow("CategoryContacts.aspx?", "MOOSTOOL :: Your Contacts", 650, 400, CreateCatSuccess);
}

var OpenChangePassWindow = function () {
    OpenModalWindow("ChangePassword.aspx?", "MOOSTOOL :: Change Password", 486, 239, ChangePasswordSuccess);
}

//Load Add alerts window
var LoadTimeZoneWindow = function (UserTimezone, IsTimeSaving) {

    OpenModalWindow("DetectTimeZone.aspx?UserTimezone=" + trimAll(UserTimezone) + "&IsTimeSaving=" + trimAll(IsTimeSaving) + "&", "MOOSTOOL :: Detect Your Current Timezone Settings", 557, 285);
}




//Dynamically loading all Contacts of user when Clicked on Add Alert Reminder Link.
function showContactsOnLoad() {
    var requestUrl = 'populateContactDetails.aspx?ContactType=AA&rand=' + Math.floor(Math.random() * 10000000);
    CreateXmlHttp();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {
        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponsePopulateContacts;

        //Initializes the request object with GET (METHOD of posting), 
        //Request URL and sets the request as asynchronous.
        XmlHttp.open("GET", requestUrl, true);

        //Sends the request to server
        sendRequest(null);
    }


}


function HandleResponsePopulateContacts() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText != '')
                document.getElementById('userContactDetails').innerHTML = XmlHttp.responseText;
            else
                document.getElementById('userContactDetails').innerHTML = '<b><div style="padding:30px;">There are no Contacts Added for You.Please Add first in "My Contacts" Section.</div></b>';
            ShowAlertReminderLayer('alertReminderLayer');
            return true;
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function unCheckAll() {
    for (var i = 0; i < window.document.form1.elements.length; i++) {
        var ev = window.document.form1.elements[i];
        var nameObj = ev.name;
        if (ev.type == 'checkbox' && ev.name != "") {
            document.getElementById(ev.name).checked = false;

        }
    }
}

function unCheckAllAA() {
    for (var i = 0; i < window.document.form1.elements.length; i++) {
        var ev = window.document.form1.elements[i];
        var nameObj = ev.name;
        if ((ev.type == 'checkbox') && (ev.name.indexOf("AA_") != -1)) {
            document.getElementById(ev.name).checked = false;

        }
    }
}
function viewSelContacts() {
    if (trimAll(document.getElementById('txtCategory').value) != '') {
        if (trimAll(document.getElementById('txtNote').value) != '') {
            var hours = 0;
            //if(document.getElementById('timeId').value == 'PM')
            //{
            //hours = (document.getElementById('hoursId').value*1)+12;
            //}
            //else if(document.getElementById('timeId').value == 'AM')
            //{
            hours = document.getElementById('hoursId').value;

            //}
            var requestUrl = 'saveAlerts.aspx?category=' + document.getElementById('txtCategory').value + '&note=' + document.getElementById('txtNote').value + '&date=' + window.alertReminderCalFrame.document.getElementById('hdnDate').value + '&hourNo=' + hours + '&minuteNo=' + document.getElementById('minutesId').value + '&val=3&rand=' + Math.floor(Math.random() * 10000000);
            CreateXmlHttp();
            // If browser supports XMLHTTPRequest object
            if (XmlHttp) {
                //Setting the event handler for the response
                XmlHttp.onreadystatechange = HandleResponseviewSelContacts;

                //Initializes the request object with GET (METHOD of posting), 
                //Request URL and sets the request as asynchronous.
                XmlHttp.open("GET", requestUrl, true);

                //Sends the request to server
                sendRequest(null);
            }
        } else {
            alert('Please select a valid Note whose details you want to save to send as an Alert.');
        }
    } else {
        alert('Please select a Category whose Note details you want to save to send as an Alert.');
    }

}

function HandleResponseviewSelContacts() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == 'InvalidCategoryName') {
                alert('Please select a valid Category Name.');
            }
            else if (XmlHttp.responseText == 'InvalidNoteName') {
                alert('Please select a valid Note Name.');
            }
            else if (XmlHttp.responseText == 'InvalidDateTime') {
                alert('Date Time selected must be greater than Current Date Time.');
            }
            else if (XmlHttp.responseText == 'NoContactFound') {
                unCheckAll();
            } else {
                unCheckAll();
                var strAlreadyAdded = XmlHttp.responseText;
                var arrSplit = strAlreadyAdded.split(',');
                if (arrSplit.length > 0) {
                    for (var i = 0; i < arrSplit.length; i++) {

                        var arrAnotherSplit = arrSplit[i].split('^');
                        checkCheckBox(arrAnotherSplit[0], arrAnotherSplit[1]);
                    }
                }
            }


        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function checkCheckBox() {

    //category name  mailid
    for (var i = 0; i < window.document.form1.elements.length; i++) {
        var e = window.document.form1.elements[i];
        var nameObj = e.name;


        //alert(strChkName);
        if ((nameObj.indexOf("AA_" + arguments[0]) != -1) && (e.type == 'checkbox') && (e.value == arguments[1])) {

            document.getElementById(e.name).checked = true;

        }
    }
}

function saveAlerts() {
    if (trimAll(document.getElementById('txtCategory').value) != '') {
        if (trimAll(document.getElementById('txtNote').value) != '') {
            var strTo = '';
            var strEmailIds = ''; //variable added Rakesh For FROM/TO show Emails Functionality

            for (var i = 0; i < window.document.form1.elements.length; i++) {
                var e = window.document.form1.elements[i];

                var nameObj = e.name;


                if (e.type == 'checkbox') {
                    if ((nameObj.indexOf("AA_") != -1) && (document.getElementById(e.name).checked)) {
                        strTo = strTo + nameObj.substring(3, nameObj.indexOf("^")) + "^" + e.value + ",";
                        strEmailIds = strEmailIds + e.value + ","; //line added Rakesh For FROM/TO show Emails Functionality

                    }
                }
            }
            strTo = strTo.substring(0, strTo.length - 1);
            strEmailIds = strEmailIds.substring(0, strEmailIds.length - 1); //line added Rakesh For FROM/TO show Emails Functionality
            if (trimAll(strTo) != '') {
                var hours = 0;
                //           if(document.getElementById('timeId').value == 'PM')
                //           {
                //               hours = (document.getElementById('hoursId').value*1)+12;
                //           }
                //           else if(document.getElementById('timeId').value == 'AM')
                //           {
                hours = document.getElementById('hoursId').value;

                //}
                var requestUrl = 'saveAlerts.aspx?category=' 
                + document.getElementById('txtCategory').value 
                + '&note=' + document.getElementById('txtNote').value 
                + '&contacts=' + strTo + '&date=' 
                + window.alertReminderCalFrame.document.getElementById('hdnDate').value 
                + '&hourNo=' + hours + '&minuteNo=' + document.getElementById('minutesId').value 
                + '&emailIdsCommaSeparated=' + strEmailIds + '&val=1&rand=' 
                + Math.floor(Math.random() * 10000000);

                CreateXmlHttp();
                // If browser supports XMLHTTPRequest object
                if (XmlHttp) {
                    //Setting the event handler for the response
                    XmlHttp.onreadystatechange = HandleResponsesaveAlerts;

                    //Initializes the request object with GET (METHOD of posting), 
                    //Request URL and sets the request as asynchronous.
                    XmlHttp.open("GET", requestUrl, true);

                    //Sends the request to server
                    sendRequest(null);
                }
            } else {
                alert('Please select any Contact.');
            }


        } else {
            alert('Please select a valid Note whose details you want to save to send as an Alert.');
        }
    } else {
        alert('Please select a Category whose Note details you want to save to send as an Alert.');
    }
}

function HandleResponsesaveAlerts() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == 'InvalidCategoryName') {
                alert('Please select a valid Category Name.');
            }
            else if (XmlHttp.responseText == 'InvalidNoteName') {
                alert('Please select a valid Note Name.');
            }
            else if (XmlHttp.responseText == 'InvalidDateTime') {
                alert('Date Time selected must be greater than Current Date Time.');
            }
            else if (XmlHttp.responseText == 'Updated') {
                alert('Alert Details are successfully updated');
            }
            else if (XmlHttp.responseText == 'ErrorInUpdation') {
                alert('There is an Exception occured while updating Alert Details.Please try again.');
            }
            else if (XmlHttp.responseText == 'Inserted') {
                alert('Alert Details are successfully saved.');
            }
            else {
                alert('There is an Exception occured while Inserting Alert Details.Please try again.');
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}


function addAnotherDate() {
    //rebind the Calendar to iFrame
    document.getElementById('alertReminderCalFrame').src = "calendar.aspx";

    //Set the time selectboxes to its initial value
    document.getElementById('hoursId').value = '00';
    document.getElementById('minutesID').value = '00';
    //document.getElementById('timeId').value='AM';

    //Uncheck all checkboxes if any checked
    unCheckAllAA();




}



/*Add Alert reminder Functionality::End*/

/*View Alert reminder Functionality::Start*/
function viewAlertDetails() {
    if (trimAll(document.getElementById('txtCategory').value) != '') {
        if (trimAll(document.getElementById('txtNote').value) != '') {
            var requestUrl = 'saveAlerts.aspx?category=' + document.getElementById('txtCategory').value + '&note=' + document.getElementById('txtNote').value + '&val=2&rand=' + Math.floor(Math.random() * 10000000);
            CreateXmlHttp();
            // If browser supports XMLHTTPRequest object
            if (XmlHttp) {
                //Setting the event handler for the response
                XmlHttp.onreadystatechange = HandleResponseViewAlerts;

                //Initializes the request object with GET (METHOD of posting), 
                //Request URL and sets the request as asynchronous.
                XmlHttp.open("GET", requestUrl, true);

                //Sends the request to server
                sendRequest(null);
            }
        } else {
            alert('Please select a Note Name.');
        }
    } else {
        alert('Please select a Category Name.');
    }
}


function HandleResponseViewAlerts() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == 'InvalidCategoryName') {
                document.getElementById('viewAlertBodyDiv').innerHTML = '<b><div style="padding:30px;">Category you have selected doesnot exists.Please select a valid Category Name.</div></b>';

            }
            else if (XmlHttp.responseText == 'InvalidNoteName') {
                document.getElementById('viewAlertBodyDiv').innerHTML = '<b><div style="padding:30px;">Note Name you have selected does not exists within specified category.Please select a valid Note Name.</div></b>';

            }
            else if (XmlHttp.responseText == 'NoContactsAdded') {
                document.getElementById('viewAlertBodyDiv').innerHTML = '<b><div style="padding:30px;">There are no Active Contacts Added for the selected note Whom Alert is to be sent.</div></b>';

            }
            else {
                document.getElementById('viewAlertBodyDiv').innerHTML = XmlHttp.responseText;
            }

            ShowAlertReminderLayer('viewAlertDiv');
            return true;

        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}
/*View Alert reminder Functionality::End*/





function PrintNote() {

    if (trimAll(document.getElementById('txtCategory').value) != '') {
        if (trimAll(document.getElementById('txtNote').value) != '') {
            LoadMoosPrintWindow();
        } else {
            alert('Please select any valid Note whose details you want to print.');
        }
    } else {
        alert('Please select any valid Category whose Note details you want to print.');
    }
}

function HideAlertReminderLayerPrint() {
    var d = 'DivPrintLayer';
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
/*End:://Print Functionality*/

/*Just Send Note and SAVE SEND NOTE Functionality :://Start*/

function justSendNote() {
    if ((document.getElementById('spanReplySentNoteID').innerText == 'Reply Note') && (arguments[0] == 'JN')) {
        if (trimAll(trimAll(document.getElementById('ToMailID').value)) != "") {
            var ConfirmMsg = confirm('Do you want to Reply this ToolNote Description?');
            if (ConfirmMsg) {
                var NoteDescription = trimAll(InnerHtmlTinyMCE('txtNoteDesc'));
                NoteDescription = NoteDescription.replace(/</g, "*lt;");
                NoteDescription = NoteDescription.replace(/>/g, "*gt;");
                NoteDescription = NoteDescription.replace(/&/g, "^^^");

                var requestUrl = 'MailReplyNote.aspx';
                var params = 'desc=' + NoteDescription + '&To=' + trimAll(document.getElementById('ToMailID').value) + '&rand=' + Math.floor(Math.random() * 10000000);
                CreateXmlHttp();
                // If browser supports XMLHTTPRequest object
                if (XmlHttp) {
                    //Setting the event handler for the response
                    XmlHttp.onreadystatechange = HandleResponseReplyMail;

                    //Initializes the request object with GET (METHOD of posting), 
                    //Request URL and sets the request as asynchronous.
                    XmlHttp.open("POST", requestUrl, true);
                    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
                    XmlHttp.setRequestHeader("Content-Type", contentType);
                    XmlHttp.setRequestHeader("Content-length", params.length);
                    //Sends the request to server
                    sendRequest(params);
                }
            }

        } else {
            alert('Oops..Unfortunately Due to some Technical Problems Reply can\'t be sent. Please try again Later.');
        }
    } else {

        //      var requestUrl = 'populateContactDetails.aspx?ContactType='+arguments[0]+'&rand='+Math.floor(Math.random() * 10000000);
        //      CreateXmlHttp();
        //      // If browser supports XMLHTTPRequest object
        //      if(XmlHttp)
        //      {
        //        //Setting the event handler for the response
        //        XmlHttp.onreadystatechange = HandleResponsePopulateContactsJustSendNote;

        //        //Initializes the request object with GET (METHOD of posting), 
        //        //Request URL and sets the request as asynchronous.
        //        XmlHttp.open("GET", requestUrl,  false);

        //        //Sends the request to server
        //       sendRequest(null);
        //       }

        //Open Just Send Note Window
        OpenModalWindow("JustSendNote.aspx?", "MOOSTOOL :: Just Send Note", 557, 285);
    }

}

function HandleResponseReplyMail() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            alert('Reply has been successfully sent.');
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}



function HandleResponsePopulateContactsJustSendNote() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (glb_SaveSendNote == 2) {
                if (XmlHttp.responseText != '')
                    document.getElementById('justSendDiv').innerHTML = XmlHttp.responseText;
                else
                    document.getElementById('justSendDiv').innerHTML = '<b><div style="padding:30px;">There are no Contacts Added for You.Please Add first in "My Contacts" Section.</div></b>';
                ShowAlertReminderLayer('sendNoteLayer');
            } else if (glb_SaveSendNote == 1) {
                if (XmlHttp.responseText != '')
                    document.getElementById('saveSendNoteDiv').innerHTML = XmlHttp.responseText;
                else
                    document.getElementById('saveSendNoteDiv').innerHTML = '<b><div style="padding:30px;">There are no Contacts Added for You.Please Add first in "My Contacts" Section.</div></b>';
                ShowAlertReminderLayer('saveSendNoteLayer');
            }
            return true;
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function checkAll() {
    //alert(window.document.form1.elements.length);
    var m = 0;
    for (var i = 0; i < window.document.form1.elements.length; i++) {
        var e = window.document.form1.elements[i];
        var nameObj = e.name;
        var strChkName = arguments[0] + m;

        //alert(arguments[0]);
        if ((nameObj.indexOf(arguments[0]) != -1) && (e.type == 'checkbox')) {
            //alert(e.name);

            document.getElementById(strChkName).checked = true;
            m++;
        }
    }
}

function checkAllAA() {
    //alert(window.document.form1.elements.length);
    var m = 0;
    for (var i = 0; i < window.document.form1.elements.length; i++) {
        var e = window.document.form1.elements[i];
        var nameObj = e.name;
        var strChkName = "AA_" + arguments[0] + "^" + m;

        //alert(arguments[0]);
        if ((nameObj.indexOf("AA_" + arguments[0] + "^") != -1) && (e.type == 'checkbox')) {

            document.getElementById(strChkName).checked = true;
            m++;
        }
    }
}

function checkAllSN() {
    //alert(window.document.form1.elements.length);
    var m = 0;
    for (var i = 0; i < window.document.form1.elements.length; i++) {
        var e = window.document.form1.elements[i];
        var nameObj = e.name;
        var strChkName = "SN_" + arguments[0] + "^" + m;

        //alert(arguments[0]);
        if ((nameObj.indexOf("SN_" + arguments[0] + "^") != -1) && (e.type == 'checkbox')) {
            //alert(e.name);
            document.getElementById(strChkName).checked = true;
            m++;
        }
    }
}

function checkAllJN() {
    //alert(window.document.form1.elements.length);
    var m = 0;
    for (var i = 0; i < window.document.form1.elements.length; i++) {
        var e = window.document.form1.elements[i];
        var nameObj = e.name;
        var strChkName = "JN_" + arguments[0] + "^" + m;

        //alert(arguments[0]);
        if ((nameObj.indexOf("JN_" + arguments[0] + "^") != -1) && (e.type == 'checkbox')) {
            //alert(e.name);
            document.getElementById(strChkName).checked = true;
            m++;
        }
    }
}


function mailNoteDetails(ReqType) {

    if (trimAll(document.getElementById('txtCategory').value) != '') {
        if (trimAll(document.getElementById('txtNote').value) != '') {
            var strTo = '';
            for (var i = 0; i < window.document.form1.elements.length; i++) {
                var e = window.document.form1.elements[i];
                var nameObj = e.name;
                if (e.type == 'checkbox') {

                    if ((nameObj.indexOf(ReqType + "_") != -1) && (document.getElementById(e.name).checked)) {
                        //alert(e.name+'-------'+e.value);
                        strTo = strTo + e.value + ',';
                    }
                }
            }
            strTo = strTo.substring(0, strTo.length - 1);

            if (trimAll(strTo) != '') {

                var NoteDescription = trimAll(InnerHtmlTinyMCE('txtNoteDesc'));
                NoteDescription = NoteDescription.replace(/</g, "*lt;");
                NoteDescription = NoteDescription.replace(/>/g, "*gt;");
                NoteDescription = NoteDescription.replace(/&/g, "^^^");

                var requestUrl = 'sendMailNote.aspx';
                var params = 'cat=' + trimAll(document.getElementById('txtCategory').value) + '&note=' + trimAll(document.getElementById('txtNote').value) + '&desc=' + NoteDescription + '&linkname=' + trimAll(document.getElementById('txtLinkName').value) + '&linkurl=' + trimAll(document.getElementById('txtLinkUrl').value) + '&To=' + trimAll(strTo) + '&rand=' + Math.floor(Math.random() * 10000000);

                CreateXmlHttp();
                // If browser supports XMLHTTPRequest object
                if (XmlHttp) {
                    //Setting the event handler for the response
                    XmlHttp.onreadystatechange = HandleResponseSendMailNow;

                    //Initializes the request object with GET (METHOD of posting), 
                    //Request URL and sets the request as asynchronous.
                    XmlHttp.open("POST", requestUrl, true);
                    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
                    XmlHttp.setRequestHeader("Content-Type", contentType);
                    XmlHttp.setRequestHeader("Content-length", params.length);
                    //Sends the request to server
                    sendRequest(params);
                }
            } else {
                alert('Select any Contact E-mail ID.')
            }
        } else {
            alert('Please select any valid Note whose details you want to Mail.');
        }
    } else {
        alert('Please select any valid Category whose Note details you want to Mail.');
    }
}

function HandleResponseSendMailNow() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            alert('E-mail regarding the note details have successfully been sent to the selected Contacts.');
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}


/*Just Send Note and SAVE SEND NOTE Functionality:://End*/

function loadFrameInOut() {
    document.getElementById('iframeInOut').src = "loadingFrame1.aspx?&rand=" + Math.floor(Math.random() * 10000000);
}

function ShowDetails(id) {
    showPopWin('MailDetails.aspx?ID=' + id + '&rand=' + Math.floor(Math.random() * 100001), 'E-Mail Details', 520, 345, null);
}

/*Rakesh Added*/

function setdefault() {
    defaultSettings();
    defaultDisable();
}

function defaultSettings() {
    document.getElementById('txtCategory').value = "";
    document.getElementById('txtNote').value = "";
    setInsertHtml("");
    document.getElementById('txtLinkName').value = "";
    document.getElementById('txtLinkUrl').value = "";


}

function defaultDisable() {
    //disabling stuff
    document.getElementById('txtCategory').disabled = true;
    document.getElementById('txtNote').disabled = true;
    document.getElementById('txtLinkName').disabled = true;
    //document.getElementById('txtLinkUrl').disabled = true;
}

function defaultHiddenSetting() {
    document.getElementById('hdnCategoryTrack').value = "-1";
    document.getElementById('hdnNotesTrack').value = "-1";
    document.getElementById('hdnLinkTrack').value = "-1";
}
var catType="";
/*CategoryShift::Rakesh*/
function functShiftCategories(catid, mode,CatType) {

    if (XmlHttp)
        XmlHttp = null;
    CreateXmlHttp();
    catType=CatType;
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {
        var requestUrl = 'CatPreferenceOrder.aspx?catid='
        + catid + '&mode=' + mode + '&type=' + CatType + '&rand=' + Math.floor(Math.random() * 10000000);

        //Setting the event handler for the response
        XmlHttp.onreadystatechange =cbfunctShiftCategories;

        //Initializes the request object with GET (METHOD of posting), 
        //Request URL and sets the request as asynchronous.
        XmlHttp.open("GET", requestUrl, true);

        //Sends the request to server
        sendRequest(null);
    }
}

function cbfunctShiftCategories() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == 'E') {
                alert('An Error Occured, Please try again after some time.');
            }
            else {
                    if(catType=="Category")
                document.getElementById('noteLinkMainCell').innerHTML = XmlHttp.responseText;
            else
                $(".noteLinkMainCell").html(XmlHttp.responseText);
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

var DeleteIndividualContact = function (CatName, ContactEmail) {

    var ConfirmVar = confirm('Are you sure you want to delete ' + ContactEmail + ' from ' + CatName + ' Category?');
    if (ConfirmVar) {
        if (XmlHttp)
            XmlHttp = null;
        CreateXmlHttp();
        // If browser supports XMLHTTPRequest object
        if (XmlHttp) {
            var requestUrl = 'AjaxDeleteContact.aspx?CatName='
            + CatName + '&ContactToBeDeleted=' + ContactEmail + '&rand=' + Math.floor(Math.random() * 10000000);

            //Setting the event handler for the response
            XmlHttp.onreadystatechange = cbDeleteIndividualContact;

            //Initializes the request object with GET (METHOD of posting), 
            //Request URL and sets the request as asynchronous.
            XmlHttp.open("GET", requestUrl, true);

            //Sends the request to server
            sendRequest(null);
        }
    }
}



function cbDeleteIndividualContact() {
    // alert(XmlHttp.readyState);
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
    
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == 'E') {
                alert('An Error Occured, Please try again after some time.');
            }
            else {
                document.getElementById('contactDiv').innerHTML = XmlHttp.responseText;
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}
var EditCategory = function (CatName, Contacts) {
    _glbCatName = CatName;
    document.getElementById('txtContactCategory').disabled = false;
    document.getElementById('txtContactCategory').value = CatName;
    document.getElementById('txtAreaContacts').value = Contacts;
    document.getElementById('txtAreaContacts').focus();
}


/* Code written by odesk team*/

function ChangePasswordPost() {
    //Validations
 
    if(trimAll(document.getElementById("txtOldPassword").value) == "")
    {
        document.getElementById("lblStatusInfo").innerHTML = "Please enter your 'Old Password'.";
        return;
    }
    if(trimAll(document.getElementById("txtNewPassword").value) == "")
    {
        document.getElementById("lblStatusInfo").innerHTML = "Please enter your 'New Password'.";
        return;
    }
    if(trimAll(document.getElementById("txtConfirmNewPassword").value) == "")
    {
        document.getElementById("lblStatusInfo").innerHTML = "Please enter 'Confirm New Password'.";
        return;
    }
    if(trimAll(document.getElementById("txtNewPassword").value) !=
     trimAll(document.getElementById("txtConfirmNewPassword").value))
    {
        document.getElementById("lblStatusInfo").innerHTML = "'New Password' & 'Confirm New Password' must be same.";
        return;
    }
    //if(document.getElementById("txtNewPassword").value.length < 4 )
    //{
       //document.getElementById("lblStatusInfo").innerHTML = "'New Password' must have atleast four characters.";
        //return;
    //}

    document.getElementById("lblStatusInfo").innerHTML = "";
    var requestUrl = 'ChangePasswordPost.aspx?OldPassword=' + trimAll(document.getElementById('txtOldPassword').value) + '&NewPassword=' + trimAll(document.getElementById('txtNewPassword').value);
    //alert(requestUrl);
    CreateXmlHttp();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {

        XmlHttp.open("POST", requestUrl, true);

        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponseChangePassword;

        var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
        XmlHttp.setRequestHeader("Content-Type", contentType);
        XmlHttp.setRequestHeader("Content-length", 2);        
       
        //Sends the request to server
        sendRequest(null);
    }
}

function HandleResponseChangePassword() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {

            if (XmlHttp.responseText == '-1') {
                document.getElementById("lblStatusInfo").innerHTML = "An error occurred, Please try again.";
            }
            else if (XmlHttp.responseText == '0') {
                document.getElementById("lblStatusInfo").innerHTML = "Your 'Old Password' doesn't match, please enter it correctly.";
            }
            else if (XmlHttp.responseText == '1') {
                document.getElementById("lblStatusInfo").innerHTML = "Your Password has changed successfully. An Email regarding your new password has been sent to your Email-Id (" + currEmail + ").";
                document.getElementById("lblStatusInfo").style.color = "Green";
            } else {
                document.getElementById("lblStatusInfo").innerHTML = "An error occurred, Please try again.";
                strColor = "Red";
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

var strCatName = ""
var strNoteName = "";

function SaveAlert() {
functAlertDate();
    var strArrTemp = new Array();
    var strTempContacts = new String();
    var strTempCatContacts = new String();
    var arrContacts = new Array();

    $(".chkInput").each(function () {
        if ($(this).attr("checked") == true) {
            strArrTemp = $(this).attr("id").split('^');
            strTempContacts = strTempContacts + $.trim(strArrTemp[1]) + ",";
            strTempCatContacts = strTempCatContacts + $.trim(strArrTemp[0]) + "^" + $.trim(strArrTemp[1]) + ",";
        }
    });
    while (0) {
        strTempContacts = $.trim(strTempContacts);
        //  alert(strTempContacts.charAt(strTempContacts.length - 1));
        if (strTempContacts.charAt(strTempContacts.length - 1) == ',')
            strTempContacts.slice(0, strTempContacts.length - 1);
        else
            break;
    }
    while (0) {
        strTempCatContacts = $.trim(strTempCatContacts);
        if (strTempCatContacts.charAt(strTempCatContacts.length - 1) == ',')
            strTempCatContacts.slice(0, strTempCatContacts.length - 1);
        else
            break;
    }
    //alert(strTempCatContacts + ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" + strTempContacts);
    arrContacts[0] = strTempContacts;
    arrContacts[1] = strTempCatContacts;

    if ($.trim(arrContacts[0]) == "") {
        document.getElementById("vsAddAlerts").style.display = "block";
        document.getElementById("vsAddAlerts").innerHTML = "Please Select Contacts to send alert.";
    }
    else {
        document.getElementById("vsAddAlerts").style.display = "none";
        var requestUrl = "AddAlertPost.aspx?strContacts=" + $.trim(arrContacts[0]) + "&strCatContacts=" + $.trim(arrContacts[1]) +
         "&hdnCalDate=" + document.getElementById("hdnCalDate").value + "&hoursId=" + document.getElementById("hoursId").value +
          "&minutesID=" + document.getElementById("minutesID").value + "&ddrTimeZones=" + document.getElementById("ddrTimeZones").value +
        "&chkDaylight=" + document.getElementById("chkDaylight").checked + "&CatName=" + strCatName + "&NoteName=" + strNoteName;
        CreateXmlHttp();

        // If browser supports XMLHTTPRequest object
        if (XmlHttp) {

            XmlHttp.open("POST", requestUrl, true);

            //Setting the event handler for the response
            XmlHttp.onreadystatechange = HandleResponseSaveAlert;

            var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

            //Sends the request to server
            sendRequest(null);
        }
    }
}

function HandleResponseSaveAlert() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == "")
                document.getElementById("vsAddAlerts").style.display = "none";
            else {
                document.getElementById("vsAddAlerts").style.display = "block";
                document.getElementById("vsAddAlerts").innerHTML = XmlHttp.responseText;
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function JustSendNotePost() {
    var strArrTemp = new Array();
    var strTempContacts = new String();
    var strTempCatContacts = new String();
    var arrContacts = new Array();
 //   alert("in");
    $(".chkInput").each(function () {
   //     alert($(this).attr("id"));
     //   alert($(this).attr("checked"));
        if ($(this).attr("checked") == true) {
            strArrTemp = $(this).attr("id").split('^');
            //alert(strArrTemp[0]);
            strTempContacts = strTempContacts + $.trim(strArrTemp[1]) + ",";
            strTempCatContacts = strTempCatContacts + $.trim(strArrTemp[0]) + "^" + $.trim(strArrTemp[1]) + ",";
        }
    });
    //alert(strTempCatContacts + ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" + strTempContacts);
    while (1) {
        strTempContacts = $.trim(strTempContacts);
        if (strTempContacts.charAt(strTempContacts.length - 1) == ',')
            strTempContacts = strTempContacts.slice(0, strTempContacts.length - 1);
        else
            break;
    }
    while (1) {
        strTempCatContacts = $.trim(strTempCatContacts);
        if (strTempCatContacts.charAt(strTempCatContacts.length - 1) == ',')
            strTempCatContacts = strTempCatContacts.slice(0, strTempCatContacts.length - 1);
        else
            break;
    }
    arrContacts[0] = strTempContacts;
    arrContacts[1] = strTempCatContacts;

    if ($.trim(arrContacts[0]) == "") {
        document.getElementById("vsJustSendNote").style.display = "block";
        document.getElementById("vsJustSendNote").innerHTML = "Please Select Contacts to send alert.";
    }
    else {
        document.getElementById("vsJustSendNote").style.display = "none";
        var requestUrl = "JustSendNotePost.aspx?hdnCatName=" + document.getElementById("hdnCatName").value + "&hdnNoteName=" + document.getElementById("hdnNoteName").value
        + "&hdnDescription=" + document.getElementById("hdnDescription").value + "&hdnNoteLink=" + document.getElementById("hdnNoteLink").value
        + "&hdnNoteLinkUrl=" + document.getElementById("hdnNoteLinkUrl").value + "&strContacts=" + $.trim(arrContacts[0]) + "&strCatContacts=" + $.trim(arrContacts[1]);
        CreateXmlHttp();

        // If browser supports XMLHTTPRequest object
        if (XmlHttp) {

            XmlHttp.open("POST", requestUrl, true);

            //Setting the event handler for the response
            XmlHttp.onreadystatechange = HandleResponseJustSendNotePost;

            var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

            //Sends the request to server
            sendRequest(null);
        }
    }
}

function HandleResponseJustSendNotePost() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == "")
                document.getElementById("vsJustSendNote").style.display = "none";
            else {
                document.getElementById("vsJustSendNote").style.display = "block";
                document.getElementById("vsJustSendNote").innerHTML = XmlHttp.responseText;
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function ForgotPasswordPost() {

    document.getElementById("vsRecoverPassword").style.display = "none";
    var requestUrl = "ForgotPasswordPost.aspx?txtmoosid=" + document.getElementById("txtmoosid").value;
    CreateXmlHttp();

    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {

        XmlHttp.open("POST", requestUrl, true);

        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponseForgotPasswordPost;

        var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

        //Sends the request to server
        sendRequest(null);
    }
}

function HandleResponseForgotPasswordPost() {

    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == "")
                document.getElementById("vsRecoverPassword").style.display = "none";
            else {
                document.getElementById("vsRecoverPassword").style.display = "block";
                document.getElementById("vsRecoverPassword").innerHTML = XmlHttp.responseText;
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}


//User picture script

var mainImgDatabaseId = 0;
var mainImgSrcPath = "";

function DeleteImages(ImageID) {
    var ConfirmMsg = confirm('Are you sure you want to delete this Image?');
    if (ConfirmMsg) {
        LoadUserPicturesWindow(ImageID);
    }
}

function CloseUserPicturesWin() {
    ClosePopUp();
}

function UserPictureSuccess() {
    mainImgDatabaseId = document.getElementById('HidmainImgDatabaseId').value;
    mainImgSrcPath = document.getElementById('HidmainImgSrcPath').value;

    if (parseInt(document.getElementById('HidImageCount').value) < 16) {
        document.getElementById("fileInput").style.display = "block";
        document.getElementById("NofileInputDiv").style.display = "none";
       
    }
    else {
        document.getElementById("fileInput").style.display = "none";
        document.getElementById("NofileInputDiv").style.display = "block";

    }
}


//Change Password script

function CloseChangePassWin() {
    ClosePopUp();
}

function ChangePasswordSuccess() {
    currEmail = document.getElementById('HidCurrEmail').value;
}

//Moos Diary script

var SelectedDate = "";
function CloseMyDiaryWin() {
    ClosePopUp();
}

function MoosDiarySuccess() {
    // First check date is valid
    var todaysDate = new Date();
    //alert(todaysDate.getDate() + "/"+(todaysDate.getMonth()+1)+"/"+ todaysDate.getFullYear());
    var day = todaysDate.getDate() < 10 ? ("0" + todaysDate.getDate()) : (todaysDate.getDate());
    var month = (todaysDate.getMonth() + 1) < 10 ? ("0" + (todaysDate.getMonth() + 1)) : (todaysDate.getMonth() + 1);
    curdt = day + "/" + month + "/" + todaysDate.getFullYear();

    //   document.getElementById('frameMyDiary').src = 'MyDiary.aspx?DiaryDate=' + curdt + '&rand=' + Math.floor(Math.random() * 10000000);
//alert("1");
    LoadMyDiary(curdt);
}


//My diary scripts
function LoadMyDiary(curdt) {
//alert(curdt);
    var requestUrl = 'MyDiary.aspx?DiaryDate=' + curdt + '&rand=' + Math.floor(Math.random() * 10000000);
    CreateXmlHttp();


    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {

        XmlHttp.open("POST", requestUrl, true);

        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponseMyDiary;

        var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

        //Sends the request to server
        sendRequest(null);
    }
}

function HandleResponseMyDiary() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == "")
            //document.getElementById("frameMyDiary").style.display = "none";
                alert("There was a problem retrieving data from the server.");
            else {
                //  document.getElementById("frameMyDiary").style.display = "block";
                document.getElementById("frameMyDiary").innerHTML = XmlHttp.responseText;
                OnLoadMyDiary();
                LoadCalenderDiary("diaryCalDiv");
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function MyDiaryPost() {

    if (trimAll(document.getElementById('txtdiaryheading').value) == "") {
        alert("Please enter 'title' of this diary record.");
        document.getElementById('txtdiaryheading').focus();
        return;
    }


    // alert("hii");
    var title = document.getElementById("txtdiaryheading").value.replace("'", "''");
    // alert(title);
    var desc = document.getElementById("txtdiarydesc").value.replace("'", "''");
    // alert(desc);
   
    //Rakesh Modified
    var rankRadioList = document.getElementsByName("ddrDiaryRank");
    for (var ii = 0; ii < rankRadioList.length; ii++)
    {
        if (rankRadioList[ii].checked)
        {
            var rating = rankRadioList[ii].value
            break;
        }
     }

    // alert(rating);
    var date = document.getElementById('hidCurrDate').value;
    //  alert(date);
    var arr = date.split('/');

    var diarydate = arr[1] + "/" + arr[0] + "/" + arr[2];
    //alert(diarydate);
    //  var diarydate = Convert.ToDateTime(DateUSFormat(Request.QueryString["DiaryDate"].ToString()));
    var requestUrl = 'MyDiaryPost.aspx?diarydate=' + diarydate + '&title=' + title + '&desc=' + desc + '&rating=' + rating;
    //alert(requestUrl);
    CreateXmlHttp();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {

        XmlHttp.open("POST", requestUrl, true);

        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponseMyDiaryPost;

        var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

        //Sends the request to server
        sendRequest(null);
    }
}

function HandleResponseMyDiaryPost() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == "")
            //document.getElementById("frameMyDiary").style.display = "none";
                alert("There was a problem retrieving data from the server.");
            else {
                //  document.getElementById("frameMyDiary").style.display = "block";
                alert("Diary entry has been saved.");
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function CloseMyDiaryWin() {
    ClosePopUp();
}

function OnLoadMyDiary() {

    $("#ddrDiaryRank td").css({ "width": "45px" });

    //alert($("#txtinp").attr("id"));
    $("#ddrDiaryRank_0").addClass("styled");
    $("#ddrDiaryRank_1").addClass("styled");
    $("#ddrDiaryRank_2").addClass("styled");
    $("#ddrDiaryRank_0").next().css({ "display": "block", "padding-top": "3px", "padding-left": "5px" });
    $("#ddrDiaryRank_1").next().css({ "display": "block", "padding-top": "3px", "padding-left": "5px" });
    $("#ddrDiaryRank_2").next().css({ "display": "block", "padding-top": "3px", "padding-left": "5px" });

    Custom.init();
}


function setDateforViewDiary() {
    document.getElementById('diaryDate').value = window.parent.frames["calDiv"].document.getElementById('hdnDate').value;
    return true;
}


//CalenderDiary.aspx scripts
function LoadCalenderDiary(CalenderDiv) {
    var requestUrl = 'calendarDiary.aspx';
    CreateXmlHttp();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {

        XmlHttp.open("POST", requestUrl, true);

        //Setting the event handler for the response
        XmlHttp.onreadystatechange = function () { HandleResponseCalenderDiary(CalenderDiv); };

        var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

        //Sends the request to server
        sendRequest(null);
    }
}

function HandleResponseCalenderDiary(CalenderDiv) {
    // alert("response"+"....."+XmlHttp.readyState+"....."+XmlHttp.responseText);
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == "")
                alert("There was a problem retrieving data from the server.");
            else {
                document.getElementById(CalenderDiv).innerHTML = XmlHttp.responseText;
                var str = "";

                str = str + ('<table id="fc" style="display:none" cellspacing="0">');
                str = str + ('<tr><td onclick="csubm()" class="year_back">&lt;</td><td colspan=5 id="mns"></td><td onclick="caddm()" class="year_forward">&gt;</td></tr>');
                str = str + ('<tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>');
                for (var kk = 1; kk <= 6; kk++) {
                    str = str + ('<tr>');
                    for (var tt = 1; tt <= 7; tt++) {
                        num = 7 * (kk - 1) - (-tt);
                        str = str + ('<td id="v' + num + '">&nbsp;</td>');
                    }
                    str = str + ('</tr>');
                }
                str = str + ('</table>');

                document.getElementById('calenderTable').innerHTML = str;
                // alert(ccm+"....."+ccy);
                // alert("in1");
                prepcalendar('', ccm, ccy);
                // alert("hii");
                openCalender('hdnDate');
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

function openCalender(txtObj) {
    // First check date is valid

    var obj = document.getElementById(txtObj);
    //obj.click();
    lcs(obj);

}


// Add Reminders script

function CloseAlertsWin() {
    ClosePopUp();
}
function functAlertDate() {
    //alert( document.getElementById('alertReminderCalFrame').contentWindow.document.getElementById("hdnDate").value);
    document.getElementById('hdnCalDate').value = document.getElementById("hdnDate").value;
}
function functResetCal() {
AddAlertSuccess();
}
function ValidatePageandProcessAlerts(fnToExecute) {

    var count = 0;
    document.getElementById("vsAddAlerts").innerHTML = "";

    if (document.getElementById("hoursId").value == "") {
        count++;
        document.getElementById("vsAddAlerts").style.display = "block";
        document.getElementById("vsAddAlerts").innerHTML = document.getElementById("vsAddAlerts").innerHTML + "Please Select Alert time hours.";
    }
 
    if (document.getElementById("minutesID").value == "") {
        count++;
        document.getElementById("vsAddAlerts").style.display = "block";
        document.getElementById("vsAddAlerts").innerHTML = document.getElementById("vsAddAlerts").innerHTML + "<br/>Please Select Alert time minutes.";
    }
    if (count == 0) {
        fnToExecute();
    }
}
var ClientId;
function AddAlertSuccess(cdate) {
if(!cdate)
{
document.getElementById("hidCurrDate").value='';
}else
{
document.getElementById("hidCurrDate").value=cdate;
}
    strCatName = document.getElementById("hidStrCatName").value;
    strNoteName = document.getElementById("hidStrNoteName").value;
    ClientId = document.getElementById("hidClientId").value;
    LoadCalenderDiary("RemainderCalenderDiv");
    fnToExec = function (currDate) {AddAlertSuccess(currDate); };
}


function functCheckCatContacts() {

    var trContacts = document.getElementById("noteId" + arguments[0]);
    if(!trContacts)
    {return;}
    if (trContacts.style.display == 'none') {
        //Show Contacts and change image if needed
        trContacts.style.display = '';
    }
    $("#" + trContacts.id + " input").each(function () {
        if (this.type == 'checkbox') {
            this.checked = true;
        }

    });
    functShowHideCatContacts(arguments[0]);
}


function functShowHideCatContacts() {
    if (document.getElementById('noteId' + arguments[0])) {
        if (document.getElementById('noteId' + arguments[0]).style.display == 'none')
            document.getElementById('noteId' + arguments[0]).style.display = '';
        else
            document.getElementById('noteId' + arguments[0]).style.display = 'none';
    }
}

//creatre contact script
var _glbCatName = "";

function CloseCatContactsWin() {
    ClosePopUp();
}

function CreateCatSuccess() {
    loadContacts();
 
}

//Just send note script

function CloseJustSendNoteWin() {
    ClosePopUp();
}

function SetCatValues() {
    document.getElementById("hdnCatName").value = trimAll(window.parent.document.getElementById("txtCategory").value);
    document.getElementById("hdnNoteName").value = trimAll(window.parent.document.getElementById("txtNote").value);
    var NoteDescription = trimAll(window.parent.InnerHtmlTinyMCE('txtNoteDesc'));
    NoteDescription = NoteDescription.replace(/</g, "*lt;");
    NoteDescription = NoteDescription.replace(/>/g, "*gt;");
    NoteDescription = NoteDescription.replace(/&/g, "^^^");

    document.getElementById("hdnDescription").value = NoteDescription;
    document.getElementById("hdnNoteLink").value = trimAll(window.parent.document.getElementById("txtLinkName").value);
    document.getElementById("hdnNoteLinkUrl").value = trimAll(window.parent.document.getElementById("txtLinkUrl").value);
    return true;

}


function CloseShowAlertsWin() {
    ClosePopUp();
}   

//view alerts script

function deletealert(alertid)
{
  var requestUrl = 'DeleteAlertPost.aspx?alertId='+alertid;
    CreateXmlHttp();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {

        XmlHttp.open("POST", requestUrl, true);

        //Setting the event handler for the response
        XmlHttp.onreadystatechange = deleteAlertHandleResponse;

        var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

        //Sends the request to server
        sendRequest(null);
    }
}

function deleteAlertHandleResponse()
{
 if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            LoadViewAlertsWindow();
            }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }

}

//moos print script

    function CloseMoosPrintNoteWin()
    {
       window.parent.hidePopWin(false);
    }    
    /*Start:://Print Functionality*/
function InitializePrintPage(){
    document.getElementById('tdCatName').innerHTML = trimAll(window.parent.document.getElementById("txtCategory").value);
    document.getElementById('tdNoteName').innerHTML = trimAll(window.parent.document.getElementById("txtNote").value);
    document.getElementById('tdNoteDesc').innerHTML = trimAll(window.parent.InnerHtmlTinyMCE('txtNoteDesc'));
}

function CallPrint() 
{ 
    var prtContent = document.getElementById("printIt"); 
    var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=1,status=0'); 
    WinPrint.document.write(prtContent.innerHTML);
    WinPrint.document.close(); 
    WinPrint.focus(); 
    WinPrint.print(); 
    WinPrint.close(); 
} 

// moos detect time zone scripts.



function CloseTimezoneWin() {
    ClosePopUp();
}   

function saveTimeZoneSettings(){
  var requestUrl = 'DetectTimeZonePost.aspx?selectedTimeZone='+$(".ddrTimeZones").val()+"&chkDaylight="+$("#chkDaylight").attr("checked");
    CreateXmlHttp();
    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {

        XmlHttp.open("POST", requestUrl, true);

        //Setting the event handler for the response
        XmlHttp.onreadystatechange = handleSaveTimeZoneSettingsResponse;

        var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

        //Sends the request to server
        sendRequest(null);
    }
}

function handleSaveTimeZoneSettingsResponse(){
 // alert("response"+"....."+XmlHttp.readyState+"....."+XmlHttp.responseText);
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        //Remove the loading div as data has come.
        RemoveLoadingDiv(PopUpLoadingDiv);
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {
            if (XmlHttp.responseText == "")
                alert("There was a problem retrieving data from the server.");
            else {
          $("#lblStatusInfo").html(XmlHttp.responseText);
            }
        }
        else {
            alert("There was a problem retrieving data from the server.");
        }
    }
}

//Forgot Password script
  function CloseForgotPassWin() {
            window.parent.hidePopWin(false);
        }

        function ValidatePageandProcess(fnToExecute) {
            var count = 0;
            document.getElementById("vsRecoverPassword").innerHTML = "";
            if (document.getElementById("txtmoosid").value == "") {
                count++;
                document.getElementById("vsRecoverPassword").style.display = "block";
                document.getElementById("vsRecoverPassword").innerHTML = document.getElementById("vsRecoverPassword").innerHTML + "Please enter your Moos-ID.";
            }
            if (count == 0) {
                fnToExecute();
            }
        }