function changePostUrl() {
	var state = document.getElementById('select').value;

	document.getElementById('txtSelectError').innerHTML='';

  if (state == 'TX') {
		document.getElementById('loginLink').href = 'https://secure.firstcash.com/Login.aspx';
  } else if (state == 'MD') {
	  document.getElementById('loginLink').href = 'https://www.cashplususa.com/Login.aspx';
  } else {
    document.getElementById('loginLink').href = 'http://www.firstcash.com/store_locator/index.php?state='+state;
  }
}
function submitForm() {
	var state = document.getElementById('select').value;
	var url;
  xmlHttp=GetXmlHttpObject();

	var firstName = document.getElementById('textfield4').value;
	var lastName = document.getElementById('textfield3').value;
	var emailAddress = document.getElementById('textfield2').value;
	var email_optin = document.getElementById('email_optin').checked;
	
  if (firstName == 'First') { firstName = ''; }
  if (lastName == 'Last') { lastName = ''; }
  if (emailAddress == 'Email') { emailAddress = ''; }

	if (state == 'TX') {
		url = 'https://secure.firstcash.com/LoanApplication.aspx?Info='+firstName+';'+lastName+';'+emailAddress;
	} else if (state == 'MD') {
		url = 'https://www.cashplususa.com/LoanApplication.aspx?Info='+firstName+';'+lastName+';'+emailAddress;
	} else {
    url = 'http://www.firstcash.com/store_locator/index.php?state='+state;
  }

	if (url !== undefined) {		
  	var urlemail="/captureemail.php?firstName="+firstName+"&lastName="+lastName+"&emailAddress="+emailAddress+"&email_optin="+email_optin+"&state="+state;
  	xmlHttp.open("GET",urlemail,true);
  	xmlHttp.send(null);
		
		window.location=url;
	}
}
function clearDefault(field, method) {
	if (method == 'focus') {
		if (field.defaultValue==field.value) { field.value = '' }
	} else if (method == 'blur') {
		if (field.value=='') { field.value = field.defaultValue }
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
	  try {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e) {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
	
	return xmlHttp;
}
