

function validateChatLoginInfo() {
	if(document.chatLoginForm.emailAddress.value=='') {
		alert('Email Address must be completed!');
		document.chatLoginForm.emailAddress.focus();
	}
	else if(validateAddress(document.chatLoginForm.emailAddress.value)==false) {
		alert("Email address format incorrect!");
		document.chatLoginForm.emailAddress.focus();
	}
	else if(document.chatLoginForm.password.value=='') {
		alert('Password must be completed');
		document.chatLoginForm.password.focus();
	}
	else {
		document.chatLoginForm.submit();
	}	
}

function validateRequestPassword() {
	if(document.chatEmailPasswordForm.emailAddress.value=='') {
		alert('Email Address must be completed!');
		document.chatEmailPasswordForm.emailAddress.focus();
	}
	else if(validateAddress(document.chatLoginForm.emailAddress.value)==false) {
		alert("Email address format incorrect!");
		document.chatEmailPasswordForm.emailAddress.focus();
	}
	else {
		document.chatEmailPasswordForm.submit();
	}
}

function validateChatRegInfo() {
	if(document.chatRegForm.emailAddress.value=='') {
		alert('Email Address must be completed!');
		document.chatRegForm.emailAddress.focus();
	}
	else if(validateAddress(document.chatRegForm.emailAddress.value)==false) {
		alert("Email address format incorrect!");
		document.chatRegForm.emailAddress.focus();
	}
	else if(document.chatRegForm.password.value=='') {
		alert('Password must be completed');
		document.chatRegForm.password.focus();
	}
	else if(checkPasswordSize(document.chatRegForm.password.value)==false) {
		alert('Password must be at least 5 characters.');
		document.chatRegForm.password.focus();
	}
	else if(document.chatRegForm.passwordV.value=='') {
		alert('Password(Verify) must be completed');
		document.chatRegForm.passwordV.focus();
	}
	else if(checkPasswordSize(document.chatRegForm.passwordV.value)==false) {
		alert('Password (verify) must be at least 5 characters.');
		document.chatRegForm.passwordV.focus();
	}
	else if(document.chatRegForm.passwordV.value!=document.chatRegForm.password.value) {
		alert('Password and Password(Verify) must be the same');
		document.chatRegForm.password.focus();
	}
	else if(document.chatRegForm.firstName.value=='') {
		alert('First Name must be completed');
		document.chatRegForm.firstName.focus();
	}
	else if(document.chatRegForm.lastName.value=='') {
		alert('Last Name must be completed');
		document.chatRegForm.lastName.focus();
	}
	else if(document.chatRegForm.chatName.value=='') {
		alert('Chat Name must be completed');
		document.chatRegForm.chatName.focus();
	}
	else if(document.chatRegForm.aboutYourself.value=='') {
		alert('About Yourself must be completed');
		document.chatRegForm.aboutYourself.focus();
	}
	else if(document.chatRegForm.acceptterms.checked!=true) {
		alert('You must agree to the Terms of Service!');
		document.chatRegForm.acceptterms.focus();
	}
	else if(document.chatRegForm.regNumber.value=='') {
		alert('Validation Number must be completed.');
		document.chatRegForm.regNumber.focus();
	}
	else {
		document.chatRegForm.submit();
	}	
}


function validateChatUpdateInfo() {
	if(document.chatRegForm.emailAddress.value=='') {
		alert('Email Address must be completed!');
		document.chatRegForm.emailAddress.focus();
	}
	else if(validateAddress(document.chatRegForm.emailAddress.value)==false) {
		alert("Email address format incorrect!");
		document.chatRegForm.emailAddress.focus();
	}
	else if(document.chatRegForm.password.value=='') {
		alert('Password must be completed');
		document.chatRegForm.password.focus();
	}
	else if(checkPasswordSize(document.chatRegForm.password.value)==false) {
		alert('Password must be at least 5 characters.');
		document.chatRegForm.password.focus();
	}
	else if(document.chatRegForm.passwordV.value=='') {
		alert('Password(Verify) must be completed');
		document.chatRegForm.passwordV.focus();
	}
	else if(checkPasswordSize(document.chatRegForm.passwordV.value)==false) {
		alert('Password (verify) must be at least 5 characters.');
		document.chatRegForm.passwordV.focus();
	}
	else if(document.chatRegForm.passwordV.value!=document.chatRegForm.password.value) {
		alert('Password and Password(Verify) must be the same');
		document.chatRegForm.password.focus();
	}
	else if(document.chatRegForm.firstName.value=='') {
		alert('First Name must be completed');
		document.chatRegForm.firstName.focus();
	}
	else if(document.chatRegForm.lastName.value=='') {
		alert('Last Name must be completed');
		document.chatRegForm.lastName.focus();
	}
	else if(document.chatRegForm.chatName.value=='') {
		alert('Chat Name must be completed');
		document.chatRegForm.chatName.focus();
	}
	else if(document.chatRegForm.aboutYourself.value=='') {
		alert('About Yourself must be completed');
		document.chatRegForm.aboutYourself.focus();
	}
	else {
		document.chatRegForm.submit();
	}	
}



function checkPasswordSize(incoming) {
	var pw=incoming;
	if(pw.length>=5) { 
		return true;
	}
	else {
		return false;
	}
}
	
function validateAddress(incoming) {
	var emailstring = incoming;
	var ampIndex = emailstring.indexOf("@");
	var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
		// find a dot in the portion of the string after the ampersand only
	var dotIndex = afterAmp.indexOf(".");
		// determine dot position in entire string (not just after amp portion)
	dotIndex = dotIndex + ampIndex + 1;
		// afterAmp will be portion of string from ampersand to dot
	afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
		// afterDot will be portion of string from dot to end of string
	var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
	var beforeAmp = emailstring.substring(0,(ampIndex));
	var email_regex = /^[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+([\.\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~])*\@(((\w+[\w\d\-]*[\w\d]\.)+(\w+[\w\d\-]*[\w\d]))|((\d{1,3}\.){3}\d{1,3}))$/;
		// index of -1 means "not found"
	if ((emailstring.indexOf("@") != "-1") &&
		(emailstring.length > 5) &&
		(afterAmp.length > 0) &&
		(beforeAmp.length > 1) &&
		(afterDot.length > 1) &&
		(email_regex.test(emailstring)) ) {
		  return true;
	} else {
			return false;
	}
	return true;
}

// start with (optional) left paren, 3 digits, optional right paren,
// a period or a hyphen or a slash, 3 more digits,
// a period or hyphen or slash,
// and 4 more digits, anchored to end of string
// minimum contents : 10 digits
		
re = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/


// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function movepic(img_name,img_src) {
	document[img_name].src=img_src;
}



