/*
PLEASE NOTE due to last minute change of requirements cms were converted to mm. The html markup was not changed accordingly.
*/
var el, unit;
function ConvertMetric(element)
{
    el = $get(element);
    CallLoader();
    var inches;


    if($get("txtIns").value == "")
    {
        CancelLoader();
        alert("Please enter a value for inches.");
        return false;        
    }   
    //perform and get cm conversion 
    if($get("txtIns").value != "")
    {
        inches = $get("txtIns").value;
        unit = " mm";
        if(isNaN(inches))
        {
            CancelLoader();
            alert("Please enter numbers only.");
            return false;
        }
        else
        {
            Calculators.ConvertToCentimetres(inches, OnComplete, OnTimeout, OnError);
        }
    }
    return true;
}

function CallLoader()
{
        //set loader
    el.innerHTML = "..calculating";
}

function CancelLoader()
{
    el.innerHTML = "";
}


function GetQuote(element)
{
    var width, height, displayArea;
    el = $get(element);
    CallLoader();
    if($get("txtWidth").value == "" || $get("txtHeight").value == "" || isNaN($get("txtWidth").value) || isNaN($get("txtHeight").value))
    {
        alert("Please enter a value for height and width - numbers only.");
        return false;
    }
    //we dont need units here
    unit = "";
    displayArea = $get("results");
    width = $get("txtWidth").value;
    height = $get("txtHeight").value;
    displayArea.style.display = '';
    Calculators.GetQuickQuote(width, height, OnComplete, OnTimeout, OnError);
}

function OnComplete(arg)
{
el.innerHTML = arg + unit;
    //return arg;
}

function OnTimeout(arg)
{
    alert(arg);
    return false;
}

function OnError(arg)
{
    CancelLoader();
    alert("An error occurred. Please check the value you entered using numbers only and try again.");
    return false;
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();