var navs=["Programs","Central","Technology"];
var thisNav;

/*
 * the following is required to override Safari css bug
 * css values set for Safari should be loaded prior to loading this
 */
document.write('<link type="text/css" rel="stylesheet" href="assets/notsafari.css" media="3d-glasses, screen and resolution > 40dpi, braille"/>');

inqInit=function() {
    FileName=getFileName();
    if(document.all || document.getElementById){
	if(document.getElementById("Intro")){
	    document.getElementById("Intro").onmouseover=function(){
		allNavOff();
	    }
	    for(i=0;i<window.navs.length;i++){
		Obj=document.getElementById(window.navs[i]);
		if(Obj){
		    Obj.onmouseover=function(){
			setBlock(this,"On");
		    }
		    Obj.onmouseout=function(){
			setBlock(this,"Off");
		    }
		}else{
		    alert("Can't locate " + window.navs[i]);
		}
	    }
	}
    }
    showLogo();
    showSectionTitle();
    showSectionHeaders();
    expandOptions();
    focusForm();
}
window.onload=inqInit;

function showLogo(){
    if(logoBlock=document.getElementById('LogoBlock')){
	if(window.isie){
	    logo=document.getElementById('Logo');
	    logo.src="assets/images/blank.gif";
	    logo.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='assets/images/logo.png',sizingMethod='image')";
	}
	logoBlock.style.visibility="visible";
    }
}

function showSectionHeaders(){
    if(window.isie){
	ProgramsObj=document.getElementById('ProgramsHead');
	CentralObj=document.getElementById('CentralHead');
	TechnologyObj=document.getElementById('TechnologyHead');
	ProgramsObj.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='assets/images/programs-head.png',sizingMethod='image')";
	CentralObj.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='assets/images/central-head.png',sizingMethod='image')";
	TechnologyObj.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='assets/images/technology-head.png',sizingMethod='image')";
    }
}

function showSectionTitle(){
    if(sectionObj=document.getElementById('SectionTitle')){
	if(window.isie){
	    src=sectionObj.src;
	    sectionObj.src="assets/images/blank.gif";
	    sectionObj.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"',sizingMethod='image')";
	}
	sectionObj.style.visibility="visible";
    }
}

function focusForm(){
    if(document.forms[0]){
	var FieldList=document.forms[0];
	for(i=0;i<FieldList.length;i++){
	    if((FieldList.elements[i].type=="text") || (FieldList.elements[i].type=="textarea") || (FieldList.elements[i].type.toString().charAt(0)=="s")) {
		document.forms[0].elements[i].focus();
		break;
	    }
	}
    }
}

function setBlock(Obj,State){
    if(State=="On"){
	if(!window.thisNav){
	    setOptions(Obj,State);
	    window.thisNav=Obj.id;
	    Obj.style.backgroundImage="none";
	}
    }else{
	if(window.thisNav){
	    // if on home page, -OR- the current rollover does not represent the current primary section
	    if(document.getElementById("HomePage") || !document.getElementById(Obj.id + "Page")){
		Obj.style.backgroundImage="url(assets/images/" + Obj.id.toLowerCase() + "-bg-nored.jpg)";
	    }
	    setOptions(Obj,State);
	    window.thisNav='';
	}
    }
}

function setOptions(Obj,State){
    if(State=="On"){
	displayState="visible";
    }else{
	displayState="hidden";
    }
    divs=Obj.getElementsByTagName("div");
    for(i=0;i<divs.length;i++){
	if(divs.item(i).id=="Options"){
	    divs.item(i).style.visibility=displayState;
	}
    }
}

function allNavOff(){
    if(window.thisNav){
	setBlock(document.getElementById(window.thisNav),"Off");
    }
}

function popupWindow(loc,width,height,params,winname){
    if(!winname){
	winname="_blank";
    }
  //  if(!params){
//	params="top=100,left=100,toolbar=no,location=no,directories=no,status=no,scrollbars=auto,resizable=yes,copyhistory=no";
  //  }
    //if(width){
	//params+=",width="+width;
    //}
   // if(height){
	//params+=",height="+height;
  //  }
    var newloc=loc;
    oldWindow=window.open(newloc,winname,params);
    oldWindow.focus();
}

function popupWindowFullScreen(loc,winname){
    w=screen.width;
    h=screen.height;
    ah=h-25;
   popupWindow(loc,w,ah,'top=0,left=0,toolbar=no,location=no,directories=no,addressbar=no,menubar=no,scrollbars=no,status=no,resizable=no');
}

function copyrightDate(){
    var Today=new Date();
    document.write("&copy; 1999-"+Today.getFullYear()+" inQ, Inc. All Rights Reserved.");
}

function getFileName(str){
    if(!str){
	str=document.location.href;
    }
    loc=str.substr(str.lastIndexOf("/")+1,str.length);
    ext=loc.split(".");
    if(ext[1]){
	extension=ext[1].length;
    }else{
	extension=0;
    }
    PageName=loc.substring(0,loc.length - extension - 1);
    return PageName;
}

function expandOptions(){
    FileName=getFileName();
    if(document.getElementsByTagName("body").item(0).id!="Home"){
	theOptions=document.getElementById("Options");
	if(theOptions){
	    OptionsA=theOptions.getElementsByTagName("A");
	    for(i=0;i<OptionsA.length;i++){
		if(getFileName(OptionsA.item(i).href)==FileName){
		    OptionsA.item(i).style.color="white";
		    showBranch(OptionsA.item(i));
		    break;
		}
	    }
	}
    }
}

function showBranch(Obj){
    if(Obj.parentNode.nodeName=="LI"){
	ObjLI=Obj.parentNode;
// 	ObjLI.className="On";
	ObjLI.style.listStyleImage="url(/assets/images/nav-arrow.gif)";
	ObjLISub=ObjLI.getElementsByTagName("UL");
	if(ObjLISub){
	    for(i=0;i<ObjLISub.length;i++){
		ObjLISub.item(i).style.display="block";
	    }
	}
	ObjLIParent=ObjLI.parentNode;
	if(ObjLIParent.nodeName=="UL"){
	    ObjLIParent.style.display="block";
	}
    }
}

function hideObj(Obj){
    Obj.style.display="none";
}

function showObj(Obj){
    Obj.style.display="block";
}

function getParentElement(Obj,ElementName){
    if(ElementName){
	while(Obj.parentNode.nodeName){
	    if(Obj.parentNode.nodeName.toLowerCase()==ElementName.toLowerCase()){
		return Obj.parentNode;
		break;
	    }else{
		Obj=Obj.parentNode;
	    }
	}
    }
}

function getChildElement(Obj,ElementName){
    if(ElementName){
	for(i=0;i<Obj.childNodes.length;i++){
	    if(Obj.childNodes[i].nodeName.toLowerCase()==ElementName.toLowerCase()){
		return Obj.childNodes[i];
	    }
	}
	return false;
    }
}

function collapseDivisions(){
    Obj=document.getElementById("Divisions");
    if(Obj){
	for(i=0;i<Obj.childNodes.length;i++){
	    if(Obj.childNodes[i].nodeName=="LI"){
		SubDivs=Obj.childNodes[i].getElementsByTagName("DIV");
		if(SubDivs){
		    hideObj(SubDivs.item(0));
		}
	    }
	}
    }
}

function showDivision(Obj){
    if(Obj.nodeName!="LI"){
	ItemObj=getParentElement(Obj,"LI");
    }else{
	ItemObj=Obj;
    }
    SubDivs=ItemObj.getElementsByTagName("DIV");
    if(SubDivs.length){
	if(SubDivs.item(0).style.display!="block"){
	    ExpandItem=SubDivs.item(0);
	}else{
	    ExpandItem=null;
	}
	collapseDivisions();
	if(ExpandItem){
	    showObj(ExpandItem);
	}
    }
}

function showBlock(Obj,BlockID,ItemNodeType,HiddenNodeType){
    alert(Obj);
    if(!BlockID){
	BlockID="Divisions";
    }
    if(!ItemNodeType){
	ItemNodeType="LI";
    }
    if(!HiddenNodeType){
	HiddenNodeType="DIV";
    }
    if(Obj.parentNode.nodeName!=ItemNodeType){
	alert(Obj.parentNode.nodeName);
    }
    DivItem=document.getElementById(BlockID);
    if(DivItem){
	ItemList=DivItem.getElementsByTagName(ItemNodeType);
	for(i=0;i<ItemList.length;i++){
	    subItem=ItemList.item(i).getElementsByTagName(HiddenNodeType);
	    if(subItem.length){
		hideObj(subItem.item(0));
	    }
	}
    }
    showObj(Obj);
}

function validateForm(theForm,Required){
    // if nothing to validate, return OK
    if(!Required){
	return true;
    }
    for(i=0;i<Required.length;i++){
	Element=document.getElementById(Required[i][0]);
	if(flagValue(Element,theForm)){
	    dataError=true;
	    Element.parentNode.parentNode.className="Error";
	}else{
	    dataError=false;
	    Element.parentNode.parentNode.className="Required";
	}
    }
    if(dataError){
	alert("Please make sure you completely fill out all required fields.\nFields requiring your attention are marked in red.");
	return false;
    }
    return true;
}

function flagValue(Obj,theForm){
    if(Obj.type=="radio" || Obj.type=="checkbox"){
	if(Obj.checked){
	    return false;
	}
    }else{
	ElementName=Obj.id.toLowerCase();
	if(ElementName.indexOf("email")>-1){
	    return isBadEmail(Obj.value);
	}else{
	    return isEmpty(Obj.value);
	}
    }
    return true;
}

function isBadEmail(checkString){
    if(checkString.indexOf("@")<1){
	return true;
    }
    if(checkString.indexOf(".")<1){
	return true;
    }
    if(checkString.indexOf(" ") > -1){
	return true;
    }
    var dotParts = checkString.split(".");
    var tld = dotParts.pop();
    if(tld.length < 2){
	return true;
    }

    /* check for invalid characters */
    for(var i = 0; i < checkString.length; i++){
        ch = checkString.substring(i, i + 1);
        if(!(
	    (ch >= "A" && ch <= "Z")
	    || (ch >= "a" && ch <= "z")
	    || (ch == "@")
	    || (ch == ".")
	    || (ch == "_")
	    || (ch == "-")
	    || (ch >= "0" && ch <= "9")
	)){
	    return true;
	}
    }
    return false;
}

function isEmpty(checkString){
    if(checkString.length<1 || checkString=="" || checkString==" "){
	return true;
    }else{
	return false;
    }
}

