/*	Lindsey's Lawn & Landscape, Inc.		 	*/
/*	Main Javascript Definitions					*/
/*	Author: Weston Wilson						*/
/*	Copyright TrueRender, LLP.	2007			*/
/************************************************/
function preloadImages( a ) {
	if(a.length>0) {
		pics = new Array(a.length);
		for(i=0;i<a.length;i++) {
			pics[i] = new Image();
			pics[i].src = "images/"+a[i]; 
		}
		return true;
	} else {
		return false;
	}
}
preloadImages(new Array("loading.gif", "bodybg.gif", "bottomleaf.jpg", "bottomleft_footerdetail.jpg", "bottomleft_img1.jpg", "bottomright_img1.jpg", "footer.jpg", "greenbg.jpg", "header.jpg", "home_commimg.jpg", "home_designimg.jpg", "home_hoasimg.jpg", "home_resimg.jpg", "leftfeaturebox.gif", "menu_bg.gif", "menu_botshad.gif", "menu_botshad_on.gif", "menu_bottom.gif", "menu_comm.gif", "menu_comm_bshad.gif", "menu_comm_on.gif", "menu_comm_tshad.gif", "menu_design.gif", "menu_design_on.gif", "menu_design_tshad.gif", "menu_hoas.gif", "menu_hoas_bshad.gif", "menu_hoas_on.gif", "menu_hoas_tshad.gif", "menu_home.gif", "menu_home_bshad.gif", "menu_home_on.gif", "menu_res.gif", "menu_res_bshad.gif", "menu_res_on.gif", "menu_res_tshad.gif", "menu_top.gif", "menu_topshad.gif", "menu_topshad_on.gif", "orchid.png", "rightcol_img1.jpg", "section_commercial.jpg", "section_design.jpg", "section_hoas.jpg", "section_residential.jpg"));

var DOMmode = new Array(3);
DOMmode[0] = false;
DOMmode[1] = false;
DOMmode[2] = false;

if (document.getElementById) {
	DOMmode[0] = true;
} else if (document.all) {
	DOMmode[1] = true;
} else if (document.layers) {
	DOMmode[2] = true;
}

function getObj( name ) {
	var obj;
	if (DOMmode[0]) {
  		obj = document.getElementById(name);
	} else if (DOMmode[1]) {
		obj = document.all[name];
	} else if (DOMmode[2]) {
   		obj = document.layers[name];
	}
  	return obj;
}

var buttonArray = [];
buttonArray[0] = 'menuTopShad';
buttonArray[1] = 'menuButton_home';
buttonArray[2] = 'menuButton_res';
buttonArray[3] = 'menuButton_comm';
buttonArray[4] = 'menuButton_hoas';
buttonArray[5] = 'menuButton_design';
buttonArray[6] = 'menuBotShad';

function setClass( cname, el ) {
	el.className = cname;
}

function buttonOver( index ) {
	obj = getObj('b'+index);
	obj1 = getObj('b'+(index-1));
	obj2 = getObj('b'+(index+1));
	setClass( buttonArray[index]+'_on', obj );
	setClass( buttonArray[(index-1)]+'_bshad', obj1 );
	setClass( buttonArray[(index+1)]+'_tshad', obj2 );
}

function buttonOut( index ) {
	obj = getObj('b'+index);
	obj1 = getObj('b'+(index-1));
	obj2 = getObj('b'+(index+1));
	setClass( buttonArray[index], obj );
	setClass( buttonArray[(index-1)], obj1 );
	setClass( buttonArray[(index+1)], obj2 );
}

function correctPNG() {
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;		
			var strNewHTML = "<span " + imgID + imgClass + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML;
			i = i-1;
		}
	}
}

//form validation
function setClassForm(obj, clsName) {
	obj.className = clsName;
}
function validate( frm ) {
	var error_array = [];
	var error_count = 0;
	if(WithoutContent( frm.elqntForm_fname.value )) {
		setClassForm(frm.elqntForm_fname,'elqntFieldError');
		error_array[error_count] = 'Please provide your first name.';
		error_count++;
	}
	if(WithoutContent( frm.elqntForm_lname.value )) {
		setClassForm(frm.elqntForm_lname,'elqntFieldError');
		error_array[error_count] = 'Please provide your last name.';
		error_count++;
	}
	if(WithoutContent( frm.elqntForm_maintxt.value )) {
		setClassForm(frm.elqntForm_maintxt,'elqntFieldError');
		error_array[error_count] = 'Please provide your phone number.';
		error_count++;
	}
	if(WithoutContent( frm.elqntForm_emailaddress.value )) {
		setClassForm(frm.elqntForm_emailaddress,'elqntFieldError');
		error_array[error_count] = 'You must provide a valid email address.';
		error_count++;
	}
	if(!check_email( frm.elqntForm_emailaddress.value )) {
		setClassForm(frm.elqntForm_emailaddress,'elqntFieldError');
		error_array[error_count] = 'The email address provided has an error, or is not in the form of email@address.com.';
		error_count++;
	}
	
	if(error_count < 1) {
		return true;
	} else {
		var msg = "The following errors were found:\n------------------------------\n\n";
		for(i=0;i<error_count;i++) {
			msg += error_array[i] + "\n\n";
		}
		alert(msg);
		error_array = [];
		error_count = 0;
		return false;
	}
	
}
function WithoutContent(ss) {
	if(ss.length > 0) {
		return false;
	}
	return true;
}

function WithContent(ss) {
	if(ss.length == 0) {
		return false;
	}
	return true;
}

//email validation
function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
		}	
	} 

	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 

	}

}