function servicesSubnavOpen(menu,menuheight) {
    clearInterval(time);
    dropdownmenu=menu;
    dropdownheight=menuheight;
    time=setInterval("increasewidth(dropdownmenu,dropdownheight)",10);
}


function servicesSubnavClose(menu, menuheight) {
    clearInterval(time);
    dropdownmenu=menu;
    dropdownheight=menuheight;
    IE7 = navigator.appVersion.indexOf("MSIE 7.") != -1;
    if (IE7==false) {
    time=setInterval("decreasewidth(dropdownmenu)",20);
    } else {
    time=setInterval("ie7decreasewidth(dropdownmenu)",20);
    }
}


function services2SubnavOpen(menu2,menuheight2) {
    clearInterval(time2);
    dropdownmenu2=menu2;
    dropdownheight2=menuheight2;
    time2=setInterval("increasewidth2(dropdownmenu2,dropdownheight2)",10);
}
function services2SubnavClose(menu2, menuheight2) {
    clearInterval(time2);
    dropdownmenu2=menu2;
    dropdownheight2=menuheight2;
    IE7 = navigator.appVersion.indexOf("MSIE 7.") != -1;
    if (IE7==false) {
    time2=setInterval("decreasewidth2(dropdownmenu2)",20);
    } else {
    time2=setInterval("ie7decreasewidth2(dropdownmenu2)",20);
    }
}

function increasewidth(flyoutmenu, flyoutheight) {
    var dynsubNav=document.getElementById(flyoutmenu);
    flyoutsub=flyoutheight;
    getnumblistitems(flyoutsub);
    var subnavheight=subnavlength*25;
    var dynsubnavheight=parseInt(document.getElementById(flyoutheight).style.height);
    if (dynsubNav.style.height == "") {dynsubNav.style.height="0px";}
    var dynsubNavwidth=parseInt(dynsubNav.style.height);
    if (dynsubNavwidth<subnavheight) {
    document.getElementById(flyoutmenu).style.display="block";
    dynsubNavwidth=dynsubNavwidth+10;
    document.getElementById(flyoutmenu).style.height=dynsubNavwidth+"px";
    document.getElementById(flyoutmenu).style.zIndex="1000";
    } else { 
    document.getElementById(flyoutmenu).style.height=subnavheight+"px";stopincrease(); 
    }
}

function decreasewidth(flyoutmenu2) {
    dynsubNavwidth=parseInt(document.getElementById(flyoutmenu2).style.height);
    if (dynsubNavwidth>=10) {
    dynsubNavwidth=dynsubNavwidth-10;
    document.getElementById(flyoutmenu2).style.height=dynsubNavwidth+"px";
    document.getElementById(flyoutmenu2).style.zIndex="50";
    } else {
    document.getElementById(flyoutmenu2).style.height="0px";
    document.getElementById(flyoutmenu2).style.display="none";
    stopincrease(); 
    }
}

function ie7decreasewidth(flyoutmenu2) {
    dynsubNavwidth=parseInt(document.getElementById(flyoutmenu2).style.height);
    if (dynsubNavwidth>=10) {
    dynsubNavwidth=dynsubNavwidth-10;
    document.getElementById(flyoutmenu2).style.height=dynsubNavwidth+"px";
    document.getElementById(flyoutmenu2).style.zIndex="50";
    } else {
    document.getElementById(flyoutmenu2).style.height="0px";
    document.getElementById(flyoutmenu2).style.display="none";
    stopincrease();  
    }
}

function increasewidth2(flyoutmenu3, flyoutheight3) {
    var dynsubNav=document.getElementById(flyoutmenu3);
    flyoutsub=flyoutheight3;
    getnumblistitems(flyoutsub);
    var subnavheight=subnavlength*25;
    var dynsubnavheight=parseInt(document.getElementById(flyoutheight3).style.height);
    if (dynsubNav.style.height == "") {dynsubNav.style.height="0px";}
    var dynsubNavwidth=parseInt(dynsubNav.style.height);
    if (dynsubNavwidth<subnavheight) {
    document.getElementById(flyoutmenu3).style.display="block";
    dynsubNavwidth=dynsubNavwidth+10;
    document.getElementById(flyoutmenu3).style.height=dynsubNavwidth+"px";
    document.getElementById(flyoutmenu3).style.zIndex="1000";
    } else { 
    document.getElementById(flyoutmenu3).style.height=subnavheight+"px";stopincrease2(); 
    }
}

function decreasewidth2(flyoutmenu4) {
    dynsubNavwidth=parseInt(document.getElementById(flyoutmenu4).style.height);
    if (dynsubNavwidth>=10) {
    dynsubNavwidth=dynsubNavwidth-10;
    document.getElementById(flyoutmenu4).style.height=dynsubNavwidth+"px";
    document.getElementById(flyoutmenu4).style.zIndex="50";
    } else {
    document.getElementById(flyoutmenu4).style.height="0px";
    document.getElementById(flyoutmenu4).style.display="none";
    stopincrease2(); 
    }
}

function ie7decreasewidth2(flyoutmenu4) {
    dynsubNavwidth=parseInt(document.getElementById(flyoutmenu4).style.height);
    if (dynsubNavwidth>=10) {
    dynsubNavwidth=dynsubNavwidth-10;
    document.getElementById(flyoutmenu4).style.height=dynsubNavwidth+"px";
    document.getElementById(flyoutmenu4).style.zIndex="50";
    } else {
    document.getElementById(flyoutmenu4).style.height="0px";
    document.getElementById(flyoutmenu4).style.display="none";
    stopincrease2();  
    }
}


function stopincrease() {
    clearInterval(time);
}
function stopincrease2() {
    clearInterval(time2);
}
function getnumblistitems(itemscont) {
    var itemscontainer=itemscont;
    var parsingcont = document.getElementById(itemscontainer);
    var subparstingcont = parsingcont.getElementsByTagName('li');
    subnavlength=subparstingcont.length;
    return subnavlength;
}



function validate_form() {
	if(document.ballpark.emailAddress.value==null||document.ballpark.emailAddress.value==""){
	 alert("Email Address is required field!");
	 document.ballpark.emailAddress.focus();
	 return false
	} else {
		var email = document.ballpark.emailAddress.value;
		if (!(echeck(email))) {
			return false;
		}
    }
	if(document.ballpark.originZip.value==null||document.ballpark.originZip.value=="") {
	 alert("Origin Zip is required field!");
	 document.ballpark.originZip.focus();
	 return false
	} else {      
		var zip = document.ballpark.originZip.value;
		var type = "Origin Zip"
		if(validateZIP(zip,type,'1')){
		} else {
		 document.ballpark.originZip.focus();
	 	 return false
		}
	}
	if(document.ballpark.destinationZip.value==null||document.ballpark.destinationZip.value=="") {
	 alert("Destination Zip is required field!");
	 document.ballpark.destinationZip.focus();
	 return false
	} else {
	var zip = document.ballpark.destinationZip.value;
	var type = "Destination Zip"
	if(validateZIP(zip,type,'2')){
    } else {
         document.ballpark.destinationZip.focus();
	 	 return false
        }
	}
	if(document.ballpark.moveDate.value==null||document.ballpark.moveDate.value=="") {
	 alert("Move Date is required field!");
	 document.ballpark.moveDate.focus();
	 return false
	} else if (document.ballpark.moveDate.value.length!==10 && document.ballpark.moveDate.value.length!==9 ) {
		alert("Invalid Move Date! Valid format is mm/dd/yyyy");
		 document.ballpark.moveDate.focus();
	 	return false
	} else {
		var date=document.ballpark.moveDate.value;    
		if (checkdatetype(date) == false) {
				document.ballpark.moveDate.focus();
				return false
            }
        }
 	if(document.ballpark.moveSize.value==null||document.ballpark.moveSize.value=="") {
	 alert("Move Size is required field!");
	 document.ballpark.moveSize.focus();
	 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("Invalid Email Address")

		  document.ballpark.emailAddress.focus();

		  return false

		}



		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		  alert("Invalid Email Address")

		  document.ballpark.emailAddress.focus();

		  return false

		}



		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		  alert("Invalid Email Address")

		  document.ballpark.emailAddress.focus();

		  return false

		}



		 if (str.indexOf(at,(lat+1))!=-1){

		  alert("Invalid Email Address")

		  document.ballpark.emailAddress.focus();

		  return false

		 }



		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		  alert("Invalid Email Address")

		  document.ballpark.emailAddress.focus();

		  return false

		 }



		 if (str.indexOf(dot,(lat+2))==-1){

		  alert("Invalid Email Address")

		  document.ballpark.emailAddress.focus();

		  return false

		 }



		 if (str.indexOf(" ")!=-1){

		  alert("Invalid Email Address")

		  document.ballpark.emailAddress.focus();

		  return false

		 }



 		 return true

	}

	function validateZIP(field,type,ziptype) {

	 var valid = "0123456789-";

	 var hyphencount = 0;



	 if (field.length!=5 && ziptype==1) {

	 alert("Please enter your 5-digit Origin Zip Code.");

	 return false

	 }
	 if (field.length!=5 && ziptype==2) {

	 alert("Please enter your 5-digit Destination Zip Code.");

	 return false

	 }

	 for (var i=0; i < field.length; i++) {

		temp = "" + field.substring(i, i+1);

		if (temp == "-") hyphencount++;

		if (valid.indexOf(temp) == "-1") {

		alert("Invalid characters in "+type+". Please try again.");

		return false;

		}

	 }

 	 return true

  }

 // Variables for the current date, year and month

 var right_now=new Date();

 var the_year=right_now.getYear();

 var dtCh= "/";

 var minYear=the_year;

 var maxYear=the_year+3;



function isInteger(s){

	var i;

  for (i = 0; i < s.length; i++){

    // Check that current character is number.

    var c = s.charAt(i);

    if (((c < "0") || (c > "9"))) return false;

  }

  // All characters are numbers.

  return true;

}



function stripCharsInBag(s, bag){

	var i;

  var returnString = "";

  // Search through string's characters one by one.

  // If character is not in bag, append to returnString.

  for (i = 0; i < s.length; i++){

    var c = s.charAt(i);

    if (bag.indexOf(c) == -1) returnString += c;

  }

  return returnString;

}



function daysInFebruary (year){

	// February has 29 days in any year evenly divisible by four,

  // EXCEPT for centurial years which are not also divisible by 400.

  return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );

}

function DaysArray(n) {

	for (var i = 1; i <= n; i++) {

		this[i] = 31

		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}

		if (i==2) {this[i] = 29}

  }

  return this

}

function checkdatetype(date) {
        var daysValue = date.indexOf('/');
        if (daysValue == 2) {
        var strBreak1=date.substring(2,3);
        var strBreak2=date.substring(5,6);
        if (strBreak1 == "/" && strBreak2 == "/") {
            var strDay=date.substring(0,2);
            var strMonth=date.substring(3,5);
            var strYear=date.substring(6);
        } else { alert("The date format should be: mm/dd/yyyy"); return false;}
        } else if (daysValue == 1) {
        var strBreak1=date.substring(1,2);
        var strBreak2=date.substring(4,5);
        if (strBreak1 == "/" && strBreak2 == "/") {
            var strDay=date.substring(0,1);
            var strMonth=date.substring(2,4);
            var strYear=date.substring(5);     
        } else { alert("The date format should be: mm/dd/yyyy"); return false; }   
        } else { alert("The date format should be: mm/dd/yyyy"); return false; }
        if (strYear.length < 4) { alert("The year should be entered with 4 integers: yyyy"); return false;}
        if (strYear.length > 4) { alert("The year should be entered with 4 integers: yyyy"); return false;}
     return true;        
}



