//RP - 2004
function ltrim(s) { return s.replace( /^\s*/, "" ); }
function rtrim(s) { return s.replace( /\s*$/, "" ); }
function trim(s) { return rtrim(ltrim(s)); }
function isBlank(s) { if(trim(s)=="")return true; }
function putCursor(obj) { if(window.focus)obj.focus(); }
function putSelection(obj) { putCursor(obj); if(window.select)obj.select(); }

function isSelected(field,indx) {
    if(field.selectedIndex < indx)	{
		return false;	
	}	
	return true;
}

function isEmpty(field,label) {
	if(isBlank(field.value)) {
		alert(label + " cannot be left blank");
		field.value='';
		putCursor(field);
		return true;
	}
	return false;
}

function isEmail(e) {
	email=e.value;

	//check if email field is blank
	if(isEmpty(e, "Email Address")) {
		return false;
	}
	//make sure the field has an '@' and a '.'
	if(email.indexOf('@')==-1 || email.indexOf('.')==-1) {
		alert("Please supply a valid email address");
		putSelection(e);
		return false;
	}
	//then make sure the '@' is before the last occurence of the '.'
	if (email.indexOf('@') > email.lastIndexOf('.')) {
		alert("Please supply a valid email address");
		putSelection(e);
		return false;
	}
	// make sure there's at least one char before the '@' symbol
	if (email.indexOf('@') < 1) {
		alert("Please supply a valid email address");
		putSelection(e);
		return false;
	}
	// check if there's at least 2 chars between the '@' and the '.'
	if ((email.lastIndexOf('.') - email.indexOf('@')) < 3) {
		alert("Please supply a valid email address");
		putSelection(e);
		return false;
	}
	// and make sure there are at least 2 chars between the '.' and the end
	if ((email.length - email.lastIndexOf('.')) < 3) {
		alert("Please supply a valid email address");
		putSelection(e);
		return false;
	}
	return true;
}

function checkedRadio(set) {
	checked=false;
	for(var n=0; n<set.length; n++) {
		if(set[n].checked) {
			checked=true;
			break;
		}
	}
	return checked;
}

//RP - 2004
function pop(file,w,h) {
	aston=window.open(file,'aston','width='+w+',height='+h+',status=no,scrollbars=yes,toolbar=no,menubar=no,resizable=yes');
	if(aston.focus)aston.focus();
}

// creates a pop up window for the floorplans
fpwin = new Object;
fpwin.closed = true;
function launchFP(file,t,w,h){
	var url = "media\/" + file;
	var closeButton = "media\/close_window2.gif";
	var winName = t;
	var winWidth = w + 50;
	var winHeight = h + 40;
	var winFeatures = "top=0,status=no,scrollbars=yes,toolbar=no,menubar=no,resizable=yes,width="+winWidth+",height="+winHeight;
	var closebutton = "media\/close_window2.gif";
	if (!fpwin.closed){
		fpwin.close();
	}
	fpwin = window.open("", winName, winFeatures);
	with(fpwin.document) {
		write("<html><head><title>");
		write(winName);
		write("</title>");
		writeln("</head><body>");
		writeln("<img src="+url+" width="+w+" height="+h+" >");
		write("<a href=\"#\" onclick=\"self.close()\">");
		write("<img src="+closeButton+" width=\"114\" height=\"13\" >");
		writeln("</a>");
		writeln("</body></html>");
		close();
	}
	if(fpwin.focus)fpwin.focus();
}