// START - File Structure Navigation  
  var openListSetup = new Array();
    var plusgifSetup;
   var minusgifSetup;
    /* 
    var highlightForeSetup;
    var highlightBackSetup;*/
    function addToOpenSetup (item) {
        for (var i = 0; i < openListSetup.length; i++) {
            if (openListSetup[i] == null) {
                openListSetup[i] = item;    
                updateCookiesSetup();
                return;     
            }
        }
        openListSetup[openListSetup.length] = item;
        updateCookiesSetup();
    }
    
    function removeFromOpenSetup (item) {   
        for (var i = 0; i < openListSetup.length; i++) {
            if (openListSetup[i] == item) {
                openListSetup[i] = null;            
            }
        }
        updateCookiesSetup();
    }

    function updateCookiesSetup() {
        var stringlist = "";
        for (var i = 0; i < openListSetup.length; i++) {
            if (openListSetup[i] != null) {
                stringlist = stringlist + openListSetup[i] + ":";
            }
        }
                
        SetCookieSetup("setupopen", stringlist, null, "/");     
    }
    
    function toggleSetup(item) {
       var obj=document.getElementById(item + "_child");
       if (obj != null) {
           visible=(obj.style.display!="none")
           var key=document.getElementById(item + "_icon");
           if (visible) {
             obj.style.display="none";
             key.innerHTML=plusgifSetup;
             removeFromOpenSetup (item);
           } 
           else {
              obj.style.display="block";
              key.innerHTML=minusgifSetup;
              addToOpenSetup(item);
           }
       }
    }

    function expandSetup(item) {
       var obj=document.getElementById(item + "_child");
       if (obj != null) {
           visible=(obj.style.display!="none")
           var key=document.getElementById(item + "_icon");
           if (!visible) {
              obj.style.display="block";
              key.innerHTML=minusgifSetup;
           }
       }
    }

    function getCookieValSetup(offset) {
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1)
            endstr = document.cookie.length;
        return unescape(document.cookie.substring(offset, endstr));
    }

    function GetCookieSetup (name) {  

        var arg = name + "=";  
        var alen = arg.length;  
        var clen = document.cookie.length;  
        var i = 0;  

        while (i < clen) {    
            var j = i + alen;    
            if (document.cookie.substring(i, j) == arg)      
                return getCookieValSetup (j);    
            i = document.cookie.indexOf(" ", i) + 1;    
            if (i == 0) break;   
        }  
        return null;
    }


    function SetCookieSetup (name, value) {  
        var argv = SetCookieSetup.arguments;  
        var argc = SetCookieSetup.arguments.length;  
        var expires = (argc > 2) ? argv[2] : null;  
        var path = (argc > 3) ? argv[3] : null;  
        var domain = (argc > 4) ? argv[4] : null;  
        var secure = (argc > 5) ? argv[5] : false;  

        document.cookie = name + "=" + value + 
            ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
            ((path == null) ? "" : ("; path=" + path)) +  
            ((domain == null) ? "" : ("; domain=" + domain)) +    
            ((secure == true) ? "; secure" : "");
        }

    function DeleteCookieSetup (name) {  
    
        var cval = GetCookieSetup("setupopen");
        if (cval == null) {
            return;
        }
    
        var exp = new Date(); 
        exp.setTime(exp.getTime() - 1);

        SetCookieSetup("setupopen", "", exp, "/");
    }
// END - File Structure Navigation



	//forces whats entered to be only numbers
	//this function was gotten from: http://www.html-html.com/forms/index_famsupp_158.html
	//note: use it like this: onKeyPress="return numbersonly(this, event)"
	function numbersonly(myfield, e, dec)
	{
		var key;
		var keychar;
		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
		keychar = String.fromCharCode(key);
		// control keys
		if ((key==null) || (key==0) || (key==8) || 
		   (key==9) || (key==13) || (key==27) )
			return true;
		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
			return true;
		// decimal point jump
		else if (dec && (keychar == "."))
		{
			myfield.form.elements[dec].focus();
			return false;
		}
		else
			return false;
	}


	//formats a phone number field as its typed in,
	//note: it forces only numbers that can be entered
	//note: use it like this: onKeyPress="return formatPhoneNumberAsTyped(this, event)"
	function formatPhoneNumberAsTyped(myfield, e)
	{
		var key;
		var keychar;
		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
		keychar = String.fromCharCode(key);
	
		//force the phone number field to beformated like this: (###) ###-####
		//but the user only has to enter numbers to do it 
		var t = myfield.value;
		t = t.replace(/[^0-9]/g,"");
		var n = t;
		//if (t.length<3) n = "("+t.substr(0,3)
		if (t.length>3) 
			n = "("+t.substr(0,3)+") "+t.substr(3,3);
		if (t.length>6) 
			n+= "-"+t.substr(6,4) ;
		
		n = n.substr(0, n.length);
		myfield.value = n;		
				
		
		// control keys
		if ((key==null) || (key==0) || (key==8) || 
		   (key==9) || (key==13) || (key==27) )
			return true;
		// allow numbers
		else if ((("0123456789").indexOf(keychar) > -1))
		{
			return true;
		}
		else	//else stop anything else from being inputted
			return false;
	}


function formatPhone (field) {
    field.value = trim(field.value);

    var ov = field.value;
    var v = "";
    var x = -1;

    // is this phone number 'escaped' by a leading plus?
    if (0 < ov.length && '+' != ov.charAt(0)) { // format it
        // count number of digits
        var n = 0;

	//we disabled the skipping of 1 because we only allow them to enter 10 digits!!!
	//this was originally to allow them to enter a 1 in front of their area code
        //if ('1' == ov.charAt(0)) {  // skip it
        //    ov = ov.substring(1, ov.length);
        //}

        for (i = 0; i < ov.length; i++) {
            var ch = ov.charAt(i);

            // build up formatted number
            if (ch >= '0' && ch <= '9') {
                if (n == 0) v += "(";
                else if (n == 3) v += ") ";
                else if (n == 6) v += "-";
                v += ch;
                n++;
            }
            // check for extension type section;
            // are spaces, dots, dashes and parentheses the only valid non-digits in a phone number?
            if (! (ch >= '0' && ch <= '9') && ch != ' ' && ch != '-' && ch != '.' && ch != '(' && ch != ')') {
                x = i;
                break;
            }
        }
        // add the extension
        if (x >= 0) v += " " + ov.substring(x, ov.length);

        // if we recognize the number, then format it
        if (n == 10 && v.length <= 40) field.value = v;
    }

    return true;
}

    function ltrim(s) {
        return s.replace( /^\s*/, "" );
    }

    function rtrim(s) {
        return s.replace( /\s*$/, "" );
    }

    function trim(s){
        return rtrim(ltrim(s));
    }
	
	///VALIDATION STUFF
function emailvalidation(entered, alertbox)
{
// E-mail Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
if (value==null || value=="")
		  {	return true;}
		  	else {
apos=value.indexOf("@"); 
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}
}

function emailnemptyvalidation(entered, alertbox)
{
// E-mail Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
apos=value.indexOf("@"); 
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}

function valuevalidation(entered, min, max, alertbox, datatype)
{
// Value Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if (value==null || value=="")
		  {	return true;}
		  	else {
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || (value<checkvalue) || (value>checkvalue))
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
}

function valuenemptyvalidation(entered, min, max, alertbox, datatype)
{
// Value Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
// Modified to allow blank entries to return true 11/02/2003
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || (value<checkvalue) || (value>checkvalue))
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

function digitvalidation(entered, min, max, alertbox, datatype)
{
// Digit Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
// Modified to allow blank entries to return true 10/19/2003
	with (entered)
	{
	checkvalue=parseFloat(value);
		if (datatype)
		{smalldatatype=datatype.toLowerCase();
			if (smalldatatype.charAt(0)=="i") 
			{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
		}
		if (value==null || value=="")
		  {	return true;}
		  	else {if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || (value<checkvalue) || (value>checkvalue))
			{if (alertbox!="") {alert(alertbox);} return false;}
			else {return true;}
		  } 
	}
}

//shows the alert box if the number of digits is not between min and max...
function digitnemptyvalidation(entered, min, max, alertbox, datatype)
{
	//first step: remove anything that isnt a digit (0-9)
	with (entered)
	{
		var t = value;
		t = t.replace(/[^0-9]/g,""); //filter to be only digits...
		if(t.length >= min && t.length <= max) //if length is good do nothing
			return true;	
	}
	
	if(alertbox != '')	//show alert box if we have text to show...
		alert(alertbox);
	return false;
	/*
// Digit Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
// Modified to allow blank entries to return true 10/19/2003
	with (entered)
	{
		checkvalue=parseFloat(value);
		if (datatype)
		{
			smalldatatype=datatype.toLowerCase();
			if (smalldatatype.charAt(0)=="i")
			{
				checkvalue=parseInt(value);
				//alert(checkvalue);
				if (value.indexOf(".")!=-1) 
				{
					checkvalue=checkvalue+1
				}
			};
		}
		// We need a copy of this value in string format so we can compare it's length to the original
		// and ensure that they are the same lenght signifying numbers only
		checkvaluestring = checkvalue.toString();
		//alert(checkvaluestring.length);
		//alert(value.length);
		if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || (value<checkvalue) || (value>checkvalue) || (checkvaluestring.length != value.length))
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			} return false;
		}
		else {return true;}
	}
	*/
}
//value!=checkvalue  Firefox does not like this
//(value<checkvalue) || (value>checkvalue)
//+'Error: value='+value.length+'Min='+min+'Max='+max+'CheckValue='+checkvalue+value
function emptyvalidation(entered, alertbox)
{
// Emptyfield Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
//with (entered)
//{
//if (value==null || value=="")
//{if (alertbox!="") {alert(alertbox+'Error: value='+value);} return false;}
//else {return true;}
//}
	with (entered)
	{
		if (value==null || value=="")
		{
			if (alertbox!="") {alert(alertbox);} return false;}
		else {
			return true;
		}
	}
}

function phonevalidation(entered, alertbox) {
// place any other field validations that you require here
// validate myradiobuttons
with (entered)
{
	//alert(entered.value.length);
	if (entered.value.length == 14) {
		return true;
	}
	else
	{
		alert(alertbox);
		return false;
	}
}
}

function valbutton(entered, alertbox) {
// place any other field validations that you require here
// validate myradiobuttons
with (entered)
{
myOption = -1;
for (i=entered.length-1; i > -1; i--) {
if (entered[i].checked) {
myOption = i;
}
}
if (myOption == -1) {
alert(alertbox);
return false;
}
else {return true;}
}
}

////////END Validation ////////////////

