//Checking that all fields are filled in on the form..
function formCheck(formobj){
    // name of mandatory fields
    var fieldRequired = Array("name", "email", "comments");
    // field description to appear in the dialog box
    var fieldDescription = Array("Name", "Email", "Comments");
    // dialog message
    var alertMsg = "Please complete the following fields:\n";
	
    var l_Msg = alertMsg.length;
	
    for (var i = 0; i < fieldRequired.length; i++){
        var obj = formobj.elements[fieldRequired[i]];
        if (obj){
            if (obj.type == null){
                var blnchecked = false;
                for (var j = 0; j < obj.length; j++){
                    if (obj[j].checked){
						blnchecked = true;
                    }
                }
                if (!blnchecked){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                continue;
            }

            switch(obj.type){
            case "select-one":
                if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                break;
            case "select-multiple":
                if (obj.selectedIndex == -1){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                break;
            case "text":
            case "textarea":
                if (obj.value == "" || obj.value == null){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                break;
            default:
            }
        }
    }

    if (alertMsg.length == l_Msg){
        return true;
    }else{
        alert(alertMsg);
        return false;
    }
}

function displayPhoto(i, cat, img)
{
    var p = i.parentNode.getElementsByTagName('a')
    for ( j=0; j<p.length; j++ ) if ( p[j] == i) break;
    
	var p = document.getElementById('photo')
	p.alt = 'Loading...'
	p.src = '/images/blank.gif'

    if ( i.getAttribute('imgwidth') != '' )
	{
	    p.style.width = i.getAttribute('imgwidth') + 'px'
	    p.style.height = i.getAttribute('imgheight') + 'px'
	}

    var oImage = new Image;
    oImage.onload = function() { p.src = oImage.src }   
    oImage.src = i.href
   	return false;
}
	
function displayFrontendPhoto(i, photoid)
{

    var p = i.parentNode.getElementsByTagName('a')
    for ( j=0; j<p.length; j++ ) if ( p[j] == i) break;

    var p = document.getElementById('photo')
	document.purchase.PhotoID.value = photoid;
	
    p.alt = 'Loading...'
    p.src = '/images/blank.gif'
    if ( i.getAttribute('imgwidth') != '' )
    {
        p.style.width = parseInt(i.getAttribute('imgwidth')) + 'px'
        p.style.height = parseInt(i.getAttribute('imgheight')) + 'px'
        p.style.margin = parseInt((474 - i.getAttribute('imgheight'))/2) + 'px ' + parseInt((833 - i.getAttribute('imgwidth'))/2) + 'px'
    }

    var oImage = new Image;
    oImage.onload = function() { p.src = oImage.src }
    p.alt = i.getElementsByTagName('img')[0].alt

    oImage.src = i.href

    p.setAttribute('imgno', j)
    return false;
}
