/* CHECK FOR MESSAGES PASSED THROUGH URL */
function checkUrl(){
	var str = window.location.search;
	
	if(str.search("msg=comments") != -1){
		alert("Thank you. Someone from our staff will be in contact with you shortly.");		
	}
	
	if(str.search("msg=appointment") != -1){
		alert("Thank you. Someone from our staff will be in contact with you shortly to confirm the requested times.");		
	}
		
	if(str.search("msg=emailpage") != -1){
		alert("Thank you. Your email has been sent.");		
	}
		
}

/* CHECK EMAIL */
/* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	if (str.indexOf(at)==-1){
	   alert("Invalid email format. Please check your email address.")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid email format. Please check your email address.")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid email format. Please check your email address.")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid email format. Please check your email address.")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid email format. Please check your email address.")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid email format. Please check your email address.")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid email format. Please check your email address.")
		return false
	 }
	 
	 return true
}

/* CONTACT FORM VALIDATION */
function ValidateCommentsForm(){
	var name=document.CommentsForm.name;
	var email=document.CommentsForm.email;
	var subject=document.CommentsForm.subject;
	var comments=document.CommentsForm.comments;
	
	if ((name.value==null)||(name.value=="Name...")||(name.value=="")||(email.value==null)||(email.value=="Your Email...")||(email.value=="")||(subject.value==null)||(subject.value=="Subject...")||(subject.value=="")||(comments.value==null)||(comments.value=="")){
		alert("Please insure all form fields are filled out.")
		return false
	}
	
	if (echeck(email.value)==false){
		email.focus()
		return false
	}
	
	return true
}

/* APPOINTMENT FORM VALIDATION */
function ValidateAppointmentForm(){
	var fname=document.AppointmentForm.fname;
	var lname=document.AppointmentForm.lname;
	var daytimephone=document.AppointmentForm.daytimephone;
	var email=document.AppointmentForm.email;
	var day1=document.AppointmentForm.day1;
	var time1=document.AppointmentForm.time1;
	
	if ((fname.value==null)||(fname.value=="")||(lname.value==null)||(lname.value=="")||(daytimephone.value==null)||(daytimephone.value=="")||(email.value==null)||(email.value=="")||(day1.value==null)||(day1.value=="")||(time1.value==null)||(time1.value=="")){
		alert("Please insure all required form fields are filled out.")
		return false
	}
	
	if (echeck(email.value)==false){
		email.focus()
		return false
	}
	
	return true
}

/* EMAIL PAGE FORM VALIDATION */
function ValidateEmailPageForm(){
	var name=document.EmailPageForm.name;
	var email_from=document.EmailPageForm.email_from;
	var email_to=document.EmailPageForm.email_to;
	
	if ((name.value==null)||(name.value=="")||(email_from.value==null)||(email_from.value=="")||(email_to.value==null)||(email_to.value=="")){
		alert("Please insure all required form fields are filled out.")
		return false
	}
	
	if (echeck(email_from.value)==false){
		email_from.focus()
		return false
	}
	
	if (echeck(email_to.value)==false){
		email_to.focus()
		return false
	}
	
	return true
}

/* SUBPAGE BUTTONS */
function toggelObject(divCount,itemID,btn1,btn2,btn3,btn4){
	var btnID = new Array(5);
	btnID[0] = "";
	btnID[1] = btn1;
	btnID[2] = btn2;
	btnID[3] = btn3;
	btnID[4] = btn4;
	var i = 1;
	for (i=1;i<=divCount;i++){
		document.getElementById("div" + i).style.display = "none";
		document.getElementById("btn" + i).src = "../PrimaryTemplateFiles/images/" + btnID[i] + ".gif";
	}
	document.getElementById("div" + itemID).style.display = "block";
	document.getElementById("btn" + itemID).src = "../PrimaryTemplateFiles/images/" + btnID[itemID] + "-over.gif";
}

/* BUDGET SLIDERS */
function setSlider(type,amount,minamount,maxamount,increment){
	var i = minamount;
	for (i=minamount;i<=maxamount;i=i+increment){
		document.getElementById(type + i).src = "../PrimaryTemplateFiles/images/spacer.gif";
	}
	document.getElementById(type + amount).src = "../PrimaryTemplateFiles/images/slider.gif";
	document.getElementById(type + "Total").value = "$" + amount + ".00";
	
	var mortgage = document.getElementById("mortgageTotal").value;
	mortgage = mortgage.replace(/\$|,/g,"");
	var utilities = document.getElementById("utilitiesTotal").value;
	utilities = utilities.replace(/\$|,/g,"");
	var maintenance = document.getElementById("maintenanceTotal").value;
	maintenance = maintenance.replace(/\$|,/g,"");
	var condofees = document.getElementById("condofeesTotal").value;
	condofees = condofees.replace(/\$|,/g,"");
	var food = document.getElementById("foodTotal").value;
	food = food.replace(/\$|,/g,"");
	var housekeeping = document.getElementById("housekeepingTotal").value;
	housekeeping = housekeeping.replace(/\$|,/g,"");
	var landscaping = document.getElementById("landscapingTotal").value;
	landscaping = landscaping.replace(/\$|,/g,"");
	var transportation = document.getElementById("transportationTotal").value;
	transportation = transportation.replace(/\$|,/g,"");
	var insurance = document.getElementById("insuranceTotal").value;
	insurance = insurance.replace(/\$|,/g,"");
	var security = document.getElementById("securityTotal").value;
	security = security.replace(/\$|,/g,"");
	var tax = document.getElementById("taxTotal").value;
	tax = tax.replace(/\$|,/g,"");
	var recreation = document.getElementById("recreationTotal").value;
	recreation = recreation.replace(/\$|,/g,"");
	
	var total = parseFloat(mortgage);
	total += parseFloat(utilities);	
	total += parseFloat(maintenance);
	total += parseFloat(condofees);
	total += parseFloat(food);
	total += parseFloat(housekeeping);
	total += parseFloat(landscaping);
	total += parseFloat(transportation);
	total += parseFloat(insurance);
	total += parseFloat(security);
	total += parseFloat(tax);
	total += parseFloat(recreation);

	document.getElementById("yourTotal").value = "$" + total + ".00";
	
	var difference = document.getElementById("planTotal").value;
	difference = difference.replace(/\$|,/g,"");
	difference = parseFloat(difference) - total;
	if (difference < 0){
		difference = String(difference);
		difference = difference.replace("-","");
		document.getElementById("differenceTotal").value = "- $" + difference + ".00";
	} else {
		document.getElementById("differenceTotal").value = "+ $" + difference + ".00";
	}
}
function minSlider(type,amount,minamount,maxamount,increment){
	var str = document.getElementById(type + "Total").value;
	str = str.replace(/\$|,/g,"");
	str = parseInt(str);
	if (str!=minamount){
		setSlider(type,eval(str)-increment,minamount,maxamount,increment);
	}
}
function plusSlider(type,amount,minamount,maxamount,increment){
	var str = document.getElementById(type + "Total").value;
	str = str.replace(/\$|,/g,"");
	str = parseInt(str);
	if (str!=maxamount){
		setSlider(type,eval(str)+increment,minamount,maxamount,increment);
	}
}

/* SET BUDGET PLANS */
function setBudgets(plan){
	if(plan=="Studios"){
		
	} else if(plan=="Deluxe Studios"){
	
	} else if(plan=="One Bedroom Suites"){
	
	}  
}

