// flash embed

function create(FO) {
	document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'
					+ FO.width + '" height="' + FO.height + '" wmode="transparent">'+'<PARAM NAME=movie VALUE="' + FO.movie + '">'+
					'<PARAM NAME="quality" value="high"><param name="wmode" value="transparent">'+'<EMBED src="' + FO.movie + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'
					+ FO.width +'" height="' + FO.height + '" swliveconnect="true" wmode="transparent">'+'</embed></object>');
};

//rollover js

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function currentdate() {
	var d=new Date()
	var year=d.getFullYear()
	document.write(year)
}

function disclaimer() { //v1.0
  alert("DISCLAIMER\n\nFloorplans, features, renderings, square footage and amenities are subject to change. Please see sales representative for details.");
}

/*function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.alt; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }*/

function quickSubmit() {
  errors = "";	
	if (document.contactus.firstName.value == "") {
		errors += "First Name\n";
	}
	if (document.contactus.lastName.value == "") {
		errors+= "Last Name\n";
	}
	if (document.contactus.address1.value == "") {
		errors+= "Address\n";
	}
	if (document.contactus.city.value == "") {
		errors+= "City\n";
	}
	if (document.contactus.state.value == "") {
		errors+= "State\n";
	}
	if (document.contactus.zip.value == "") {
		errors+= "Zip\n";
	}
	if (document.contactus.phone.value == "") {
		errors+= "Phone\n";
	}
	if (document.contactus.email.value == "") {
		errors+= "Email\n";
	}
	if (errors == "") {
		document.contactus.submit();
	} else {
		alert("Please fill in the following fields:\n" + errors);
	}
	
}

function quickSubmitTwo() {
  errors = "";	
	if (document.getElementById("i-first").value == "") {
		errors += "First Name\n";
	}
	if (document.getElementById("i-last").value == "") {
		errors+= "Last Name\n";
	}
	if (document.getElementById("i-address").value == "") {
		errors+= "Address\n";
	}
	if (document.getElementById("i-city").value == "") {
		errors+= "City\n";
	}
	if (document.getElementById("i-state").value == "") {
		errors+= "State\n";
	}
	if (document.getElementById("i-zip").value == "") {
		errors+= "Zip\n";
	}
	if (document.getElementById("i-phone").value == "") {
		errors+= "Phone\n";
	}
	if (document.getElementById("i-email").value == "") {
		errors+= "Email\n";
	}
	if (errors == "") {
		document.getElementById("contactus").submit();
	} else {
		alert("Please fill in the following fields:\n" + errors);
	}
	
}

function communtiySubmit() {
  errors = "";
	if (document.availability.firstname.value == "First Name") {
		errors += "First Name\n";
	}
	if (document.availability.lastname.value == "Last Name") {
		errors+= "Last Name\n";
	}
	if (document.availability.phone.value == "Phone") {
		errors+= "Phone\n";
	}
	if (document.availability.email.value == "Email") {
		errors+= "Email\n";
	}
	if (errors == "") {
		document.availability.submit();
	} else {
		alert("Please fill in the following fields:\n" + errors);
	}
	
}

function communtiySubmitTwo() {
  errors = "";
	if (document.getElementById("firstname").value == "First Name") {
		errors += "First Name\n";
	}
	if (document.getElementById("lastname").value == "Last Name") {
		errors+= "Last Name\n";
	}
	if (document.getElementById("phone").value == "Phone") {
		errors+= "Phone\n";
	}
	if (document.getElementById("email").value == "Email") {
		errors+= "Email\n";
	}
	if (errors == "") {
		document.contactus.submit();
	} else {
		alert("Please fill in the following fields:\n" + errors);
	}
}

String.prototype.truncate = function(){
    var re = this.match(/^.{0,95}[\S]*/);
    var l = re[0].length;
    var re = re[0].replace(/\s$/,'');
    if(l < this.length)
        re = re + "...";
    return re;
}

function generateRandomNumber() {
	randomnumber = Math.floor(Math.random()*10000000);
}

$(document).ready(function(){
	var date = new Date();
	$.getJSON("http://www.edenglen.com/news-and-events/blog/feed/?feed=json&jsonp=?",
		 function(data){
				entry = data[0];

				var monthNames = [ "January", "February", "March", "April", "May", "June",
													 "July", "August", "September", "October", "November", "December" ];
				var d = new Date(entry.date);
				var date = monthNames[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
				$("#newsContainerDate").html(date);                
				var title = entry.title;
				$("#newsContainerTitle").html(title);

				var content = entry.excerpt;
				
				content = content.truncate();
				
				content = content + " <a href=\"http://www.edenglen.com/news-and-events/blog/\">More &gt;</a>";
				$("#newsContainerContent").html(content);

	 });
});

function clearFirst() {
	if (document.getElementById("firstname").value == "First Name") {
		document.getElementById("firstname").value = "";
	} else if (document.getElementById("firstname").value == "") {
		document.getElementById("firstname").value = "First Name";
	};
};

function clearLast() {
	if (document.getElementById("lastname").value == "Last Name") {
		document.getElementById("lastname").value = "";
	} else if (document.getElementById("lastname").value == "") {
		document.getElementById("lastname").value = "Last Name";
	};
};

function clearEmail() {
	if (document.getElementById("email").value == "Email") {
		document.getElementById("email").value = "";
	} else if (document.getElementById("email").value == "") {
		document.getElementById("email").value = "Email";
	};
};

function clearPhone() {
	if (document.getElementById("phone").value == "Phone") {
		document.getElementById("phone").value = "";
	} else if (document.getElementById("phone").value == "") {
		document.getElementById("phone").value = "Phone";
	};
};

function onprodClear() {
	if (document.getElementById("saddr").value == "Enter Starting Address") {
		document.getElementById("saddr").value = "";
	} else if (document.getElementById("saddr").value == "") {
		document.getElementById("saddr").value = "Enter Starting Address";
	};
};
