var d = new Date();
var dateData = new Array();

for (i=0;i<31;i++) {
	dateData[i] = new Array(0,'','','');
}

var num = 1;
var photoRow = new Array('#fff','#eee');

// Menu bar preloader
if (document.images) {
	pic1= new Image(230,30);
	pic1.src="http://www.hawkmeadowmontessori.com/images/bxRed2.png";
	pic2= new Image(230,30);
	pic2.src="http://www.hawkmeadowmontessori.com/images/bxGreen2.png";
}

function initialize() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map_canvas"),{size: new GSize(540,233)}); 
		//var map = new GMap2(document.getElementById("map_canvas"));
		var center = new GLatLng(41.679458, -73.855056)
		var marker = new GMarker(center);
		
		map.setCenter(center, 11);
		map.addOverlay(marker);
		map.addControl(new GSmallZoomControl3D());
	}
}

// Login form
function checkLogin(thisForm) {
	with (thisForm) {
		if (username.value == '') {
			alert('Invalid Username - please try again.');
			username.focus();
			return false;
		} else if (password.value == '' || password.value.length < 6) {
			alert('Invalid Password - please try again.');
			password.value = '';
			password.focus();
			return false;
		} else {
			return true;
		}
	}
}

// Email form
function checkEmail(thisForm) {
	with (thisForm) {	
		if (!eCheck(email.value)) {
			alert('Invalid Email Address - please try again.');
			email.value = '';
			email.focus();
			return false;
		} else {
			return true;
		}
	}
}

// Password reset form
function checkPass(thisForm) {
	with (thisForm) {	
		if (password1.value == '' || password1.value.length < 6 || password1.value != password2.value) {
			alert('Invalid New Password - please try again.');
			password1.value = password2.value = '';
			password1.focus();
			return false;
		} else if ((password1.value).indexOf(' ') != -1) {
			alert('Invalid New Password - please try again.');
			password1.value = password2.value = '';
			password1.focus();
			return false;
		} else {
			return true;
		}
	}
}

// Account form
function checkAccount(thisForm) {
	with (thisForm) {	
		if (firstName.value.split(' ').join('') == '') {
			alert('Invalid First Name - please try again.');
			firstName.focus();
			return false;
		} else if (lastName.value.split(' ').join('') == '') {
			alert('Invalid Last Name - please try again.');
			lastName.focus();
			return false;
		} else if (!eCheck(email.value)) {
			alert('Invalid Email Address - please try again.');
			email.focus();
			return false;
		} else {
			return true;
		}
	}
}

function eCheck(str) {

	var at = '@';
	var dot = '.';
	var dotdot = '..';
	var lat = str.indexOf(at);
	var ldot = str.indexOf(dot);
	var ldotdot = str.indexOf(dotdot);
	var lstr = str.length;

	if (lat < 1 || lat == lstr) {
		return false;
	} else if (ldot < 1 || ldot >= lstr - 2) {
		return false;
	} else if (str.indexOf(at, (lat + 1)) != -1) {
		return false;
	} else if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
		return false;
	} else if (ldotdot != -1) {
		return false;
	} else if (str.indexOf(dot, (lat + 2)) == -1) {
		return false;
	} else if (str.indexOf(' ') != -1) {
		return false;
	} else {
		return true;
	}			
}

function showHideNote(n) {
	var o = document.getElementById("note"+n);
	if (o.style.display == "inline-block") {
		o.style.display = "none";
	} else {
		o.style.display = "inline-block";
	}
}

function checkNote(thisForm) {
	var oEditor = FCKeditorAPI.GetInstance('body');
	var oDOM = oEditor.EditorDocument;
	var strFCKEditorText = "";
	if (document.all) { // If IE
		strFCKEditorText = oDOM.body.innerText;
	} else {
		var r = oDOM.createRange();
		r.selectNodeContents(oDOM.body);
		strFCKEditorText = r.toString();
	} 

	with (thisForm) {
		if (!title.value) {
			alert('You must enter a Notice Title');
			title.focus();
			return false;
		} else if (strFCKEditorText.length == 0 || (strFCKEditorText.length == 1 && strFCKEditorText.charCodeAt(0) == 160)) {
			alert('You must enter some Notice Content');
			return false;
		} else {
			return true;
		}
	}
	
}

function updateEventDate() {
	with (document.frmGallery) {
		evDate.value = gallery_year.value + '-' + gallery_month.value + '-' + gallery_day.value;
	}
}

// check gallery form
function checkGallery(thisForm) {
	with (thisForm) {
		var dd = gallery_day.value;
		var mm = gallery_month.value;
		var yy = gallery_year.value;
		
		if (!gallery_title.value) {
			alert('You must enter a Gallery Title');
			gallery_title.focus();
		} else if ((dd == 31 && (mm == 4 || mm == 6 || mm == 9 || mm == 11)) || (mm == 2 && ((dd > 28 && yy%4 != 0) || (dd > 29 && yy%4 == 0)))) {
			alert('You have selected an Invalid Date');
		} else if (document.jumpLoaderApplet.getUploader().getFileCount() == 0) {
			alert('You must upload at least 1 photo');
		} else {
			document.jumpLoaderApplet.getUploader().startUpload();
		}
	}
}

function extract(ref) {
    if (ref.indexOf('/') > -1)
        filename = ref.substring(ref.lastIndexOf('/')+1,ref.length);
    else
        filename = ref.substring(ref.lastIndexOf('\\')+1,ref.length);
    return filename;
}