/* $Id: common.js,v 1.1 2002/10/02 18:49:42 shaggy Exp $ */

/*
Copyright (c) 2001, 2002 by Martin Tsachev. All rights reserved.
http://www.mtweb.org

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the conditions available at
http://www.opensource.org/licenses/bsd-license.html
are met.
*/

if (self.location != top.location) {
	document.write('<p>Reloading mtWeb in top frame in 3 seconds...</p>');
	setTimeout('top.location.href = self.location.href', 3000);
}

function validateString(str, warning, min, max) {
	if (!min) { min = 1; }
	if (!max) {	max = 65535; }

	if (!str.value || str.value.length < min || str.value.length > max) {
		alert(unescape(warning));
		str.focus();
		str.select();
		return false;
	}
	return true;
}


function validateEmail(email) {
	if (!email.value) {
		return true;
	}

	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email.value)) {
		alert('Incorrect email address');
		email.focus();
		email.select();
		return false;
	}
	return true;
}

function validateMatch(var1, var2, msg) {
	if (var1.value != var2.value) {
		alert(unescape(msg));
		var1.focus();
		var1.select();
		return false;
	}
	return true;
}