/*
Author: William La Morte &copy; copyright 2000
Email: wlm@xiio.com
http://www.xiio.com
There are no requirements for using this API. I only ask that you leave this comment intact.
This API was written to assist with my own works as well assist other developers with their work.
If you improve or enhance this script, please place your name and date below this comment. Report bugs or questions/comments to author
*/

/*
Improved by:
Date:
*/

//handle browser resizing problem for navigator 4
if(!window.orig_width) {
  window.onresize = reset_layers;
  window.orig_width = window.innerWidth;
  window.orig_height = window.innerHeight;
}

function reset_layers() {
    if (window.innerWidth != orig_width || window.innerHeight != orig_height) {
      location.reload();
    }
}

//declare globals to build object reference
var whichDom = "", styleObj = ""
var isNav4, isNav6, isIE
var isBrand = navigator.appName
var agt = navigator.userAgent.toLowerCase()
var navVer = parseInt(navigator.appVersion)

//these variables are handy for determining which styles to load
isNav4 = (isBrand == "Netscape" && navVer < 5) ? true : false
isNav6 = (isBrand == "Netscape" && navVer >= 5) ? true : false
isNav46 = ((isBrand == "Netscape") && (parseFloat(navigator.appVersion) >= parseFloat(4.6)) && (parseFloat(navigator.appVersion) < parseFloat(4.7))) ? true : false
isNav47 = ((isBrand == "Netscape") && (parseFloat(navigator.appVersion) >= parseFloat(4.7))) ? true : false
isIE = ((agt.indexOf("msie") != -1) && (parseInt(navVer) >= 4)) ? true : false

if ((navigator.appVersion.indexOf("Mac") != -1)) {
	document.write("<LINK REL=stylesheet HREF=\"style.css\" TYPE=\"text/css\">"); }
else {
	document.write("<LINK REL=stylesheet HREF=\"style.css\" TYPE=\"text/css\">"); 
}


//load a style sheet depending on users browser
/*
if (isNav4)	{
	document.write('<link="stylesheet" href="style.css">')
} else if (isNav6)	{
	document.write('<link="stylesheet" href="style.css">')
} else	{
	document.write('<link="stylesheet" href="style.css">')
}
*/

//construct object reference
if(isNav6)  {
  whichDom = '.getElementById("'
  styleObj = '").style'
} else if (isNav4)  {
  whichDom = '["'
  styleObj = '"]'
} else {
  whichDom = ".all."
  styleObj = ".style"
}

//Preload the navigation images
image1= new Image();
image1.src = "images/company_off.gif";
image1on = new Image();
image1on.src = "images/company_on.gif";
image1stay = new Image();
image1stay.src = "images/company_on.gif";

image1a= new Image();
image1a.src = "images/company_history.gif";
image1aon = new Image();
image1aon.src = "images/company_history_on.gif";

image1b= new Image();
image1b.src = "images/company_methodology.gif";
image1bon = new Image();
image1bon.src = "images/company_methodology_on.gif";

image1c= new Image();
image1c.src = "images/company_management.gif";
image1con = new Image();
image1con.src = "images/company_management_on.gif";

image2= new Image();
image2.src = "images/services_off.gif";
image2on = new Image();
image2on.src = "images/services_on.gif";
image2stay = new Image();
image2stay.src = "images/services_on.gif";

image3= new Image();
image3.src = "images/projects_off.gif";
image3on = new Image();
image3on.src = "images/projects_on.gif";
image3stay = new Image();
image3stay.src = "images/projects_on.gif";

image4= new Image();
image4.src = "images/news_off.gif";
image4on = new Image();
image4on.src = "images/news_on.gif";
image4stay = new Image();
image4stay.src = "images/news_on.gif";

image5= new Image();
image5.src = "images/contact_off.gif";
image5on = new Image();
image5on.src = "images/contact_on.gif";
image5stay = new Image();
image5stay.src = "images/contact_on.gif";

image6= new Image();
image6.src = "images/careers_off.gif";
image6on = new Image();
image6on.src = "images/careers_on.gif";
image6stay = new Image();
image6stay.src = "images/careers_on.gif";

image7= new Image();
image7.src = "images/logins_off.gif";
image7on = new Image();
image7on.src = "images/logins_on.gif";
image7stay = new Image();
image7stay.src = "images/logins_on.gif";

image8= new Image();
image8.src = "images/home_off.gif";
image8on = new Image();
image8on.src = "images/home_on.gif";
image8stay = new Image();
image8stay.src = "images/home_on.gif";

image2a= new Image();
image2a.src = "images/services1.gif";
image2aon = new Image();
image2aon.src = "images/services1_on.gif";

image2b= new Image();
image2b.src = "images/services2.gif";
image2bon = new Image();
image2bon.src = "images/services2_on.gif";

image2c= new Image();
image2c.src = "images/services3.gif";
image2con = new Image();
image2con.src = "images/services3_on.gif";

image2d= new Image();
image2d.src = "images/services4.gif";
image2don = new Image();
image2don.src = "images/services4_on.gif";

image3b= new Image();
image3b.src = "images/industries_off.gif";
image3bon = new Image();
image3bon.src = "images/industries_on.gif";
image3bstay = new Image();
image3bstay.src = "images/industries_on.gif";

//End loading

//Set imageStay to nothing
imageStay = ""

// Check to make sure browser is not too old to display Javascript stuff
if (navigator.appVersion.indexOf("2.") != -1){
        check = false;
        }
if ((navigator.appVersion.indexOf("3.") != -1) && (navigator.appName.indexOf("Explorer") != -1)){
        check = false;
        }
else {
        check = true;
        }


var error = "";
var rfString = "";
var form = "";
function ValidateForm(form) {
	error = "";
	for (i=0; i<form.elements.length; i++) {
		// FIRST CHECK TO SEE IF REQUIRED FIELDS EXIST
		if (form.elements[i].name.indexOf("reqfields") != -1) {
			rfString = form.reqfields.value;
			break;
		}
	}
	if (rfString) {
		validateReqFields(form)
	}
	else {
		validateAllFields(form)
	}
	if (error) {
		alert('This form could not be processed because of the following errors:\n\n' + error);
		return false;
	}
	else if (form.name == 'survey') {
		//alert('this: '+form.name);
		alert('Please be patient while the program processes your survey submission. Click OK to continue.');
	}
}

function validateReqFields(form) {
	rfString = form.reqfields.value;
	rfArray = rfString.split(",");
	rfCount = rfArray.length-1;
	rnametemp = "";
	for (x=0; x<=rfCount; x++) {
		for (i=0; i < form.elements.length; i++) {
			if (form.elements[i].name == rfArray[x]) {
				if ((form.elements[i].type == 'radio' || form.elements[i].type == 'checkbox') && rnametemp != form.elements[i].name) {
					rnametemp = form.elements[i].name;
					checkRadio(rnametemp,form);
				}
				else if (form.elements[i].name.indexOf("email") != -1) {
					checkEmail(form.elements[i].value)
					}
				else if (form.elements[i].value == "") {
					if (form.elements[i].name == rfArray[x]) {
						error = error + '* ' + form.elements[i].name + ' is empty\n'
					}
				}
			}
			if (error) { 
				break;
			}
		}
	}
}

function validateAllFields(form) {
	rnametemp = "";
	for (i=0; i < form.elements.length; i++) {
		if (form.elements[i].type == 'radio' && rnametemp != form.elements[i].name) {
			rnametemp = form.elements[i].name;
			checkRadio(rnametemp,form);
		}
		else if (form.elements[i].name.indexOf("email") != -1) {
			checkEmail(form.elements[i].value)
			}
		else if (form.elements[i].value == "") {
			error = error + '* ' + form.elements[i].name + ' is empty\n'
		}
	}
}

function checkRadio(fname,form) {
	valcheck = "";
	alMsg = "";
	maxnum = form.elements[fname].length
	for (z=0;z<maxnum;z++) {
		if (form.elements[fname][z].checked) {
			valcheck = "1";
			break;
		}
	}
	if (!valcheck) {
		error = error + '* one or more fields remain unchecked\n';
	}
}


//load image when mouseover
function imageon(name){
        if (imageStay != name){
                document[name].src = eval(name + "on.src");
        }
}

//load image when mouseoff
function imageoff(name){
        if (imageStay != name){
                document[name].src = eval(name + ".src");
        }
}

function on(name){
        if (check == true){
        imageon(name);
        }
}
function off(name){
        if (check == true){
        imageoff(name);
        }
}

//keep the image there when clicked even if mousedoff
function stay(name){
        if (check == true){
        document[name].src = eval(name + "stay.src");
        if (imageStay != name){
                if (imageStay != ""){
                        document[imageStay].src = eval(imageStay + ".src");
                }
        }
        imageStay = name
        }
}

//API object reference
function theObject(obj) {
var theObj
	if (typeof obj == "string")
		theObj = eval("document" + whichDom + obj + styleObj)
	else
		theObj = obj
		return theObj
}

function moveObjTo(obj, x, y) {
var theObj = theObject(obj)
	if (isNav4) {
		theObj.moveTo(x,y)
	} else if (isIE) {
		theObj.pixelLeft = x
		theObj.pixelTop = y
	} else	{//nav6
		theObj.left = x +"px"
		theObj.top = y +"px"
	}
}




//nav6 returns string values for positionable elements ie. left "100px"
//must parse string values and convert to number values
function moveObjBy(obj, deltaX, deltaY) {
var theObj = theObject(obj)
  if (isNav4) {
    theObj.moveBy(deltaX, deltaY)
  } else if (document.all) {
    theObj.pixelLeft += deltaX
    theObj.pixelTop += deltaY
  } else  {
    var theLeft = getObjLeft(theObj)
    var theTop = getObjTop(theObj)
    setObjLeft(theObj, parseInt(theLeft)+deltaX)
    setObjTop(theObj, parseInt(theTop)+deltaY)
  }
}

function setZIndex(obj, z) {
var theObj = theObject(obj)
	theObj.zIndex = z
}

function getZIndex(obj)	{
var theObj = theObject(obj)
	return theObj.zIndex
}

function setBGColor(obj, color) {
var theObj = theObject(obj)
	if (isNav4) {//ng
		theObj.bgColor = color
	} else {
		theObj.backgroundColor = color//ok IE and nav6
    //beware nav6 returns rgb values ie rgb(255 255 255) when
		//specifying hexidecimal value
    //but will return colornames if specified 
		//for example, if background-color:red is specified nav6 returns red
		// if background-color #ff0000 is specified nav6 returns 255 000 000
	}
}

function getBGColor(obj)	{
var theObj = theObject(obj)
	if (isNav4)	{//buggy
		return theObj.bgColor
	} else	{//IE returns named value or hexadecimal
		return theObj.backgroundColor
		//nav6 returns rgb(255 255 255)!!!
	}
}

function setBorderColor(obj, color)  {
var theObj = theObject(obj)//ng nav4
  theObj.borderColor = color//ok IE and nav6
}

//netscape 6 returns parameters for all four borders
function getBorderColor(obj)	{
var theObj = theObject(obj)
	return theObj.borderColor
}

function show(obj) {
var theObj = theObject(obj)
	lastObj = theObject(lastItem)
	lastObj.visibility = "hidden"
	theObj.visibility = "visible"
	
	lastItem = theObject(obj)
}

function hide(obj) {
var theObj = theObject(obj)
	theObj.visibility = "hidden"
}

//nav4 reads and returns value of "show" but also reads "visible"
//nav4 reads and returns value of "hide" but also reads "hidden"
//test???
function getObjVisibility(obj)	{
var theObj = theObject(obj)
	if (theObj.visibility == "" || theObj.visibility == null)	{
		return "visible"
	} else	{
		return theObj.visibility
	}
}

//nav6 returns string value ie left = 100px
//parse values???
function getObjLeft(obj)  {
var theObj = theObject(obj)
  if (isNav4) {
    return theObj.left
  } else if (isIE)  {
    return theObj.pixelLeft
  } else  {
    return parseInt(theObj.left)
  }
}

function setObjLeft(obj, l)	{
var theObj = theObject(obj)
	if (isNav4)	{
		theObj.left = l
	} else if (isIE)	{
		theObj.pixelLeft = l
	} else  {//nav6
    theObj.left = l + "px"
  }
}

function getObjTop(obj)  {
var theObj = theObject(obj)
  if (isNav4) {
    return theObj.top
  } else if (isIE)  {
    return theObj.pixelTop
  } else  {
    return parseInt(theObj.top)
  }
}

function setObjTop(obj, t)	{
var theObj = theObject(obj)
	if (isNav4)	{
		theObj.top = t
	} else if (isIE)	{
		theObj.pixelTop = t
	} else  {//nav6
    theObj.top = t + "px"
  }
}

function getObjHeight(obj) {
var theObj = theObject(obj)
	if (isNav4) {
		return theObj.clip.height
	} else if (isIE) {
		return theObj.pixelHeight
	} else	{//nav6
		return parseInt(theObj.height)
	}
}

function setObjHeight(obj,h)	{
var theObj = theObject(obj)
	if (isNav4)	{//does not work nav4
		theObj.height = h
	} else if (isIE)	{
		theObj.pixelHeight = h
	} else  {//nav6
    theObj.height = h + "px"
  }
}

function getObjWidth(obj) {
var theObj = theObject(obj)
	if (isNav4) {
		return theObj.clip.width
	} else if (document.all) {
		return theObj.pixelWidth
	} else	{//nav6
		return parseInt(theObj.width)
	}
}

function setObjWidth(obj,w)	{
	var theObj = theObject(obj)
	if (isNav4 || isNav6)	{//does not work nav4
		theObj.width = w
	} else	{
		theObj.pixelWidth = w
	}
}

//set dimensions in one shot
//ie4 and nav6 only
function setObjDimensions(obj,h,w)	{
var theObj = theObject(obj)
	if (isNav4)	{//does not work nav4
		theObj.height = h
		theObj.width = w
	} else if	(isIE)	{
		theObj.pixelHeight = h
		theObj.pixelWidth = w
	} else	{
		theObj.height = h + "px"
		theObj.width = w + "px"
	}
}

function getInsideWindowWidth() {//ok
	if (isNav4 || isNav6) {
		return window.innerWidth
	} else {
		return document.body.clientWidth
	}
}

function getInsideWindowHeight() {//ok
	if (isNav4 || isNav6) {
		return window.innerHeight
	} else {
		return document.body.clientHeight
	}
}

function getPageLeft(obj)	{
var theObj = theObject(obj)
	if (isNav4 || isNav6)	{
	return theObj.pageX
	}	else	{
		 return theObj.offsetLeft
	}
}

function getPageTop(obj)	{
var theObj = theObject(obj)
	if (isNav4 || isNav6)	{
	return theObj.pageY
	}	else	{
		 return theObj.offsetTop
	}
}

//change a div's content
//usage: changeObj('object','hello')
//can create some cool effects for dynamic menus in conjuntion with showAndHide()
function changeObj(obj, replace)	{
	if (isNav4)	{
		document[obj].writeln(replace)
		document[obj].close()
	} else {
		document.all(obj).innerHTML = replace
	}
}

//this is a pretty neat sliding layer routine that slides a layer to the center of the users screen
//the usage example slides a layer at a 45 degree angle across the users screen
//usage: slide('object',20,20,100)
//the finalLeft variable can also be a fixed integer
var finalLeft = new Array()
var timerID = new Array()
var count = 0
function slide(obj,x,y,speed) {
count++
finalLeft[count] = parseInt( (getInsideWindowWidth()/2) - (getObjWidth(obj)/2) )
var expr = 
	'if (getObjLeft("' +obj+ '") <' +finalLeft[count]+ ') {' +
    'moveObjBy("' +obj+ '"' + ',' +x+ ',' +y+ ')' +
  '} else  {' +
    'clearInterval(' +timerID[count]+ ')' +
  '}'
  timerID[count] = setInterval(expr,speed)
}

//showHide() is a utility function using the custom javascript API
//usage: showHide('objectName', '[show | hide | toggle]')
//can also alter the visibility of more than one object
//-----------showHide('object1','hide','object2','show','object3','toggle')
function showHide()	{
var args = arguments
	for (var i = 0; i < args.length; i += 2)	{
	if (typeof args[i] == "string")
		var theObj = theObject(args[i])
	if (args[i+1] == "toggle")
		if ((getObjVisibility(theObj) == "visible") || (getObjVisibility(theObj) == "show"))
			hide(theObj)
		else show(theObj)
		else if (args[i+1] == "hide")	hide(theObj)
		else if (args[i+1] == "show")	show(theObj)
	}
}

//revised showHide() to handle z-index issue with navigator 6
function showAndHide()	{
var args = arguments
	for (var i = 0; i < args.length; i += 2)	{
		if (typeof args[i] == "string")	{
			var theObj = theObject(args[i])
		}
		if (args[i+1] == "toggle")	{
			if ((getObjVisibility(theObj) == "visible") || (getObjVisibility(theObj) == "show"))	{
				hide(theObj)
        setZIndex(theObj,0)
			} else	{
				setZIndex(theObj,100)
        show(theObj)
			}
		} else if (args[i+1] == "hide")  {
      hide(theObj)
      setZIndex(theObj,0)
    } else if (args[i+1] == "show")  {
      show(theObj)
      setZIndex(theObj,100)
    } else  {
      theObj.visibility = "visible"
    }
	}
}


/*
open a new window, center it and set dimensions relative to the users screen
url: url of new document
name: document name
statbar: boolean yes or no for statusbar display
scroll: boolean yes or no for scrollbars
locate: boolean yes or no for locationbars
x: set the new window height with a percentage value relative to the users screen
y: set the new window width with a pecentage value relative to the users screen
usage: javascript:winOpen('index.htm','newwin','yes','yes','yes',.5,.5)
*/
function winOpen(url,name,statbar,scroll,locate,x,y)	{
var adjustedleft = 8//optional
var adjustedheight = 30//adjust height because of windows taskbar
var screenwidthremainder = screen.availWidth%2//really not needed, but won't hurt
var screenheightremainder = screen.availHeight%2
var screenwidth = screen.availWidth - screenwidthremainder
var screenheight = screen.availHeight - screenheightremainder
var winheight = parseInt(screenheight)* y//set new window height properties
var winwidth = parseInt(screenwidth)* x//set new window width properties
var winleft = parseInt(screenwidth/2) - (winwidth/2) - adjustedleft//optional
var wintop = parseInt(screenheight/2) - (winheight/2) - adjustedheight

var win = window.open(url,name,'width=' +winwidth+ ',height=' +winheight+',status=' +statbar+',scrollbars='+scroll+',location='+locate+',top='+wintop+',left='+winleft)
}

/*
set status bar message
usage: onmouseover="return msg('Hello')" onmouseout="return msg('Goodbye')"
*/
function msg(x)	{
if (window.status !=x)
window.status = x
return true
}