//ENQUIRY FORM DROP DOWN
//----------------------

function enquiryForm(select) {

    if (select.value == "Other") {
        if (!select.parentNode.getElementsByTagName("input")[0]) {
            var otherInput = document.createElement("input");
            otherInput.setAttribute("type", "text");
            otherInput.setAttribute("size", "30");
            otherInput.setAttribute("name", "frmHearaboutOther");
            otherInput.setAttribute("maxlength", "100");
            select.parentNode.appendChild(otherInput);
        } else {
            var otherInput = select.parentNode.getElementsByTagName("input")[0];
        };
        otherInput.focus();
    }
    
    else if (select.value == "Press article") {
        if (!select.parentNode.getElementsByTagName("input")[0]) {
            var otherInput = document.createElement("input");
            otherInput.setAttribute("type", "text");
            otherInput.setAttribute("size", "30");
            otherInput.setAttribute("name", "frmPressArticleOther");
            otherInput.setAttribute("value", "Which: ");
            otherInput.setAttribute("maxlength", "100");
            select.parentNode.appendChild(otherInput);
        } else {
            var otherInput = select.parentNode.getElementsByTagName("input")[0];
        };
        otherInput.focus();
    }
    
    else {
        if (select.parentNode.getElementsByTagName("input").length > 0) {
            select.parentNode.removeChild(select.parentNode.getElementsByTagName("input")[0]);
        };
    };
    
}

//JAVASCRIPT FLASH INSERTION
//--------------------------

function flash(url, img, width, height, flashversionuser) {

    if (!flashversionuser) {
        flashtest = 6;
    } else {
        flashtest = parseInt(flashversionuser);
    }; 
    
    //alert("Flash installed (2=yes): "+flashinstalled);
    //alert("Flash version installed: "+flashversion);    
    //alert("Testing for: "+flashtest);        

    if (flashinstalled == 2 & flashversion >= flashtest) {
        
        document.write('<object width="'+width+'" height="'+height+'" align="middle" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">');
        document.write('<param value="sameDomain" name="allowScriptAccess" />');
        document.write('<param value="'+url+'" name="movie" />');
        document.write('<param value="high" name="quality" />');
        //document.write('<param value="noscale" name="scale" />');
        document.write('<param value="transparent" name="wmode" />');
        document.write('<param value="lt" name="salign" />');
        document.write('<param value="#ffffff" name="bgcolor" /><embed width="'+width+'" height="'+height+'" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="sameDomain" wmode="transparent" bgcolor="#ffffff" salign="lt" quality="high" src="'+url+'">');
        document.write('</embed>');
        document.write('</object>');
    } else {
        document.write('<img src="'+img+'" width="'+width+'" height="'+height+'" alt="" />');
    };
    
    flashtest == null;

}

//FORM VALIDATION
//---------------

function checkRequired(form) {

    //alert(formid);
    var error = 0;
    var setfocus = 0;
    
    var inputs = form.getElementsByTagName("input");
    for (i=0; i<inputs.length; i++) {
        if (inputs[i].title == "required") {
            if (inputs[i].value == "") {
                //alert("Please complete all fields.");
                inputs[i].style.borderColor = "red";
                if (!setfocus) {
                    inputs[i].focus();
                    setfocus = 1;
                };
                //return false;
                error = 1;
            } else {
				//EMAIL ADDRESS FORMATTING ON INPUT WITH NAME 'frmEmail'
				
				var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				var filterResult = filter.test(inputs[i].value);
				
				if (inputs[i].name == "frmEmail" & filterResult == false) {
				
					inputs[i].style.borderColor = "red";
                    if (!setfocus) {
                        inputs[i].focus();
                        setfocus = 1;
                    };
					error = 2;
				
				} else {				
					inputs[i].style.borderColor = "";
				};
            };
        };
    }
    
    var selects = form.getElementsByTagName("select");
    for (i=0; i<selects.length; i++) {
        if (selects[i].title == "required") {
            if (selects[i].value == "") {
                //alert("Please complete all fields.");
                selects[i].style.borderColor = "red";
                if (!setfocus) {
                    selects[i].focus();
                    setfocus = 1;
                };
                //return false;
                error = 1;
            } else {
				
                selects[i].style.borderColor = "";
            };
        };
    }
    
    var textareas = form.getElementsByTagName("textarea");
    for (i=0; i<textareas.length; i++) {
        if (textareas[i].title == "required") {
            if (textareas[i].value == "") {
                //alert("Please complete all fields.");
                textareas[i].style.borderColor = "red";
                if (!setfocus) {
                    textareas[i].focus();
                    setfocus = 1;
                };
                //return false;
                error = 1;
            } else {
                textareas[i].style.borderColor = "";
            };
        };
    }
    
    if (error == 1) {
		alert("Required fields have been left blank.");
		return false;
	} else if (error == 2) {
		alert("An email address is of incorrect format.");
		return false;
	} else {
	    return true;
	};
    
}

//FLASH DETECTION
//---------------

var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";

if (navigator.plugins && navigator.plugins.length)
{
	x = navigator.plugins["Shockwave Flash"];
	if (x)
	{
		flashinstalled = 2;
		if (x.description)
		{
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else
		flashinstalled = 1;
	if (navigator.plugins["Shockwave Flash 2.0"])
	{
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin)
		flashinstalled = 2;
	else
		flashinstalled = 1;
}
else
	MSDetect = "true";
