// JavaScript Document

//Pop up window ... centered
function popMe(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

//Varify Estimate
function checkEstimate(form) {        
var firstName = new String(form.first_name.value);
	if (firstName==''){
	alert("You must enter your first name");
	form.first_name.focus();
	form.first_name.select();
	return false;
 	}
 	
var lastName = new String(form.last_name.value);
	if (lastName==''){
	alert("You must enter your last name");
	form.last_name.focus();
	form.last_name.select();
	return false;
 	}
   
var address = new String(form.email.value);
	if ((address.indexOf("@") == -1) || (address.indexOf(".") == -1) || (address.length < 7)) {
	alert("You must specify a valid email address.");
	form.email.focus();
	form.email.select();
	return false;
	} 

var myPhone = new String(form.phone.value);
	if (myPhone==''){
	alert("You must enter your phone number");
 	form.phone.focus();
	return false;
	}
	
var myPeople = new String(form.people.value);
	if (myPeople==''){
	alert("You must enter the number of people");
 	form.people.focus();
	return false;
	}
	
var myEvent = -1;
	for (i=form.radiobutton_type.length-1; i > -1; i--) {
	if (form.radiobutton_type[i].checked) {
	myEvent = i; i = -1;
	}
	
	}
	if (myEvent == -1) {
	alert("You must select an Event Type");
	return false;
	}
	
var myLocation = -1;
	for (i=form.radiobutton_location.length-1; i > -1; i--) {
	if (form.radiobutton_location[i].checked) {
	myLocation = i; i = -1;
	}
	
	}
	if (myLocation == -1) {
	alert("You must select a Location");
	return false;
	}
	
var myAlcohol = -1;
	for (i=form.radiobutton_alcohol.length-1; i > -1; i--) {
	if (form.radiobutton_alcohol[i].checked) {
	myAlcohol = i; i = -1;
	}
	
	}
	if (myAlcohol == -1) {
	alert("You must specify if alcohol is needed");
	return false;
	}
}


//Varify Newsletter
function checkNewsletter(form) {        
var firstName = new String(form.first_name.value);
	if (firstName==''){
	alert("You must enter your first name");
	form.first_name.focus();
	form.first_name.select();
	return false;
 	}
 	
var lastName = new String(form.last_name.value);
	if (lastName==''){
	alert("You must enter your last name");
	form.last_name.focus();
	form.last_name.select();
	return false;
 	}
   
var address = new String(form.email.value);
	if ((address.indexOf("@") == -1) || (address.indexOf(".") == -1) || (address.length < 7)) {
	alert("You must specify a valid email address.");
	form.email.focus();
	form.email.select();
	return false;
	} 
}


//Varify Menu
function checkMenu(form) {        
var firstName = new String(form.first_name.value);
	if (firstName==''){
	alert("You must enter your first name");
	form.first_name.focus();
	form.first_name.select();
	return false;
 	}
 	
var lastName = new String(form.last_name.value);
	if (lastName==''){
	alert("You must enter your last name");
	form.last_name.focus();
	form.last_name.select();
	return false;
 	}
   
var address = new String(form.email.value);
	if ((address.indexOf("@") == -1) || (address.indexOf(".") == -1) || (address.length < 7)) {
	alert("You must specify a valid email address.");
	form.email.focus();
	form.email.select();
	return false;
	} 

var myPhone = new String(form.phone.value);
	if (myPhone==''){
	alert("You must enter your phone number");
 	form.phone.focus();
	return false;
	}
	
//------- options -------
	
var myStyle = -1;
	for (i=form.radiobutton_style.length-1; i > -1; i--) {
	if (form.radiobutton_style[i].checked) {
	myStyle = i; i = -1;
	}
	
	}
	if (myStyle == -1) {
	alert("You must choose your turkey style");
	return false;
	}
	
var myPresentation = -1;
	for (i=form.radiobutton_presentation.length-1; i > -1; i--) {
	if (form.radiobutton_presentation[i].checked) {
	myPresentation = i; i = -1;
	}
	
	}
	if (myPresentation == -1) {
	alert("You must choose your presentation");
	return false;
	}
	
var myVeg = -1;
	for (i=form.radiobutton_veggies.length-1; i > -1; i--) {
	if (form.radiobutton_veggies[i].checked) {
	myVeg = i; i = -1;
	}
	
	}
	if (myVeg == -1) {
	alert("You must choose your vegetable");
	return false;
	}
	
var myStuffing = -1;
	for (i=form.radiobutton_stuffing.length-1; i > -1; i--) {
	if (form.radiobutton_stuffing[i].checked) {
	myStuffing = i; i = -1;
	}
	
	}
	if (myStuffing == -1) {
	alert("You must choose your stuffing");
	return false;
	}
	
var myBread = -1;
	for (i=form.radiobutton_bread.length-1; i > -1; i--) {
	if (form.radiobutton_bread[i].checked) {
	myBread = i; i = -1;
	}
	
	}
	if (myBread == -1) {
	alert("You must choose your bread");
	return false;
	}
}

// Smooth Scroll Back to Top

function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}
