
var pixels_width = window.screen.width;
var pixels_height = window.screen.height;

var nWidth= "740";
var nHeight="560";

if(pixels_width < 740){
    nWidth = "540";
}
if(pixels_height < 560){
    nHeight = "300";
}

var options = "scrollbars,location,resizable,status,";
options += "height=" + nHeight + ",width=" + nWidth;
options += ",screenX=10,screenY=10,top=10,left=10";
options += "scrollbars=yes,resizable=yes,status=yes,location=no,menubar=no";

// pop-up pay window at the end of registration.
function popPay(form) {
	form.target = 'pay';
	// url = form.action;  url cannot be relative in IE or this code appears as text!
	payWindow = window.open('uploading.php','pay',options);
	if (!payWindow.opener) payWindow.opener = window;
	payWindow.focus();
	form.submit();
}

function validateComplete(formObj)
{
	var miss = '';
	if (emptyField(formObj.Name)) 		miss += "your name,\n      ";
	if (emptyField(formObj.Street))		miss += "your street and house number/name,\n      ";
	if (emptyField(formObj.Town))		miss += "your city/town,\n      ";
	if (emptyField(formObj.Postcode))	miss += "your postal code,\n      ";
	if (emptyField(formObj.DayPhone))	miss += "your day phone no.,\n      ";
	if (emptyField(formObj.NightPhone))	miss += "your evening phone no.,\n      ";
	if (emptyField(formObj.Email))		miss += "your email address,\n      ";
	if (emptyField(formObj.OccupationFather))	miss += "the father\'s occupation,\n      ";
	if (emptyField(formObj.OccupationMother))	miss += "the mother\'s occupation,\n      ";
	if (emptyField(formObj.WorkTimes))	miss += "the mother\'s work times,\n      ";
	if (emptyField(formObj.ChildName1))	miss += "each child\'s name,\n      ";
	if (emptyField(formObj.ChildAge1))	miss += "each child\'s age,\n      ";
	if (emptyField(formObj.Interests))	miss += "your interests,\n      ";
	if (emptyField(formObj.StudentTasks))	miss += "expected tasks,\n      ";
	if (emptyField(formObj.WeeklyPayment))	miss += "weekly payment,\n      ";
	if (emptyField(formObj.Reference))	miss += "a suitable reference,\n      ";
	// if (emptyField(formObj.DateFrom1) || emptyField(formObj.DateTo1))
	//					miss += "your required dates,\n      ";
	if ((checkDate('CalFrom1') > 0) || (checkDate('CalTo1') > 0))
						miss += "your required dates (click calendar image),\n      ";
	else if (compareDates(formObj.DateFrom1.value,formObj.DateTo1.value) >= 0)
						miss += "your end date precedes the start,\n      ";
	if (emptyField(formObj.PlacementPeriod))	
						miss += "period of stay,\n      ";
	if (miss != '') {
		alert("Please ensure that all required fields are completed - \ni.e. "
				+miss+
				"and a suitably sized photo (if you have one).");
		return false;
	} else {
		popPay(formObj);
		return false;  // no need to submit (again on IE!) because popPay does it explicitly!
	}
}

// Check to see if field is empty
function emptyField(textObj)
{
	if (textObj) {
		if (textObj.value.length == 0) return true;
		for (var i=0; i<textObj.value.length; ++i) {
			var ch = textObj.value.charAt(i);
			if (ch != ' ' && ch != '\t') return false;
		}
	} else  return false;
	return true;
}
