// JavaScript for movers quote request form by I-I Tsai, Dec. 12, 2005
//validate big quote request form on quote-request.htm
function validate_quoterequest( form )
{
  if ( form.contactname.value.length < 1 ) 
  {
    alert( "Please enter your name so that we can get back to you with your moving quote" );
    form.contactname.focus();
	return false;
  }
  if ( form.contact.value.length < 1 ) 
  {
    alert( "Please enter a phone number so that we can get back to you with your moving quote" );
    form.contact.focus();
	return false;
  }
  if ( form.movingfromselect.options[form.movingfromselect.selectedIndex].disabled || form.movingfromselect.value == "MovingFromCity")
  {
    alert( "Please select a city that you are moving from" );
    form.movingfromselect.focus();
	return false;
  }
  if ( form.movingtoselect.options[form.movingtoselect.selectedIndex].disabled || form.movingtoselect.value == "MovingToCity")
  {
    alert( "Please select a city that you are moving to" );
    form.movingtoselect.focus();
	return false;
  }
  if ( form.typeofmove.value == "PLT")
  {
    alert( "Please select a service wanted so that we can get back to you with your moving quote" );
    form.typeofmove.focus();
	return false;
  }
  if ( form.persons.value == "Persons")
  {
    alert( "Please select the number of persons in your household so that we can get back to you with your moving quote" );
    form.persons.focus();
	return false;
  }
  if ( form.rooms.value == "FurnishedRooms")
  {
    alert( "Please select the number of furnished rooms in your household so that we can get back to you with your moving quote" );
    form.rooms.focus();
	return false;
  }
  return true;
}

//validate "Other" selection drop down
function validate_select(obj)
{
	if(obj.name == "movingfromselect")
	{
		if(obj.value == "Other")
		{
			showLayer('movingfromdiv');
		}
		else
		{
			hideLayer('movingfromdiv');
		}
	}
	else
	{
		if(obj.value == "Other")
		{
			showLayer('movingtodiv');
		}
		else
		{
			hideLayer('movingtodiv');
		}
	}
}

function showLayer(layerid)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(layerid).style.visibility = "visible";
		document.getElementById(layerid).style.display = "block"; 
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[layerid].style.visibility = "visible";
		document.getElementById(layerid).style.display = "block"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[layerid].visibility = "visible";
		document.getElementById(layerid).style.display = "block"; 
	}
}

function hideLayer(layerid)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(layerid).style.visibility = "hidden";
		document.getElementById(layerid).style.display = "none"; 
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[layerid].style.visibility = "hidden";
		document.getElementById(layerid).style.display = "none"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[layerid].visibility = "hidden";
		document.getElementById(layerid).style.display = "none"; 
	}
}

function validate_province(obj) 
{
    var disabled = obj.options[obj.selectedIndex].disabled;
    if(disabled) 
	{
		obj.selectedIndex = obj.selectedIndex+1;
        return false;
    }
    else 
	{
		obj.defaultSelectedIndex = obj.selectedIndex;
	}

    return true;
}

//validate city page forms
function validate( form ){
  if ( form.contactname.value.length < 1 ) {
    alert( "Please enter your name so that we can get back to you with your moving quote" );
    return false;
  }
  if ( form.contact.value.length < 1 ) {
    alert( "Please enter an email address or phone number so that we can get back to you with your moving quote" );
    return false;
  }
    if ( form.message.value.length < 1 ) {
    alert( "Please enter a message or question.  Our team is pleased to help." );
    return false;
  }

  return true;
}

//print page function that opens the print window.
function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
}

//open a pop up window for email an article
function openPopUpWindow(url,winName,features) {
  window.open(url,winName,features);
}

//email an article function
function emailanarticle()
{
	var url=document.URL; 
	var title=document.title; 
	var popupwindowurl = "/emailanarticle.php?url="+url+"&title="+title; 
	openPopUpWindow(popupwindowurl,'','scrollbars=no,resizable=yes,width=450,height=350');
}

function validateemailanarticle( form )
{	
	if ( form.sendername.value.length < 1 ) {
		alert( "Please enter your name." );
		form.sendername.focus();
		return false;
	}
	if ( form.receivername.value.length < 1 ) {
		alert( "Please enter receiver's name." );
		form.receivername.focus();
		return false;
	}
	if ( form.receiveremail.value.length < 1 ) {
		alert( "Please enter receiver's email." );
		form.receiveremail.focus();
		return false;
	}

	return true;
}

//bookmark page function
function bookmarkus() 
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
	{
		var url=document.URL;
		var title=document.title;
		
		window.external.AddFavorite(url,title);
	}
	else 
	{
		var msg = "Press CTRL+D to add a bookmark to this site";
		if(navigator.appName == "Netscape")
		{
			alert(msg);
		}
	}
}

//date picker for quote request form on every page
<!--
// you may use/modify this code, but please give credit as a courtesy
// script by Arash Ramin (http://www.digitalroom.net)
function setcurrentdate() 
{
  // changes the date selector menus to the current date
  var currentDate = new Date();
  currentDate.setDate(currentDate.getDate()+14); 

  document.requestquote.year.selectedIndex = 0;
  document.requestquote.month.selectedIndex = currentDate.getMonth();

  setdays();  
  document.requestquote.day.selectedIndex = currentDate.getDate() - 1;
}

function setdays() 
{
  var y = document.requestquote.year.options[document.requestquote.year.selectedIndex].value;
  var m = document.requestquote.month.selectedIndex;
  var d;
  // find number of days in current month
  if ( (m == 3) || (m == 5) || (m == 8) || (m == 10) ) 
  {
    days = 30;
  }
  else if (m == 1) 
  {
    // check for leapyear - Any year divisible by 4, except those divisible by 100 (but NOT 400)
    if ( (Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))) )
      days = 29
    else
      days = 28
  }
  else {
    days = 31;
  }

  // if (days in new month > current days) then we must add the extra days
  if (days > document.requestquote.day.length) 
  {
    for (i = document.requestquote.day.length; i < days; i++) 
	{
      document.requestquote.day.length = days;
      document.requestquote.day.options[i].text = i + 1;
      document.requestquote.day.options[i].value = i + 1;
    }
  }
  
  // if (days in new month < current days) then we must delete the extra days
  if (days < document.requestquote.day.length) 
  {
    document.requestquote.day.length = days;
    if (document.requestquote.day.selectedIndex == -1) 
      document.requestquote.day.selectedIndex = days -1;
  }
}

function populate_year()
{
	document.writeln("<select name=\"year\" class=\"quoteselect\" onchange=\"setdays();\">");
	<!--
	// get current year and show the dates for the next 2 years
	var currentDate = new Date();
	var currentYear = currentDate.getYear();
	if (currentYear < 2000) 
	{
	  currentYear += 1900;
	}
	
	for (i = 0; i < 4; i++) 
	{
	  document.writeln('<OPTION VALUE="' + currentYear + '">' + currentYear);
	  currentYear++;
	}	
  	// -->
	document.writeln("</select>");
}

function populate_month()
{
	document.writeln("<select name=\"month\" class=\"quoteselect\" onchange=\"setdays();\">");
	document.writeln("<option value=\"January\">Jan</option>");
	document.writeln("<option value=\"February\">Feb</option>");
	document.writeln("<option value=\"March\">Mar</option>");
	document.writeln("<option value=\"April\">April</option>");
	document.writeln("<option value=\"May\">May</option>");
	document.writeln("<option value=\"June\">June</option>");
	document.writeln("<option value=\"July\">July</option>");
	document.writeln("<option value=\"August\">Aug</option>");
	document.writeln("<option value=\"September\">Sept</option>");
	document.writeln("<option value=\"October\">Oct</option>");
	document.writeln("<option value=\"November\">Nov</option>");
	document.writeln("<option value=\"December\">Dec</option>");
	document.writeln("</select>");
}

function populate_day()
{
	document.writeln("<select class=\"quoteselect\" name=\"day\">");
	// Netscape doesn't seem to like a SELECT menu without any <OPTION> elements
	for (i = 1; i < 32; i++) {
	  document.writeln('<option value="' + i + '">' + i+'</option>');
	  }
	// -->
	document.writeln("</select>");
}
//-->

function validateblogquestion(form)
{
	if ( form.subject.value.length < 1 ) 
	{
		alert( "Please enter a subject of your question." );
		form.subject.focus();
		return false;
	}
	if ( form.message.value.length < 1 ) 
	{
		alert( "Please enter a question.  Our team is pleased to help." );
		form.message.focus();
		return false;
	}
	return true;
}
