//<!-- TOPIC Javascript Libraries -->
/* 
 * Functions to preload/swap images
 */

// detect browser capabilities
var capable = (document.getElementById && document.getElementsByTagName);
var color_faa = "#CC5407";
var color_student = "#007AA9";

// swap in the image
function imgIn(image, state)
{
    if(capable && image != null) {
        // swap to the rollover mode
        // if state is null, assume default state is off

       	var src = image.src;
        if(state != null && (state == "on" || state == "cl")) {
        	image.src = src.replace("_cl.gif", "_ro.gif");
        } else {
        	image.src = src.replace("_wh.gif", "_ro.gif");
		}
    }
}

// swap out the image
function imgOut(image, state) 
{
    if(capable && image != null) {

        // revert to the idle state
        // if state is null, assume default state is off

       	var src = image.src;
        if(state != null && (state == "on" || state == "cl")) {
        	image.src = src.replace("_ro.gif", "_cl.gif");
        } else {
        	image.src = src.replace("_ro.gif", "_wh.gif");
		}
    }
}

/*
 * Functions to open links in a new window
 */
var fafsa_newwin='';

// open a popup window
function popWindow(theUrl,width,height,full) {
    // use defaults if width and height were not supplied
    var ismoz = navigator.userAgent.indexOf("Gecko");
    var isie = navigator.userAgent.indexOf("MSIE");
    var default_width = 600;
    var default_height = 450;
    var offset_width = (isie != -1) ? 4 : 0;
    var offset_height = (isie != -1) ? 45 : 0;
    var popType = (full) ? ",scrollbars=yes,resizable=yes,status=yes,toolbar=yes,menubar=yes,location=yes,directories=yes" : ",scrollbars=no,resizable=no,status=no";
    
    var popWidth = (width) ? width + offset_width : default_width + offset_width;
    var popHeight = (height) ? height + offset_height : default_height + offset_height;
    var popLeft = self.screen.availWidth/2 - popWidth/2;
    var popTop = self.screen.availHeight/2 - popHeight/2;
    
    if(theUrl) {
        if(fafsa_newwin) {
            fafsa_newwin.close();
        }
        newwin = window.open(theUrl,'fafsa_win','left='+popLeft+',top='+popTop+',width='+popWidth+',height='+popHeight+popType);
        if (newwin) {
			newwin.focus();
		}
    }

    return;
}

// function to execute on loading
function InitForm(szField, szMsg, szType, szIndex) {
	SetFocus(szField);
	
	if (szMsg && szMsg.length > 0) {
		with(document.FAFSA) {
			if (szIndex && szIndex != "null" && szIndex != "" && szIndex != "0") {
				if (confirm(szMsg)) {
					confirmErr.value = "1";
					confirmErr.name = "szCONFIRMXX" + szIndex;
					NextPage();
				}
			} else {
				alert(szMsg);
			}
		}
	}
}

// funtion to set focus on the form field
// funtion to set focus on the form field
function SetFocus(szField)
{
	if (szField) {
		var fieldType = "" + szField.type;
		
		// no focus on disabled fields
		if (!szField.disabled) {
			// no focus on these fields
			if (fieldType == "checkbox" ||
	    		fieldType == "radio" ) {
	    		return;
	 		} else if (fieldType == "text" || 
				fieldType == "textarea"    ||
				fieldType == "password"    || 
				fieldType == "file") {
				szField.focus();
				szField.select();
				return;
			} else if (fieldType.indexOf("select") >= 0) {
				szField.focus();
				return;
			}
		}
	} else {
		with (document.FAFSA) {
			for (var i=0; i<length; i++) {
				var fieldType = "" + elements[i].type;
				
				// no focus on disabled fields
				if (!elements[i].disabled) {
					// no focus on these fields
					if (fieldType == "checkbox" ||
			    		fieldType == "radio" ) {
			    		break;
			 		} else if (fieldType == "text" || 
						fieldType == "textarea" 	||
						fieldType == "password" 	|| 
						fieldType == "file") {
						elements[i].focus();
						elements[i].select();
						break;
					} else if (fieldType.indexOf("select") >= 0) {
						elements[i].focus();
						break;
					}
				}
			}
		} 
	}
}

// function to set the menuitem active, usually on the load of the page
function setMenuitemOn(szMenuId, bFAA) {
  if (capable) {
     var ID = document.getElementById(szMenuId);
     if (ID != null) {
     	var url;
     	var color;
     	if (bFAA) {
     		url = "#ffffff url(/fotw1112/images/faa_left_main_on.gif) repeat-y";
     		color = color_faa;
     	} else {
     		url = "#ffffff url(/fotw1112/images/left_main_on.gif) repeat-y";
     		color = color_student;
     	}  
     	ID.style.background = url;
     	ID.style.color = color;
     }
  }
}

// function to set the submenu active, usually on the load of the page
// bTwo = ture when the submenu has two lines
function setSubmenuOn(szMenuId, bTwo, bFAA) {
  if (capable) {
     var ID = document.getElementById(szMenuId);
     if (ID != null) {
     	var url="";
     	var color="";
     	if (bTwo) {
     		url = (bFAA)? "#ffffff url(/fotw1112/images/faa_subnav_on.gif) no-repeat" : 
     					  "#ffffff url(/fotw1112/images/subnav_on.gif) no-repeat";
     	} else {
     		url = (bFAA)? "#ffffff url(/fotw1112/images/faa_subnav_on.gif) no-repeat" : 
     					  "#ffffff url(/fotw1112/images/subnav_on.gif) no-repeat";
     	}
     	color = (bFAA)? color_faa : color_student;
     	
     	ID.style.background = url;
     	ID.style.color = color;
     }
  }
}
