/* <![CDATA[ */
function setcat(chosen) {
//	var URI =  selected_text.replace(/[&^ 0-9/]+/g,'');
	location.href= "/formstart/step1/GH/"+chosen;
}

function searchvalidate() {
	if (document.search.query.value == "" || document.search.query.value == "Search...") {
		alert('Please enter a valid keyword');
		return false;
	} 
}

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Please enter a valid e-mail")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Please enter a valid e-mail")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please enter a valid e-mail")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Please enter a valid e-mail")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter a valid e-mail")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Please enter a valid e-mail")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Please enter a valid e-mail")
		return false
	 }

	 return true					
}

function validateZIP(field) {
	var valid = "0123456789-";
	var hyphencount = 0;
	
	if (field.length!=5 && field.length!=10) 
		return false;

	for (var i=0; i < field.length; i++) {
		temp = "" + field.substring(i, i+1);
		if (temp == "-") 
			hyphencount++;
		if (valid.indexOf(temp) == "-1")
			return false;
		if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-"))
			return false;
	}
	return true;
}

function popup(param) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(param, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=600,height=600');");
}

var index = 5;
var frameWidth = 220;
function pollBtns() {
	if(index==0) {
		$("#scrollLeft").css('opacity',.2);
	} else if(index==12) { 
		$("#scrollRight").css('opacity',.2);
	}else {
		$("#scrollLeft").css('opacity',1);
		$("#scrollRight").css('opacity',1);
	} 
}
function scrollRight() {

	if(index < 12) {

		index++;
		$("#photo_frame").animate({
			left: (-1) * index * frameWidth
		}, 800, "easeOutExpo", function() { pollBtns(); });
	}
 }

function scrollLeft() {

	if(index > 0) {

		index--;
		$("#photo_frame").animate({
			left: (-1) * index * frameWidth
		}, 800, "easeOutExpo", function() { pollBtns(); });
	}
 }

$(document).ready(function() {
	$("form.catform").submit(function() {
		if(!validateZIP($("form.catform input[name=PC]").val())) {
			alert("Please enter your zipcode");
			$("form.catform input[name=PC]").focus();
			return false;
		}
		return true;
	});
	$("#step2form").submit(function() {
		if(!validateZIP($("#PC").val())) {
			alert("Please enter your zipcode");
			$("#PC").focus();
			return false;
		}
		if($('#FN').val() == '') {
			alert('Please enter your first name.');
			$('#FN').focus();
			return false;
		}
		if($('#LN').val() == '') {
			alert('Please enter your last name.');
			$('#LN').focus();			
			return false;
		}
		if($('#S1').val() == '') {
			alert('Please enter your address.');
			$('#S1').focus();			
			return false;
		}
		if($('#CT').val() == '') {
			alert('Please enter a city.');
			$('#CT').focus();
			return false;
		}
		if($('#SP').val() == '') {
			alert('Please select a state.');
			return false;
		}
		if($('#PC').val() == '') {
			alert('Please enter a zip code.');
			$('#PC').focus();
			return false;
		}
		if(!echeck($('#EM').val())) {
			$('#EM').focus();
			return false;
		}
		if($('#HP1').val() == '' || $('#HP1').val().length < 3) {
			alert('Please enter a area code.');
			$('#HP1').focus();
			return false;
		}
		if($('#HP2').val() == '' || $('#HP2').val().length < 3) {
			alert('Please enter a phone prefix.');
			$('#HP2').focus();
			return false;
		}
		if($('#HP3').val() == '' || $('#HP3').val().length < 4) {
			alert('Please enter the last four digits.');
			$('#HP3').focus();
			return false;
		}
		return true;
	});
	$("#lovechain").bind('submit', function(){
		if($("input.service[type=checkbox]:checked").length < 1) {
			alert('Please select a service you are interested in');
			return false;
		}
	});
	$("#lovechain #WINDOWS").click(function() {
		if($(this).attr('checked')==true) $("#windows-interest").show();
		if($(this).attr('checked')==false) $("#windows-interest").hide();
	});
	$("#lovechain #SIDING").click(function() {
		if($(this).attr('checked')==true) {
			$("#siding-desc").show();
			$("#siding-portal-service-code").show();
		}
		if($(this).attr('checked')==false) {
			$("#siding-desc").hide();
			$("#siding-portal-service-code").hide();
		}
	});
	$("#lovechain #SUNROOM").click(function() {
		if($(this).attr('checked')==true) $("#sunroom-service").show();
		if($(this).attr('checked')==false) $("#sunroom-service").hide();
	});
	$("#lovechain #ROOM_ADDITIONS").click(function() {
		if($(this).attr('checked')==true) {
			$("#room-addition-product-service").show();
			$("#room-addition-more-details").show();
		}
		if($(this).attr('checked')==false) {
			$("#room-addition-product-service").hide();
			$("#room-addition-more-details").hide();
		}
	});
	$("#lovechain #FULL_KITCHEN_REMODELING").click(function() {
		if($(this).attr('checked')==true) {
			$("#optinquest").show();
			$("#kitchen-remodeling-desc").show();
		}
		if($(this).attr('checked')==false) {
			$("#optinquest").hide();
			$("#kitchen-remodeling-desc").hide();
		}
	});
	jQuery.easing.def = "easeOutExpo";
	$("#scrollLeft").click(function() { 
		scrollLeft();
		pollBtns();
	});
	$("#scrollRight").click(function() {
		scrollRight();
		pollBtns();
	});
	pollBtns();
});
/* ]]> */