//sets the value of a dhtml object given its id.
function SetValue(id, val)
{
    var obj = GetObj(id);
    if (obj != null)
    {
        if (obj.value)
			obj.value = val;
    }
}
function ClickItem(itemId)
{
	var obj = GetObj(itemId);
	if (obj != null)
		obj.checked = true;
}
function FormatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}
function StartOver()
{
	if (confirm("Are you sure you want to start over?  By clicking 'Yes' you will lose your current selections and be redirected to the start of the wizard."))
	{
		window.location.href = "Main.aspx";
	}
}

function Logout(type)
{
    if (confirm("Are you sure you want to log out?"))
    {
	    if (type == 'app')
	        window.close();
	    else
	        window.location.href = '';
	}
}

//Sets the value of a radio list item to true given its id
function SetRadioValue(id)
{
    var obj = GetObj(id);
    if (obj != null)
        obj.checked = true;
}

//Returns a dhtml object given its Id
function GetObj(objId)
{
    if (document.getElementById)
		return document.getElementById(objId);
	else if (document.all)
	    return document.all[objId];
	else if (document.layers)
	    return document.layers[objId];
	else
	    return null;
}

//sets the background colour of an object to the html colour
//specified
function MouseOver(obj, colour)
{
    if (obj.bgColor)
		obj.bgColor = colour;
}
//opens a popup window given a url, width and height.  This will currently
//open the window with toolbars but no status bar - ToDo: this should be changed so
//that these are input parameters
function PopupWindow(url, width, height, toolbars, status, scrolling, resize, location)
{
    var options = '';
    
    if (width == null)
        width = window.width;
    if (height == null)
        height = window.height;
    if (toolbars == null)
        toolbars = 'yes';
    if (status == null)
        status = 'yes';
    if (scrolling == null)
        scrolling = 'yes';
    if (resize == null)
        resize = 'yes';
    if (location == null)
        location = 'yes';
        
    var options = 'location='+location+', resizable='+resize+', scrollbars='+scrolling+', toolbar='+toolbars+', status='+status+', width='+width+', height='+height;
    window.open(url, 'nm', options); 
}
//opens a popup window given a url, width and height.  This will currently
//open the window with toolbars but no status bar - ToDo: this should be changed so
//that these are input parameters
function PopupWindow2(url, name, width, height, toolbars, status, scrolling, resize, location)
{
    var options = '';
    
    if (width == null)
        width = window.width;
    if (height == null)
        height = window.height;
    if (toolbars == null)
        toolbars = 'yes';
    if (status == null)
        status = 'yes';
    if (scrolling == null)
        scrolling = 'yes';
    if (resize == null)
        resize = 'yes';
    if (location == null)
        location = 'yes';
        
    var options = 'location='+location+', resizable='+resize+', scrollbars='+scrolling+', toolbar='+toolbars+', status='+status+', width='+width+', height='+height;
    window.open(url, name, options); 
}

function show(obj) //shows requested div
{
    if (GetObj('start')!=null)
		GetObj('start').style.visibility='hidden';
	if (GetObj('QLD')!=null)
		GetObj('QLD').style.visibility='hidden';
	if (GetObj('NSW')!=null)
		GetObj('NSW').style.visibility='hidden';
	if (GetObj('VIC')!=null)
		GetObj('VIC').style.visibility='hidden';
	if (GetObj('WA')!=null)
		GetObj('WA').style.visibility='hidden';
	if (GetObj('NZ')!=null)
		GetObj('NZ').style.visibility='hidden';
	if (GetObj('NT')!=null)
		GetObj('NT').style.visibility='hidden';
	if (GetObj('TAS')!=null)
		GetObj('TAS').style.visibility='hidden';
	if (GetObj('SA')!=null)
		GetObj('SA').style.visibility='hidden';
	if (GetObj(obj)!=null)
		GetObj(obj).style.visibility='visible'; // shows requested layer
}

function ToggleLites(litePrice)
{
	var objLites = GetObj('divLites');
	var objHidden = GetObj('hdnSelectedItem');
	if (litePrice != 0)
	{
		objLites.style.visibility = 'visible';
		objHidden.value = objLites.value;
	}
	else
	{
		objLites.style.visibility = 'hidden';
		objHidden.value = 0;
	}
}