// JavaScript Document

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 isPhone(str) {
	var phone2 = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/; 
	if (str.match(phone2)) {
   		return true;
 	} else {
 		return false;
 	}
}

function validate_contactForm(frm) {
  var value = '';
  var _qfMsg = '';
  
  value = frm.elements['cname'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your name\t';
  }
  value = frm.elements['email'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your email address\t';
  } else {
	  fd = frm.elements['email'];
	  if (fd) {
		  value = fd.value;
		  if ( value != '' && !isEmail(value) ) {
			_qfMsg = _qfMsg + '\n - Incorrect email address\t';
		  }
	  }
  }
  value = frm.elements['subject'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your subject\t';
  }
  value = frm.elements['message'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your message\t';
  }
  if (_qfMsg != '') {
    _qfMsg = 'Invalid information entered.\n' + _qfMsg;
    alert(_qfMsg);
    return false;
  }
  return true;
}

function validate_careerForm(frm) {
  var value = '';
  var _qfMsg = '';
  
  value = frm.elements['m_email'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your email address\t';
  } else {
	  fd = frm.elements['m_email'];
	  if (fd) {
		  value = fd.value;
		  if ( value != '' && !isEmail(value) ) {
			_qfMsg = _qfMsg + '\n - Incorrect email address\t';
		  }
	  }
  }
  value = frm.elements['m_fname'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your first name\t';
  }
  value = frm.elements['m_lname'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your last name\t';
  }
  value = frm.elements['m_city'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your city\t';
  }
  value = frm.elements['m_zip'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your ZIP/Postal Code\t';
  }
  value = frm.elements['m_country'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Enter your country\t';
  }
  value = frm.elements['m_resume'].value;
  if (value == '') {
    _qfMsg = _qfMsg + '\n - Resume field is empty\t';
  }
  
  if (_qfMsg != '') {
    _qfMsg = 'Invalid information entered.\n' + _qfMsg;
    alert(_qfMsg);
    return false;
  }
  return true;
}

function changeProvince(frm, xindex) {
	if (xindex == 0) {
	} else if (xindex > 12) {
		frm.m_country.selectedIndex = 189;
	} else {
		frm.m_country.selectedIndex = 30;
	}
}