function getXMLHTTPReq()
{
	var myRequest;
	try{myRequest = new ActiveXObject("Msxml2.XMLHTTP");}
	catch(e)
	{
		try{myRequest = new ActiveXObject("Microsoft.XMLHTTP");}
		catch(oc){myRequest = null;}
	}

	if(!myRequest && typeof XMLHttpRequest != "undefined")
	{
		myRequest = new XMLHttpRequest();
	}
	return myRequest;
}

function signInUp(formId){	

		var frm = document.getElementById(formId);
		var url;
		var status;
		var propertyID;		
		var redirectToAcct = (formId == 'formSignUp') ? frm.chkToNewAcct.checked : frm.chkToMyAcct.checked;
		
		url = '/listmailer/ListMailerSignIn/signUp_AJAX.asp?doNotCacheIE=' + Math.random()
		url += (formId == 'formSignUp' ? '&email=' +  $("#"+formId + " #email").val() + '&password=' +  $("#"+formId + " #password").val() + '&password2=' +  $("#"+formId + " #password2").val() + '&firstName=' + $("#"+formId + " #firstName").val() : '&email=' + $("#"+formId + " #emailSignIn").val() + '&password=' +  $("#"+formId + " #passwordSignIn").val());

		var req = getXMLHTTPReq();
		
		if(req != null){
			req.open('GET', url, true);
			req.onreadystatechange = function() 
			{
				if(req.readyState == 4 && req.status == 200)
				{ 
					status = req.responseText;

					if (status == 'signedUp' || status == 'signedIn')
					{
						if (getCookie('saveProperty')){     /* Save Property */
							propertyID = getCookie('saveProperty').split('|');
							saveProperty(propertyID[0], propertyID[1]);
							savePropertyOnload();
							setCookie('saveProperty', '', '', '/', '', '');
						}
						else if (getCookie('saveSearch')){   /* Save Search */
							saveSearch(getCookie('saveSearch'));
							setCookie('saveSearch', '', '', '/', '', ''); 
						}
						
						updateSignIn();
						$.fn.colorbox.close();
						if(redirectToAcct) location.href = '/listmailer/';
					}
					else
					{   
						if (status == 'wrongEmail'){
							$('#RequiredSignIn').html('Sorry, we have no record of this e-mail address. Please try again or create a new account.');
						}else if (status == 'invalidPassword'){
							$('#RequiredSignIn').html('Sorry, Your password did not match.');
						}else if (status == 'wrongPassword'){
							$('#RequiredSignIn').html('Sorry, Your password did not match. Try again, or click I Forgot My Password and we will e-mail your password.');
						}
					}
				}
			}
			req.send(null);
		} 
	}

function forgotPwd(formId){

	var frm = document.getElementById(formId);
	var url;
	var status;

	url = '/listmailer/ListMailerSignIn/forgotPwd_AJAX.asp?doNotCacheIE=' + Math.random() + '&email=' + $("#"+formId + " #emailSignIn").val()

	var req = getXMLHTTPReq();
		
	if(req != null){
		req.open('GET', url, true);
		req.onreadystatechange = function() 
		{
			if(req.readyState == 4 && req.status == 200)
			{ 
				status = req.responseText;
					  
				if (status == 'passwordSent'){
					$('#RequiredSignIn').html('Your password has been sent to you.');
				}else{
					$('#RequiredSignIn').html('Sorry, we have no record of this e-mail address. Please try again or create a new account.');
				}
			}
		}
		req.send(null);
	} 
}
	
jQuery(document).ready(function(){ 

    $(".quicksignin").colorbox({
        'opacity':0.7,
		'width': 450,
        'height': 390
    }); 
	$(".quicksignup").colorbox({
        'opacity':0.7,
		'width': 450,
        'height': 550
    });
	
});


