﻿var lastID = null;
var el;
function addFileUploadField()
{
    if (!document.getElementById || !document.createElement)
        {
        alert('It seems that you have an old browser type. You cannot add extra upload fields without upgrading your browser.');
        return false;
        }		
    var div = document.getElementById ("moreUps");
	
    if (!div)
    {
        alert('Cannot find target element.');
        return false;
    }

    var newLine = document.createElement ("br");
    div.appendChild (newLine);
	
    var newUploadBox = document.createElement ("input");
	
    // Set up the new input for file uploads
    newUploadBox.type = "file";
    //newUploadBox.size = "60";
	
    // The new box needs a name and an ID
    if (!lastID)
    {
        lastID = 100;
    }
    else if(lastID > 101)
    {
        alert('You can attach a maximum of 3 files.');
        return false;
    }
	    
    newUploadBox.setAttribute ("id", "dynamic" + lastID);
    newUploadBox.setAttribute ("name", "dynamic:" + lastID);
    div.appendChild (newUploadBox);
    
    lastID++;
}


function toggleDiv(div)
{
    var el = document.getElementById(div);
    if(el.style.display != 'none')
    {
        el.style.display = 'none';
    }
    else
    {
        el.style.display = '';
    }
}


function SendAppointmentMail(element)
{
    el = $get(element);
    var body, fName, lName, add1, add2, town, postCode, tel1, tel2, email, time;
    fName = $get("txtFName").value;
    lName = $get("txtLName").value;
    add1 = $get("txtAdd1").value;
    add2 = $get("txtAdd2").value;
    town = $get("txtTown").value;
    postCode = $get("txtPostcode").value;
    tel1 = $get("txtTel1").value;
    tel2 = $get("txtTel2").value;
    email = $get("txtEmail").value;
    time = $get("txtTime").value;
    
    
    //built body
    body = "\nName: " + fName + " " + lName + "\n";
    body += "Address: " + add1 + " " + add2 + " " + town + " " + postCode + "\n";
    body += "Telephone: " + tel1 + " Contact Telephone: " + tel2 + "\n";
    body += "Email: " + email + "\n";
    body += "Best Time: " + time + "\n";
    
    TudorMail.SendAppointmentMail(body, Complete, Error, OnTimeout);
}

function Complete(arg)
{
    el.innerHTML = arg;
}

function Error(arg)
{
    alert("An error occurred. Please ensure you have filled in your details completely and try again.");
    return false;
}

