/*

:::::: MBDA PORTAL JAVASCRIPT FUNCTIONS ::::::

ATTENTION: Update these comments with your information immediately after any changes, thank you!

Last edited by: Jim Goldbloom
Last edited on: 04/30/2009

READ ME: 
This is the official repository for ALL portal JavaScript functions and global variables
called within /templates/layout.php and managed via the CMT template system.  Never remove anything,
simply comment code out if you are deprecating something so we have history of what was added. 

*/

/* 

:::::: GLOBAL VARS DECLARATION AREA ::::::

Note: Try not to use too many global variables, they impact performance.

*/

var SBD_data=0; // required for MENU NAV JQUERY
var myWidth = 0;
var myHeight = 0;
document.WM = new Object();
document.WM.menu = new Object();
document.WM.menu.dropdown = new Array();

/* 

:::::: START OF JAVASCRIPT FUNCTIONS ::::::

Note: Put newest at the top of this file, add detailed comments, dates added/updated and author details.

*/

// Function called in header feature "search engine" sub-template...
function ValidateHeaderSearch() {

	var formField=document.search_header;
	
	var result = true;
	if (formField.query.value == "" || formField.query.value.length<2) {
	
	var text="No valid search phrase was specified...\n\nTips to Successful Search Results:\n\n- Separate multiple words with a single space\n- ";
	text+="Do not include a,if,the,an,for,from,is or any special characters or";
	text+=" punctuation\n- Use as few words as possible each no less than 2 characters, case insensitive.\n\n";
	text+="Please enter at least one term in the search box at least 2 characters in length...";
	alert(text);
	formField.query.focus();
	result = false;
}
	
return result;

} // end of function

// Used to validate portal login...
function validate(form) {

	var msg="";
	var fc;
	var info="\n\nPlease note only registered members of MBDA.gov may login...\nIf you are not a current member please REGISTER (It's Free)... ";
	
		if (!namevalid(form.password)) {msg += "- Password  \n"; fc=form.password;}
		if (!namevalid(form.username)) {msg += "- Member Name \n"; fc=form.username;}
	
		if (msg != "") {
			alert("WE'RE SORRY...\n\nThe following case sensitive information was not completed properly during login: \n\n" + msg + info);
			fc.focus();
			return false;
		}
		else {return true;}
                   
} // end function

function ChangeDivText (id,text) {

	// By: Jim Goldbloom for MBDA.gov 9/27/04
	// Function to alter text inside any div tag.
	// Pass the div ID name and text to change to as arguments.
	// NS4 compatibility requires different HTML body code - see comments for isLayer/Netscape4
	// below...
	
			isLayer = document.layers?true:false;
			isIE = navigator.appName.indexOf("Microsoft") != -1
			isByID = !isIE && document.getElementById?true:false;
	
			if (isIE || isByID) {
					// MSIE 4 or later and any browser not requiring layers
					document.getElementById(id).innerHTML = text;
			}
	
			if (isLayer) {
				// Netscape 4 only - hardcode your source like this...
					// <ilayer name="ilayer_name"><layer name="layer_name">OriginalText</layer></ilayer>
					document.ilayer_name.document.layer_name.document.write(text);
					document.ilayer_name.document.layer_name.document.close();
			}

} // end function

function checkEverything(form_name,checked) {

	// Pass name of form and true/false - this will check/uncheck all checkboxes in the form
		var adjust = document.getElementById(form_name);
		var input, i = 0, inputs = adjust.getElementsByTagName('input');
		while (input = inputs.item(i++)) {
			if (input.getAttribute('type') == 'checkbox' && input.getAttribute('disabled')==false && checked==true) {input.checked=true;}
			if (input.getAttribute('type') == 'checkbox' && input.getAttribute('disabled')==false && checked==false) {input.checked=false;}
		 }

} // end function

function NSresize() {

	if(navigator.appName=="Netscape")
	{
		location.reload();
	}

} // end function


function WM_initializeToolbar(){
	var i;
    if ((document.all)&&(document.all('container')))
	{
		for(i = 0; i < document.all('container').all.length; i++)
		{
		    if ((document.all('container').all[i].className == 'header') |(document.all('container').all[i].className == 'links'))
			{
				document.WM.menu.dropdown[document.WM.menu.dropdown.length] = document.all('container').all[i];
	    	}
		}
    }else if ((document.getElementsByTagName && document.getElementById)&&(document.getElementById('container')))
	{
		var contained = document.getElementById('container').getElementsByTagName('div');
		for(i = 0; i < contained.length; i++)
		{
			if ((contained[i].getAttribute('class') == 'header') || (contained[i].getAttribute('class') == 'links'))
			{
				document.WM.menu.dropdown[document.WM.menu.dropdown.length] = contained[i];
			}
		}
    }
} // end function

function WM_collapse(item,bucket_id){

	if(navigator.appName=="Netscape"){
		//alert(bucket_id);
		window.location.href='/templates/collection.php?collect_bucket=' + bucket_id + '&site_id=1';
	}

    if(document.WM.menu.dropdown.length){
	//alert(document.WM.menu.dropdown[item + 1].style.display)
		if (document.WM.menu.dropdown[item].style.display == 'none'){
		    document.WM.menu.dropdown[item].style.display = '';
		   	document.images[document.WM.menu.dropdown[item - 1].id + 'images'].src = '/images/folder_open.gif';
		}
		else {
	    	document.WM.menu.dropdown[item].style.display = 'none';
		    document.images[document.WM.menu.dropdown[item - 1].id + 'images'].src = '/images/folder_closed.gif';
		}
    }
} // end function

function expandit(hideThis,curobj,images){

	if(images){
		var temp = curobj.src.split("/");
		//alert();
		if(temp[temp.length-1] == 'folder_open.gif')
			curobj.src = '/images/folder_closed.gif';
		else
			curobj.src = '/images/folder_open.gif';
	}

	if (document.all)
		folder=document.all[hideThis].style;
	else
		folder=document.layers[hideThis];


	if (folder.display=="")
	folder.display="none"
	else
	folder.display=""

} // end function

function GetBrowserSize() {
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement &&
		  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
  
} // end function

function openApp(pageToLoad) {
	
	GetBrowserSize(); // Creates global variables myHeight and myWidth

	var winName = "_blank";
	var width=myWidth-50;
	var height=myHeight-50;
	var center=true;
	
	// Safety catches
	if (width<600) {width=750;}
	if (height<100) {height=550;}

    var xposition=0; 
	var yposition=50;
    
	if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
    }
    
	var args = "width=" + width + ","
    + "height=" + height + ","
    + "location=0,"
    + "menubar=1,"
    + "resizable=1,"
    + "scrollbars=1,"
    + "status=1,"
    + "titlebar=1,"
    + "toolbar=1,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    window.open( pageToLoad,winName,args );
	return false;

} // end function

function NotAllSpace(A_Str)  {

	Len = A_Str.value.length;

	for (i = 0; i < Len; i++)
	{
		if (A_Str.value.charAt(i) != " ")
		return true;	//runs throught the string, if it hits something other than a space it returns TRUE
	}
	return false;

} // end function

function validateForm(form) {

  var msg = "";
  var len = form.elements.length;

  for (var i = 0; i < len; i++)
  {
    var field_value = form.elements[i].value;
    if (field_value == null || field_value == "")
    {
      var field_name = form.elements[i].name;
      msg += field_name + "\n";
    }
  }

	if (msg == "")
  {
    return true;
  }
	else
	{
		alert("The following required fields were not completed:\n\n" + msg);
		return false;
	}

} // end function

function checkAll(value, form_name, checkbox_name) {

  var form = document.forms[form_name];

  for (i = 0; i < form.length; i++)
  {
    if (form.elements[i].type == "checkbox" && form.elements[i].disabled==false && form.elements[i].name == checkbox_name)
    {
      form.elements[i].checked = value;
    }
  }

} // end function

function namevalid(name) {

	if (name.value.length != 0 && NotAllSpace(name))
		return true;
	return false;

} // end function

function popwindow(window_url) {

	location=window_url;

} // end function



/* END OF FILE */