﻿// JScript File

// http://www.somacon.com/p355.php
String.prototype.Trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function ProvidersInitialise()
{
    alert( "ProvidersInitialise()" );
}
function RadioOption( adi )
{
    RadioSetDivVisibility( GetHtmlElement( "divAll" ), "A", adi );
    RadioSetDivVisibility( GetHtmlElement( "divDirect" ), "D", adi );
    RadioSetDivVisibility( GetHtmlElement( "divInter" ), "I", adi );
}

function RadioSetDivVisibility( div, adi_required, adi_sent )
{
    if( adi_required == adi_sent )
        div.style.display = "block";
    else
        div.style.display = "none";
}
function RadioSetDivVisibilityOld( div, adi_required, adi_sent )
{
    if( adi_required == adi_sent )
    {
        div.style.visibility = "visible";
        div.style.height = "";
    }
    else
    {
        div.style.visibility = "collapse";
        div.style.height = "0px";
    }
}

function RunYell()
{
    var postcode = GetAspTextBoxValue( "txtPostcode" );   
    if( postcode == "" )
    {
        alert( "Please enter a town, city or postcode" );
        return;
    }
    var url = "http://www.yell.com/ucs/UcsSearchAction.do?keywords=Mortgage+brokers&location=" + escape(postcode);
    window.open( url );
}

function LoadProvidersWebsite()
{
    var msg = "Select a provider from the list";
    if( GetHtmlElement( "divAll" ).style.display == "block" )
        LoadWebsiteFromListbox( GetAspElement( "lstAll" ), msg );
    else if( GetHtmlElement( "divDirect" ).style.display == "block" )
        LoadWebsiteFromListbox( GetAspElement( "lstDirect" ), msg );
    else if( GetHtmlElement( "divInter" ).style.display == "block" )
        LoadWebsiteFromListbox( GetAspElement( "lstInter" ), msg );
}

function LoadBrokersWebsite()
{
    LoadWebsiteFromListbox( GetAspElement( "lstBrokers" ), "Select a broker from the list" );
}

function LoadWebsiteFromListbox( lst, msg )
{
    if( lst.selectedIndex < 0 )
    {
        alert( msg );
        return;
    }
    var url = lst.options[ lst.selectedIndex ].value;
    window.open( MakeUrl( url ) );        
}

function MakeUrl( url )
{
    if( url.indexOf( "http" ) != 0 )
        url = "http://" + url;
    return url;
}

function GetAspDropdownlistValue( id )
{
    var element = GetAspElement( id );
    if( element == null )
        return "";
    if( element.selectedIndex < 0 || element.selectedIndex > element.options.length )
        return "";
    return element.options[ element.selectedIndex ].value;
}

function IsAspRadiobuttonChecked( id )
{
    var element = GetAspElement( id );
    if( element == null )
        return false;
    return element.checked;
}

function IsAspCheckboxChecked( id )
{
    var element = GetAspElement( id );
    if( element == null )
        return false;
    return element.checked;
}
function GetAspTextBoxValue( id )
{
    var element = GetAspElement( id );
    if( element == null )
        return "";
    return element.value;
}
function SetAspTextBoxValue( id, str )
{
    var element = GetAspElement( id );
    if( element == null )
        return "";
    element.value = str;
}

function GetPrefix()
{
    return "ctl00_ContentPlaceHolder1_";
}
function GetAspElement( id )
{
    return document.getElementById( GetPrefix() + id );
}
function GetHtmlElement( id )
{
    return document.getElementById( id );
}