function hasValue(field) {
	return (field.value && field.value.length > 0 && field.value.substr(0,1) != ' ');
}
function chkBroker() {
	f = document.getElementById('frmBroker');
	
	
	//if (!hasValue(f.officeName)) {
	//	alert('Please enter a company name');
	//	f.officeName.focus();
	//	return false;
	//}
	if (!hasValue(f.brokerName)) {
		alert('Please enter broker name');
		f.brokerName.focus();
		return false;
	}
	var myRegxp = /[0-9a-zA-Z_]/
	if (!myRegxp.test(f.brokerURL.value)) {
		alert('Broker URL Name may only contain alphanumeric characters.  Spaces and special characters are not allowed.');
		f.brokerURL.focus();
		return false;
	}
	if (!hasValue(f.brokerContact)) {
		alert('Please enter a contact name');
		f.brokerContact.focus();
		return false;
	}
	if (!hasValue(f.brokerEmail)) {
		alert('Please enter an email address');
		f.brokerEmail.focus();
		return false;
	}
	
	return chkBroker2();
	/*
	// check that email is not already taken
	errDiv = document.getElementById('badEmail');
	errDiv.innerHTML='';
	errDiv.style.display='none';
	if(document.checkisopen) {
		document.checkisopen = false;
		if (emailChecker) {
			emailChecker.abort();
			delete emailChecker;
		}
	}
	
	var emailChecker = createXMLHttpRequest();
	if (emailChecker) {
		myURL = 'index.cfm?fuseaction=brokers.checkEmail&email='+f.brokerEmail.value;
		if (f.brokerId) {
			myURL += '&brokerId='+f.brokerId.value;
		}
		emailChecker.open("GET",myURL,true);
		document.checkisopen=true;
		emailChecker.onreadystatechange=function() {
			if (emailChecker.readyState == 4) {
				result = emailChecker.responseText;
				document.checkisopen=false;
				if(result.indexOf('OK') == -1 ) {
					errDiv.innerHTML='<span class="errorText">Invalid email address!</span>';
					errDiv.style.display='block';
					alert('That email address is already in use!');
					f.brokerEmail.focus();
					oktogo=false;
					// end OK result
				} else {
					return chkBroker2();
				}
				// end readystate 4
			}
			// end ready state function
		}
		emailChecker.send(null);
	} else {
		return chkBroker2();
	}*/
	return false;
}
function chkBroker2() {
	f = document.getElementById('frmBroker');
	if (!hasValue(f.brokerPhone)) {
	alert('Please enter a phone number');
	f.brokerPhone.focus();
	return false;
	}
	
	/*if (!hasValue(f.brokerLicense)) {
	alert('Please enter broker license');
	f.brokerLicense.focus();
	return false;
	}*/
	
	if (!hasValue(f.brokerPassword)) {
	alert('Please enter a password');
	f.brokerPassword.focus();
	return false;
	}
	
	
	/*if (!hasValue(f.address1)) {
		alert('Please enter an address');
		f.address1.focus();
		return false;
	}*/
	/*if (!hasValue(f.city)) {
		alert('Please enter a city');
		f.city.focus();
		return false;
	}*/
	/*if (!hasValue(f.zip)) {
		alert('Please enter a zip code');
		f.zip.focus();
		return false;
	}*/
	/*if (!hasValue(f.countryId)) {
		alert('Please choose a country');
		f.countryId.focus();
		return false;
	}*/
	/*if (f.countryId.value == 1) {
		if (!hasValue(f.stateId)) {
			alert('Please choose a state');
			f.stateId.focus();
			return false;
		}
	}*/
	/*if (!hasValue(f.localPhone)) {
		alert('Please enter an office phone number');
		f.packageId.focus();
		return false;
	}*/
	
	if (!f.termsAgreement.checked) {
		alert('You must agree to the terms and conditions before proceeding');
		return false;
	}
	
	f.submit();
	return true;
}

function chkBroker3 () {
	f = document.getElementById('frmBroker');
	if (!f) f = document.getElementById('frmBrokerCC');
	if (!f) return true;
		if (f.packageId && !hasValue(f.packageId)) {
			alert('Please choose a package');
			f.packageId.focus();
			return false;
		}
		if (f.ccName && !hasValue(f.ccName)) {
			alert('Please enter name on credit card');
			f.ccName.focus();
			return false;
		}
		if (f.ccNumber && !hasValue(f.ccNumber)) {
			alert('Please enter a credit card number');
			f.ccNumber.focus();
			return false;
		}
		if (f.ccCVV && !hasValue(f.ccCVV)) {
			alert('Please enter a credit card security code');
			f.ccCVV.focus();
			return false;
		}
		if (f.ccExpMonth && !hasValue(f.ccExpMonth)) {
			alert('Please choose an expiration month');
			f.ccExpMonth.focus();
			return false;
		}
		if (f.ccExpYear && !hasValue(f.ccExpYear)) {
			alert('Please choose an expiration year');
			f.ccExpYear.focus();
			return false;
		}
		if (f.ccAddress && !hasValue(f.ccAddress)) {
			alert('Please enter an address for credit card');
			f.ccAddress.focus();
			return false;
		}
		if (f.ccCity && !hasValue(f.ccCity)) {
			alert('Please enter a city for credit card');
			f.ccCity.focus();
			return false;
		}
		if (f.ccStateId && !hasValue(f.ccStateId)) {
			alert('Please choose a state for credit card');
			f.ccStateId.focus();
			return false;
		}
		if (f.ccZip && !hasValue(f.ccZip)) {
			alert('Please enter a zip code for credit card');
			f.ccZip.focus();
			return false;
		}
	
}

function chkPostAd () {
	f = document.getElementById('frmBroker');
	
	if (!hasValue(f.brokerContact)) {
		alert('Please enter a contact name');
		f.brokerContact.focus();
		return false;
	}
	
	if (!hasValue(f.brokerEmail)) {
		alert('Please enter an email address');
		f.brokerEmail.focus();
		return false;
	}
	
	if (!hasValue(f.brokerPhone)) {
	alert('Please enter a phone number');
	f.brokerPhone.focus();
	return false;
	}
	
	if (!hasValue(f.brokerPassword)) {
	alert('Please enter a password');
	f.brokerPassword.focus();
	return false;
	}
}

function showHideUpload() {
	o = document.getElementById('fileUpload');
	if (o.style.visibility == 'hidden') {
		showUpload();
	}
	else {
		hideUpload();
	}
}
function showUpload() {
	o = document.getElementById('fileUpload');
	myURL='index.cfm?fuseaction=brokers.uploadphoto';
	o.src=myURL;
	o.height=60;
	o.style.height='60px';
	o.style.visibility = '';
	
}
function hideUpload() {
	o = document.getElementById('fileUpload');
	o.style.visibility = 'hidden';
	o.height=1;
	o.style.height='1px';
}
function deleteImg() {
	f = document.getElementById('frmBroker');
	if (f.brokerPhoto.value.length > 0) {
		f.brokerPhoto.value='';
		i = document.getElementById('brokerImg')
		i.src = '';
		alert('Photo deleted successfully');
		showUpload();
	} else {
		alert('No photo to delete');
	}
}
function chgImg(path) {
	f = document.getElementById('frmBroker');
	f.brokerPhoto.value=path;
	i = document.getElementById('brokerImg')
	i.src = path;
	hideUpload();
}

function sortit(what) {
	document.frmListBrokers.sortorder.value=what;
	document.frmListBrokers.submit();
}
