﻿function prepassOnLoad() // Fired by SharePoint on load.
	{
		//Search box
		var searchBox = document.getElementById("searchInput");
	
		if(searchBox != null)
		{
			if(isEmpty(searchBox.value) || isWhitespace(searchBox.value) || searchBox.value == "Search PrePass.com")
			{
				searchBox.value = "Search PrePass.com";
				searchBox.className = "searchBlur";
			}
		}	 
	}
function search()
{
	var searchBox = document.getElementById("searchInput");
	var searchValue = searchBox.value;
	
	if(isEmpty(searchValue) || isWhitespace(searchValue) || searchValue == "Search PrePass.com")
	{
		alert("Please enter one or more search words.");
	}
	else
	{
		window.location = "/Search/Results.aspx?k=" + searchValue ;
	}
	
}

// whitespace characters 
var whitespace = " \t\n\r"; 

// Check whether string s is empty. 
function isEmpty(s) 
{ 
	return ((s == null) || (s.length == 0)) 
} 

// Check wether string is whitespace
function isWhitespace (s) 
{ 
var i; 

// Is s empty? 
if (isEmpty(s)) 
	return true; 

// Search through string's characters one by one 
// until we find a non-whitespace character. 
// When we do, return false; if we don't, return true. 

for (i = 0; i < s.length; i++) 
{ 
// Check that current character isn't whitespace. 
var c = s.charAt(i); 

if (whitespace.indexOf(c) == -1) return false; 
} 

// All characters are whitespace. 
return true; 
} 

function searchBoxFocus()
{
	var searchBox = document.getElementById("searchInput");
	var searchValue = searchBox.value;
	
	if(searchValue == "Search PrePass.com")
	{
		searchBox.value = "";
		searchBox.className = "searchFocus";
	}
}

function searchBlur()
{
	var searchBox = document.getElementById("searchInput");
	var searchValue = searchBox.value;
	
	if(isEmpty(searchValue) || isWhitespace(searchValue))
	{
		searchBox.value = "Search PrePass.com";
		searchBox.className = "searchBlur";
	}
	
}
/*********************END SEARCH FUNCTIONS*******************************************/ 
function ExpandCollapse(obj,itemId)
{
	
	var theAnswer = document.getElementById("answer" + itemId); 
	theAnswer.className = (theAnswer.className == "answerClosed") ? "answerOpen" : "answerClosed";

	//get the image and swap it
	var theImage = document.getElementById("qId" + itemId);

	if(theAnswer.className == "answerClosed")
	{
		theImage.src = "/_layouts/prepass/images/expand.jpg";
	}
	else
	{
		theImage.src = "/_layouts/prepass/images/collapse.jpg";
	}
}

function ExpandAllFaqQuestions(expand)
{
	if(typeof(window.external) != 'undefined')
	{
		//yes, this is evil browser sniffing, but only IE has this bug
		document.getElementsByName = function(name, tag)
		{
		    if(!tag)
		    {
	        	tag = '*';
	    	}
		    var elems = document.getElementsByTagName(tag);
		    var res = []
		    for(var i=0;i<elems.length;i++){
		        att = elems[i].getAttribute('name');
		        if(att == name) {
		            res.push(elems[i]);
		        }
		    }
		    return res;
		}
	}

	//alert('inside function');
   	// Returns a collection with all the quesions
   	var aInput=document.getElementsByName("answer");
   
   	for (var i=0; i < aInput.length; i++)
  	{
   		var q = aInput[i];
   		q.className = (expand) ? "answerOpen" : "answerClosed";
   	}
}

