﻿//=======================================================================
//echeck :  Checks whether the supplied string complies to email 
//          formatting
function echeck(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
}

//=======================================================================
//numberCheck :  Checks whether the supplied string complies to cell  
//               number formatting
function numberCheck(str) {
    var number = str.split("-");

    if (str.indexOf("_") != -1) {
        return false;
    }

    if (str.length != 12)
        return false;
    if ((number[0].length != 3) || (number[1].length != 3) || (number[2].length != 4)) {
        return false;
    }
    return true;
}



//===========================================================================
//ValidateRegistration :    Validates all the fields on the form and checks
//                          and checks whether they comply to the formatting
//                          specifications
function ValidateRegistration() {
    var returnval;
    //alert("validate All invoked from update button");
    if (document.getElementById('ctl00_MainContent_txtName').value == '') {
        alert("Please complete all the fields - Name required");
        return false;
    }

    if (document.getElementById('ctl00_MainContent_txtSurname').value == '') {
        alert("Please complete all the fields - Surname required");
        return false;
    }

    if (ValidateForm('ctl00_MainContent_txtEmailAddress', 'Email')) {
        returnval = true;
    }
    else {
        alert("Please enter a valid email address")
        return false;
    }

    if (ValidateForm('ctl00_MainContent_cellNumber', 'CellNumber')) {
        returnval = true;
    }
    else {
        alert("Please check cell number format : xxx-xxx-xxxx");
        return false;
    }
    if (document.getElementById('ctl00_MainContent_cbTermsAndConditions').checked) {
        returnval = true;
    }
    else {
        alert("Please read and accept the Terms and Conditions");
        return false;
    }
    //alert(returnval);
    return returnval;


}




//=======================================================================
//ValidateForm : Validates the supplied control against the validation type
function ValidateForm(controlToValidate, validationType) {

    var ValidationControl = document.getElementById(controlToValidate);

    switch (validationType) {
        case ("CellNumber"):
            {
                return numberCheck(ValidationControl.value.toString());
            }
        case ("Email"):
            {
                if ((ValidationControl.value == null) || (ValidationControl.value == "")) {
                    ValidationControl.focus()
                    return false
                }
                if (echeck(ValidationControl.value) == false) {
                    ValidationControl.value = ""
                    ValidationControl.focus()
                    return false
                }
                return true
            }
    }
}

//=====================================================================
//NotifyLogin : Notifies the user that the system is in the process of
//              logging in
function NotifyLogin() {
    document.getElementById('ctl00_MainContent_btnLogin').style.display = "none";
    change();
    document.getElementById('ctl00_MainContent_lblError').innerText = "Validating credentials...";
    return true;
}

//===================================================================
//change    : Change the controls class to a new one
//id        : Control id
//newclass  : class to change to
function change() {
    var label = document.getElementById('ctl00_MainContent_lblError');
    label.style.color = '#999999';

}

//=====================================================================
//NotifyRegister :  Notifies the user that the system is in the process of
//                  registering a new user
function NotifyRegister() {
    change();
    document.getElementById('ctl00_lblError').innerText = "Registering new user...";

}

//==================================================================
//ShowNavigation : Sets the navigation image for the current page
function ShowNavigation() {
    var currentPage = location.pathname;
    //var temp2 = window.location;
    switch (currentPage.toLowerCase()) {
        case '/login.aspx':
            {
                if (document.getElementById('login') != null)
                    document.getElementById('login').src = 'images/navibuttons/loginbut-over.gif';

            } break;
        case '/timeline.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/terms.aspx':
            {
                if (document.getElementById('index') != null)
                    document.getElementById('index').src = 'images/homebut-over.gif';

            } break;
        case '/telecoms.aspx':
            {
                if (document.getElementById('markets') != null)
                    document.getElementById('markets').src = 'images/markets-over.gif';

            } break;
        case '/sitemap.aspx':
            {
                if (document.getElementById('index') != null)
                    document.getElementById('index').src = 'images/homebut-over.gif';

            } break;
        case '/services_hosted.aspx':
            {
                if (document.getElementById('products') != null)
                    document.getElementById('products').src = 'images/products-over.gif';

            } break;
        case '/services_deployment.aspx':
            {
                if (document.getElementById('products') != null)
                    document.getElementById('products').src = 'images/products-over.gif';

            } break;
        case '/services.aspx':
            {
                if (document.getElementById('products') != null)
                    document.getElementById('products').src = 'images/products-over.gif';

            } break;
        case '/privacy.aspx':
            {
                if (document.getElementById('index') != null)
                    document.getElementById('index').src = 'images/homebut-over.gif';

            } break;
        case '/people.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/news_ustrademark.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/news_telefonica.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/news_statement.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/news_modot.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/news_maryland.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/partnering.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/news_garmin.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;

        case '/news_estimotion.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/news_congress2008.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;

        case '/news_boardapp.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;

        case '/news_belgium.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/news_belgium02.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/casestudies.aspx':
            {
                if (document.getElementById('casestudies') != null)
                    document.getElementById('casestudies').src = 'images/casestudies-over.gif';

            } break;
        case '/news.aspx':
            {
                if (document.getElementById('news') != null)
                    document.getElementById('news').src = 'images/navibuttons/newsbut-over.gif';

            } break;
        case '/maryland.aspx':
            {
                if (document.getElementById('casestudies') != null)
                    document.getElementById('casestudies').src = 'images/casestudies-over.gif';

            } break;
        case '/media.aspx':
            {
                if (document.getElementById('markets') != null)
                    document.getElementById('markets').src = 'images/markets-over.gif';

            } break;
        case '/logistics.aspx':
            {
                if (document.getElementById('markets') != null)
                    document.getElementById('markets').src = 'images/markets-over.gif';

            } break;
        case '/automotive.aspx':
            {
                if (document.getElementById('markets') != null)
                    document.getElementById('markets').src = 'images/markets-over.gif';

            } break;
        case '/government.aspx':
            {
                if (document.getElementById('markets') != null)
                    document.getElementById('markets').src = 'images/markets-over.gif';

            } break;
        case '/telecoms.aspx':
            {
                if (document.getElementById('markets') != null)
                    document.getElementById('markets').src = 'images/markets-over.gif';

            } break;
        case '/products.aspx':
            {
                if (document.getElementById('products') != null)
                    document.getElementById('products').src = 'images/products-over.gif';

            } break;
        case '/trafficscience.aspx':
            {
                if (document.getElementById('products') != null)
                    document.getElementById('products').src = 'images/products-over.gif';

            } break;
        case '/markets.aspx':
            {
                if (document.getElementById('markets') != null)
                    document.getElementById('markets').src = 'images/markets-over.gif';

            } break;
        case '/about.aspx':
            {
                if (document.getElementById('about') != null)
                    document.getElementById('about').src = 'images/about-over.gif';

            } break;
        case '/index.aspx':
            {
                if (document.getElementById('index') != null)
                    document.getElementById('index').src = 'images/navibuttons/homebut-over.gif';

            } break;
        case '/main.aspx':
            {
                if (document.getElementById('Home') != null)
                    document.getElementById('Home').src = 'images/HomeSelect.gif';

            } break;
        case '/userProfile.aspx':
            {
                if (document.getElementById('MyProfile') != null)
                    document.getElementById('MyProfile').src = 'images/MyProfSelect.gif';
            }
            break;
        case '/routes.aspx':
            {
                if (document.getElementById('Routes') != null)
                    document.getElementById('Routes').src = 'images/ZonesSelect.gif';
            }
            break;
        case '/routeReports.aspx':
            {
                if (document.getElementById('reports') != null)
                    document.getElementById('reports').src = 'images/ReportsSelect.gif';
            }
            break;
        case '/feedback.aspx':
            {
                if (document.getElementById('feedback') != null)
                    document.getElementById('feedback').src = 'images/FeedbackSelect.gif';
            }

            break;
        case '/notifications.aspx':
            {
                if (document.getElementById('notifications') != null)
                    document.getElementById('notifications').src = 'images/NotificationsSelect.gif';

            } break;

    }
}


//==================================================================================
//ClosePopup    : Closes the map popup and destroys the map object
//popUpName     : modal popup containing map
function ClosePopup(popUpName) {
    $find(popUpName).hide();
}

//========================================================
//disableControl    :   disables the specified control
function disbleControl(controlName) {
    document.getElementById(controlName).disabled = true;
}

function ConfirmTransaction() {



}