function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function xml_http_request1() {
	try {
	  request1 = new XMLHttpRequest();
	} catch (e) {
	try {
	  request1 = new ActiveXObject('Msxml2.XMLHTTP');
	} catch (e) {
	try {
	  request1 = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (e) {
	  document.write('XMLHttpRequest not supported'); }
	}
	}
}
function xml_http_request_get1(xhrg_cookie) {
	// document.getElementById("msg_area").innerHTML = 'xhrg_cookie 1 = ' + xhrg_cookie;
	//document.getElementById("msg_area").innerHTML = '1';
	xml_http_request1();
	// document.getElementById("msg_area").innerHTML = 'xhrg_cookie 2 = ' + xhrg_cookie;
	//document.getElementById("msg_area").innerHTML = '2';
	request1.onreadystatechange = function() {
		// document.getElementById("msg_area").innerHTML = 'request1.readyState = ' + request1.readyState;
		//document.getElementById("msg_area").innerHTML = '3';
		if (request1.readyState == 4) {
			// document.getElementById("msg_area").innerHTML = 'request1.status = ' + request1.status;
			//document.getElementById("msg_area").innerHTML = '4';
			if (request1.status == 200) {
				// document.getElementById("msg_area").innerHTML = 'request1.responseText = ' + request1.responseText;
				//document.getElementById("msg_area").innerHTML = '5';
				var data_array = request1.responseText.split('|||');
				var first_name = data_array[1];
				var user_type = data_array[2];
				if (first_name != '' && first_name != 'ERROR' && first_name.length <= 19) {
					document.getElementById("username_label_area").innerHTML = '<th width="300" scope="col" id="corp_login" nowrap>Welcome,&nbsp;<a href="/cgi-bin/start.cgi/z.corp-landing-login-profile-maintenance.htm" title="maintain personal information and preferences">'+first_name+'</a>!&nbsp;&nbsp;&nbsp;<a href="/cgi-bin/start.cgi/z.corp-logout.htm?luc='+xhrg_cookie+'">log&nbsp;out</a></th>';	
				}
				// document.getElementById("msg_area").innerHTML = 'xhrg_cookie = ' + xhrg_cookie;
				if (user_type == 'end user') {
					// document.getElementById("msg_area").innerHTML = 'eu = ' + first_name;
				} else {
					if (user_type == 'reseller') {
						// document.getElementById("msg_area").innerHTML = 're = ' + first_name;
					}
				}
			}
		}
	}
	// document.getElementById("msg_area").innerHTML = 'xhrg_cookie in url = ' + xhrg_cookie;
	url_text="http://" + document.location.host + "/cgi-bin/start.cgi/z.get_first_name.htm?uc=" + encodeURIComponent(xhrg_cookie);
	// document.getElementById("msg_area").innerHTML = 'abort is next url_text = ' + url_text;
	//request1.abort();
	// document.getElementById("msg_area").innerHTML = 'hey, open is next';
	// document.getElementById("msg_area").innerHTML = 'request1.status = ' + request1.status;
	// request1.open("GET", url_text, true);
	
	try {
	  request1.open("GET", url_text, true);   	// open server interface
	} catch (err) {                   			// if error occurs
	  alert("request1.open() failed.\n" + err);	// show error
	  return;
	}
	
	// document.getElementById("msg_area").innerHTML = 'send is next';
	//document.getElementById("msg_area").innerHTML = '2a';
	request1.send(null);
	// document.getElementById("msg_area").innerHTML = 'after send';
	//document.getElementById("msg_area").innerHTML = '2b';
}

function xml_http_request2() {
	try {
	  request2 = new XMLHttpRequest();
	} catch (e) {
	try {
	  request2 = new ActiveXObject('Msxml2.XMLHTTP');
	} catch (e) {
	try {
	  request2 = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (e) {
	  document.write('XMLHttpRequest not supported'); }
	}
	}
}

function xml_http_request_get2(xhr_luc,xhr_lp) {
	xml_http_request2();
	url_text="http://www.kissingerassoc.com/cgi-bin/start.cgi/z.check_fields.htm?luc=" + encodeURIComponent(xhr_luc) + "&lp=" + encodeURIComponent(xhr_lp);
	// false is synchronous;
	request2.open("GET", url_text, false);
	request2.send(null);
	var response_table = request2.responseText.split('|||');
	if (response_table[1] == 'true') {
		return true;
	} else {
		return false;
	}
}

function check_login_fields() {
	var xhr_luc = document.getElementById("luc").value;
	var xhr_lp = document.getElementById("lp").value;
	if (xhr_luc == '' || xhr_lp == '') {
		// window.alert('please enter a username and a password');
		document.getElementById("msg_area").innerHTML = '<font color="#FF0000">please enter a username and a password</font>';
		return false;
	} else {
		var check_value = xml_http_request_get2(xhr_luc,xhr_lp);
		if (check_value == true) {
			return true;
		} else {
			// window.alert('invalid username and/or password');
			document.getElementById("msg_area").innerHTML = '<font color="#FF0000">invalid username and/or password</font>';
			document.getElementById("luc").value = '';
			document.getElementById("lp").value = '';
			return false;
		}
	}
}

function check_cookie() {
var raw_cookie = readCookie('kcorp');
var cookie_array = raw_cookie.split('|||');
var luc = cookie_array[0];
var end_user_flag = cookie_array[1];
var auto_login_flag = cookie_array[2];
var auto_login_skip_flag = cookie_array[3];
var stay_logged_in_flag = cookie_array[4];
// document.getElementById("msg_area").innerHTML = 'luc='+luc+' end_user_flag='+end_user_flag+' auto_login_flag='+auto_login_flag+' auto_login_skip_flag='+auto_login_skip_flag+' stay_logged_in_flag='+stay_logged_in_flag;
// stay_logged_in_flag is for when someone does not have auto_login_flag set, but has logged in and should stay logged in
//if (luc != '' && luc != 'ERROR' && auto_login_skip_flag == '0' && (auto_login_flag == '1' || stay_logged_in_flag == '1')) {
if (luc != '' && luc != 'ERROR' && (stay_logged_in_flag == '1' || (auto_login_flag == '1' && auto_login_skip_flag == '0'))) {
	// if (end_user_flag == 2 && auto_login_flag == '1') {
		// window.location = "/cgi-bin/start.cgi/z.corp-landing-login-business-partner-portal.htm";		
	// } else {
		// document.getElementById("cu_area").innerHTML = '<a href="http://www.kissingerassoc.com/cgi-bin/start.cgi/z.corp-landing-login-business-partner-portal.htm?luc=businesspartnerportal"><img src="http://www.kissingerassoc.com/images/portal-button-ka.gif" border="0" /></a>&nbsp;<a href="http://www.kissingerassoc.com/cgi-bin/start.cgi/z.corp-landing-login-customer-portal.htm?luc=customerportal"><img src="http://www.kissingerassoc.com/images/portal-button.gif" width="52" height="59" border="0" align="top" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.kissingerassoc.com/cgi-bin/start.cgi/z.corp-landing-login-business-partner-portal.htm?luc=businesspartnerportal"><img src="http://www.kissingerassoc.com/images/portal-button-bp.gif" border="0" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>';
		 if (end_user_flag == 2) {
			 // document.getElementById("cu_area").innerHTML = '';
			 document.getElementById("cu_area").innerHTML = '<a href="http://www.kissingerassoc.com/cgi-bin/start.cgi/z.corp-landing-login-business-partner-portal.htm?luc=businesspartnerportal"><img src="http://www.kissingerassoc.com/images/portal-button-ka.gif" border="0" /></a>';
		 } else {
			 document.getElementById("cu_area").innerHTML = '<a href="http://www.kissingerassoc.com/cgi-bin/start.cgi/z.corp-landing-login-customer-portal.htm?luc=customerportal"><img src="http://www.kissingerassoc.com/images/portal-button.gif" width="52" height="59" border="0" align="top" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.kissingerassoc.com/cgi-bin/start.cgi/z.corp-landing-login-business-partner-portal.htm?luc=businesspartnerportal"><img src="http://www.kissingerassoc.com/images/portal-button-bp.gif" border="0" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		 }
		document.getElementById("luc_input_tag_area").innerHTML = '';
		document.getElementById("lp_input_tag_area").innerHTML = '';
		document.getElementById("password_label_area").innerHTML = '';
		document.getElementById("signup_link_area").innerHTML = '';
		document.getElementById("forgot_link_area").innerHTML = '';
		document.getElementById("submit_button_image_area").innerHTML = '';
		document.getElementById("username_label_area").innerHTML = '<th width="300" scope="col" id="corp_login">Welcome, <a href="/cgi-bin/start.cgi/z.corp-landing-login-profile-maintenance.htm" title="maintain personal information and preferences">'+luc+'</a>!</th>';
		xml_http_request_get1(luc);
	// }
} else {
	document.getElementById("cu_area").innerHTML = '<a href="http://www.kissingerassoc.com/cgi-bin/start.cgi/z.corp-landing-login-customer-portal.htm?luc=customerportal"><img src="http://www.kissingerassoc.com/images/portal-button.gif" width="52" height="59" border="0" align="top" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.kissingerassoc.com/cgi-bin/start.cgi/z.corp-landing-login-business-partner-portal.htm?luc=businesspartnerportal"><img src="http://www.kissingerassoc.com/images/portal-button-bp.gif" border="0" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	document.getElementById("luc").value = '';
	document.getElementById("lp").value = '';
	document.getElementById("luc").disabled = false;
	document.getElementById("lp").disabled = false;
	if (luc != '' && luc != 'ERROR' && auto_login_skip_flag == '1') {
		auto_login_skip_flag = '0';
		writeCookieKcorp(luc, end_user_flag, auto_login_flag, auto_login_skip_flag, stay_logged_in_flag);
	}
}
}

function clear_msg_area() {
	document.getElementById("msg_area").innerHTML = '';
}
