function contact_pageLoaded() {
	var emailPart1 = getElementValue( 'contact_elem_part1' );
	var emailPart2 = getElementValue( 'contact_elem_part2' );
	if ( emailPart1 && emailPart2 ) {
		emailPart1 = emailPart1.replace( /\*/g, '' );
		emailPart2 = emailPart2.replace( /\*/g, '' );

		var newString = '<a href="mailto:' + emailPart1 + '@' + emailPart2 + '" class="bodylink">Click here to email us!</a>';

		setInnerHTML( 'contact_elem_part3', newString );
	}
}

function rental1_pageLoaded() {
	setInnerHTML( 'formal_quote_div', '<a href="#" onclick="return rental1_validatePage();" class="bodytext"><strong>Ready for a formal quote? Click here to fill in your contact information!</strong></a>' );
	setInnerHTML( 'calculate_button_div', '' );
}

function rental1_validatePage() {
	var length = getElementValue( 'floor_length' );
	var width = getElementValue( 'floor_width' );

	if ( isInt( length ) && isInt( width ) ) {
		document.forms[ 'formal_quote_form' ].submit();
		return true;
	}

	alert( 'Please select a floor length and width in the drop downs so we can give you a quote.' );
	return false;
}

function rental2_validatePage() {
	return generic_validatePage();
}

function installquote_validatePage() {
	return generic_validatePage();
}

function contact_validatePage() {
	return generic_validatePage();
}

function generic_validatePage() {
	var realname = getElementValue( 'realname' );
	var emailaddress = getElementValue( 'emailaddress' );
	var phonenumber = getElementValue( 'phonenumber' );

	if ( !realname || realname.length < 1 ) {
		alert( 'Please provide your name.' );
		return false;
	}

	if ( ( !emailaddress || emailaddress.length < 1 ) && ( !phonenumber || phonenumber.length < 1 ) ) {
		alert( 'Please provide either an email address or a phone number.' );
		return false;
	}

	return true;
}

function getCostOfStage( width, length ) {
	return ( 10 * width * length ) + 370;
}

function getRoomToMove( width, length ) {
	return ( width * length ) / 4;
}

function getShoulderToShoulder( width, length ) {
	return ( width * length ) / 3;
}

//setInnerHTML( 'center_intro_text', "Calculate your LED dance floor! Enter the size you'd like in the drop downs below. Then, look to the right to see how many people your floor will hold, and how much the base price is!" );

function setInnerHTML( elemName, txt ) {
	var elem = document.getElementById( elemName );
	if ( elem ) {
		elem.innerHTML = txt;
	}
}

function getElementValue( elemName ) {
	var elem = document.getElementById( elemName );
	if ( elem ) {
		return elem.value;
	}
	return 0;
}

function setElementValue( elemName, val ) {
	var elem = document.getElementById( elemName );
	if ( elem ) {
		elem.value = val;
	}
}

function doCalculation() {
	var length = getElementValue( 'floor_length' );
	var width = getElementValue( 'floor_width' );
	if ( isInt( length ) && isInt( width ) ) {
		//alert( getCostOfStage( width, length ) );

		setElementValue( 'floor_length_step2', length );
		setElementValue( 'floor_width_step2', width );

		var num = new NumberFormat( getCostOfStage( width, length ) ).toFormatted();
		var floor_cost = '$' + num;
		var floor_room_to_move = Math.round( getRoomToMove( width, length ) );
		var floor_shoulder_to_shoulder = Math.round( getShoulderToShoulder( width, length ) );

		setInnerHTML( 'floor_cost', floor_cost );
		setInnerHTML( 'floor_room_to_move', floor_room_to_move );
		setInnerHTML( 'floor_shoulder_to_shoulder', floor_shoulder_to_shoulder );
	}
}



//http://sharkysoft.com/tutorials/jsa/content/013.html
function isInt( str ) {
	var i = parseInt (str);

	if (isNaN (i))
		return false;

	i = i . toString ();
	if (i != str)
		return false;

	return true;
}



