var checkOwnerOnly = 'N';
var checkVacationerOnly = 'N';
var checkWebsiteOnly = 'N';
var checkAgencyOnly = 'N';

function loginVacationer() {
	if (document.getElementById('Login_Cd').value == '') {
		alert("Please enter a login code/email");
	}
	if (document.getElementById('Login_Password').value == '') {
		alert("Please enter a password");
	}
	document.vacationerloginform.userLoginCd.value = document.getElementById('Login_Cd').value;
	document.vacationerloginform.password.value = document.getElementById('Login_Password').value;
	checkLogin(document.vacationerloginform.userLoginCd.value, document.vacationerloginform.password.value, 'V');
}

function loginOwner() {
	if (document.getElementById('Login_Cd').value == '') {
		alert("Please enter a login code/email");
	}
	if (document.getElementById('Login_Password').value == '') {
		alert("Please enter a password");
	}
	document.ownerloginform.userLoginCd.value = document.getElementById('Login_Cd').value;
	document.ownerloginform.password.value = document.getElementById('Login_Password').value;
	checkLogin(document.ownerloginform.userLoginCd.value, document.ownerloginform.password.value, 'O');
}

function loginAgency() {
	if (document.getElementById('Login_Cd').value == '') {
		alert("Please enter a login code/email");
	}
	if (document.getElementById('Login_Password').value == '') {
		alert("Please enter a password");
	}
	document.agencyloginform.userLoginCd.value = document.getElementById('Login_Cd').value;
	document.agencyloginform.password.value = document.getElementById('Login_Password').value;
	checkLogin(document.agencyloginform.userLoginCd.value, document.agencyloginform.password.value, 'A');
}

function loginWebsite() {
	if (document.getElementById('Login_Cd').value == '') {
		alert("Please enter a login code/email");
	}
	if (document.getElementById('Login_Password').value == '') {
		alert("Please enter a password");
	}
	document.websiteloginform.userLoginCd.value = document.getElementById('Login_Cd').value;
	document.websiteloginform.password.value = document.getElementById('Login_Password').value;
	checkLogin(document.websiteloginform.userLoginCd.value, document.websiteloginform.password.value, 'W');
}

function checkLoginCode(loginCode) {
	try {websiteCheckLoginCode(ivsPortal, ivsSessionId, ivsType, ivsAgencyId, bcrSecurityKey, loginCode, '');} catch(e) {alert(e);}
	var HTMLCode="<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=center colspan=3><TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=center><BR />Please Wait While We Try To Find Your Login Information.....<BR /><BR /></TD></TR></TABLE></TD></TR></TABLE>";
	if (document.getElementById('loginfields')) {document.getElementById('loginfields').innerHTML = HTMLCode;}
	HTMLCode="";
	if (document.getElementById('namefields')) {document.getElementById('namefields').innerHTML = HTMLCode;}
	if (document.getElementById('choosefields')) {document.getElementById('choosefields').innerHTML = HTMLCode;}
	if (document.getElementById('buttonfields')) {document.getElementById('buttonfields').innerHTML = HTMLCode;}
}

function checkLoginCodeReturn(returnCode, name, age, first, last, telNbr, vacationerFl, websiteFl, agencyFl, ownerFl) {
	// Return from websiteCheckLoginCode call
	if (checkOwnerOnly == 'Y') {checkOwnerLoginCodeReturn(returnCode, name, ownerFl); return;}
	if (checkVacationerOnly == 'Y') {checkVacationerLoginCodeReturn(returnCode, name, vacationerFl); return;}
	if (checkWebsiteOnly == 'Y') {checkWebsiteLoginCodeReturn(returnCode, name, websiteFl); return;}
	if (checkAgencyOnly == 'Y') {checkAgencyLoginCodeReturn(returnCode, name, agencyFl); return;}

	var messageHTMLCode = '';
	var loginHTMLCode = '';
	var nameHTMLCode = '';
	var buttonsHTMLCode = '';
	var chooseHTMLCode = '';
	var logins = 0;
	if (vacationerFl == 'Y') {logins++;}
	if (websiteFl == 'Y') {logins++;}
	if (agencyFl == 'Y') {logins++;}
	if (ownerFl == 'Y') {logins++;}
	if (returnCode == 0) {
		// Found login.  Ask for password and details
		messageHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=center><font size=4><b>Welcome Back " + name + "!<br />Please enter your password below and then click the login link.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=left>Your Password&nbsp;<font color='#FF0000'>*</font><br /><Input Type=Password Size=30 Maxlength=25 id=Login_Password Name=Login_Password value='' >&nbsp;&nbsp&nbsp;</TD></TR></TABLE>";
		if (logins > 1) {
			chooseHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=center><b>The email address entered is valid for more than one portal.  After you enter your password please select the portal you wish to login to by clicking on the link below.</b></TD></TR></TABLE>";
		}
		else {
			chooseHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=center><b>After you enter your password please click on the link below to login.</b></TD></TR></TABLE>";
		}
		buttonsHTMLCode = "<TABLE cellspacing=0 align=center border=0><TR>";
		if (vacationerFl == 'Y') {
			buttonsHTMLCode = buttonsHTMLCode + "<td align=center><a href='javascript:void(0)' onclick=loginVacationer(); target=vacationer>Vacationer Portal</a><br />( <a href='http://www.integratedvacationsystems.com/cgi-bin/IVS/vacationer/presentforgottenlogin.pl?agencyId=" + ivsAgencyId + "&userLoginCd=" + document.getElementById('Login_Cd').value + "' target=vacationer>forgotten password</a> )</td><td><img src=images/spacer.gif width=20 height=10></td>";
		}
		if (websiteFl == 'Y') {
			buttonsHTMLCode = buttonsHTMLCode + "<td align=center><a href='javascript:void(0)' onclick=loginWebsite(); target=website>Website Portal</a><br />( <a href='http://www.integratedvacationsystems.com/cgi-bin/IVS/website/presentforgottenlogin.pl?agencyId=" + ivsAgencyId + "&userLoginCd=" + document.getElementById('Login_Cd').value + "' target=website>forgotten password</a> )</td ><td><img src=images/spacer.gif width=20 height=10></td>";
		}
		if (agencyFl == 'Y') {
			buttonsHTMLCode = buttonsHTMLCode + "<td align=center><a href='javascript:void(0)' onclick=loginAgency(); target=agency>Agency Portal</a><br />( <a href='http://www.integratedvacationsystems.com/cgi-bin/IVS/agency/presentforgottenlogin.pl?agencyId=" + ivsAgencyId + "&userLoginCd=" + document.getElementById('Login_Cd').value + "' target=agency>forgotten password</a> )</td ><td><img src=images/spacer.gif width=20 height=10></td>";
		}
		if (ownerFl == 'Y') {
			buttonsHTMLCode = buttonsHTMLCode + "<td align=center><a href='javascript:void(0)' onclick=loginOwner(); target=owner>Owner Portal</a><br />( <a href='http://www.integratedvacationsystems.com/cgi-bin/IVS/owner/presentforgottenlogin.pl?agencyId=" + ivsAgencyId + "&userLoginCd=" + document.getElementById('Login_Cd').value + "' target=owner>forgotten password</a> )</td ><td><img src=images/spacer.gif width=20 height=10></td>";
		}
		buttonsHTMLCode = buttonsHTMLCode + "</TR></TABLE>";		

		if (document.getElementById('message')) {document.getElementById('message').innerHTML = messageHTMLCode;}
		if (document.getElementById('loginfields')) {document.getElementById('loginfields').innerHTML = loginHTMLCode;}
		if (document.getElementById('choosefields')) {document.getElementById('choosefields').innerHTML = chooseHTMLCode;}
		if (document.getElementById('buttonfields')) {document.getElementById('buttonfields').innerHTML = buttonsHTMLCode;}
		document.getElementById('Login_Password').focus();
	}
	else {
		// Didn't find person.  Ask for repeat fields.
		messageHTMLCode = "<TABLE cellspacing=0 cellpadding=0 border=0 align=center><TR><TD><font color='#FF0000'><br /><br /><b>This email address was not found on our system.  Please check that it is correct.  If you are not currently a member please click the Sign-Up link in the top right hand corner of the screen to set up an account.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "";
		if (document.getElementById('message')) {document.getElementById('message').innerHTML = messageHTMLCode;}
		if (document.getElementById('loginfields')) {document.getElementById('loginfields').innerHTML = loginHTMLCode;}
		if (document.getElementById('choosefields')) {document.getElementById('choosefields').innerHTML = chooseHTMLCode;}
		if (document.getElementById('buttonfields')) {document.getElementById('buttonfields').innerHTML = buttonsHTMLCode;}
		document.loginform.Login_Cd.focus();
	}
}

function checkLogin(loginCd, loginPassword, type) {
	websiteCheckLogin(ivsPortal, ivsSessionId, ivsType, ivsAgencyId, bcrSecurityKey, loginCd, loginPassword, type);
}

function checkLoginReturn(returnCode, type) {
	if (returnCode == 0) {
		// Login good.  Log the user in
		if (type == 'V') {
			document.vacationerloginform.submit();
		}
		if (type == 'O') {
			document.ownerloginform.submit();
		}
		if (type == 'A') {
			document.agencyloginform.submit();
		}
		if (type == 'W') {
			document.websiteloginform.submit();
		}
	}
	else {
		// Invalid login.
		messageHTMLCode = "<TABLE cellspacing=0 cellpadding=0 border=0 align=center><TR><TD><font color='#FF0000'><b>This email address/password combination was not found on our system.  Please check that it is correct.</b></font></TD></TR></TABLE>";
		if (document.getElementById('message')) {document.getElementById('message').innerHTML = messageHTMLCode;}
	}
}

function checkOwnerLoginCode(loginCode) {
	checkOwnerOnly = 'Y';
	checkLoginCode(loginCode);
}

function checkOwnerLoginCodeReturn(returnCode, name, ownerFl) {
	// Return from websiteCheckLoginCode call
	var messageHTMLCode = '';
	var loginHTMLCode = '';
	var nameHTMLCode = '';
	var buttonsHTMLCode = '';
	if (returnCode == 0 && ownerFl == 'Y') {
		// Found login.  Ask for password and details
		messageHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=center><font size=4><b>Welcome Back " + name + "!<br />Please enter your password below and then click the login link.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=left>Your Password&nbsp;<font color='#FF0000'>*</font><br /><Input Type=Password Size=30 Maxlength=25 id=Login_Password Name=Login_Password value='' >&nbsp;&nbsp&nbsp;</TD></TR></TABLE>";
		buttonsHTMLCode = "<TABLE cellspacing=0 align=center border=0><TR>";
		buttonsHTMLCode = buttonsHTMLCode + "<td align=center><a href='javascript:void(0)' onclick=loginOwner(); target=owner>Owner Portal</a><br />( <a href='http://www.integratedvacationsystems.com/cgi-bin/IVS/owner/presentforgottenlogin.pl?agencyId=" + ivsAgencyId + "&userLoginCd=" + document.getElementById('Login_Cd').value + "' target=owner>forgotten password</a> )</td ><td><img src=images/spacer.gif width=20 height=10></td>";
		buttonsHTMLCode = buttonsHTMLCode + "</TR></TABLE>";

		if (document.getElementById('message')) {document.getElementById('message').innerHTML = messageHTMLCode;}
		if (document.getElementById('loginfields')) {document.getElementById('loginfields').innerHTML = loginHTMLCode;}
		if (document.getElementById('buttonfields')) {document.getElementById('buttonfields').innerHTML = buttonsHTMLCode;}
		document.getElementById('Login_Password').focus();
	}
	else {
		// Didn't find person as owner.  Ask for repeat fields.
		messageHTMLCode = "<TABLE cellspacing=0 cellpadding=0 border=0 align=center><TR><TD><font color='#FF0000'><b>This email address was not found on our system.  Please check that it is correct.  If you are not currently a member please use one of the links below to set-up an account.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "";
		messageHTMLCode = "<TABLE cellspacing=0 cellpadding=0 border=0 align=center><TR><TD><font color='#FF0000'><br /><br /><b>This email address was not found on our system.  Please check that it is correct.  If you are not currently a member please click the Sign-Up link in the top right hand corner of the screen to set up an account.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "";
		if (document.getElementById('message')) {document.getElementById('message').innerHTML = messageHTMLCode;}
		if (document.getElementById('loginfields')) {document.getElementById('loginfields').innerHTML = loginHTMLCode;}
		if (document.getElementById('buttonfields')) {document.getElementById('buttonfields').innerHTML = buttonsHTMLCode;}
		document.loginform.Login_Cd.focus();
	}
}

function checkVacationerLoginCode(loginCode) {
	checkVacationerOnly = 'Y';
	checkLoginCode(loginCode);
}

function checkVacationerLoginCodeReturn(returnCode, name, vacationerFl) {
// Return from websiteCheckLoginCode call
	var messageHTMLCode = '';
	var loginHTMLCode = '';
	var nameHTMLCode = '';
	var buttonsHTMLCode = '';
	if (returnCode == 0 && vacationerFl == 'Y') {
		// Found login.  Ask for password and details
		messageHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=center><font size=4><b>Welcome Back " + name + "!<br />Please enter your password below and then click the login link.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=left>Your Password&nbsp;<font color='#FF0000'>*</font><br /><Input Type=Password Size=30 Maxlength=25 id=Login_Password Name=Login_Password value='' >&nbsp;&nbsp&nbsp;</TD></TR></TABLE>";
		buttonsHTMLCode = "<TABLE cellspacing=0 align=center border=0><TR>";
		buttonsHTMLCode = buttonsHTMLCode + "<td align=center><a href='javascript:void(0)' onclick=loginVacationer(); target=vacationer>Vacationer Portal</a><br />( <a href='http://www.integratedvacationsystems.com/cgi-bin/IVS/vacationer/presentforgottenlogin.pl?agencyId=" + ivsAgencyId + "&userLoginCd=" + document.getElementById('Login_Cd').value + "' target=vacationer>forgotten password</a> )</td><td><img src=images/spacer.gif width=20 height=10></td>";
		buttonsHTMLCode = buttonsHTMLCode + "</TR></TABLE>";

		if (document.getElementById('message')) {document.getElementById('message').innerHTML = messageHTMLCode;}
		if (document.getElementById('loginfields')) {document.getElementById('loginfields').innerHTML = loginHTMLCode;}
		if (document.getElementById('buttonfields')) {document.getElementById('buttonfields').innerHTML = buttonsHTMLCode;}
		document.getElementById('Login_Password').focus();
	}
	else {
		// Didn't find person as owner.  Ask for repeat fields.
		messageHTMLCode = "<TABLE cellspacing=0 cellpadding=0 border=0 align=center><TR><TD><font color='#FF0000'><b>This email address was not found on our system.  Please check that it is correct.  If you are not currently a member please use one of the links below to set-up an account.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "";
		buttonsHTMLCode = "<TABLE cellspacing=0 align=center border=0><TR>";
		buttonsHTMLCode = buttonsHTMLCode + "<td align=center><a href='vacationer_signup.html' target=vacationer><img src=images/signupnoww.gif></a><br /></td><td><img src=images/spacer.gif width=50 height=10></td>";
		buttonsHTMLCode = buttonsHTMLCode + "</TR></TABLE>";
		if (document.getElementById('message')) {document.getElementById('message').innerHTML = messageHTMLCode;}
		if (document.getElementById('loginfields')) {document.getElementById('loginfields').innerHTML = loginHTMLCode;}
		if (document.getElementById('buttonfields')) {document.getElementById('buttonfields').innerHTML = buttonsHTMLCode;}
		document.loginform.Login_Cd.focus();
	}
}

function checkAgencyLoginCode(loginCode) {
	checkAgencyOnly = 'Y';
	checkLoginCode(loginCode);
}

function checkAgencyLoginCodeReturn(returnCode, name, agencyFl) {
	// Return from websiteCheckLoginCode call
	var messageHTMLCode = '';
	var loginHTMLCode = '';
	var nameHTMLCode = '';
	var buttonsHTMLCode = '';
	if (returnCode == 0 && agencyFl == 'Y') {
		// Found login.  Ask for password and details
		messageHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=center><font size=4><b>Welcome Back " + name + "!<br />Please enter your password below and then click the login link.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "<TABLE width=100% cellspacing=0 cellpadding=0 border=0 align=center><TR><TD align=left>Your Password&nbsp;<font color='#FF0000'>*</font><br /><Input Type=Password Size=30 Maxlength=25 id=Login_Password Name=Login_Password value='' >&nbsp;&nbsp&nbsp;</TD></TR></TABLE>";
		buttonsHTMLCode = "<TABLE cellspacing=0 align=center border=0><TR>";
		buttonsHTMLCode = buttonsHTMLCode + "<td align=center><a href='javascript:void(0)' onclick=loginAgency(); target=agency>Agency Portal</a><br />( <a href='http://www.integratedvacationsystems.com/cgi-bin/IVS/agency/presentforgottenlogin.pl?agencyId=" + ivsAgencyId + "&userLoginCd=" + document.getElementById('Login_Cd').value + "' target=agency>forgotten password</a> )</td ><td><img src=images/spacer.gif width=20 height=10></td>";
		buttonsHTMLCode = buttonsHTMLCode + "</TR></TABLE>";		

		if (document.getElementById('message')) {document.getElementById('message').innerHTML = messageHTMLCode;}
		if (document.getElementById('loginfields')) {document.getElementById('loginfields').innerHTML = loginHTMLCode;}
		if (document.getElementById('buttonfields')) {document.getElementById('buttonfields').innerHTML = buttonsHTMLCode;}
		document.getElementById('Login_Password').focus();
	}
	else {
		// Didn't find person.  Ask for repeat fields.
		messageHTMLCode = "<TABLE cellspacing=0 cellpadding=0 border=0 align=center><TR><TD><font color='#FF0000'><b>This email address was not found on our system.  Please check that it is correct.  If you are not currently a member please use one of the links below to set-up an account.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "";
		messageHTMLCode = "<TABLE cellspacing=0 cellpadding=0 border=0 align=center><TR><TD><font color='#FF0000'><br /><br /><b>This email address was not found on our system.  Please check that it is correct.  If you are not currently a member please click the Sign-Up link in the top right hand corner of the screen to set up an account.</b></font></TD></TR></TABLE>";
		loginHTMLCode = "";
		if (document.getElementById('message')) {document.getElementById('message').innerHTML = messageHTMLCode;}
		if (document.getElementById('loginfields')) {document.getElementById('loginfields').innerHTML = loginHTMLCode;}
		if (document.getElementById('buttonfields')) {document.getElementById('buttonfields').innerHTML = buttonsHTMLCode;}
		document.loginform.Login_Cd.focus();
	}
}

