﻿
function viewProfile() {
    alert("TEST");
}

function logOff() {
    var logOutButton = document.getElementById(prefix + "btnLogOff");
    logOutButton.click();
}


function highlight(field) {
    field.focus();
    field.select();
}

function removeSpaces(string) {
 return string.split(' ').join('');
}


function populateHiddenPostcode() {
    
    var hdnPostcode = document.getElementById("contentMaster_masterPage_mainContent_contentMainContent_hdnPostcode");
    var txtPostcode = document.getElementById("txtPostcode");
    var newValue = removeSpaces(txtPostcode.value);

    if ((newValue == "enterpostcode") || (newValue == "")) {
        alert("Please enter a valid postcode");
        return false;
    }
    if (newValue.length < 3) {
        alert("Please enter a valid postcode");
        return false;
    }

    if ((newValue.length == 3) || (newValue.length == 4)) {
        hdnPostcode.value = newValue;
        return true;
    }
    if (newValue.length == 6) {
        //We take the first 3 characters from the string
        hdnPostcode.value = newValue.substring(0, 3)
        return true;
    }
    if (newValue.length == 7) {
        //We take the first 4 characters from the string
        hdnPostcode.value = newValue.substring(0, 4)
        return true;
    }
    if (newValue.length > 7) {
        //We take the first 4 characters from the string
        hdnPostcode.value = newValue.substring(0, 4)
        return true;
    }
}

// Check if this is the first ime in this box
// if so clear it.
function checkFirstTime(textbox)
{
    if ("1" == GetDomValue(textbox, "icFirstTime"))
    {
        textbox.value = "";
        SetDomValue(textbox, "icFirstTime", "0");
    }
}

function GetDomValue(element, name)
{
    return element.getAttribute(name);
}

function SetDomValue(element, name, value)
{
    return element.setAttribute(name, value);
}
