﻿function writeflash(page){
var flashbox = document.getElementById('flashbox');	
if(page == "home"){
		flashbox.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="778" height="188"><param name="movie" value="media/flash/' + page + '.swf" /><param name="quality" value="high" /><embed src="media/flash/' + page + '.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="778" height="188"></embed>';
	}else{
		flashbox.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="778" height="188"><param name="movie" value="../media/flash/' + page + '.swf" /><param name="quality" value="high" /><embed src="../media/flash/' + page + '.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="778" height="188"></embed>';
	}
}
/// jump phone number fields
function numTyped(current, next,maxlen) {
  var len = current.length;
  if (len==maxlen) {
    next.focus();
  }
}

/////
///onKeyPress="return numbersonly(this, event)"
/////

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;
	if (window.event){
		key = window.event.keyCode;
	}else if (e){
		key = e.which;
	}else{
		return true;
	}
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ){
		return true;
	}else if ((("+1234567890").indexOf(keychar) > -1)){
		return true;
	}else if (dec && (keychar == ".")){
		myfield.form.elements[dec].focus();
		return false;
	}else{
		return false;
	}
}



/// popup window function
function popup(URL,w,h) {

day = new Date();
id = day.getTime();

var width = w;
var height = h;

var left = ((screen.width-width)/2);
var top = ((screen.height-height)/2);

eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + '');");
}



// disclaimer footer
function footer()
{
var root = 'http://66.153.118.118/montesereno/';

var footer_code = '<table width="778" border="0" cellspacing="0" cellpadding="0">';
footer_code = footer_code + '<tr>';
footer_code = footer_code + '<td width="778" align="center" valign="middle"><img src="' + root + 'media/common/spacer.gif" alt="" width="1" height="25" border="0"></td>';
footer_code = footer_code + '</tr>';
footer_code = footer_code + '<tr height="13">';
footer_code = footer_code + '<td width="778" height="13" bgcolor="#54797F" align="center" valign="middle"><a href="mailto:info@monteserenoliving.com"><img src="' + root + 'media/common/email_03.gif" alt="" width="216" height="11" border="0" vspace="2"></a></td>';
footer_code = footer_code + '</tr>';
footer_code = footer_code + '<tr height="13">';
footer_code = footer_code + '<td class="disc" width="778" height="13" align="center" valign="middle">&copy; 2006 Monte Sereno, All Rights Reserved. <a href="javascript:popup(\'' + root + 'disclaimer.html\',\'650\',\'550\');" class="disc"><b>Privacy &amp; Disclaimer</b></a></td>';
footer_code = footer_code + '</tr>';
footer_code = footer_code + '</table>';

return footer_code;
}

/// form validation starts here

var new_fieldname = ""

//this is the onclick that calls this function
//
// onClick="return check(form,form.elements.length)"
//

function check(form,x)

{


	var message = ""

	var more_message = new Array //(4)

	var showmsg = "no"

	var doItNow = "yes"



	var required = new Array (12)



	if (doItNow == "yes") 	{



			var i = 0;


						if (form.first_name.value == "")
							{more_message [i++] = "Please Enter Your First Name"}
						
						if (form.last_name.value == "")
							{more_message [i++] = "\nPlease Enter Your Last Name"}
							
						/*if (form.address_1.value == "")
							{more_message [i++] = "\nPlease Enter Your Address"}
						
						if (form.city.value == "")
							{more_message [i++] = "\nPlease Enter Your City"}
						
						if (form.state.value == "")
							{more_message [i++] = "\nPlease Enter Your State"}*/
						
						
						////phone validation
						
			
							if ( count_phoneboxes() >= 1 && count_phoneboxes() < 3)
							{
								more_message [i++] = "\nPlease Enter Your Phone Number Completely"
							}
			
							if ( count_altphoneboxes() >= 1 && count_altphoneboxes() < 3)
							{
								more_message [i++] = "\nPlease Enter Your Alternate Phone Number Completely"
							}						
		
							if ( count_faxboxes() >= 1 && count_faxboxes() < 3)
							{
								more_message [i++] = "\nPlease Enter Your Fax Number Completely"
							}

						
						///end phone validation
						if (form.email.value == "")
						{
							more_message [i++] = "\nPlease Enter Your E-mail Address"
						}
						else
						{
							if (checkEmail(form.email.value)==false)
							{
								more_message [i++] = "\nPlease Enter A Valid E-mail Address"
							}
							else if ( form.email.value != form.confirm_email.value )
							{
								more_message [i++] = "\nPlease Verify That Both Your E-mail Address Are Correct"
							}
						}
						
						
						if (more_message != "") {

								if (message == "") {message = more_message}

									else

									{message = message + "\n" + more_message}

				        }

						if (message > "")

								{showmsg = "yes"}																

						if (showmsg == "yes")

			{
				alert("The following form field(s) were incomplete or incorrect:\n\n" + message + "\n\n Please complete or correct the form and submit again.")
				return false;
			}
			else
			{ 
				form.submit()
				//document.form.send_form.disabled=true;
				return true;
			}

		}

}

/// functions for form validation script


/// phone functions
function count_phoneboxes() {
	box_checked = 0;
	with (document.form) { 
		for (var i=0; i < elements.length; i++) { 
			if (elements[i].name == 'phone[]')
				if (  elements[i].value != "" )
				{ 
						box_checked = box_checked + 1;
				}
		}
	}
	return box_checked;
}

function count_altphoneboxes() { 
	box_checked = 0;
	with (document.form) { 
		for (var i=0; i < elements.length; i++) { 
			if (elements[i].name == 'alt_phone[]')
				if (  elements[i].value != "" )
				{ 
						box_checked = box_checked + 1;
						
				}
		}
	}
	return box_checked;
}

function count_faxboxes() { 
	box_checked = 0;
	with (document.form) { 
		for (var i=0; i < elements.length; i++) { 
			if (elements[i].name == 'fax[]')
				if (  elements[i].value != "" )
				{ 
						box_checked = box_checked + 1;
				}
		}
	}
	return box_checked;
}

////email validation

function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
	{
		return (true)
	}
	else
	{
		return (false)
	}
}


