﻿    var modalWin = null;

function InitializeAjaxRequest(isPopup) {
    if ($get('LeadPage_AjaxProgress') != null && $get('ctl00_cphMain_hdnProcess') != null && $get('ctl00_cphMain_hdnProcess').value == 'LeadPage') {
        window.scrollTo(0, 0);
        document.body.style.overflow = 'hidden';
        $get('container').style.display = 'none';
        $get('footer').style.display = 'none';
        $get('LeadPage_AjaxProgress').style.height = screen.Height;
        $get('LeadPage_AjaxProgress').style.width = screen.Width;
        $get('LeadPage_AjaxProgress').style.display = 'block';
        document.body.scroll = "no";
    }
    else if ($get('LeadPage_AjaxProgress') != null && $get('ctl00_cphMain_hdnProcess') != null && $get('ctl00_cphMain_hdnProcess').value == 'ConfirmPage') {
        window.scrollTo(0, 0);
        document.body.style.overflow = 'hidden';
        $get('container').style.display = 'none';
        $get('footer').style.display = 'none';
        $get('LeadPage_AjaxProgress').style.height = screen.Height;
        $get('LeadPage_AjaxProgress').style.width = screen.Width;
        $get('LeadPage_AjaxProgress').style.display = 'block';
        document.body.scroll = "no";
    }
    else if ($get('AjaxProgress') != null) {
        $get('AjaxProgress').style.height = screen.availHeight;
        $get('AjaxProgress').style.display = 'block';
    }
}


function EndAjaxRequest() {
    if ($get('LeadPage_AjaxProgress') != null && $get('ctl00_cphMain_hdnProcess') != null && $get('ctl00_cphMain_hdnProcess').value == 'LeadPage') {
        $get('ctl00_cphMain_hdnProcess').value = '';
        $get('LeadPage_AjaxProgress').style.display = 'none';
        $get('container').style.display = 'inline';
        $get('footer').style.display = 'inline';
        document.body.scroll = "yes";
    }
    else if ($get('LeadPage_AjaxProgress') != null && $get('ctl00_cphMain_hdnProcess') != null && $get('ctl00_cphMain_hdnProcess').value == 'ConfirmPage') {
        $get('ctl00_cphMain_hdnProcess').value = '';
        $get('LeadPage_AjaxProgress').style.display = 'none';
        $get('container').style.display = 'inline';
        $get('footer').style.display = 'inline';
        document.body.scroll = "yes";
    }
    else if ($get('AjaxProgress') != null) {
        $get('AjaxProgress').style.display = 'none';
        document.body.scroll = "yes";
    }
}


var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}

function isDate(dtStr) {
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strMonth = dtStr.substring(0, pos1)
    var strDay = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        alert("The date format should be : mm/dd/yyyy")
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        alert("Please enter a valid month (mm/dd/yyyy)")
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        alert("Please enter a valid day (mm/dd/yyyy)")
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        alert("Please enter a valid 4 digit year between " + minYear + " and " + maxYear)
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        alert("Please enter a valid date (mm/dd/yyyy)")
        return false
    }
    return true
}

function ValidateCurrentDate(serverDt, schDate) {
    if (serverDt != null) {
        var date1 = new Date(schDate);
        var date2 = new Date(serverDt);
        if (date1 < date2) {
            alert("Selected date should be greater than or equal to the current date.");
            return false;
        }
    }
    return true;
}

function ValidateInquriyDetails(validationGroup) {
    if (typeof (Page_ClientValidate) == 'function') {
        if (Page_ClientValidate(validationGroup) == false) {
            return false;
        }

        $get('ctl00_cphMain_hdnProcess').value = 'LeadPage';

    }

    //ctl00$cphMain$tcServices$tpFS$ucConInqFS$txtMoveDate

    //var ctrltcServicesID = 'ctl00_cphMain_tcServices';
    var ctrldtID = '';
    //var ctrltcServices = $find(ctrltcServicesID);    
    var dt = null;
    var strSelectedTab = $get('ctl00_cphMain_hdnServices').value;

    //ctrltcServicesID = 'ctl00$cphMain$tcServices';
    // Full Service
    if (strSelectedTab == 'FULLSERVICE') {
        ctrldtID = 'ctl00_cphMain_ucConInqFS_txtMoveDate';
    }
    //Containerized
    else if (strSelectedTab == 'CONTAINERIZED') {
        ctrldtID = 'ctl00_cphMain_ucConInqContz_txtMoveDate';
    }
    // Truck Rental
    else if (strSelectedTab == 'TRUCKRENTAL') {
        ctrldtID = 'ctl00_cphMain_ucTR_txtMoveDate';
    }

    dt = $get(ctrldtID);

    if (dt != null && dt.value != '') {

        if (isDate(dt.value) == false) {
            dt.focus();
            return false
        }

        var hdnServerDt = $get('ctl00_cphMain_hdnServerDate');

        if (hdnServerDt != null && hdnServerDt.value != '') {
            var date1 = new Date(dt.value);
            var date2 = new Date(hdnServerDt.value);
            if (date1 < date2) {
                alert("Move date should be greater than or equal to the current date.");
                dt.focus();
                return false;
            }

        }

    }

}


//function InquiryConfirmation(consumerID, message) {
//    var result = confirm(message);

//    if (result) {
//        __doPostBack('UPDATE', consumerID);
//    }

//}
function InquiryConfirmation(consumerID) {
    __doPostBack('UPDATE', consumerID);
}



//movingprofile.aspx

function FunOnClick(OfferURL) {
    newwindow = window.open(OfferURL, '', '');
    if (window.focus) { newwindow.focus() }
    return false;
}



function ValidateMoveContactDetail() {


    if (typeof (Page_ClientValidate) == 'function') {
        if (Page_ClientValidate() == false) {
            return false;
        }
    }

    dt = $get('ctl00_cphMain_txtMoveDate');

    if (dt != null && dt.value != '') {

        if (isDate(dt.value) == false) {
            return false
        }

        var hdnServerDt = $get('ctl00_cphMain_hdnServerDate');

        if (hdnServerDt != null && hdnServerDt.value != '') {
            var date1 = new Date(dt.value);
            var date2 = new Date(hdnServerDt.value);
            if (date1 < date2) {
                alert("Move date should be greater than or equal to the current date.");
                return false;
            }

        }

    }

}

// Trim's the text
function Trim(str) {
    return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

function isNumeric(event) {
    var BrowserName = GetBrowserName();

    var evtobj = window.event ? event : event

    if (BrowserName == 'Microsoft Internet Explorer') {
        if ((window.event.keyCode < 46) || (window.event.keyCode > 57) || (window.event.keyCode == 47) || (window.event.keyCode == 46)) {
            window.event.keyCode = 0
        }
    }
    else if (BrowserName == 'Firefox') {
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
        if ((keyCode < 46) || (keyCode > 57) || (keyCode == 47) || (keyCode == 46)) {
            if ((keyCode == 9) || (keyCode == 8))
                return true;
            else
                return false;
        }
        return true;
    }
    else if (BrowserName == 'Safari') {
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
        if ((keyCode < 46) || (keyCode > 57) || (keyCode == 47) || (keyCode == 46)) {
            if ((keyCode == 9) || (keyCode == 8))
                return true;
            else
                return false;
        }
        return true;
    }
    return true;
}

// function isDecimal() {
//     if ((window.event.keyCode < 46) || (window.event.keyCode > 57) || (window.event.keyCode == 47)) {
//         window.event.keyCode = 0
//     }
//     else if (window.event.keyCode == 46) {
//         var parts = window.event.srcElement.value.split('.');
//         if (parts.length == 2)
//             window.event.keyCode = 0
//     }
// }

function ChangeFocus(objTxtbx1, objTxtbx2, objNoOfChars, event) {
    if (isNumeric(event)) {
        objTxtbx2 = document.getElementById(objTxtbx2);
        //if (objTxtbx1.document.selection.type != "Text") {
            if (objTxtbx1.value.length == objNoOfChars)
                objTxtbx2.focus();
        //}
    }
    else
        return false;
}


// view agent popup function.
function FunViewAgents(movingpartnerid) {

    if (window.showModalDialog) {
        window.showModalDialog("agentlist.aspx?partnerid=" + movingpartnerid.toString(), "", "");
    }
    else {
        modalWin = window.open("agentlist.aspx?partnerid=" + movingpartnerid.toString(), "", "width=600px,height=500px;");
        window.onfocus = function() {
            if (modalWin && !modalWin.closed) {
                self.blur();
                modalWin.focus();
            }
        }
    }
}

function GetBrowserName() {
    var nVer = navigator.appVersion;
    var nAgt = navigator.userAgent;
    var browserName = navigator.appName;
    var fullVersion = '' + parseFloat(navigator.appVersion);
    var majorVersion = parseInt(navigator.appVersion, 10);
    var nameOffset, verOffset, ix;

    // In MSIE, the true version is after "MSIE" in userAgent
    if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
        browserName = "Microsoft Internet Explorer";
        fullVersion = nAgt.substring(verOffset + 5);
    }
    // In Opera, the true version is after "Opera" 
    else if ((verOffset = nAgt.indexOf("Opera")) != -1) {
        browserName = "Opera";
        fullVersion = nAgt.substring(verOffset + 6);
    }
    // In Chrome, the true version is after "Chrome" 
    else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
        browserName = "Chrome";
        fullVersion = nAgt.substring(verOffset + 7);
    }
    // In Safari, the true version is after "Safari" 
    else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
        browserName = "Safari";
        fullVersion = nAgt.substring(verOffset + 7);
    }
    // In Firefox, the true version is after "Firefox" 
    else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
        browserName = "Firefox";
        fullVersion = nAgt.substring(verOffset + 8);
    }
    // In most other browsers, "name/version" is at the end of userAgent 
    else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
        browserName = nAgt.substring(nameOffset, verOffset);
        fullVersion = nAgt.substring(verOffset + 1);
        if (browserName.toLowerCase() == browserName.toUpperCase()) {
            browserName = navigator.appName;
        }
    }
    // trim the fullVersion string at semicolon/space if present
    if ((ix = fullVersion.indexOf(";")) != -1) fullVersion = fullVersion.substring(0, ix);
    if ((ix = fullVersion.indexOf(" ")) != -1) fullVersion = fullVersion.substring(0, ix);

    majorVersion = parseInt('' + fullVersion, 10);
    if (isNaN(majorVersion)) {
        fullVersion = '' + parseFloat(navigator.appVersion);
        majorVersion = parseInt(navigator.appVersion, 10);
    }

    //     document.write('Browser name  = ' + browserName + '<br>');
    //     document.write('Full version  = ' + fullVersion + '<br>');
    //     document.write('Major version = ' + majorVersion + '<br>');
    //     document.write('navigator.appName = ' + navigator.appName + '<br>');
    //     document.write('navigator.userAgent = ' + navigator.userAgent + '<br>');


    return browserName;

}


//////////////////////////////////////////////////Modal Popup//////////////////////////////////////////////
// Small popups
function showPopUp(url, pName) {
    var varModalOptions = new ModalOptions(null, null, pName, 450, 200);
    varModalOptions.resizable = false;
    varModalOptions.onClose = OnCloseManagerAffiliatePopup;
    OpenManagerAffiliatePopup(url, varModalOptions);

    return false;
}

//
function OpenManagerAffiliatePopup(varUrl, varModalOptions) {

    //
    varModalOptions.url = varUrl;
    varModalOptions.userData = ExitMode.None;
    OpenModalPopup(varModalOptions);
}


function OnCloseManagerAffiliatePopup() {

    //var upnlAddAffiliate = document.getElementById("ctl00_cphMain_upnlAffiliate");
    //ShowHideControlsByTag("select", true);
    if (varModalWindow.options.userData == ExitMode.OK) {
        __doPostBack('', '');

    }
    //ReloadUpdatePanel("upnlDocument", "wtabProject");

    return false;
}

//
function CloseManagerAffiliatePopup() {
    //
    CloseModalPopup(window.top.varModalWindow);

    //
    return false;
}

//prototype window starts here...
//
var ExitMode = { None: 0, OK: 1, Cancel: 2 };

//
function SetExitMode(varExitMode) {
    window.top.varModalWindow.options.userData = varExitMode;
}

//
function ModalOptions(url, id, title, width, height, userData, onShow, onClose) {
    this.url = url ? url : null;
    this.id = id ? id : "window_" + new Date().getTime();
    this.title = title ? title : "&nbsp;";
    this.minWidth = 100;
    this.minHeight = 20;
    this.width = width ? width : 200;
    this.height = height ? height : 300;
    this.minimizable = true;
    this.maximizable = true;
    this.resizable = true;
    this.closable = true;
    this.draggable = true;
    this.wiredDrag = true;
    this.userData = null;
    this.onShow = onShow ? onShow : Prototype.emptyFunction;
    this.onClose = onClose ? onClose : Prototype.emptyFunction;
}

//
function OpenModalPopup(varModalOptions) {

    //
    varModalWindow = null;
    popupClosed = false;

    //
    //    var varUrl = SetPageID(varModalOptions.url);
    var varUrl = varModalOptions.url;

    //
    varModalWindow = new Window(varModalOptions, { url: varUrl,
        title: varModalOptions.title,
        className: "alphacube",
        minWidth: varModalOptions.minWidth,
        minHeight: varModalOptions.minHeight,
        width: varModalOptions.width,
        height: varModalOptions.height,
        minimizable: varModalOptions.minimizable,
        maximizable: varModalOptions.maximizable,
        resizable: varModalOptions.resizable,
        closable: varModalOptions.closable,
        draggable: varModalOptions.draggable,
        wiredDrag: varModalOptions.wiredDrag,
        gridX: 1,
        gridY: 1,
        userData: varModalOptions.userData,
        onShow: varModalOptions.onShow,
        onClose: varModalOptions.onClose,
        destroyOnClose: true
    });

    varModalWindow.showCenter(true);

    //
    setTimeout(function() { ShowHideControlsByTag("select", false); }, 3000);

    return false;
}

//
function CloseModalPopup(varModalWindow, checkForSaveChanges) {
    var check = true;
    if (varModalWindow != null) {
        if (typeof (checkForSaveChanges) == "undefined")
            check = true;
        else
            check = checkForSaveChanges;

        /*if (check)
        //if (IsPageDataChanged()) 
        {
            //            if (confirm('Your changes have not been saved. To stay on the page so that you can save your changes, click Cancel.') == false)
            if (confirm('Your Password is not been updated. Are you sure you want to close this window?') == false)
                return;
        }*/

        varModalWindow.close();
    }
    //else
    //window.location.href = SetPageID('../Admin/Home.aspx');
}


function ChangePopupClosedValue() {
    popupClosed = false;
}
function ShowHideControlsByTag(tagName, isShow) {
    if ((popupClosed == true) && (isShow == false)) {
        setTimeout(function() { ChangePopupClosedValue(); }, 3000);
        return;
    }
    var pVarArray = document.getElementsByTagName(tagName);
    var pControl;

    for (var i = 0; i < pVarArray.length; i++) {

        pControl = pVarArray[i];
        if (pControl != null) {
            if (isShow == false)
                pControl.style.visibility = "hidden";
            else
                pControl.style.visibility = "visible";
        }
    }
}

function CloseConfirmationPopup() {
    //
    CloseConfirmationModalPopup(window.parent.varModalWindow);

    //
    return false;
}

function CloseConfirmationModalPopup(varModalWindow) 
{
    varModalWindow.close();
}

function CloseConfirmModalPopupDelegate() {


    if (varModalWindow.options.userData == ExitMode.OK) {
        __doPostBack('UPDATE', '');
    }

    return false;
}

function CloseConfirmPopup(varModalWindow) {
    varModalWindow.close();
}

