/* Browser Detection Script */
browserVars = new browserVarsObj();
if(!browserVars.type.getById) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = new Function('e', 'browserVars.updateMouse(e)');

function browserDetect()
{
	this.getById = document.getElementById?true:false;
	this.layers = document.layers?true:false;
	this.ns4 = ((this.layers) && (!this.getById));
	this.ns6 = ((navigator.userAgent.indexOf('Netscape6') != -1) && (this.getById));
	this.moz = ((navigator.appName.indexOf('Netscape') != -1) && (this.getById) && (!this.ns6));
	this.ie  = ((!this.layers) && (this.getById) && (!(this.ns6 || this.moz)));
	this.opera = window.opera?true:false;
}


function browserVarsObj()
{
	this.updateMouse = browserVarsObjUpdateMouse;
	this.updateVars = browserVarsObjUpdateVars;
	
	this.mouseX = 0;
	this.mouseY = 0;
	
	this.type = new browserDetect();
	this.width = 0;
	this.height = 0
	this.screenWidth = screen.width;
	this.screenHeight = screen.height;
	this.scrollWidth = 0;
	this.scrollHeight = 0;
	this.scrollLeft = 0;
	this.scrollTop = 0;
	this.updateVars();
}

function browserVarsObjUpdateMouse(e)
{
	if(!this.type.ie)
	{
		this.mouseX = e.pageX;
		this.mouseY = e.pageY;
	}
	else
	{
		this.mouseX = window.event.clientX + this.scrollLeft;
		this.mouseY = window.event.clientY + this.scrollTop;
	}
}

function browserVarsObjUpdateVars()
{
	if(!this.type.getById)
	{
		this.width = window.innerWidth;
		this.height = window.innerHeight;
		this.scrollWidth = document.width;
		this.scrollHeight = document.height;
		this.scrollLeft = window.pageXOffset;
		this.scrollTop = window.pageYOffset;
		if(this.width < this.scrollWidth) this.width -= 16
		if(this.height < this.scrollHeight) this.height -= 16
	}
	else
	{
		if((!(this.type.ns6 || this.type.moz)) && (document.body))
		{
			this.width = document.body.offsetWidth;
			this.height = document.body.offsetHeight;
			this.scrollWidth = document.body.scrollWidth;
			this.scrollHeight = document.body.scrollHeight;
			this.scrollLeft = document.body.scrollLeft;
			if (document.documentElement)
			{
				this.scrollTop = document.documentElement.scrollTop;
			} else {
				this.scrollTop = document.body.scrollTop;
			}
			
		}
		
		if((this.type.ns6 || this.type.moz) && (document.body))
		{
			this.width = window.innerWidth;
			this.height = window.innerHeight;
			this.scrollWidth = document.body.scrollWidth;
			this.scrollHeight = document.body.scrollHeight;
			this.scrollLeft = window.pageXOffset;
			this.scrollTop = window.pageYOffset;
		}
	}
}





/* Floating DIV script */

/*
myName = new floater('myDivID', Position, Width, Height, Vertical Margin, Horizontal Margin);
For Width & Height, use -1 for automatic.
Positions: 
__________
|1   2   3|
|         |
|8   9   4|   <-- The page
|         |
|7___6___5|

*/
function initFloaters()
{
	if(!document.getElementById) return;
	allFloaters = new Array();

	floater1 = new floater('floater1Div', 3, -1, -1, 10, 140);
}

function floater(div, position, width, height, hMargin, vMargin)
{
	this.div = document.getElementById(div);
	this.div.style.visibility = 'visible';
	if(width == -1) width = this.div.offsetWidth;
	if(height == -1) height = this.div.offsetHeight;
	this.position = position;
	this.width = width;
	this.height = height;
	this.hMargin = hMargin;
	this.vMargin = vMargin;

	this.doFloat = doFloat;
	this.idNo = allFloaters.length;
	allFloaters[allFloaters.length] = this;
	this.floatTimer = setInterval("allFloaters[" + this.idNo + "].doFloat()", 50);
}

function doFloat()
{
	browserVars.updateVars();

	var w = browserVars.width - this.width;
	var h = browserVars.height - this.height;
	var xPos = 0;
	var yPos = 0;
	
	if(this.position == 1){ xPos = this.hMargin; yPos = this.vMargin; }
	if(this.position == 2){ xPos = w/2; yPos = this.vMargin; }
	if(this.position == 3){ xPos = w - this.hMargin; yPos = this.vMargin; }
	if(this.position == 4){ xPos = w - this.hMargin; yPos = h/2; }
	if(this.position == 5){ xPos = w - this.hMargin; yPos = h - this.vMargin; }
	if(this.position == 6){ xPos = w/2; yPos = h - this.vMargin; }
	if(this.position == 7){ xPos = this.hMargin; yPos = h - this.vMargin; }
	if(this.position == 8){ xPos = this.hMargin; yPos = h/2; }
	if(this.position == 9){ xPos = w/2; yPos = h/2; }

	if(isNaN(xPos) || isNaN(yPos)) return;

	this.div.style.left = browserVars.scrollLeft + xPos + "px";
	this.div.style.top = browserVars.scrollTop + yPos + "px";
}



// Return the value of the radio button that was checked.
// Return an empty string if none are checked, or
// there are no radio buttons
function getRadioValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


// Function that validates the Order form to assure that all required fields are entered
function validateOrderForm(form) {
  var errors = '';
  
  if (form.firstname.value=="") {
    errors+='- First Name\n';
  }
  if (form.lastname.value=="") {
    errors+='- Last Name\n';
  }
  if (form.address1.value=="") {
    errors+='- Address\n';
  }
  if (form.city.value=="") {
    errors+='- City you live in\n';
  }
  if (form.state.options[form.state.selectedIndex].value=="") {
    errors+='- Select the State you live in\n';
  }
  if (form.zip.value=="") {
    errors+='- Zip Code\n';
  }
  if (form.email.value=="") {
    errors+='- Email address\n';
  }
  if (form.phone1a.value=="") {
    errors+='- Enter your Phone area code HI!!!\n';
  }
  
  // alert ("radio selected="+getRadioValue(document.forms['orderForm'].elements['after']) );
  
  if (getRadioValue(document.forms['orderForm'].elements['after'])=="") {
    errors+='- After (Callback time)\n';
  }
  if (getRadioValue(document.forms['orderForm'].elements['before'])=="") {
    errors+='- Before (Callback time)\n';
  }
  if (form.phone1b.value=="" || form.phone1c.value=="") {
    errors+='- Complete entering your Phone number\n';
  }
  if (form.ccname.value=="") {
    errors+='- Name as it appears on Card\n';
  }
  if (form.cctype.options[form.cctype.selectedIndex].value=="") {
    errors+='- Credit Card Type\n';
  }
  if (form.ccnumber.value=="") {
    errors+='- Credit Card Number\n';
  }
  if (form.ccmonth.options[form.ccmonth.selectedIndex].value=="") {
    errors+='- Select the Month of Expiration Date\n';
  }
  if (form.ccyear.options[form.ccyear.selectedIndex].value=="") {
    errors+='- Select the Year of Expiration Date\n';
  }
  if (form.cccid.value=="") {
    errors+='- CID\n';
  }
  if (errors) {
    alert('Please enter required data in the following field(s):\n\n'+errors);
    return false;
  }
  
  return true;
}


function getCalcEstimate(form) {
  var content_vlue = document.getElementById("printableQuote").innerHTML;
  document.orderForm.calculatorContent.value = content_vlue;
  return true;
}
