
function getObjRef(obj) {
	if (document.getElementById) {
		return document.getElementById(obj);
	} else if (document.all) {
		return document.all[obj];
	} else {
		return null;
	}
}

function debugWrite(message)
{
    if(window.Debug)
    {
        window.Debug.writeln(message);
    }
}

// registered by basepage use to call all onload js functions
function basePageStartUp()
{
    hideEventValidatorDiv();
}

function hideEventValidatorDiv()
{
    inputObj = getObjRef("__EVENTVALIDATION");
    
    if (inputObj!=null && inputObj.parentElement !=null)
    {
        inputObj.parentElement.style.display = "none";
    }
}

function fillSearchDefaultText() {
	/* getObjRef('searchBox').value="Search using keywords" */;
}

function fillSearchHomesDefaultText(id) {
    txtPostcode = getObjRef(id);
    if (txtPostcode!=null && txtPostcode.value.length==0)
    {
	    getObjRef(id).value="Enter postcode";
    }
}

function fillDirectionsDefaultText(id) {
	getObjRef(id).value="Enter postcode";
}

function showImage(imageUrl, imageId) 
{
    imageObj = getObjRef(imageId);
    if (imageObj!=null)
    {
        imageObj.src = imageUrl;
    }
}

function showImage(imageUrl, imageId, artistsImpressionRef, showImpression) 
{
    showImage(imageUrl, imageId, null, artistsImpressionRef, showImpression);
}

function showImage(imageUrl, imageId, imageAlt, artistsImpressionRef, showImpression, typicalHomeRef, showTypical) 
{
    imageObj = getObjRef(imageId);
    var impressionInfoObj = getObjRef(artistsImpressionRef);
    var typicalInfoObj = getObjRef(typicalHomeRef);
    
    if (imageObj!=null)
    {
        imageObj.src = imageUrl;
        if (imageAlt != null)
        {
            imageObj.alt = imageAlt;
        }
    }
    
    if(impressionInfoObj != null)
    {
        if(showImpression != "true")
        {                    
            impressionInfoObj.style.display = 'none';
        }
        else
        {
            impressionInfoObj.style.display = '';
        }        
    }
    
    if(typicalInfoObj != null)
    {        
        if(showTypical != "true")
            typicalInfoObj.style.display = 'none';
        else
            typicalInfoObj.style.display = '';
    }
}

function resetCountyList() 
{
    var countyListName = getObjRef("countylistId");
    var countyList;
    if (countyListName != null)
    {
        countyList = getObjRef(countyListName.value);
        
        if (countyList !=null)
        {
            countyList.selectedIndex = 0;
        }
    }
    return true;
}

function resetPostCode()
{
    var countyListId = getObjRef("countylistId");
    var countyList;
    if (countyListId != null)
    {
        countyList = getObjRef(countyListId.value);
        
        if (countyList !=null)
        {
            if (countyList.selectedIndex != 0)
            {
                var postCodeId = getObjRef("postcodeId");
                var postCode = getObjRef(postCodeId.value);
                if (postCode!=null)
                {
                    postCode.value = "Enter postcode";
                }
            }
        }
    }
    return true;
}

function compareMinmaxValuesCondition(cond)
{
    var result = 1;
    
    var minValue = VAM_GetTextValue(cond.IDToEval, cond.Trim);
    var maxValue = VAM_GetTextValue(cond.IDToEval2, cond.Trim);

    // if either are optional, no validation is required
    if((minValue != "Optional" && maxValue != "Optional") || (minValue != "-1" && maxValue != "-1"))
    {
        minValue_Int = parseInt(minValue);
        maxValue_Int = parseInt(maxValue);

        if(minValue_Int > maxValue_Int)
        {
            result = 0;
        }
    }
    return result;
}

function formCheckAll(sender)
{
    //Gets all 'input' tags in the 'ul' which contains the 'sender' checkbox
    var list = sender.parentNode.parentNode.parentNode.getElementsByTagName("input");

    //Loop through and find only the checkboxes; set their checkbox values to that of the senders
    for(var i = 0; i < list.length; i++)
    {
        if(list[i].type == "checkbox")
            list[i].checked = sender.checked;
    }
}

//this works because the 'All' checkbox is last in the list
//should maybe come up with a more elegant way of doing this
function formUnCheckAll(sender)
{
    //number of 'li'
    var listCount = sender.parentNode.parentNode.childNodes.length
    //get first 'input' of last 'li'
    var lastCheckBox = sender.parentNode.parentNode.childNodes[listCount - 1].getElementsByTagName("input")[0];

    if(lastCheckBox.type == "checkbox")
        lastCheckBox.checked = false;
}