﻿// JScript File

// These functions are used to show popups on pages. used when popup code is on page.

var _source;
// keep track of the popup div
var _popup1;

function showConfirmEmail(source, popupName, MlsId) {
    debugger;
    document.getElementById("hdMlsId").value = MlsId;
    var browserName = navigator.appName;
    if (browserName == "Microsoft Internet Explorer") {
        //document.body.style.overflow = 'hidden';
        document.body.style.overflow = 'auto';
    }

    this._source = source;
    //  find the confirm ModalPopup and show it

    this._popup1 = $find(popupName);
    // Show the popup
    this._popup1.show();
}
function ValidateEmailFavorites()
{

    if (document.getElementById("txtEmailFavorite").value == "") {
        document.getElementById("divEmail").style.display = "inline";
        document.getElementById("divEmailError").style.display = "none";
        return false;
    }
    else if (document.getElementById("txtEmailFavorite").value != "") {
        var tEmail = CheckValidListViewFavoriteEmail();
        if (tEmail == false)
            return false;
        if (tEmail == true)
            document.getElementById("divEmailError").style.display = "none";
        document.getElementById("divEmail").style.display = "none";
    }
     document.getElementById("divSendEmailProgress").style.display = "inline";
     document.getElementById("ImageButton4").style.display = "inline";
     document.getElementById("ImageButton2").style.display = "none";
}
function CheckValidListViewFavoriteEmail() {
    //var ErrorMsg = "Enter a valid email";
    EmailPattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
    if (!EmailPattern.test(document.getElementById("txtEmailFavorite").value)) {
        document.getElementById("divEmailError").style.display = "inline";
        document.getElementById("divEmail").style.display = "none";
        //document.getElementById(id).focus();
        //document.getElementById(id).select();
        return false;
    }
    return true;
}

function showConfirm(source,popupName)
{
var browserName=navigator.appName; 
if(browserName == "Microsoft Internet Explorer")
{
//document.body.style.overflow = 'hidden';
document.body.style.overflow = 'auto';
}

this._source = source;
//  find the confirm ModalPopup and show it

this._popup1 = $find(popupName);
// Show the popup
this._popup1.show();
}
function showConfirm1(source, popupName) {
    //debugger;
var _Includecount=0;
    var _count=0;
    Parent = document.getElementById('dlListFavorites');
    var items = Parent.getElementsByTagName('input');
    for (i = 0; i < items.length; i++) {
        if (items[i].type == "checkbox") {
            if (items[i].checked == true) {
                _count = 1;
		 var CheckboxId = items[i].id;
                var DivId = document.getElementById(CheckboxId.substring(0, CheckboxId.lastIndexOf('_') + 1) + 'divshbtn');
                if (document.getElementById(DivId.id).style.display == "inline") {
                    _Includecount = 1;
                }
            }
        }
    }
      if (_Includecount == 1) {
        document.getElementById("IncludeNotes").style.display = "inline";
        document.getElementById("chkIncludeNotes").checked = true;
    }
    if (_count == 1) {
        var browserName = navigator.appName;
        if (browserName == "Microsoft Internet Explorer") {
            //document.body.style.overflow = 'hidden';
            document.body.style.overflow = 'auto';
        }

        this._source = source;
        //  find the confirm ModalPopup and show it

        this._popup1 = $find(popupName);
        // Show the popup
        this._popup1.show();
        return false;
    }
    else {
        alert("Please first select some active listings to email by checking them.");
        return false;
    }
}
function showConfirm2(source, popupName) {
    //debugger;
    var _count = 0;
    Parent = document.getElementById('dlListFavorites');
    var items = Parent.getElementsByTagName('input');
    for (i = 0; i < items.length; i++) {
        if (items[i].type == "checkbox") {
            if (items[i].checked == true) {
                _count = 1;
            }
        }
    }
    if (_count == 1) {
        var browserName = navigator.appName;
        if (browserName == "Microsoft Internet Explorer") {
            //document.body.style.overflow = 'hidden';
            document.body.style.overflow = 'auto';
        }

        this._source = source;
        //  find the confirm ModalPopup and show it

        this._popup1 = $find(popupName);
        // Show the popup
        this._popup1.show();
        return false;
    }
    else {
        alert("Please first select some homes for directions by checking them.");
        return false;
    }
}
function showConfirm3(source, popupName,MlsId,PropertyAddress) {
    //debugger;
    //alert(MlsId);
    document.getElementById("hdMlsId").value = MlsId;
    document.getElementById("SpanDirecitonsTo").innerHTML = PropertyAddress;
    
    this._source = source;
    //  find the confirm ModalPopup and show it

    this._popup1 = $find(popupName);
    // Show the popup
    this._popup1.show();
    return false;
}
function okClick1()
{

//  find the confirm ModalPopup and hide it    
this._popup1.hide();

//alert(this._source.id.indexOf('$'));
//  use the cached button as the postback source
if(this._source1.id.indexOf('$') == -1)
{

__doPostBack(this._source1.id.replace(/_/g,'$'), '');
}
else
{

__doPostBack(this._source1,'');
}    

}


function cancelClick1()
{
//  find the browser type
var browserName=navigator.appName; 
if(browserName == "Microsoft Internet Explorer")
{ 
document.body.style.overflow = 'auto';
}

// Hide the popup
this._popup1.hide();

//  clear the event source
this._source1 = null;
this._popup1 = null;


}
function Cross(source,popupName)
{
//  find the browser type
var browserName=navigator.appName; 
if(browserName == "Microsoft Internet Explorer")
{ 
document.body.style.overflow = 'auto';
}
this._source = source;
//  find the confirm ModalPopup and show it

this._popup1 = $find(popupName);

// Hide the popup
this._popup1.hide();

//  clear the event source
this._source1 = null;
this._popup1 = null;


}
