/**
  Tran The Anh - javascript file
**/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
		return true;
	} else {
		return false;
	}
}

function isPhoneNumber(string) {
	if (string == '') {
		return false;
	}

	for (i = 0; i < string.length; ++i) {
		switch (string.charAt(i)) {
			case ' ':
			case '+':
			case '-':
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':

			break;

			default:
				return false;
			break;
		}
	}

	return true;
}


/** Functions **/

function contactSubmit()
{
	var form = document.forms['contact'];
        form.name.value = form.name.value.trim();
        if (form.name.value == '') {
                alert('You have to enter your name');
                form.name.focus();
                return;
        }
        form.email.value = form.email.value.trim();
        if (!isEmail(form.email.value)) {
                alert('You have to enter your email address');
                form.email.focus();
                return;
        }
	/**
        form.phone.value = form.phone.value.trim();
        if (!isPhoneNumber(form.phone.value)) {
                alert('You have to enter your phone number');
                form.phone.focus();
                return;
        }
        form.address.value = form.address.value.trim();
        if (form.address.value == '') {
                alert('You have to enter your address');
                form.address.focus();
                return;
        }
	**/
        form.message.value = form.message.value.trim();
        if (form.message.value == '') {
                alert('You have to enter your message');
                form.message.focus();
                return;
        }

	form.submit();
}

function contactReset()
{
	var form = document.forms['contact'];
	form.reset();
}
