// This file cosnists of all the common JavaScript code that is being used

/*************************** Browser Window Size and Position****************/
/*copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005*/
function pageWidth() {
    return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 
   
function pageHeight() {
    return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

function posLeft() {
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 

function posTop() {
    return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 

function posRight() {
    return posLeft()+pageWidth();
} 
function posBottom() {
    return posTop()+pageHeight();
}

/*************************** Scroll height & width****************/
function getPageHeightWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight + document.body.offsetTop;
  	}
	return yWithScroll;
}

function getPageWidthWithScroll(){
	if (window.innerWidth && window.scrollMaxX) {// Firefox
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		xWithScroll = document.body.offsetWidth + document.body.offsetLeft;
  	}
	return xWithScroll;
}

/*************************** Image Swap, preload and rollover functions ****************/
function MM_swapImgRestore() 
{ //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d)
 { //v4.01
  var p,i,x;  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) 
  {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() 
{ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
/*************************** Image Swap, preload and rollover functions ****************/

/*************************** MainMenu ****************/
function toggleState(curElem) {
	var navElem = document.getElementById('menuItems');
	
	if (navElem) {
		var arrNavItems = navElem.getElementsByTagName("A");
		//remove any "selected" class from each menu item
		for(i=0;i<arrNavItems.length;i++) {
			arrNavItems[i].className = arrNavItems[i].className.replace('selected', '');
		}
	}
	//add "selected" to the clicked item
	curElem.className += " selected";
}
/*************************** MainMenu ****************/

/*************************** Start Script for dynamic Accordion Style  ****************/

function addEvent(elm, evType, fn, useCapture) {
	if(elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} 
	else if (elm.attachEvent){
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else{
		elm['on' + evType] = fn;
	}
}

function findAccordions() {
	var bulletLists = document.getElementsByTagName("ul");
	var accordionList;
	var accordionListItems;
	var firstChildElem;
	var DOMwalker;
	for (i=0;i<bulletLists.length;i++) {
		if (bulletLists[i].className.indexOf("accordion")!=-1) {
			accordionList = bulletLists[i];
			accordionListItems = accordionList.getElementsByTagName("li");
			for(j=0;j<accordionListItems.length;j++) {
			    accordionListItems[j].onclick = doExpand;
				if(accordionListItems[j].hasChildNodes()) {
				    if(document.createTreeWalker) {
				        DOMwalker = document.createTreeWalker(accordionListItems[j], NodeFilter.SHOW_ELEMENT, null, false);
				        firstChildElem = DOMwalker.firstChild();
				    }else{
				        firstChildElem = accordionListItems[j].firstChild;
				    }
				    if(firstChildElem && firstChildElem.tagName) {
				        firstChildElem.style.cursor="pointer";
				    }		       
			    }  
			}
		}
	}
}
function doExpand(e) 
{
    if (window.event) window.event.cancelBubble = true;
    else e.stopPropagation();    
    
    var listItems;
    if (this.parentNode.className.indexOf("accordion")!=-1)
    {
        listItems = this.parentNode.getElementsByTagName("li");
        for(m=0;m<listItems.length;m++) {
		    listItems[m].className = "";
		}
    }
    this.className = "expanded";
}

addEvent(window, 'load', findAccordions, false);

/*************************** End Script for dynamic Accordion Style  ****************/


/*
CSS Browser Selector v0.2.7
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
var css_browser_selector = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();

/*************************** Pop up a modal window  ****************/

function showModal(pageUrl, height, width) {

	var custompagesFolder="";   // <-----edit this
	
	//Added by Avinash for IE
	var browser=navigator.appName;
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
    
    
	var tempIframe = document.createElement('iframe');
	tempIframe.id = "modal";
	tempIframe.name = "modal";
	tempIframe.frameBorder = "0";
	tempIframe.scrolling="no";
	tempIframe.height = "0";
	tempIframe.width = "1";
	tempIframe.style.position="absolute";
	
	//tempIframe.style.overflow = "hidden";
	tempIframe.allowTransparency=true;	
	//tempIframe.src = custompagesFolder+ pageUrl;
	tempIframe.src = pageUrl;
	
	document.body.appendChild(tempIframe);
	//return false;
}
function CenterModal(width,height){
	var elementId = "modal";
	var visibleHeight = pageHeight();
	var visibleWidth = pageWidth();
	element = document.getElementById(elementId);
	
	//alert("width="+element.offsetWidth);
	
	//**** changed by kashyap due to IE6 drop-down overlaying
	//element.width = width;
	element.width = width-20;
	
	element.height = height+20;
	if(element.height > visibleHeight){
		element.style.top = "20px";
	}else{
		element.style.top = (visibleHeight-element.height)/2 + "px";
	}
	
	
	//**** changed by kashyap due to IE6 issue reported by Honeywell QA
	//element.style.left = (visibleWidth-element.width)/2 + "px";
	element.style.left = "5px";
	
	var totalHeight = getPageHeightWithScroll();
	var totalWidth = getPageWidthWithScroll();
	//alert("elementHeight="+element.height+"   total="+totalHeight);
	var tempCoverDiv = document.createElement('div');
	tempCoverDiv.id = "coverLayer";
	tempCoverDiv.style.height=totalHeight+"px";
	tempCoverDiv.style.width=totalWidth+"px";
	
	document.body.appendChild(tempCoverDiv);
}
function closeModalWindow() {
	var tempIframe = document.getElementById('modal');
	var tempCoverDiv = document.getElementById('coverLayer');
	if(tempIframe) tempIframe.parentNode.removeChild(tempIframe);
	if(tempCoverDiv) tempCoverDiv.parentNode.removeChild(tempCoverDiv);
}

/*************************** End pop up a modal window  ****************/

function hideElement(contentId, btnId){
	contentElement = document.getElementById(contentId);
	btnElement = document.getElementById(btnId);
	if(contentElement.style.display == "none" || contentElement.style.display == ""){
		if(btnElement != null)btnElement.innerHTML = 'Hide <a href="javascript:void(0)" onclick="hideElement(\'instructionContent\',\'hide1\')"><img src="/images/btnHide.jpg" alt="Hide" /></a>';
		contentElement.style.display = "block";
	}else{
		if(btnElement != null)btnElement.innerHTML = 'Show <a href="javascript:void(0)" onclick="hideElement(\'instructionContent\',\'hide1\')"><img src="/images/btnShow.jpg" alt="Show" /></a>';
		contentElement.style.display = "none";
	}
}

function expandList(listId, btnId){
	contentElement = document.getElementById(listId);
	btnElement = document.getElementById(btnId);
	//alert("style="+contentElement.style.display);
	if(contentElement.style.display == "none" || contentElement.style.display == ""){
		btnElement.setAttribute("src","/images/minus.jpg");
		btnElement.setAttribute("alt","Hide");
		contentElement.style.display = "block";
	}else{
		btnElement.setAttribute("src","/images/plus.jpg");
		btnElement.setAttribute("alt","Show");
		contentElement.style.display = "none";
	}
}





