﻿
var ERROR_DISPLAY = 'ALERT';
var PARTNER = '';
var DOMAIN_ID = ''; //(5083612 - relocation)  (5082489 - vanlins)
var INITIAL_SERVICE = '1001';
	
var Type = '';
var Service = '';
var FromPostal = '';
var FromCountry = '1';
var ToCountry = '1';
var ToState = '';
var ToCity = '';
var Size = '';
var MovingDate = '';
var FirstName = '';
var LastName = '';
var Email = '';
var DayTel = '';
var EveningTel = '';
var VehicleType = '';
var VehicleMake = '';
var VehicleModel = '';
var VehicleYear = '';
var VehicleCondition = '';

function Init()
{
	document.getElementById('ddlMovingType').value = INITIAL_SERVICE;
	MovingTypeChange(document.getElementById('ddlMovingType'));
	InitilizeDdlState('ddlMovingToState'); 
	InitilizeDdlState('ddlAutoToState');
}
function MovingTypeChange(ddl) 
{
	switch (ddl.value) {
		case ('1001'):
		case ('1013'):
			document.getElementById('trMovingZipCode').style.display = 'block';
			document.getElementById('trMovingToState').style.display = 'block';
			document.getElementById('trMovingSize').style.display = 'block';
			document.getElementById('trAutoZipCode').style.display = 'none';
			document.getElementById('trAutoToState').style.display = 'none';
			document.getElementById('trCarInfo').style.display = 'none';
			break;
		case ('1002'):
			document.getElementById('trMovingZipCode').style.display = 'none';
			document.getElementById('trMovingToState').style.display = 'none';
			document.getElementById('trMovingSize').style.display = 'none';
			document.getElementById('trAutoZipCode').style.display = 'block';
			document.getElementById('trAutoToState').style.display = 'block';
			document.getElementById('trCarInfo').style.display = 'block';
			break;			
	}
	SetFormTitle();
}
function SetFormTitle()
{
	switch(document.getElementById('ddlMovingType').value)
	{
		case('1002'):
			document.getElementById('divUloadWarning').style.display = 'none';
			if (document.getElementById('spnTitle') != null) document.getElementById('spnTitle').innerHTML = "<H1>Get Free Auto Transport Quotes</H1>";
			break;
		case('1001'):
			document.getElementById('divUloadWarning').style.display = 'none';
			if (document.getElementById('spnTitle') != null) document.getElementById('spnTitle').innerHTML = "<H1>Get Free Moving Quotes</H1>";
			break;
		case('1013'):
			document.getElementById('divUloadWarning').style.display = 'block';
			if (document.getElementById('spnTitle') != null) document.getElementById('spnTitle').innerHTML = "<H1>Get Free Self Service Moving Quotes</H1>";
			break;
	}
}
function SubmitForm() 
{
	Type = 'Moving';
	Service = document.getElementById('ddlMovingType').value;
	FromPostal = '';
	FromCountry = '1';
	ToCountry = '1';
	ToState = '';
	ToCity = '';
	Size = '';
	MovingDate = document.getElementById('txtMovingDate').value;
	FirstName = document.getElementById('txtFirstName').value;
	LastName = document.getElementById('txtLastName').value;
	Email = document.getElementById('txtEmail').value;
	DayTel = document.getElementById('txtDayPhone').value;
	EveningTel = document.getElementById('txtEveningPhone').value;
	VehicleType = '';
	VehicleMake = '';
	VehicleModel = '';
	VehicleYear = '';
	VehicleCondition = '';
	switch(Service)
	{
		case('1002'):
			FromPostal = document.getElementById('txtAutoZipCode').value;
			ToState = document.getElementById('ddlAutoToState').value;
			ToCity = document.getElementById('txtAutoToCity').value;
			VehicleType = document.getElementById('ddlVehicleType').value;
			VehicleMake = document.getElementById('txtVehicleMake').value;
			VehicleModel = document.getElementById('txtVehicleModel').value;
			VehicleYear = document.getElementById('txtVehicleYear').value;
			VehicleCondition = document.getElementById('ddlVehicleCondition').value;			
			break;
		case('1001'):
			FromPostal = document.getElementById('txtMovingZipCode').value;
			ToState = document.getElementById('ddlMovingToState').value;
			ToCity = document.getElementById('txtMovingToCity').value;
			Size = document.getElementById('ddlMovingSize').value;				
			break;		
		case('1013'):
			Service = document.getElementById('ddlMovingType').value;
			FromPostal = document.getElementById('txtMovingZipCode').value;
			ToState = document.getElementById('ddlMovingToState').value;
			ToCity = document.getElementById('txtMovingToCity').value;
			Size = document.getElementById('ddlMovingSize').value;				
			break;
	}
	BuildQueryString();
}
function BuildQueryString()
{
	var queryString = '';
	if (Type == 'Moving') {
		queryString += "?Type=movingquote";
		queryString += "&Service=" + Service;
		queryString += ((FromPostal != '')? "&FromPostal=" + FromPostal : '');
		queryString += ((FromCountry != '')? "&FromCountry=" + FromCountry : '');
		queryString += ((ToCity != '')? "&ToCity=" + ToCity : '');
		queryString += ((ToState != '')? "&ToState=" + ToState : '');
		queryString += ((ToCountry != '')? "&ToCountry=" + ToCountry : '');		
		queryString += ((Size != '')? "&Size=" + Size : '');
		queryString += ((MovingDate != '')? "&MovingDate=" + MovingDate : '');
		queryString += ((FirstName != '')? "&FirstName=" + FirstName : '');
		queryString += ((LastName != '')? "&LastName=" + LastName : '');
		queryString += ((Email != '')? "&Email=" + Email : '');
		queryString += ((DayTel != '')? "&DayTel=" + DayTel : '');
		queryString += ((EveningTel != '')? "&EveningTel=" + EveningTel : '');
		queryString += ((VehicleType != '')? "&VehicleType=" + VehicleType : '');
		queryString += ((VehicleMake != '')? "&VehicleMake=" + VehicleMake : '');
		queryString += ((VehicleModel != '')? "&VehicleModel=" + VehicleModel : '');
		queryString += ((VehicleYear != '')? "&VehicleYear=" + VehicleYear : '');
		queryString += ((VehicleCondition != '')? "&VehicleCondition=" + VehicleCondition : '');		
		queryString += ((PARTNER != '')? "&Partner=" + PARTNER : '');
		queryString += ((DOMAIN_ID != '')? "&Domain_ID=" + DOMAIN_ID : '');
		queryString += "&IP=JSWidget";
	}
	if (Validate())
	{
        pic1 = new Image(1, 1);
        //pic1.src = "http://localhost:1647/relocationweb/RemoteTracking.aspx" + queryString;
        pic1.src = "http://www.vanlines.com/RemoteTracking.aspx" + queryString;
		document.getElementById('dvForm').style.display = 'none';
        document.getElementById('dvThankYou').style.display = 'block';
	}
}
var stateIdArray = new Array(-1,4,3,6,5,7,8,9,11,10,12,13,14,15,17,18,19,16,20,21,22,25,24,23,26,27,29,28,30,33,37,34,35,36,38,31,32,39,40,41,42,43,44,45,46,47,48,49,52,51,50,53,55,54,56);
var stateNameArray = new Array("Select a state","Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","District of Columbia","Florida","Georgia","Guam","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virgin Islands","Virginia","Washington","West Virginia","Wisconsin","Wyoming");
function InitilizeDdlState(objId)
{
	document.getElementById(objId).options.length = 0;
	for(var i=0; i< stateIdArray.length; i++) 
	{	
	    var anOptionA = new Option(stateNameArray[i],stateIdArray[i]);
	    document.getElementById(objId).options.add(anOptionA);
	}
}

function Validate()
{
	var Errors = '';
	switch(document.getElementById('ddlMovingType').value)
	{
		case('1001'):
		case('1013'):
			if (document.getElementById('txtMovingZipCode').value == '') 
				Errors += 'From ZipCode - Required\n\r';
			else
				if (!ValidateZipCode(document.getElementById('txtMovingZipCode').value)) 
					Errors += 'From ZipCode - Invalid\n\r';
			if (document.getElementById('ddlMovingToState').value == -1) 
				Errors += 'To State - Required\n\r';
			if (document.getElementById('ddlMovingSize').value == '0000') 
				Errors += 'Moving Size - Required\n\r';		
			break;
		case('1002'):
			if (document.getElementById('txtAutoZipCode').value == '') 
				Errors += 'From ZipCode - Required\n\r';
			else
				if (!ValidateZipCode(document.getElementById('txtAutoZipCode').value)) 
					Errors += 'From ZipCode - Invalid\n\r';
			if (document.getElementById('ddlAutoToState').value == -1) 
				Errors += 'To State - Required\n\r';
			if (VehicleType == '') 
				Errors += 'Vehicle Type - Required\n\r';	
			if (VehicleMake == '') 
				Errors += 'Vehicle Make - Required\n\r';	
			if (VehicleModel == '') 
				Errors += 'Vehicle Model - Required\n\r';	
			if (VehicleYear == '') 
				Errors += 'Vehicle Year - Required\n\r';	
			else
				if (!ValidateVehicleYear(VehicleYear))
					Errors += 'Vehicle Year - Invalid\n\r';	
			if (VehicleCondition == '') 
				Errors += 'Vehicle Condition - Required\n\r';	
			break;
	}
	if (ToCity == '') 
		Errors += 'To City - Required\n\r';		
	if (MovingDate == '') 
		Errors += 'Moving Date - Required\n\r';	
	else
		if (!ValidateDateFormat(MovingDate))
			Errors += 'Invalid Date Format mm/dd/yy\n\r';	
		else if (!ValidateDate(MovingDate))
			Errors += 'Invalid Date - Must be a future date (' + MovingDate + ')\n\r';		
	if (FirstName == '') 
		Errors += 'First Name - Required\n\r';	
	if (LastName == '') 
		Errors += 'Last Name - Required\n\r';	
	if (MovingDate == '') 
		Errors += 'Moving Date - Required\n\r';	
	if (Email == '') 
		Errors += 'Email - Required\n\r';	
	else if (!ValidateEmail(Email))
		Errors += 'Email - Invalid\n\r';	
	if ((DayTel == '') && (EveningTel == ''))
		Errors += 'Atleast one telephone is required\n\r';	
	else
	{
		if (DayTel != '')
		{
			if (!ValidateTelephone(DayTel))
				Errors += 'Day Phone - invalid\n\r';
		}
		if (EveningTel != '')
		{
			if (!ValidateTelephone(EveningTel))
				Errors += 'Evening Phone - invalid\n\r';
		}		
	}
	if (Errors != '')
	{
		if (ERROR_DISPLAY == 'ALERT')
			alert(Errors);
//		else
//			document.getElementById('spnErrors').style.display = 'block';
		return false;
	}
	else
	{
//		document.getElementById('spnErrors').style.display = 'none';
		return true;
	}
}
function ValidateZipCode(zipcode)
{
	if (zipcode.match(/^\d\d\d\d\d$/))
		return true;
	else
		return false;
}
function ValidateVehicleYear(vehicleYear)
{
	if (vehicleYear > 1900)
		return true;
	else
		return false;
}
function ValidateDate(date)
{
	if (!(date.match(/^\d{1,2}\/\d{1,2}\/\d{2,4}$/))) return false;
	var myArray = date.split("/");
	var day = myArray[1];
	var month = myArray[0];
	var year = myArray[2];
	if (year < 2000) year = '20' + year;
	var myDate = new Date();
	var today = new Date();
	myDate.setFullYear(year,month - 1, day);
//alert(myDate);
	if (myDate <= today)
		return false;
	else
		return true;
}
function ValidateDateFormat(date)
{
	if (!(date.match(/^\d{1,2}\/\d{1,2}\/\d{2,4}$/))) 
		return false;
	else
		return true;
}	
function ValidateEmail(email)
{
	if (!(email.match(/\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6}/))) 
		return false;
	else
		return true;
}
function ValidateTelephone(telephone)
{
	telephone = replaceIt(telephone, ' ', ''); 
	telephone = replaceIt(telephone, '.', '');
	telephone = replaceIt(telephone, '(', '');
	telephone = replaceIt(telephone, ')', '');
	if (!(telephone.match(/^1? ?-?\(?\d{3}\)?.?-? ?\d{3}-?.? ?\d{4}$/))) 
		return false;
	else
	{
		if (telephone.length != 10)
			return false;
		else
			return true;
	}
}		
function replaceIt(sString, sReplaceThis, sWithThis) 
{ 
	if (sReplaceThis != "" && sReplaceThis != sWithThis) 
	{ 
		var index = 0;
		var counter = 0; 
		var start = 0; 
		var before = ""; 
		var after = ""; 
		while (counter<sString.length) 
		{ 
			index++;
			start = sString.indexOf(sReplaceThis, counter); 
			if (start == -1) 
			{ 
				break; 
			} 
			else 
			{ 
				before = sString.substr(0, start); 
				after = sString.substr(start + sReplaceThis.length, sString.length); 
				sString = before + sWithThis + after; 
				counter = before.length + sWithThis.length;
				sString = sString.replace('##REPLACEID##',index); 
			} 
		} 
	} 
	return sString; 
} 
function CreateForm()
{
var html = '';
html += "<link href='http://www.vanlines.com/css/QuoteForm_v1001.css' rel='stylesheet' type='text/css' />";
html += "<div class='fullform'>";
html += "	<div class='divtop'><!-- --></div>";
html += "	<div class='ff_wrap'>";
html += "		<div id='divUloadWarning'></div>";
html += "		<span id='spnTitle'><H1>Get Free Moving Quotes</H1></span>";
html += "		<div id='dvForm'>";
html += "			<div class='ff_head'>";
html += "				<p>Please choose any of the services below to get a quick quote for your upcoming move.</p>";
html += "				<div id='div1' style='display:none'>";
html += "					* Please note:<br />";
html += "					This service is for out-of-state moves only. If you need help moving within the same state, please select 'Full Service Movers' from the list below.";
html += "				</div>";
html += "			</div>";
html += "			<div class='ff_body'>";
html += "				<div class='ff_segment'>";
html += "					<div class='headset'><h2>Services:</h2></div>";
html += "					<div class='segment_wrap'>";
html += "						<div class='segment_fields'>";
html += "							<div class='sf_field'>Service Needed:</div>";
html += "							<div class='sf_value'>";
html += "								<select id='ddlMovingType' onchange='MovingTypeChange(this)' onkeyup='MovingTypeChange(this)'>";
html += "									<option value='1001'>Full Service Movers</option>";
html += "									<option value='1002'>Moving a Car</option>";
html += "									<option value='1013'>U-Load They'll Drive</option>";
html += "								</select>";
html += "							</div>";
html += "						</div>";
html += "					</div>";
html += "					<div class='segment_footer'><!-- --></div>";
html += "				</div>";
html += "				<div class='ff_segment'>";
html += "					<div class='headset'><h2>Moving From:</h2></div>";
html += "					<div class='segment_wrap'>";
html += "						<div class='segment_fields' id='trAutoZipCode' style='display:none'>";
html += "							<div class='sf_field'>Shipping Zip Code:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' maxlength='5' id='txtAutoZipCode' />";
html += "							</div>";
html += "						</div>";
html += "						<div class='segment_fields' id='trMovingZipCode' style='display:block'>";
html += "							<div class='sf_field'>Moving From Zip Code:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' class='sf_zip' maxlength='5' id='txtMovingZipCode' />";
html += "							</div>";
html += "						</div>";
html += "					</div>";
html += "					<div class='segment_footer'><!-- --></div>";
html += "				</div>";
html += "				<div class='ff_segment'>";
html += "					<div class='headset'><h2>Moving To:</h2></div>";
html += "					<div class='segment_wrap' id='trAutoToState' style='display:none'>";
html += "						<div class='segment_fields'> ";
html += "							<div class='sf_field'>City:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' id='txtAutoToCity' />";
html += "							</div>";
html += "						</div>";
html += "						<div class='segment_fields'> ";
html += "							<div class='sf_field'>State Shipping To:</div>";
html += "							<div class='sf_value'>";
html += "								<select id='ddlAutoToState'></select>";
html += "							</div>";
html += "						</div>";
html += "					</div>";
html += "					<div class='segment_wrap' id='trMovingToState' style='display:block'>";
html += "						<div class='segment_fields'>";
html += "							<div class='sf_field'>City:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' id='txtMovingToCity' />";
html += "							</div>";
html += "						</div>";
html += "						<div class='segment_fields'>";
html += "							<div class='sf_field'>I am Moving To:</div>";
html += "							<div class='sf_value'>";
html += "								<select id='ddlMovingToState' ></select>";
html += "							</div>";
html += "						</div>";
html += "					</div>";
html += "					<div class='segment_footer'><!-- --></div>";
html += "				</div>";
html += "				<div class='ff_segment'>";
html += "					<div class='headset'><h2>Moving Info:</h2></div>";
html += "					<div class='segment_wrap'>";
html += "						<div class='segment_fields' id='trMovingSize' style='display:block'>";
html += "							<div class='sf_field'>Size Of Move:</div>";
html += "							<div class='sf_value'>";
html += "								<select id='ddlMovingSize'>";
html += "									<option value='0000'>Select Weight</option>";
html += "									<option value='0602'>Studio 1500 lbs</option>";
html += "									<option value='0604'>1 BR Small 3000 lbs</option>";
html += "									<option value='0605'>1 BR Large 4000 lbs</option>";
html += "									<option value='0606'>2 BR Small 4500 lbs</option>";
html += "									<option value='0607'>2 BR Large 6500 lbs</option>";
html += "									<option value='0608'>3 BR Small 8000 lbs</option>";
html += "									<option value='0609'>3 BR Large 9000 lbs</option>";
html += "									<option value='0610'>4 BR Small 10000 lbs</option>";
html += "									<option value='0612'>4 BR Large 12000 lbs</option>";
html += "									<option value='0611'>Over 12000 lbs</option>";
html += "									<option value='0601'>Partial Home</option>";
html += "								</select>";
html += "							</div>";
html += "						</div>";
html += "						<div class='segment_fields'>";
html += "							<div class='sf_field'>Date of Move:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' class='sf_date' id='txtMovingDate' value='mm/dd/yy' onfocus=\"if(this.value=='mm/dd/yy') {this.value='';}\" onblur=\"if(this.value=='') {this.value='mm/dd/yy';}\" />";
html += "							</div>";
html += "						</div>";
html += "					</div>";
html += "					<div class='segment_footer'><!-- --></div>";
html += "				</div>";
html += "				<div class='ff_segment' id='trCarInfo' style='display:none'>";
html += "					<div class='headset'><h2>Vehicle Information:</h2></div>";
html += "					<div class='segment_wrap'>";
html += "						<div class='segment_fields'>";
html += "							<div class='car_wrap'>";
html += "								<div class='car_field'>";
html += "									Vehicle Type<br />";
html += "									<select id='ddlVehicleType'>";
html += "										<option value='0ZC'>Car</option>";
html += "										<option value='0ZM'>Motorcycle</option>";
html += "										<option value='0ZU'>SUV</option>";
html += "										<option value='0ZT'>Truck</option>";
html += "										<option value='0ZV'>Van</option>";
html += "										<option value='0ZOT'>Other</option>";
html += "									</select>";
html += "								</div>";
html += "								<div class='car_field'>";
html += "									Running?<br />";
html += "									<select id='ddlVehicleCondition'>";
html += "										<option value='0U01'>Yes</option>";
html += "										<option value='0U00'>No</option>";
html += "									</select>";
html += "								</div>";
html += "							</div>";
html += "							<div class='car_wrap'>";
html += "								<div class='car_field'>";
html += "									Make<br />";
html += "									<input type='text' id='txtVehicleMake' />";
html += "								</div>";
html += "								<div class='car_field'>";
html += "									Model<br />";
html += "									<input type='text' id='txtVehicleModel' />";
html += "								</div>";
html += "								<div class='car_field'>";
html += "									Year<br />";
html += "									<input type='text' id='txtVehicleYear' />";
html += "								</div>";
html += "							</div>";
html += "						</div>";
html += "					</div>";
html += "					<div class='segment_footer'><!-- --></div>";
html += "				</div>";
html += "				<div class='ff_segment'>";
html += "					<div class='headset'>";
html += "						<h2>Contact Information:</h2>";
html += "					</div>";
html += "					<div class='segment_wrap'>";
html += "						<div class='segment_fields'>";
html += "							<div class='sf_field'>First Name:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' id='txtFirstName' />";
html += "							</div>";
html += "						</div>";
html += "						<div class='segment_fields'>";
html += "							<div class='sf_field'>Last Name:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' id='txtLastName' />";
html += "							</div>";
html += "						</div>";
html += "						<div class='segment_fields'>";
html += "							<div class='sf_field'>Email:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' id='txtEmail' />";
html += "							</div>";
html += "						</div>";
html += "						<div class='segment_fields'>";
html += "							<div class='sf_field'>Day Phone:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' id='txtDayPhone' />";
html += "							</div>";
html += "						</div>";
html += "						<div class='segment_fields'>";
html += "							<div class='sf_field'>Evening Phone:</div>";
html += "							<div class='sf_value'>";
html += "								<input type='text' id='txtEveningPhone' />";
html += "							</div>";
html += "						</div>";
html += "					</div>";
html += "					<div class='segment_footer'><!-- --></div>";
html += "				</div>";
html += "				<div class='ff_segment'>";
html += "					<div class='sf_button'><input type='button' value='Done' onclick='SubmitForm()'/></div>";
html += "				</div>";
html += "			</div>";
html += "		</div>";
html += "		<div id='dvThankYou' style='display:none'>";
html += "			<b>Thank You</b><br />";
html += "			You will be contacted shortly.";
html += "		</div>";
html += "	</div>";
html += "	<div class='divbot'><!-- --></div>";
html += "</div>";

	
	document.write(html);

	setTimeout("Init();", 1500);
}

//setTimeout("Init();", 1500);
