//Function to Set Current Page's Nav Item ON
function setCurrentNav(topNav,subNav) {
	if (topNav) {
		document.getElementById('link' + topNav).className = 'topNavON';
		//document.getElementById('td' + topNav).className = 'navTableON';
	}
	if (subNav != 'na') {
		document.getElementById('linkSub' + subNav).className = 'subNavON';
		document.getElementById('tdSub' + subNav).className = 'subNavTableON';
		document.getElementById('tdSub' + subNav).onmouseover = null;
		document.getElementById('tdSub' + subNav).onmouseout = null;
	}
}
//Function to remove leading and trailing spaces from fields
function trim(tmpString){
	
	//Replaces leading spaces
	while(tmpString.charAt(0) == " "){
		tmpString = tmpString.substring(1, tmpString.length);
	}
	
	//Removes trailing spaces
	while(tmpString.charAt(tmpString.length - 1) == " "){
		tmpString = tmpString.substring(0, tmpString.length - 1);
	}
	
	//Returns string
	return tmpString;
}
//Function to validate dates
function dateChecker(date) {
	var year;
	var month;
	var day;
	var validDate;
	validDate = true;
	//Tests to make sure the string is exactly 10 characters long
	if (date.length != 10) {validDate = false; return validDate}
	//Extracts month, day, year, and slashes from string 
	sep = "/"
	month = date.substring(0, 2);
	firstSlash = date.substring(2, 3);
	day = date.substring(3, 5);
	secondSlash = date.substring(5, 6);
	year = date.substring(6, 10);
	//Test to ensure numeric values
	if (isNaN(month)) validDate = false;
	if (isNaN(day)) validDate = false;
	if (isNaN(year)) validDate = false;
	//Tests month, day, year, and slashes
	if (month < 1 | month > 12) validDate = false;
	if (firstSlash != sep) validDate = false;
	if (day < 1 | day > 31) validDate = false;
	if (secondSlash != sep) validDate = false;
	if (year < 0 | year > 2999) validDate = false;
	//Checks to make sure that April, June, Sept, or November 31st isn't entered
	if ((month == 4 | month == 6 | month == 9 | month == 11) & (day == 31)) validDate = false;
	//Tests February
	if (month == 2) {
		var g = parseInt(year/4)
		if (isNaN(g)) validDate = false;
		if (day > 29) validDate = false;
		if (day == 29 & ((year/4) != g)) validDate = false;
	}
	//Returns true or false
	return validDate;
}
//Function to validate Claim Date (must be less than today)
function claimDateChecker(month,day,year) {
	var now = new Date();
	var nowYear = now.getFullYear();
	var nowMonth = now.getMonth();
	var nowDay = now.getDate();
	
	if (nowMonth < 10){
		nowMonth = '0' + nowMonth;
	}
	if (nowDay < 10){
		nowDay = '0' + nowDay;
	}
	
	if (year < nowYear){return true}
	if (year > nowYear){return false}
	if (month > (parseInt(nowMonth) + 1)){return false}
	if (day > nowDay){return false}
return true
}
//Function to remove Twistie image alt values
function changeTwistieAlts() {
var images = document.images;
var imgSource;
for (i=0;i<images.length;i++) {
imgSource = images[i].src.toLowerCase();
if ((imgSource.indexOf('expand.gif')>-1)||(imgSource.indexOf('collapse.gif'))>-1) {
images[i].alt = '';
}
}
}
//The following function are for Phone Number validation
function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}
function stripChars(s, delimiters){
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in delimiters, append to returnString.
	for (i = 0; i < s.length; i++){   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (delimiters.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}
function checkPhone(strPhone, international){
	var digits = "0123456789";
	var phoneNumberDelimiters = "()-. ";
	var minDigitsInIPhoneNumber = 10;
	if(international) phoneNumberDelimiters += "+";
	s=stripChars(strPhone,phoneNumberDelimiters);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function newPhoneCheck(strPhone) {
	if(strPhone.search(/^[0-9][0-9][0-9]\-[0-9][0-9][0-9]\-[0-9][0-9][0-9][0-9]$/) != -1) 
		return true; 
	else
		return false;
} 
//force all attachments to new windows
function setAttachmentsNewWindow() {
       for (var i = 0; i < document.links.length; i++) {
              //Use the target property of the link object to append the target window to open the attachments
 if ( ( "" + document.links[i] ).indexOf( "$FILE" ) != -1 ) {
                document.links[i].target = "_resource_win" ;
 }
       }
 } 
//Function to Hide/Show Product Attributes
function hideShow(hidethis) {
	 if( document.getElementById(hidethis).style.display=='none' ){
		document.getElementById(hidethis + 'Img').src = 'twistieOn.gif'; 
		document.getElementById(hidethis).style.display = '';   
	 }
	else{
		document.getElementById(hidethis + 'Img').src = 'twistie.gif'; 
		document.getElementById(hidethis).style.display = 'none';
	 }
}
function expandCollapse(ec,count,img) {
	var i=0
	for (i=1;i<=count;i++)
	{
		if (document.getElementById('row' + i)) {
		document.getElementById('row' + i + 'Img').src = 'twistie' + img + '.gif'; 
		document.getElementById('row' + i).style.display = ec
		}
		else {
		break
		}
	}
}
function contentSearch(searchString) {
if (searchString > "" ) {
window.location='/CMS/SBI.nsf/vwContentSearch?SearchView&Query=' + searchString + '&Start=1&Count=10';
}
else {
alert('Please enter a search keyword.');
}
}
function submitEnter(myfield,e,search){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)   {
   contentSearch(search);
   return false;
   }
else
   return true;
}

