var mainActive = "";
var subActive = "";

function setMenu (){
	currentElement = document.getElementById("s" + mainNavCurrent);
	if ( currentElement ) {
		var j=0;
		var i=0;
		var currentElementChild = currentElement.childNodes;
		for ( i=0; i<currentElementChild.length; i++ ) {
			if (currentElementChild[i].tagName == "LI"){
				if ( j == subNavCurrent-1 ) {
					currentElementChild[i].className += " down";
				} // end if
				j++;
			} // end if	
		} // end for
	} // end if
	
/*	for ( i=0; i<10; i++ ) {
		var currentElement = document.getElementById("subnav" + i);
		if ( currentElement && i != mainNavCurrent ) {
			currentElement.style.display = "none";
			currentElement.parentNode.className += " inactive";
		}
	}*/
	for ( i=0; i<10; i++ ) {
		var currentElement = document.getElementById("subnav" + i);
		if ( currentElement ) {
			if ( i != mainNavCurrent ) {
				currentElement.parentNode.className += " inactive";
			} else {
				currentElement.style.display = "block";
			}
		}
	}
	
} // end setMenu

function showMenu () {
	if ( mainActive ) {
		showSubMenu(mainActive);
	} else if ( subActive ) {
		showSubMenu(subActive);
	} else {
		//setTimeout('showSubMenu('+null+')', 100);
		showSubMenu(null);
	}
/*
	currentElement = document.getElementById("subnav" + id);
	if ( currentElement ) {
		currentElement.style.display = "block";
	}
*/
}

function showSubMenu (id) {
	var i = 0;
	if ( id ) {	
		for ( i=0; i<10; i++ ) {
			var currentElement = document.getElementById("subnav" + i);
			if ( currentElement ) {
				if ( i != id ) {
					currentElement.style.display = "none";
				} else {
					currentElement.style.display = "block";
					currentElement.className = "subnav inactive";
					document.getElementById("n" + i).className += " hover";
				}
			}
		}
	} else if ( !mainActive && !subActive ) {
		for ( i=0; i<10; i++ ) {
			var currentElement = document.getElementById("subnav" + i);
			if ( currentElement ) {
				currentElement.style.display = "none";
				document.getElementById("n" + i).className = "";
			}
		}
		document.getElementById("subnav" + mainNavCurrent).style.display = "block";
	}
}

preloadImages('images/btn_aboutus_over.gif','images/btn_services_over.gif','images/btn_portfolio_over.gif','images/btn_news_over.gif','images/btn_contact_over.gif')

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function _CF_onError(form_object, input_object, object_value, error_message) {
	alert(error_message);
	return false;	
}

function _CF_hasValue(obj, obj_type) {
	if (obj_type == "TEXT" || obj_type == "PASSWORD") {
		if (obj.value.length == 0) return false;
		else return true;
	} else if (obj_type == "SELECT") {
		for (i=0; i < obj.length; i++) {
			if (obj.options[i].selected) return true;
		}
		return false;	
	} else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX") {
		if (obj.checked) return true;
		else return false;	
	} else if (obj_type == "RADIO" || obj_type == "CHECKBOX") {
		for (i=0; i < obj.length; i++) {
			if (obj[i].checked) return true;
		}
		return false;	
	} else if (obj_type == "BOOLEAN") {
	    if(obj.value == "true") return true;
	    else return false;
	    }
}

function  _CF_checkCFForm_1(_CF_this) {
	if  (!_CF_hasValue(_CF_this.franchisor, "TEXT" )) {
		if  (!_CF_onError(_CF_this, _CF_this.franchisor, _CF_this.franchisor.value, "Please enter franchisor name.")) {
			return false; 
		}
	}
	if  (!_CF_hasValue(_CF_this.first, "TEXT" )) {
		if  (!_CF_onError(_CF_this, _CF_this.first, _CF_this.first.value, "Please enter your first name.")) {
			return false; 
		}
	}
	if  (!_CF_hasValue(_CF_this.last, "TEXT" )) {
		if  (!_CF_onError(_CF_this, _CF_this.last, _CF_this.last.value, "Please enter your last name.")) {
			return false; 
		}
	}
	if  (!_CF_hasValue(_CF_this.email, "TEXT" )) {
		if  (!_CF_onError(_CF_this, _CF_this.email, _CF_this.email.value, "Please enter your email adddress.")) {
			return false; 
		}
	}
	if  (!_CF_hasValue(_CF_this.work, "TEXT" )) {
		if  (!_CF_onError(_CF_this, _CF_this.work, _CF_this.work.value, "Please enter your work phone.")) {
			return false; 
		}
	}
	if  (!_CF_hasValue(_CF_this.location, "TEXT" )) {
		if  (!_CF_onError(_CF_this, _CF_this.location, _CF_this.location.value, "Please enter desired locations.")) {
			return false; 
		}
	}
	if  (!_CF_hasValue(_CF_this.hear, "TEXT" )) {
		if  (!_CF_onError(_CF_this, _CF_this.hear, _CF_this.hear.value, "Please tell us how you heard about us.")) {
			return false; 
		}
	}
	if  (!_CF_hasValue(_CF_this.capital, "TEXT" )) {
		if  (!_CF_onError(_CF_this, _CF_this.capital, _CF_this.capital.value, "Please enter your available capital.")) {
			return false; 
		}
	}
	if  (!_CF_hasValue(_CF_this.time, "TEXT" )) {
		if  (!_CF_onError(_CF_this, _CF_this.time, _CF_this.time.value, "Please enter a time frame.")) {
			return false; 
		}
	}
	return true;
}

function _CF_submitForm(_CF_this)
{
    _CF_this.D6C543950313F.value = "8BA09C03143C89E7";
    _CF_this.submit();
}

function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight=window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight ) {
			windowHeight=
			document.documentElement.clientHeight;
		} else {
			if (document.body&&document.body.clientHeight ) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('wrapper').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position='relative';
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight))+'px';
			} else {
				footerElement.style.position='static';
			}
		}
	}
}
function setColumns() {
	if (document.getElementById) {
		var contentHeight = document.getElementById('wrapper').offsetHeight;
		var columnLeft = document.getElementById('column-left');
		var columnRight = document.getElementById('column-right');
		var contentSub = document.getElementById('content-sub');
		var contentSubSub = document.getElementById('content-sub-sub');
		var footer = document.getElementById('footer');
		var columnLeftHeight = columnLeft.offsetHeight;
		var columnRightHeight = columnRight.offsetHeight;

		if ( columnLeftHeight > columnRightHeight ) {
			columnRight.style.height = columnLeftHeight+'px';
			if ( contentSub ) {
				contentSub.style.height = footer.offsetTop - contentSub.offsetTop - 30 +'px';
			}
			if ( contentSubSub ) {
				contentSubSub.style.height = footer.offsetTop - contentSubSub.offsetTop - 30 +'px';
			}
		} else if ( columnRightHeight > columnLeftHeight ) {
			columnLeft.style.height = columnRightHeight+'px';
		}
	}
} // end function


window.onload = function() {
  setColumns();
  setMenu();
  showMenu();
}

/*	
window.onload = function() {
  setFooter();
}

window.onresize = function() {
  setColumns();
}
*/
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } 

    // check dropdowns
    // 1. Concepts Interest
    var ddlConceptInterest = document.getElementById('00N30000000g4pP');
    if (typeof ddlConceptInterest == 'object')
    {
        var index = ddlConceptInterest.selectedIndex;
        var value = ddlConceptInterest.options[index].value;
        if (value == '')
        {
            // flag the error
            errors+='- Concept Interest is required.\n';
        }
    }    
    // 2. Time Frame
    var ddlTimeFrame = document.getElementById('00N30000000fNn3');
    if (typeof ddlTimeFrame == 'object')
    {
        var index = ddlTimeFrame.selectedIndex;
        var value = ddlTimeFrame.options[index].value;
        if (value == '')
        {
            // flag the error
            errors+='- Time Frame is required.\n';
        }
    }    
    // 3. Liquid Capital
    var ddlLiquidCapital = document.getElementById('00N30000000fNjJ');
    if (typeof ddlLiquidCapital == 'object')
    {
        var index = ddlLiquidCapital.selectedIndex;
        var value = ddlLiquidCapital.options[index].value;
        if (value == '')
        {
            // flag the error
            errors+='- Liquid Capital is required.\n';
        }
    }    
    
    if (errors) alert('The following error(s) occurred:\n'+errors);
    //document.MM_returnValue = (errors == '');
    if(errors == ''){
        return true;
        }
    return false;
} }

function popUp(URL) {
        newwindow = window.open(URL,'name','height=300,width=450,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0');
        if (window.focus) {
            newwindow.focus();
            }
        return false;
        }