
strSelectedPage = String('registration');

var strSelectedRegistrationPage = String('1');
var iRegistrationPage = Number(1);

nav_registration_page1_off = CreateImage('images/nav1_off.gif');
nav_registration_page1_over = CreateImage('images/nav1_over.gif');
nav_registration_page1_on = CreateImage('images/nav1_on.gif');

nav_registration_page2_off = CreateImage('images/nav2_off.gif');
nav_registration_page2_over = CreateImage('images/nav2_over.gif');
nav_registration_page2_on = CreateImage('images/nav2_on.gif');

nav_registration_page3_off = CreateImage('images/nav3_off.gif');
nav_registration_page3_over = CreateImage('images/nav3_over.gif');
nav_registration_page3_on = CreateImage('images/nav3_on.gif');

nav_previous_off = CreateImage('images/button_previous_off.gif');
nav_previous_over = CreateImage('images/button_previous_over.gif');

nav_next_off = CreateImage('images/button_next_off.gif');
nav_next_over = CreateImage('images/button_next_over.gif');

nav_finish_off = CreateImage('images/button_submit_off.gif');
nav_finish_over = CreateImage('images/button_submit_over.gif');

function RegistrationNavClick(strPage) 
{
	if (bLoaded)
	{	
		if (strPage != strSelectedRegistrationPage)
		{
			// Unhighlight the previous navigation
			ChangeImage('nav_registration_page' +strSelectedRegistrationPage, 'nav_registration_page' +strSelectedRegistrationPage +'_off');
			
			// Highlight the new navigation
			ChangeImage('nav_registration_page' +strPage, 'nav_registration_page' +strPage +'_on');
			
			// Display the correct contents
			DocumentObject('registration_page_1', true).display = (strPage == "1" ? 'inline' : 'none');
			DocumentObject('registration_page_2', true).display = (strPage == "2" ? 'inline' : 'none');
			DocumentObject('registration_page_3', true).display = (strPage == "3" ? 'inline' : 'none');

            if (strPage == "1")
                FocusElement('txtSerialNumber');
            else if (strPage == "2")
                FocusElement('txtAddress');
            else if (strPage == "3")
                FocusElement('txtBirthDate');

            /*
			if (document.getElementById('registration_finished'))
			    DocumentObject('registration_finished', true).display = 'none';

			if (document.getElementById('registration_error'))
			    DocumentObject('registration_error', true).display = 'none';
			*/
			
			iRegistrationPage = Number(strPage);
			
			// Registration the new selection
			strSelectedRegistrationPage = strPage;
			
			if (iRegistrationPage == 1)
			    document.getElementById('nav_previous').style.display = 'none';
			else
			    document.getElementById('nav_previous').style.display = 'inline';

			if (iRegistrationPage == 3)
			{
			    document.getElementById('nav_next').style.display = 'none';
			    document.getElementById('nav_finish').style.display = 'inline';
			}
			else
			{
			    document.getElementById('nav_next').style.display = 'inline';
			    document.getElementById('nav_finish').style.display = 'none';
			}
		}
	}	
}

function RegistrationNavOver(strPage)
{
	if (bLoaded)
	{
	    if (strPage != strSelectedRegistrationPage)
	    {
		    ChangeImage(('nav_registration_page' +strPage), ('nav_registration_page' +strPage +'_over'));
		    //ChangeImageSelected(('nav_registration_page' +strPage), ('nav_registration_page' +strPage +(strPage == strSelectedRegistrationPage ? '_on' : '_over')));
		}
	}
}

function RegistrationNavOut(strPage) 
{
	if (bLoaded)
	{
	    if (strPage != strSelectedRegistrationPage)
	    {
		    ChangeImage(('nav_registration_page' +strPage), ('nav_registration_page' +strPage +'_off'));
		    //ChangeImageSelected(('nav_registration_page' +strPage), ('nav_registration_page' +strPage +(strPage == strSelectedRegistrationPage ? '_on' : '_off')));
		}
	}
}

function RegistrationPrevious()
{
	if (bLoaded) 
	{
		if (iRegistrationPage > 1)
		{
	        RegistrationNavClick(String(iRegistrationPage - 1));
		}
	}
}

function RegistrationNext() 
{
	if (bLoaded) 
	{
		if (iRegistrationPage < 3)
		{
	        RegistrationNavClick(String(iRegistrationPage + 1));
		}
	}
}

var bFocusElementSet = false;
    
function FocusPageElement(sElementId, iNavPage)
{
    if (!bFocusElementSet)
    {
        RegistrationNavClick(iNavPage);
        
        FocusElement(sElementId);

        bFocusElementSet = true;
    }
}

function FocusElement(sElementId)
{
    if (document.getElementById(sElementId))
        document.getElementById(sElementId).focus();
}

function ValidateForm()
{
    bFocusElementSet = false;
    
    var errors = [];
    
    if (document.getElementById('txtSerialNumber').value.trim().length == 0) 
    {
        errors.push('Serial Number'); 
        FocusPageElement('txtSerialNumber', '1'); 
    }

    if (document.getElementById('txtFirstName').value.trim().length == 0) 
    {
        errors.push('First Name'); 
        FocusPageElement('txtFirstName', '1'); 
    }

    if (document.getElementById('txtLastName').value.trim().length == 0) 
    {
        errors.push('Last Name'); 
        FocusPageElement('txtLastName', '1'); 
    }

    if (document.getElementById('txtAddress').value.trim().length == 0) 
    {
        errors.push('Address'); 
        FocusPageElement('txtAddress', '2'); 
    }
    
    if (document.getElementById('txtCity').value.trim().length == 0)
    {
        errors.push('City');
        FocusPageElement('txtCity', '2'); 
    }
    
    if (document.getElementById('txtState').value.trim().length == 0)
    {
        errors.push('State');
        FocusPageElement('txtState', '2'); 
    }
    
    if (document.getElementById('txtZipCode').value.trim().length == 0)
    {
        errors.push('Zip Code');
        FocusPageElement('txtZipCode', '2'); 
    }
    
    if (document.getElementById('txtCountry').value.trim().length == 0)
    {
        errors.push('Country');
        FocusPageElement('txtCountry', '2'); 
    }

    if (document.getElementById('txtPhoneNumber').value.trim().length == 0)
    {
        errors.push('Phone Number');
        FocusPageElement('txtPhoneNumber', '3'); 
    }
    if (document.getElementById('txtPurchasePrice').value.trim().length == 0)
    {
        errors.push('Purchase Price');
        FocusPageElement('txtPurchasePrice', '3'); 
    }
    if (document.getElementById('ddPurchasedFrom').value.trim() == '(select)')
    {
        errors.push('Purchased From');
        FocusPageElement('ddPurchasedFrom', '3'); 
    }
    
    if (document.getElementById('ddDealerRating').value.trim() == 0)
    {
        errors.push('Dealer Rating');
        FocusPageElement('ddDealerRating', '3'); 
    }

    if (errors.length > 0) 
    {
        alert('Please fill in the following required fields:\n\n' + errors.join(', '));
        return false;
    }
    else
        return true;        
}

function HasFocus(oBox)
{
    oBox.className = 'textbox_focus';
}

function NoFocus(oBox)
{
    oBox.className = 'textbox_blur';
}

/* 
function PNGChangeImage(oImg, sState)
{
    var oSpan = document.getElementById(oImg)
    var currentAlphaImg = oSpan.filters(0).src

    var currentState = '';
    
    if (currentAlphaImg.indexOf('_off') != -1)
        currentState = '_off';
    else if (currentAlphaImg.indexOf('_over') != -1)
        currentState = '_over';
    else if (currentAlphaImg.indexOf('_on') != -1)
        currentState = '_on';
    else
        return;

    oSpan.filters(0).src = currentAlphaImg.replace(currentState, sState);
}
*/