
function load_function(page){
	if(page == "gallery.php"){
		resize_pic_div();

	} else if (page == "index.php"){
		document.images['home_pic'].src='img/rotating.gif';
		
	} else if (page == "getstarted.php"){
		if(document.theform != null){
			document.theform.first_name.focus();
		}
	}
	
	document.onmouseover = nostatus
	document.onmouseout = nostatus
	document.onmousedown = nostatus
}

function load_home_img(){
	change_pic(document.getElementById('pic_0'),0,1);
	document.images['big_pic1'].style.marginTop=0;
	document.images['big_pic1'].style.borderWidth=1;
	document.images['big_pic1'].style.borderStyle='solid';
	document.images['big_pic1'].style.borderColor='black';
}

function resize_pic_div(){
	if(parseInt(document.getElementById("inner_table").offsetHeight) > parseInt(document.getElementById("outer_div").offsetHeight)){
		document.getElementById("outer_div").style.width = "106px";
	} else {
		document.getElementById("outer_div").style.width = "89px";
	}
	
	document.getElementById("loading_row").style.visibility = "hidden";
	document.getElementById("start_pics").value = "1";
}

function nostatus(){
	window.status = company_name;
	return true
}

function promptLogin(){
	var x = confirm("This is a password protected area.\nWould you like to continue?");
	if(x){
		document.location.href = "admin";
	} else {
		return;
	}
}

function textCounter(area,maxlength){
	if(area.value.length >= maxlength){
		alert("You've reached the " + maxlength + " character limit.");
		area.value = area.value.substring(0, maxlength);
		event.returnValue = false;
	}
}


//Color Palette functions
var color1 = 1;
var color2 = 2;
var color_counter = 0;
function change_color(val,elem){
	if(elem==color1 || elem==color2){
		return;
	}
	
	color_counter++;
	if(color_counter % 2){
		color1 = elem;
		if(document.images["color_image1"].filters != null){ document.images["color_image1"].filters[0].apply(); }
		document.images["color_image1"].offSrc = document.images["color_image1"].src;
		document.images["color_image1"].src = "img/photos/colors/" + val;
		if(document.images["color_image1"].filters != null){ document.images["color_image1"].filters[0].play(); }
	} else {
		color2 = elem;
		if(document.images["color_image2"].filters != null){ document.images["color_image2"].filters[0].apply(); }
		document.images["color_image2"].offSrc = document.images["color_image2"].src;
		document.images["color_image2"].src = "img/photos/colors/" + val;
		if(document.images["color_image2"].filters != null){ document.images["color_image2"].filters[0].play(); }
	}

	for(var i=1; i<=7; i++){
		if(i==color1 || i==color2){
			document.getElementById("color_"+elem).style.fontWeight = "bold";
		} else {
			document.getElementById("color_"+i).style.fontWeight = "normal";
		}
	}
}


//Photo gallery functions
function change_pic(elem, num){
	var start_pics = document.getElementById("start_pics").value;
	if(start_pics == "1"){
		if(document.images['big_pic1'].filters != null){
			document.images['big_pic1'].filters[0].apply();
		}
		document.images['big_pic1'].offSrc = document.images['big_pic1'].src;
		document.images['big_pic1'].src = document.images[elem.name].src;
		if(document.images['big_pic1'].filters != null){
			document.images['big_pic1'].filters[0].play();
		}
		
		for(var i=0; i < num_pics; i++){
			document.getElementById("pic_"+i).style.borderWidth = "1px";
			document.getElementById("pic_"+i).style.borderColor = "black";
			document.getElementById("pictd_"+i).style.backgroundColor = "white";
		}
		document.getElementById(elem.id).style.borderWidth = "2px";
		document.getElementById(elem.id).style.borderColor = "#7E587E";
		document.getElementById("pictd_"+num).style.backgroundColor = "#571B7e";
		if(document.getElementById(elem.id).height > 70){
			document.images['big_pic1'].height = "390";
			document.images['big_pic1'].width = 29250 / document.getElementById(elem.id).height;
		} else {
			document.images['big_pic1'].height = document.getElementById(elem.id).height / 0.1875;
			document.images['big_pic1'].width = "400";
		}
	}
}


//Testimonials Page
function validate_testimonials_form(){
	clear_testimonials_form();
	var required = "";
	if (document.theform.name.value.length == 0) { required += "\n     - Name"; document.theform.name.className = "textBoxRequired"; }
	if (document.theform.email.value.length == 0) { required += "\n     - Email"; document.theform.email.className = "textBoxRequired"; }
	if (document.theform.comment.value.length == 0) { required += "\n     - Comment"; document.theform.comment.className = "textBoxRequired"; }
	else if (document.theform.email.value.search(/(\w+[\w|\.|-]*\w+)(@\w+[\w|\.|-]*\w+\.\w{2,4})/) == -1) { required += "\n     - Please specify a valid email address"; document.theform.email.className = "textBoxRequired"; }
	
	if (required != "") {
		alert("Please fill in the required fields:" + required);
		return false;
	}
}
		
function reset_testimonials_form(){
	var x = confirm("Are you sure you want to erase all of your data?");
	if(x){
		clear_testimonials_form();
		document.theform.name.focus();
		document.theform.reset();
	}
}

function clear_testimonials_form(){
	document.theform.name.className = "textBox";
	document.theform.email.className = "textBox";
	document.theform.comment.className = "textBox";
}

function show_form(){
	document.getElementById("comment_output").style.height = "132px";
	document.getElementById("comment_output").style.width = "525px";
	document.getElementById("comment_form").style.display = "";
	document.getElementById("comment_header").style.display = "none";
	document.theform.name.focus();
}


//Get started page
function validate_getstarted_form(){
	clear_getstarted_form();
	var required = "";
	if (document.theform.first_name.value.length == 0) { required += "\n     - First Name"; document.theform.first_name.className = "textBoxRequired"; }
	if (document.theform.last_name.value.length == 0) { required += "\n     - Last Name"; document.theform.last_name.className = "textBoxRequired"; }
	if (document.theform.street.value.length == 0) { required += "\n     - Address"; document.theform.street.className = "textBoxRequired"; }
	if (document.theform.zip.value.length == 0) { required += "\n     - Zip"; document.theform.zip.className = "textBoxRequired"; }
	if (document.theform.phone1.value.length == 0 || document.theform.phone2.value.length == 0 || document.theform.phone3.value.length == 0) { required += "\n     - Phone Number"; document.theform.phone1.className = "textBoxRequired"; document.theform.phone2.className = "textBoxRequired"; document.theform.phone3.className = "textBoxRequired"; }
	if (document.theform.email.value.length == 0) { required += "\n     - Email"; document.theform.email.className = "textBoxRequired"; }
	else if (document.theform.email.value.search(/(\w+[\w|\.|-]*\w+)(@\w+[\w|\.|-]*\w+\.\w{2,4})/) == -1) { required += "\n     - Please specify a valid email address"; document.theform.email.className = "textBoxRequired"; }
	
	if (required != "") {
		alert("Please fill in the required fields:" + required);
		document.theform.second_half.value = 0;
		return false;
	}
	
	if(document.theform.second_half.value == 0){
		document.getElementById("table1").style.display = "none";
		document.getElementById("table2").style.display = "";
		document.theform.second_half.value = 1;
		return false;
	}
	
	if ((document.theform.second_half.value == 1) && (document.theform.hear_about.value.length == 0)) {
		alert("How did you hear about us?");
		document.theform.hear_about.className='textBoxRequired';
		return false;
	}
	
	if ((document.theform.hear_about.value == "Referral") && (document.theform.hear_about_referral.value.length == 0)) {
		alert("Who referred you?");
		document.theform.hear_about_referral.className='textBoxRequired';
		document.theform.hear_about_referral.focus();
		return false;
	}
}

function reset_getstarted_form(){
	var x = confirm("Are you sure you want to erase all of your data?");
	if(x){
		document.getElementById("table1").style.display = "";
		document.getElementById("table2").style.display = "none";
		document.theform.second_half.value = 0;
		
		clear_getstarted_form();
		document.theform.first_name.focus();
		document.getElementById("referral_text").style.display = "none";
		document.theform.reset();
	}
}

function clear_getstarted_form(){
	document.theform.first_name.className='textBox';
	document.theform.last_name.className='textBox';
	document.theform.street.className='textBox';
	document.theform.zip.className='textBox';
	document.theform.phone1.className='textBox';
	document.theform.phone2.className='textBox';
	document.theform.phone3.className='textBox';
	document.theform.email.className='textBox';
	document.theform.hear_about_referral.className='textBox';
}

function check_referral(elem){
	if(elem.value == "Referral"){
		document.getElementById("referral_text").style.display = "";
		document.theform.hear_about_referral.focus();
	} else {
		document.getElementById("referral_text").style.display = "none";
	}
}

function go_back(){
	document.getElementById("table1").style.display = "";
	document.getElementById("table2").style.display = "none";
	document.theform.second_half.value = 0;
}