/*
 * Common.js
 * Description: Contains javascript functions that are commonly used
 * in pages.
 *
 * Version
 * 0.1		Blake Wilson		Initial Version
 *
 */
var yellowStar = new Image(); 
yellowStar.src = '/images/star_yellow.gif';
var greyStar = new Image(); 
greyStar.src = '/images/star_grey.gif';
var redStar = new Image(); 
redStar.src = '/images/star_red.gif';

//Saves the current screen scroll position to the hidden field
function saveBodyScroll(theBody) {
	document.getElementById('hdnScrollPosition').value = theBody.scrollTop;
}

//Sets the screen scroll position to the hidden field value
function loadBodyScroll(theBody) {
	var hdnScroll;
	
	hdnScroll = document.getElementById('hdnScrollPosition');
	
	if (hdnScroll.value.length > 0) {
		theBody.scrollTop = hdnScroll.value;
	}
}

function OSBEK(e)
{		
	if(!e) e = window.event;
	if(e.keyCode==13){

		//GoSearch(null,'ctl00_PlaceHolderMain_SearchBox_InputKeywords',null,true,false,null,null,null,null,'\u002fEnglish\u002fPages\u002fSearchResults.aspx\u002fResults.aspx', 'This Site','This List', 'This Folder', 'Related Sites', '\u002fEnglish\u002f_layouts\u002fOSSSearchResults.aspx');
		SD06736D6_Submit();	
		e.returnValue=false;
		e.cancel = true;
	
		return false;
	}
}

function fireSetFastNavs(){
	window.setTimeout(function() {removeFastNavs();},10)
}
  
  //function for hiding fast nav option in calendar
function setFastNavHidden(calendarID){

	var calendarO = eval(calendarID);

	var fastNavigation = calendarO.GetFastNavigation();   
	var table = fastNavigation.DomElement;   
	if (!table)   
	{   
		table = fastNavigation.CreateLayout();   
		fastNavigation.DomElement = table;   
	} 
	
	//table.style.display = "none"; 
	//alert(table.innerHTML);
	table.style.width = "1px";
	table.style.height = "1px";
	table.style.visibility = "hidden";

	var titleID = calendarID + "_Title";   
	var titleCell = document.getElementById(titleID);   
	titleCell.innerHTML = "<a style='cursor:default' onclick=''>" + titleCell.innerHTML + "</a>";  
}

function toggleAll(containerid) {
			
	var chk = document.getElementById(containerid + '_chk');
	var container = document.getElementById(containerid);
	
	var objs = container.getElementsByTagName('input');
	
	on = chk.checked;
	
	for (i=0; i < objs.length; i++) {
		if (objs[i].type == "checkbox") {
			objs[i].checked = on;
		}
	}
	
	toggleOne(containerid);
}

function toggleOne(id) {
	p = document.getElementById(id).parentNode;
	
	while (p != null) {
		var chk = document.getElementById(p.id + '_chk');
		var objs = p.getElementsByTagName('input');
		
		allon = true;
		
		for (i=0; i < objs.length; i++) {
			if (objs[i].type == "checkbox" && objs[i].id != p.id + '_chk') {
				allon &= objs[i].checked;
			}
		}
		
		if (chk != null) {
			chk.checked = allon;
		}
		
		p = p.parentNode;
	}
}

function TypeChanged() {
	selIndex = document.getElementById('bktype').selectedIndex - 1;
	
	ddl = document.getElementById('bkgrade');
	ClearOptions(ddl);

	for (i = 0; i < ratings[selIndex].length; i++) {
		AddToOptionList(ddl, ratings[selIndex][i][1], ratings[selIndex][i][0]);
	}
}

function ClearOptions(OptionList) {
   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}

function AddToOptionList(OptionList, OptionValue, OptionText) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

var enterHandlers = [
	[["ctl00_UserLogon1_username"],["ctl00_UserLogon1_signin"]],
	[["ctl00_UserLogon1_password"],["ctl00_UserLogon1_signin"]]
];

document.onkeydown = handleKeyPress; //non-ie
document.onkeypress = handleKeyPress; //ie
			
//capture enter button pressed anywhere on page and stop it from submitting form, 
//since it may not hit the correct submit button & fire the wrong event on the server side
function handleKeyPress(e)
{
	if(!e){
		e = window.event;
	}
	key = e.keyCode;
	
	if(key==13){
		src = "";
		if (e.srcElement){
			src = e.srcElement.name;
		}
		else if (e.target){
			src = e.target.name;
		}
		
		if (src) {
		
			try {
				if (document.getElementsByName(src)[0].type == "submit") return true;
			}
			catch(err) {
				return true;
			}
			
			for (i = 0; i < enterHandlers.length; i++) {
				if (enterHandlers[i][0] == src) {
					document.getElementsByName(enterHandlers[i][1])[0].click();
					break;
				}
			}
			
		}				
		e.returnValue=false;
		e.cancel = true;
	
		return false;
	}
}


function isUndefined(vValue) {
    return typeof vValue == 'undefined';
}

function isNull(vValue) {
   	return typeof vValue == 'object' && !vValue;
}
