// JavaScript Document
/*
This file contains all functions that are needed specificially to manipulate IE 6 and below
*/
var msie = navigator.userAgent.toLowerCase().indexOf("msie")==-1? false:true;

function $(id){
  if (typeof id == 'string')
		id = document.getElementById(id);
  return id;
}

function init(){
	if ($("email"))
		$("email").focus();
}

function fixInputLayers(obj, maxHeight){
	//empty stub for all browsers
}

function findPos(obj){
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function showOverlay(){
	$("canvasOverlay").style.display="block";
	$("fullPg").style.display="block";
	hideInputs("divFrame");
	setTimeout("showInputs('fullPg')",200);
}

function showInputs(obj){
	//wrapper for dispInputs
	dispInputs(obj,'');
}

function hideInputs(obj){
	//wrapper for dispInputs
	dispInputs(obj,'none');
}

function dispInputs(obj,disp){
	if (!obj)
		obj=document.getElementsByTagName("body")[0]; //default to whole document
	else
		obj=$(obj);
	
	var inputTags = Array("input","select","textarea");
	for (var j=0; j < inputTags.length; j++){
		var inpts = obj.getElementsByTagName(inputTags[j]);
		for (var i=0; i < inpts.length; i++){
			inpts[i].style.display=disp;
		}//next input
	}//next input tag
	
	//also hide html containing flash
	if ($("flashSlideShow")){
		$("flashSlideShow").style.display=disp;
	}
	if ($("divHeader")){
		$("divHeader").style.display=disp;
	}
	if ($('slideshow')){
		$('slideshow').style.display=disp;
	}
	if ($('slideshowBody')){
		$('slideshowBody').style.display=disp;
	}
}

function hideOverlay(){
	$("canvasOverlay").style.display="none";
	$("fullPg").style.display="none";
	pageAltered=false;
	//reset page height & width
	$("innerCanvas").style.width="660px";
	$("innerCanvas").style.height="550px";
	$("innerCanvas").style.marginLeft="-330px";
	$("innerCanvas").style.top="-290px";
	
	//if there was a flash video (iframe) then clear the innerCanvas contents to stop the sound/video
	if ($("innerCanvas").getElementsByTagName("iframe").length>0){
		$("innerCanvasMain").innerHTML="";
	}
	if ($("divHeader")){
		$("divHeader").style.display="";
	}
	if ($('slideshow')){
		$('slideshow').style.display='';
	}
	if ($('slideshowBody')){
		$('slideshowBody').style.display='';
	}
	if ($('companyDiv')){
		$('horizon').removeChild($('companyDiv'));
	}

	showInputs("divFrame");
}

function requestQuote(){
	var ic=$('innerCanvas');

	if (msie){
		$("innerCanvas").style.overflow="hidden";
	}

	$("canvasOverlay").style.display="block";
	$("fullPg").style.display="block";
	hideInputs("divFrame");

	ic.style.height='600px';
	ic.style.top='-315px';
	$('innerCanvasMain').innerHTML='<iframe width="650" height="570" frameborder="0" src="requestquote.php"></iframe>';
	//create the slide show if it doesn't already exist
	//creating this iframe after the request a quote iframe has been loaded causes problems
	if(!$('companySlideshow')){
		$("horizon").innerHTML+='<div id="companyDiv" style="position: absolute; top: -315px; height:640px; background-color: #ffffff; margin-left: -530px; left: 50%;"><iframe id="companySlideshow" frameborder="0" height="0" width="0"></iframe></div>';
	}
}

function HTTPGet(uri, callbackFunction, callbackParameter){
	var xmlHttp = new XMLHttpRequest();
	xmlHttp.open('GET', uri, true);
	xmlHttp.send(null);

	if (callbackFunction){
		xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4){
				if (xmlHttp.status == 200){
					callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
				}else{
					callbackFunction(xmlHttp.statusText, xmlHttp, callbackParameter);
				}
			}
		}
	}
}

function evalJS(txt, obj){
	//try executing any inline javascript
	var jsPos = txt.indexOf('<script type="text/javascript">');
	if (jsPos!=-1){
		var js = txt.substr(jsPos+31, txt.indexOf('</script>')-(jsPos+31));
		eval(js);
	}
}

function evalResp(respText, xmlHttp, p1){
	if (xmlHttp.status == 200){
		evalJS(respText, p1);
	}else{
		alert(respText);
	}
}
