// JavaScript Document

/* auxillary functions */

var isIE = ((navigator.appName.indexOf("Microsoft") != -1) ? true:false);

function preloadImages(){
	var img_path = "img/";
	imageObj = new Image();
	for ( i=0; i<=arguments.length-1; i++ ){
		var img_src = img_path + arguments[i];
		imageObj.src= img_src;
		//alert(img_src);
	}
}

function isValidEmail(email)
{
	var AtPos = email.indexOf("@")
	var StopPos = email.lastIndexOf(".")
	var validemail = true;

	if (email == "")
		validemail = false;

	if (AtPos == -1 || StopPos == -1)
		validemail = false;

	if (StopPos < AtPos)
		validemail = false;

	if (StopPos - AtPos == 1)
		validemail = false;

	return validemail;
}


function logmein()
{
	var email = document.theForm["email"].value;
	var regemail = document.theForm["regemail"].value;
	
	if(!document.theForm["disclosure"].checked)
	{
		alert("Please confirm that you have read the disclosures and important information on this page before signing in. Please scroll down if you cannot see this information.");
		return;
	}
	
	document.theForm["meetingid"].value = meetingid;
	document.theForm["mct"].value = mct;
	
	document.theForm3["meetingid"].value = meetingid;
	document.theForm3["mct"].value = mct;
	
	if(!isValidEmail(email) && !isValidEmail(regemail))
		alert("Please enter your email address");
	else
	{
		if(isValidEmail(email))
		{
			if((document.theForm["password"].value.length > 1) && (document.theForm["password"].value != "Password"))
				document.theForm.submit();
			else
				alert("Please enter your password");
		}
		else
		{
			document.theForm3["email"].value = regemail;
			document.theForm3.submit();
		}
	}
}

function logmein2()
{
	var email = document.theForm2["email"].value;
	var regemail = document.theForm2["regemail"].value;
	if(!isValidEmail(email) && !isValidEmail(regemail))
		alert("Please enter your email address");
	else
	{
		if(isValidEmail(email))
		{
			if((document.theForm2["password"].value.length > 1) && (document.theForm2["password"].value != "Password"))
				document.theForm2.submit();
			else
				alert("Please enter your password");
		}
		else
		{
			document.theForm3["email"].value = regemail;
			document.theForm3.submit();
		}
	}
}

function setMettingId(meeting_id) {
	document.theForm2["meetingid"].value = meeting_id;
	document.theForm3["meetingid"].value = meeting_id;
}

function registerme()
{
	var email = document.theForm["email"].value;
	if(!isValidEmail(email))
		alert("Please enter your email address");
	else
	{
		document.theForm3["email"].value = email;
		document.theForm3.submit();
	}
}

function registerme2()
{
	var email = document.theForm2["email"].value;
	if(!isValidEmail(email))
		alert("Please enter your email address");
	else
	{
		document.theForm3["email"].value = email;
		document.theForm3.submit();
	}
}

function inputFocus(fieldObj)
{
	if (fieldObj.id=='password' || fieldObj.id=='password_txt') {
		if(!isIE)
			fieldObj.setAttribute('type','password');
	}
	fieldObj.value = '';
	fieldObj.focus();
}

function inputBlur(fieldObj)
{
	var mid = fieldObj.id;
	if (fieldObj.value=='') {
		if (fieldObj.id=='password'|| fieldObj.id=="password_txt") {
			//changeInputType(mid, 'text');
			
			if(!isIE)
				fieldObj.setAttribute('type','text');

			fieldObj = document.getElementById(mid);
			fieldObj.value = "Password";
		}
		else {
			fieldObj.value = "Enter email";
		}
	}
}

function clearfield(thefield)
{
	document.theForm[thefield].value = "Enter email";
}

function clearfield2(thefield)
{
	document.theForm2[thefield].value = "Enter email";
}

function changeInputType(objID, oType)
{
	var oldObject = document.getElementById(objID);
	var newObject = document.createElement('input');
	newObject.type = oType;
	if(oldObject.value) newObject.value = oldObject.value;
	if(oldObject.size) newObject.size = oldObject.size;
	if(oldObject.name) newObject.name = oldObject.name;
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.onfocus) newObject.onfocus = oldObject.onfocus;
	if(oldObject.onblur) newObject.onblur = oldObject.onblur;
	if(oldObject.className) newObject.className = oldObject.className;
	oldObject.parentNode.replaceChild(newObject,oldObject);
	return;
}

function goToVideoPage() {
	if(!document.theForm["disclosure"].checked) {
		alert('Please confirm that you have read the disclosures and important information on this page before playing the video. Please scroll down if you cannot see this information.');
	} else {
		window.location="mc_2009_qol_video.html"
	}
}