// JavaScript Document
    $('#slide-show').cycle({
		fx: 'fade',
		speed:  2500
	});
	
$(document).ready(function() {



	
//closes popup window and clears the timer used by set interval
function closePopUp(){
	$('#appt-send').fadeOut('slow');
    //document.getElementById("mailConf").style.display = "none";
//    document.getElementById("mailConf").style.visibility = "invisible";
    }

//Handles each step of the AJAX call 1 - 3 display processing, 4 display thankyou
function processChange() {
if(obj.readyState == 1 || obj.readyState == 2 || obj.readyState == 3){
	document.getElementById("mailConf").style.display = "block";
    document.getElementById("mailConf").style.visibility = "visible";
	        document.getElementById("mailConf").style.background = "#252525 url('images/mail-send.jpg') no-repeat";

}
if(obj.readyState == 4) {
	if(obj.status == 200) {
		document.getElementById("mailConf").style.display="block";
   		document.getElementById("mailConf").style.visibility="visible";
        document.getElementById("mailConf").style.background = "#252525 url('images/mail-sent.jpg') no-repeat";
		var close=setTimeout("closePopUp()",2500);
	}
	else {
		alert("Something must have went wrong");
	}
}
}

function validEmail(emailStr){
	var emailTxt = document.getElementById("emailInput");
	var phoneTxt = document.getElementById("phoneInput");
	var url = 'contact.php?email='+emailTxt;

	var emailRegexStr = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	return emailRegexStr.test(emailStr); 
}
function sendInfo(){
	_gaq.push(['_trackEvent', 'User Inquiry', 'Appointment', 'Canyon Ranch Living Miami Beach']); //Google analytics event tracking
	var firstNameTxt = document.getElementById("firstInput");
	var lastNameTxt = document.getElementById("lastInput");
	var emailTxt = document.getElementById("emailInput");
	var phoneTxt = document.getElementById("phoneInput");
	var int1Txt = document.getElementById("interestedInput1");
	var int2Txt = document.getElementById("interestedInput2");
	var int3Txt = document.getElementById("interestedInput3");
	var int4Txt = document.getElementById("interestedInput4");
	var rangeFromTxt = document.getElementById("fromInput");
	var rangeToTxt = document.getElementById("toInput");
	var availTxt = document.getElementById("timeAvail");
	var url = 'contact.php?firstName=' + firstNameTxt.value + '&lastName=' + lastNameTxt.value +'&email=' + emailTxt.value +'&phone=' + phoneTxt.value +'&interested1=' + int1Txt.value +'&interested2=' + int2Txt.value +'&interested3=' + int3Txt.value +'&interested4=' + int4Txt.value +'&rangeFrom=' + rangeFromTxt.value +'&rageTo=' + rangeToTxt.value +'&available=' + availTxt.value;
//Check if email or phone input is blank or displays default text
	if((emailTxt.value=="i.e. JSmith@gmail.com" || emailTxt.value=="") && (phoneTxt.value=="i.e. 555 555 5555" || phoneTxt.value=="")){
		alert("Please enter a phone number or email address so we can contact you.");
		emailTxt.focus();
		return;
	}
//
//check if valid email address
	var emailTxt = document.getElementById("emailInput");
	var phoneTxt = document.getElementById("phoneInput");
	if(!validEmail(emailTxt.value)){
		alert("Please enter a valid email address.");
		emailTxt.focus();
		return;
	}
//
//AJAX CALL
	if(window.XMLHttpRequest) {
		obj = new XMLHttpRequest(); //new object
		obj.onreadystatechange = processChange; //change dhtml if success or alert on faliure
		obj.open("GET", url, true); //open connection
		obj.send(null);  //send
	} 
	else if (window.ActiveXObject) {
		obj = new ActiveXObject("Microsoft.XMLHTTP");
		if (obj) {
			obj.onreadystatechange = processChange;
			obj.open("GET", url, true);
			obj.send();
		}
	} 
	else {
		alert("Your web browser doesn't support AJAX!");
	}
}
}); //END DOCUMENT READY FUCNTION
