function highlight(which,what) {
	if (what==1) {
		which.style.backgroundColor = "yellow";
	}
	else {
		which.style.backgroundColor = "lightyellow";
	}
}
function getWeather() {
	var xmlhttp = new httpRequest();
	if (xmlhttp) {
		xmlhttp.open("GET", "http://www.studenthaulers.com/weather.php", true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				showWeather(xmlhttp.responseXML);
			}
			else {
				var w = document.getElementById("weather");
				w.innerHTML = "<p>Getting Weather...</p>";
			}
		}
		xmlhttp.send();
	}
}
function showWeather(xml) {
	var w = document.getElementById("weather");
	var output = "";
	output += "<p><b>Kalamazoo Temperature: " + xml.getElementsByTagName("temp_f").item(0).firstChild.data + "&deg; F</b><br>";
	output += "Winds " + xml.getElementsByTagName("wind_string").item(0).firstChild.data + "<br/>";
	output += "<font color=silver size=1>As observed at " + xml.getElementsByTagName("location").item(0).firstChild.data + " on " + xml.getElementsByTagName("observation_time_rfc822").item(0).firstChild.data + "</p>";
	w.innerHTML = output;
}
function contactForm() {
	document.write('<script language="javascript" src="js/calendar.js"></script>');
	document.write('<p><b>Contact us now!</b><br/>');
	document.write('Use the form below to request a quote or <br/>schedule a job.</p>');
	document.write('<p>Your name:<br/><input type="text" id="realname"></p>');
	document.write('<p>Email address:<br/><input type="text" id="email"></p>');
	document.write('<p>Phone number:<br/><input type="text" id="phone"></p>');
	document.write('Location of job:<br/><textarea rows="2" cols="18" id="address"></textarea>');
	document.write('<p>Description of job:<br/><textarea rows="5" cols="18" id="comments"></textarea></p>');
	document.write('<p><input type="checkbox" id="showdate" onclick="showHide(this,\'datetime\');">&nbsp;<label for="showdate">Select date and time</label></p>');
	document.write('<div id="datetime" style="display:none;"><p><a href="javascript:fPopCalendar(\'date\');">Date:</a><br/><input type="text" id="date" onclick="fPopCalendar(\'date\')"></p>');
	document.write('<p>Time:<br/><select id="time">');
	document.write('<option value="Any time">Any time</option>');
	document.write('<option value="8:00-10:00">8:00-10:00</option>');
	document.write('<option value="9:00-11:00">9:00-11:00</option>');
	document.write('<option value="10:00-12:00">10:00-12:00</option>');
	document.write('<option value="11:00-1:00">11:00-1:00</option>');
	document.write('<option value="12:00-2:00">12:00-2:00</option>');
	document.write('<option value="1:00-3:00">1:00-3:00</option>');
	document.write('<option value="2:00-4:00">2:00-4:00</option>');
	document.write('<option value="3:00-5:00">3:00-5:00</option>');
	document.write('<option value="Other">Other</option>');
	document.write('</select></div>');
	document.write('<p><select id="contactmethod">');
	document.write('<option value="">Preferred contact method</option>');
	document.write('<option value="email">Email</option>');
	document.write('<option value="phone">Phone</option>');
	document.write('</select></p>');
	document.write('<p><select id="referral">');
	document.write('<option value="">How did you hear about us?</option>');
	document.write('<option value="google">Google Search</option>');
	document.write('<option value="facebook">Facebook</option>');
	document.write('<option value="newspaper">Newspaper Advertisement</option>');
	document.write('<option value="phonebook">Telephone Book</option>');
	document.write('<option value="saw_a_truck">Saw Your Truck</option>');
	document.write('<option value="signage">Saw Your Signs</option>');
	document.write('<option value="flyer">Flyer</option>');
	document.write('<option value="wordofmouth">Word of Mouth</option>');
	document.write('</select></p>');
	document.write('<p><input type="button" class="submitButton" value="Contact Us!" onclick="javascript:contactUs();"></p>');
	document.write('<div id="ty" style="display:none;"><p align=center><img src="img/thank_you_from_tim.jpg" alt="That you for contacting us!" border="2"></p><p>Your request has been submitted.</p></div>');
}
function showHide(box,div) {
	if (box.checked) {
		document.getElementById(div).style.display="";
	}
	else {
		document.getElementById(div).style.display="none";
		if (div=="datetime") closeCalendar();
	}
}
function contactUs() {
	if (document.getElementById("realname").value.length==0) {
		alert("Please provide your name.");
		document.getElementById("realname").focus();
		return;
	}
	if (document.getElementById("email").value.length==0) {
		alert("Please provide your email address.  We promise not to share this information with anyone.");
		document.getElementById("email").focus();
		return;
	}
	if (document.getElementById("phone").value.length==0) {
		alert("Please provide your telephone number.  We promise not to share this information with anyone.");
		document.getElementById("phone").focus();
		return;
	}
	if (document.getElementById("address").value.length==0) {
		alert("Please provide the location of the job.");
		document.getElementById("address").focus();
		return;
	}
	var xmlhttp = new httpRequest();
	var url = "http://www.studenthaulers.com/formmail.php";
	var parameters = "recipients=webrequests@studenthaulers.com";
	if (checkEmail(document.getElementById("email").value)) {
		parameters += "&mail_options="+encodeURI("FromAddr="+document.getElementById("email").value);
	}
	else {
		parameters += "&mail_options="+encodeURI("FromAddr=webrequest@studenthaulers.com");
	}
	parameters += "&realname="+encodeURI(document.getElementById("realname").value);
	parameters += "&email="+encodeURI(document.getElementById("email").value);
	parameters += "&phone="+encodeURI(document.getElementById("phone").value);
	parameters += "&comments="+encodeURI(document.getElementById("comments").value);
	if (document.getElementById("showdate").checked) {
		parameters += "&jobdate="+encodeURI(document.getElementById("date").value);
		parameters += "&jobtime="+encodeURI(document.getElementById("time").value);
	}
	parameters += "&address="+encodeURI(document.getElementById("address").value);
	parameters += "&contactmethod="+encodeURI(document.getElementById("contactmethod").value);
	parameters += "&referral="+encodeURI(document.getElementById("referral").value);
	parameters += "&env_report="+encodeURI("REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE");
	parameters += "&required="+encodeURI("email:Email Address");
	parameters += "&subject="+encodeURI("Web Request from "+document.getElementById("realname").value);
	
	if (xmlhttp) {
		xmlhttp.open('POST', url, false);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", parameters.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(parameters);
		createPop("350","345","Thank you for contacting Student Haulers.","ty");
	}
}
function httpRequest(){
	var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
	if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
		for (var i=0; i<activexmodes.length; i++) {
			try {
				return new ActiveXObject(activexmodes[i])
			}
			catch(e){
				//suppress error
			}
		}
	}
	else if (window.XMLHttpRequest) {// if Mozilla, Safari etc
		return new XMLHttpRequest();
	}
	else {
		return false;
	}
}
function createPop(width,height,title,id) {
	// ensure the given ID exists
	obj = document.getElementById(id);
	if (obj == null) return;
	width = width.replace(/\s/g,'');  // remove spaces from width parameter
	height = height.replace(/\s/g,'');  // remove spaces from height parameter
	// Create semi-transparent div to cover the screen
	e = document.createElement("div");
	e.id = "NSPopTransparent";
	e.style.opacity = ".5";                  
	e.style.MozOpacity = ".5";               
	e.style.KhtmlOpacity = ".5";
	e.style.filter = "alpha(opacity=50)";
	e.style.height = "100%";
	e.style.width = "100%";
	oContainer = document.body.appendChild(e);
	// if the document is longer than the screen height 
	if (document.body.offsetHeight + 24 > oContainer.offsetHeight)
	e.style.height = (document.body.offsetHeight + 24) + "px";
	disableAll(document.body,"input");
	disableAll(document.body,"select");
	disableAll(document.body,"textarea");
	// create outside div
	e = document.createElement("div");
	e.id = "NSPopUP";
	e.style.height = height;
	e.style.width = width;
	// center the outside div within the viewable section of the document
	 var top = (getWindowSize()[1] / 2) - (height);
	if (width.substr(width.length-1) == "%")
	  var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (width/100 * getWindowSize()[0] /2 );
	else
	  var left = (getWindowSize()[0] / 2) + getScrollXY()[0] - (width / 2 );
	if (height.substr(width.length-1) == "%")
	  var top = (getWindowSize()[1] / 2) + getScrollXY()[1] - (height/100 * getWindowSize()[1] /2 );
	else
	  var top = (getWindowSize()[1] / 2) + getScrollXY()[1]- (height / 2 );
	e.style.left = left + "px";
	e.style.top = top + "px";
	oPop=document.body.appendChild(e);
	// create title bar
	e = document.createElement("div");
	e.id = "NSPopTitle";
	// Make the box movable when the mouse is pressed on the title bar
	e.onmousedown = movePop
	oTitle = oPop.appendChild(e);
	// Add a close button to the title bar
	e = document.createElement("img");
	e.style.width = "16px";
	e.style.height = "16px";
	e.hspace = "10";
	e.src = "img/close.gif";
	e.id ="NSPopCloseButton";
	e.onclick = closePopUp;
	oTitle.appendChild(e);
	// Add the Title Text
	e = document.createElement("span");
	e.id = "NSPopTitleText";
	e.innerHTML = title;
	oTitle.appendChild(e);
	 // create body of popup
	e = document.createElement("div");
	e.id = "NSPopBodyFrame";
	e.style.height = (oPop.offsetHeight - oTitle.offsetHeight - 2) + "px";
	oBody = oPop.appendChild(e);
	e = document.createElement("div");
	e.id="NSPopBodyText";
	e.innerHTML = obj.innerHTML;
	oText= oBody.appendChild(e);
}
/* function closePopUp()
--------------------------------
   Removes the semi-transparent div
   Removes the Pop-Up window
   enables all elements
--------------------------------   */
function closePopUp(){
	oDiv = document.getElementById("NSPopTransparent");
	document.body.removeChild(oDiv);
	oDiv = document.getElementById("NSPopUP");
	document.body.removeChild(oDiv);
	enableAll(document.body,"input");
	enableAll(document.body,"select");
	enableAll(document.body,"textarea");
}
/* Global Variables required for popup move events
-------------------------------------------------- */
var mouseStartX = -99999;
var mouseStartY = -99999;
var popLeft;
var popTop;
/* function movePop()
----------------------------------
  Starts the watch for the mousemove
  and mouseup events on the document 
  object.
---------------------------------- */  
function movePop() {
	 mouseStartX = -99999;
	 mouseStartY = -99999;
	 popLeft= document.getElementById("NSPopUP").offsetLeft;
	 popTop = document.getElementById("NSPopUP").offsetTop;
	 document.onmousemove = movePop1;
	 document.onmouseup = endMovePop;
}
/* function movePop1(e)
----------------------------------
   perform the actual move of the popup
   e = mouse move event
---------------------------------- */   
function movePop1(e) {
	if (!e) var e = window.event;  // if IE, then we need to assign e
		if (e.pageX) {    // FF, opera, netscape
			posX = e.pageX;   
			posY = e.pageY;
		}
		else if (e.clientX) {  // IE
			posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;  
			posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		obj = document.getElementById("NSPopUP");
		// alert(vLeft)
		if (mouseStartX == -99999) mouseStartX = posX;  // -99999 is an arbitrary number.  It is unlikely to be hit 
		if (mouseStartY == -99999) mouseStartY = posY;
		var offsetX = posX - mouseStartX; // determine the difference from where the mouse started to where it is now
		var offsetY = posY - mouseStartY;
		vPosX = popLeft + offsetX;
		vPosY = popTop + offsetY;
		// ensure that the pop-up is not moved off the screen
		if (vPosX < 0) vPosX = 0;
		if (vPosX + obj.offsetWidth > document.body.offsetWidth +10) vPosX = document.body.offsetWidth - obj.offsetWidth +10;
		if (vPosY < 0) vPosY = 0;
		if (document.body.offsetHeight > getWindowSize()[1]) {
		if (vPosY + obj.offsetHeight > document.body.offsetHeight + 20) vPosY = document.body.offsetHeight - obj.offsetHeight + 20;
	}
	else {
		if (vPosY + obj.offsetHeight > getWindowSize()[1] -1) vPosY = getWindowSize()[1] - obj.offsetHeight -1;
	}
	obj.style.left = vPosX + "px";
	obj.style.top = vPosY + "px";
}
/* function endMovePop()
----------------------------------
   disables the watch for the mousemove and 
   mouseup events on the document object
---------------------------------- */   
function endMovePop() {
	document.onmousemove = function() {};
	document.onmouseup = function() {};
}
/* function disableAll(obj,type)
--------------------------------   
  Disable all elements of the specified type
  within the specified object
-------------------------------- */
function disableAll(obj,type) {
	oInput = obj.getElementsByTagName(type);
	for (i=0;i<oInput.length ;i++) {
		oInput[i].disabled = true;
}
}
/* function enableAll(obj,type)
--------------------------------   
   Enable all elements of the specified type
   within the specified object
--------------------------------  */   
function enableAll(obj,type) {
	oInput = obj.getElementsByTagName(type);
	for (i=0;i<oInput.length ;i++) {
		oInput[i].disabled = false;
	}
}
function getWindowSize() {
	var myWidth = 0;
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) { 
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth, myHeight] ;
}
function getScrollXY() {
	 var scrOfX = 0;
	 var scrOfY = 0;
	 if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	 } 
	 else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		 //DOM compliant
		 scrOfY = document.body.scrollTop;
		 scrOfX = document.body.scrollLeft;
	 } 
	 else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		 //IE6 standards compliant mode
		 scrOfY = document.documentElement.scrollTop;
		 scrOfX = document.documentElement.scrollLeft;
	 }
	 return [ scrOfX, scrOfY ];
}
function checkEmail(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 E-mail ID")
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID")
	    return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID")
	    return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID")
	    return false
	 }
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }
		 return true					
}