function OpenLegendPopUp()
{
  var helpWin
  helpWin = window.open('http://www.moving.com/Moving_and_Planning/Quotes/AvailableServicesLegendPopUp.asp', 'helpWin', 'width=460,height=475,toolbar=no,scrollbars=yes,resizable=yes');
  helpWin.focus();
}
function setMoveType(newMoveType) {
	if(newMoveType==3) {
		//International
		Element.hide('toState');
		Element.hide('fromZip');
		Element.show('fromCountry');
		Element.show('fromCity');
		Element.show('toCountry');
		Element.hide('toCityText');
		Element.hide('toCity');
		$('toCountrySelect').value = 0;
		$('fromCountrySelect').value = 0;
	}
	else if (newMoveType==1) {
		//Full Service
		Element.show('toState');
		Element.show('fromZip');
		Element.hide('toZip');
		Element.show('toCity');
		Element.hide('toCityText');
		Element.show('weight');
		Element.hide('fromCountry');
		Element.hide('fromCity');
		Element.hide('toCountry');
		Element.hide('fromState');
		Element.hide('fromProvince');
		Element.hide('toProvince');
	}
	else {
		//Everything Else
		Element.show('toState');
		Element.hide('toZip');
		Element.show('toCity');
		Element.show('fromZip');
		Element.hide('toCityText');
		Element.hide('weight');
		Element.hide('fromCountry');
		Element.hide('fromCity');
		Element.hide('toCountry');
		Element.hide('fromState');
		Element.hide('fromProvince');
		Element.hide('toProvince');

	}
}
function updateFromStates(countryid) {
	if(countryid==1) {
		Element.hide('fromProvince');
		Element.hide('fromCity');
		Element.show('fromZip');
	}
	else if(countryid==2) {
		//Show Canadian Provinces
		Element.show('fromProvince');
		Element.hide('fromState');
		Element.hide('fromCity');
		Element.hide('fromZip');
	}
	else {
		Element.hide('fromState');
		Element.hide('fromZip');
		Element.hide('fromProvince');
		Element.show('fromCity');
	}
}
function updateToStates(countryid) {
	if(countryid==1) {
		//Show ZIP code stuff
		Element.hide('toProvince');
		Element.hide('toCity');
		Element.hide('toCityText');
		Element.show('toZip');
	}
	else if(countryid==2) {
		//Show Canadian Provinces
		Element.show('toProvince');
		Element.hide('toState');
		Element.hide('toCity');
		Element.hide('toCityText');
		Element.hide('toZip');
	}
	else {
		Element.hide('toState');
		Element.hide('toProvince');
		Element.hide('toZip');
		Element.hide('toCityText');
		Element.show('toCityText');
	}
}
function setMonthDays()
{
var optDay = $('day');
var optMonth = $('month');
var nMonth = $('month').value;
var nYear = $('year').options[$('year').selectedIndex].value;
var nMaxDay;
var i;
var nCurrentDay = optDay.selectedIndex + 1;
var maxDate = new Date();
maxDate.setDate(maxDate.getDate() + 179);
var minDate = new Date();
minDate.setDate(minDate.getDate() + 14);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

if (nMonth == 2)
{ if (((nYear % 4 == 0) && (nYear % 100 != 0)) || (nYear % 400 == 0))
nMaxDay = 29;
else
nMaxDay = 28;
}
else if (nMonth == 4 || nMonth == 30 || nMonth == 9 || nMonth == 11)
nMaxDay = 30
else
nMaxDay = 31;

if (nCurrentDay > nMaxDay)
nCurrentDay = nMaxDay;

var selected = optMonth.value;
var maxMonth = 12;
var minMonth = 1;
var nMinDay = 1;
if(maxDate.getFullYear() == nYear) {
	maxMonth = maxDate.getMonth() +1;
	if(nMonth==maxMonth) {
		nMaxDay = maxDate.getDate();
	}
}
if(minDate.getFullYear() == nYear) {
	minMonth = minDate.getMonth() +1;
}
optMonth.length=0;
var j=0;
for (i=minMonth;i<=maxMonth;i++) {
	optMonth[j] = new Option;
	optMonth[j].text = months[i-1];
	optMonth[j].value = i;
	j++;
}
optMonth.value = selected;
if(minDate.getFullYear() == nYear) {
	if($('month').value==minMonth) {
		nMinDay = minDate.getDate();
	}
}
selected = optDay.value;
optDay.length = 0;
j=0;
for (i=nMinDay; i<=nMaxDay; ++i)
{ 
optDay[j] = new Option;
optDay[j].text = i;
optDay[j].value = i;
j++;
}
if(nMaxDay < selected) {
	selected = nMaxDay;
}
optDay.value = selected;
}

function initDateFields() {
	var maxDate = new Date();
	var minDate = new Date();
	var optYear = $('year');
	maxDate.setDate(maxDate.getDate() + 179);
	minDate.setDate(minDate.getDate() + 14);

	$('month').value = minDate.getMonth() + 1;
	$('day').value = minDate.getDate();
	optYear.length=0;
	optYear[0] = new Option();
	optYear[0].value = minDate.getFullYear();
	optYear[0].text = minDate.getFullYear();
	if(minDate.getFullYear() != maxDate.getFullYear()) {
		optYear[1] = new Option();
		optYear[1].value = maxDate.getFullYear();
		optYear[1].text = maxDate.getFullYear();
	}
	setMonthDays();
}
function checkPhone() {
	if($('workPhone').value == "" && $('homePhone').value=="" && $('mobilePhone').value == "") {
		alert('You must provide a phone number');
	return false;
	}
	return true;
}
function submitMovers2() {
var valid = new Validation('moverform', {onSubmit:false});
Validation.add('validate-phone', 'Please enter your phone number in the format ###-###-####x###', {pattern: new RegExp("^[0-9]{3}\-[0-9]{3}\-[0-9]{4}(x[0-9]+)?$")});
var result = valid.validate();
if (result == true && checkPhone()) {
	pageTracker._trackPageview('/outgoing/moving');
	$('moverform').submit();
}
}
function submitMovers() {
var valid = new Validation('moverform', {onSubmit:false});
Validation.add('validate-phone', 'Please enter your phone number in the format ###-###-####x###', {pattern: new RegExp("^[0-9]{3}\-[0-9]{3}\-[0-9]{4}(x[0-9]+)?$")});
var result = valid.validate();
if (result == true) {
	pageTracker._trackPageview('/outgoing/moving');
	$('moverform').submit();
}
}

