function highlightCat( obj, catid, sub )
{
	//this is going to take care of opening subcategories if necessary, highlighting subcat pictures
	//and showing the description panel on the right.
	trail = "";
	for( idx in catids )
	{
		num = catids[idx];

		trail += "\n" + num;

		o = document.getElementById( "catlink" + num );
		p = document.getElementById( "catimagelink" + num );
		q = document.getElementById( "rightproductinfo" + num );

	//	if( o )
	//	{
			if( o != obj)
			{
				//o.className = (num == catid) || (num == opencat) ? "cathighlight" : "categorylink";
			}
			
			if(p)
			{
				p.className = (num == catid) ? "thumblinkhover" : "thumblink";
			}
			
			if(q)
			{
				q.style.display = (num == catid) ? 'block' : 'none';
			}
	//	}
	}
	

//	document.write(trail);
}


function resetForm(name)
{
    document.forms[name].reset();
}

function validateForm(name)
{
    var validateform = document.forms[name];
    var error = false;
    var errorMessage = "The following errors appeared in your form: \n";
    if(isEmpty(validateform.elements["name"].value))
    {
        error = true;
        errorMessage += 'Contact name is empty \n';
    }
    //if(validateform.elements["requestEmail"].checked)
    //{
    if(isEmpty(validateform.elements["email"].value))
    {
        error = true;
        errorMessage += 'you must enter an e-mail address in order for us to contact you \n';    
    }
    //}
    if(!isEmpty(validateform.elements["email"].value))
    {
        if(checkEmail(validateform.elements["email"].value))
        {
            error = true;
            errorMessage += 'you have entered an incorrect e-mail address \n';
        }
    }
    if(isEmpty(validateform.elements["company"].value))
    {
        error = true;
        errorMessage += 'company is empty \n';
    }
    if(isEmpty(validateform.elements["postcode"].value))
    {
        error = true;
        errorMessage += 'postcode is empty \n';
    }
    if(isEmpty(validateform.elements["address"].value))
    {
        error = true;
        errorMessage += 'address is empty \n';
    }    
    if(isEmpty(validateform.elements["telephone"].value))
    {
        error = true;
        errorMessage += 'telephone is empty \n';
    }
    else if(checkPhone(validateform.elements["telephone"].value))
    {
        error = true;
        errorMessage += 'invalid telephone number \n';        
    }
    if(error)
    {
        alert(errorMessage);
    }
    return !error;
}

//email
function checkEmail(strng) 
{
    var error = false;
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) 
    { 
       error = true;
    }
    else 
    {
        var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (strng.match(illegalChars)) 
        {
          error = true;
        }
    }
    return error;    
}

// phone number - strip out delimiters and check its a number

function checkPhone(string) 
{
    var error = false
    var stripped = string.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    for(var i = 0; i < stripped.length ; i++)
    {
        if(isNaN(parseInt(stripped.charAt(i)))) 
        {
           error = true;
        }
    }
    return error;
}

// non-empty textbox
function isEmpty(string) 
{
    var isEmpty = false;
    if (string.length == 0) 
    {
        isEmpty = true;
    }
    return isEmpty;
}

function submitForm(formName, validate)
{
    if(validate)
    {
        if(!validateForm(formName))
        {
            return;
        }
    }
    document.forms[formName].submit();
}
