function openwindow(link)
{
window.open(link,"_blank","height=550,width=750,status=no,toolbar=no,menubar=no,location=no,resizable=yes,,scrollbars=no");
}

function confirm_delete()
{
  if (confirm("Are you sure you want to delete?")==true)
    return true;
  else
    return false;
}

function enable2ndApplicant(form)
{
	if (form.chkJoint.checked) {
		form.firstname2.disabled = false;
		form.surname2.disabled = false;
		form.chkMr2.disabled = false;
		form.chkMrs2.disabled = false;
		form.chkMs2.disabled = false;
		form.chkOther2.disabled = false;
	} else {
		form.firstname2.disabled = true;
		form.surname2.disabled = true;
		form.chkMr2.disabled = true;
		form.chkMrs2.disabled = true;
		form.chkMs2.disabled = true;
		form.chkOther2.disabled = true;
	}
}

function checkFormFields(form)
{
	foundError = false; // used at end of script to decide if to submit or not

	var formTypes //initial value is null because we gave it no other value
	formTypesErr = "";
	if (form.cubeTraderPro.checked || form.privateClientOptions.checked || form.privateClientShares.checked || form.privateClientWarrants.checked)  {
		formTypes = true;
	} 
	if (formTypes != true) {
		formTypesErr = "Please choose the forms you would like to request.\r";
		foundError = true;
	}

	surname = "";
    if(form.surname.value == "") {
        surname = "Surname\r";
        foundError = true;
    }	
	firstname = "";
    if(form.firstname.value == "") {
        firstname = "First Name\r";
        foundError = true;
    }
	address = "";
    if(form.address.value == "") {
        address = "Address\r";
        foundError = true;
    }
	suburb = "";
    if(form.suburb.value == "") {
        suburb = "Suburb\r";
        foundError = true;
    }
	state = "";
    if(form.state.value == "") {
        state = "State\r";
        foundError = true;
    }
	postcode = "";
    if(form.postcode.value == "") {
        postcode = "Postcode\r";
        foundError = true;
    }
	country = "";
    if(form.country.value == "") {
        country = "Country\r";
        foundError = true;
    }
	homephone = "";
    if(form.homephone.value == "") {
        homephone = "Home Phone\r";
        foundError = true;
    }
	workphone = "";
    if(form.workphone.value == "") {
        workphone = "Work Phone\r";
        foundError = true;
    }     
	mobilephone = "";
    if(form.mobilephone.value == "") {
        firstname = "Mobile Phone\r";
        foundError = true;
    }
	fax = "";
    if(form.fax.value == "") {
        fax = "Fax\r";
        foundError = true;
    }
	email = "";
    if(form.email.value == "") {
        email = "Email\r";
        foundError = true;
    }
	emailconfirm = "";
    if(form.emailconfirm.value == "") {
        emailconfirm = "Confirmation Email Address\r";
        foundError = true;
    }
    emailSame = "";
    if (form.email.value != form.emailconfirm.value && emailconfirm == "") {
		emailSame = "Email address and confirmation email address are not equal.";
		foundError = true;
    }
	
	if(foundError == false) {
		if (form.postalAddress.value == "") {
			form.postalAddress.value = form.address.value;
		}
		if (form.postalSuburb.value == "") {
			form.postalSuburb.value = form.suburb.value;
		}
		if (form.postalState.value == "") {
			form.postalState.value = form.state.value;
		}
		if (form.postalPostCode.value == "") {
			form.postalPostCode.value = form.postcode.value;
		}
		if (form.postalCountry.value == "") {
			form.postalCountry.value = form.country.value;
		}
		
		if (!form.chkJoint.checked) {
			form.jointAnd.value = "";
		} else {
			form.firstname2.disabled = false;
			form.surname2.disabled = false;
			form.chkMr2.disabled = false;
			form.chkMrs2.disabled = false;
			form.chkMs2.disabled = false;
			form.chkOther2.disabled = false;
		}
		
		alert ("Thankyou for your enquiry. You will be contacted shortly.")
		return true;
		// go to specific URL here.
	} else { // SELECT THE FIRST PROBLEM FIELD
		errorMessage = "The following required fields were not entered: \r" + formTypesErr+surname +firstname +address+suburb+state+postcode+country+homephone+workphone+mobilephone+fax+email+emailconfirm + emailSame;
		alert(errorMessage);
		return false;
	}
}