//DFI OBJECT
var DFI = {
		classExpand:"toggleCriteria",
		classContract:"closeCriteria",
		classSwapImagePlus:"xplus",
		classSwapImageMinus:"xminus",
		wWidth:0,
		wHeight:0,
		isIE:(navigator.appName == "Microsoft Internet Explorer"),
		isIEsix:(document.compatMode && document.all)?true:false,
		isIEseven:(document.documentElement && typeof document.documentElement.style.maxHeight!="undefined") ? true : false,
		hasLoaderBackground:false,
		bgTransparency:80,
  LAYOUT:{
			showHideByClass:function(x){//## PRIVATE
						var arrEls = document.getElementsByTagName("*");
						var arrElsLen = arrEls.length;
						for(var i=0;i<arrElsLen;i++) {
										if(arrEls[i].className==x&&(arrEls[i].style.display=="none"||(!arrEls[i].style.display)))arrEls[i].style.display="block";
										else if(arrEls[i].className==x&&arrEls[i].style.display=="block")arrEls[i].style.display="none";
						}	
				},
				toggleTableRow:function(trClassName,swapImage,startOpen) {//##Event Listener## //## PUBLIC
						var ie = (navigator.appName == "Microsoft Internet Explorer");
						//alert(ie);
						var arrTRs = document.getElementsByTagName("tr");
						var x = arrTRs.length;
						if (typeof startOpen != "undefined") {
								if(ie) {// Explorer Branch
										for (var i = 0;i<x;i++) {  
												var arrTempEl = arrTRs[i];
												if ((arrTempEl.className.indexOf(trClassName)!=-1) && (arrTempEl.style.display == "none" )) {arrTempEl.style.display = "block"}
												else if ((arrTempEl.className.indexOf(trClassName)!=-1) && (arrTempEl.style.display == "block" || !arrTempEl.style.display)) {arrTempEl.style.display = "none"}
												else{}
										}
								} else {// Normal Browsers Branch
										for (var i = 0;i<x;i++) {  
																var arrTempEl = arrTRs[i];
																if ((arrTempEl.className.indexOf(trClassName)!=-1) && arrTempEl.style.display == "none") {arrTempEl.style.display = "table-row"}
																else if ((arrTempEl.className.indexOf(trClassName)!=-1) && (arrTempEl.style.display == "table-row" || !arrTempEl.style.display)) {arrTRs[i].style.display = "none"}
																else{}
										}
								} 
						} else {
						  if(ie) {// Explorer Branch
										for (var i = 0;i<x;i++) {  
												var arrTempEl = arrTRs[i];
												if ((arrTempEl.className.indexOf(trClassName)!=-1) && (arrTempEl.style.display == "none"  || !arrTempEl.style.display )) {arrTempEl.style.display = "block"}
												else if ((arrTempEl.className.indexOf(trClassName)!=-1) && arrTempEl.style.display == "block") {arrTempEl.style.display = "none"}
												else{}
										}
								} else {// Normal Browsers Branch
										for (var i = 0;i<x;i++) {  
																var arrTempEl = arrTRs[i];
																if ((arrTempEl.className.indexOf(trClassName)!=-1) && (arrTempEl.style.display == "none" || !arrTempEl.style.display)) {arrTempEl.style.display = "table-row"}
																else if ((arrTempEl.className.indexOf(trClassName)!=-1) && (arrTempEl.style.display == "table-row" )) {arrTRs[i].style.display = "none"}
																else{}
										}
								}
						}
						if(swapImage&&this.className.indexOf(DFI.classSwapImagePlus)!=-1){
									DFI.DOM.swapClasses(this,DFI.classSwapImagePlus,DFI.classSwapImageMinus);
						} else if (swapImage&&this.className.indexOf(DFI.classSwapImageMinus)!=-1) {
									DFI.DOM.swapClasses(this,DFI.classSwapImageMinus,DFI.classSwapImagePlus);
						}
				},
				toggleLayer:function(whichLayer,changeImage,byClass){//##Event Listener## //## PUBLIC
						if(changeImage && (this.className==DFI.classContract)) {
								DFI.DOM.swapClasses(this,DFI.classContract,DFI.classExpand);
						} else {
								DFI.DOM.swapClasses(this,DFI.classExpand,DFI.classContract);
						}
						if (!byClass) {
										if (document.getElementById) {
										// this is the way the standards work
										var style2 = document.getElementById(whichLayer).style;
										style2.display = style2.display? "":"block";
										}
										else if (document.all) {
										// this is the way old msie versions work
										var style2 = document.all[whichLayer].style;
										style2.display = style2.display? "":"block";
										}
										else if (document.layers) {
										// this is the way nn4 works
										var style2 = document.layers[whichLayer].style;
										style2.display = style2.display? "":"block";
										}
							} else {
										DFI.LAYOUT.showHideByClass(whichLayer);
							}
				},
				displayPageError:function(targetElement,strMsg,isError){
					 var my_div = document.createElement('div');
						my_div.innerHTML = isError?"<div class='errorMsg'><span class='errorMessage' id='ctl00_phContent_upload_lblErrorMessage'><span class='wrapErr'>You must upload a csv file</span></span></div>":"<div class='errorMsg'><span class='errorMessage' id='ctl00_phContent_upload_lblErrorMessage'><span class='wrapNoErrr'>Your data has been uploaded</span></span></div>";
						DFI.DOM.insertAfter(my_div,targetElement);
				},
				removePageError:function(elAfter,strMsg){
				}
		},
		FORM:{
			 /*autoSelect:function(arrElements,arrOptions){
				  arrElements.each(function(oSelect,index){
							 //alert("processing "+oSelect);
								var opts = oSelect.options;
								$A(opts).each(function(v,i){
									  //alert("trying option: "+i);
											if(v==arrOptions[index]) {oSelect.options.selecteIndex = i;alert("found match ... options set to required value - success")}
								})
						})
				},
			 autoCompleteFromSelect:function (sSelect,sTgtEl,useValue) {//## PUBLIC
						var sTxtVal = useValue?sSelect.options[sSelect.selectedIndex].value:sSelect.options[sSelect.selectedIndex].innerHTML;
						sTgtEl.innerHTML = sTxtVal;
    },*/
				disable:function(arrElements) {
					 arrElements.each(function(value,index){
						   value.disabled= true;
						})
				},
				enable:function(arrElements) {
						 arrElements.each(function(value,index){
						   value.enabled= true;
						})
				}
		},
		AJAX:{
		/*
		method:GET,
		currSSscript:false,
		objTemp:{},
		setCurrSSscript:function(){},
		setRefresh:function(){},
		parseJSONtoTemp:function(){}
		*/
		},
		DRAW:{
		     isFirstTimeLoader:true,
			 hasTransBg:false,
			 divImgWrap:document.createElement("div"),
			 divBg:document.createElement("div"),
		     drawLoader:function(sImg,sId,bDrawBg){//## PUBLIC
		                if(DFI.isIEsix && !(DFI.isIEseven))DFI.DOM.hideAllSelects();
		                if(!(this.isFirstTimeLoader)){
		                  this.divImgWrap.style.display="block";
		                  if(bDrawBg)this.divBg.style.visibility="visible";
		                  
		                  return false
		                  }
		                
						this.divImgWrap.setAttribute("id",sId);
						this.divImgWrap.innerHTML = "<img src='" + sImg + "' />";
					 document.body.insertBefore(this.divImgWrap,document.body.firstChild);
					    
						if(DFI.isIEsix)this.divImgWrap.style.position="absolute";
						if(DFI.isIEsix)DFI.DOM.addScrollEvent(function(){DFI.DRAW.divImgWrap.style.marginTop=document.documentElement.scrollTop+"px"});
						if(bDrawBg)this.drawTransBg();
						this.isFirstTimeLoader = false;
		  },
				drawTransBg:function(sId){//## PUBLIC
				   //if(DFI.hasLoaderBackground)DFI.DRAW.divBg.style.display = "block";
				   //DFI.hasLoaderBackground=true;
					 (typeof sId != "undefined")?DFI.DRAW.divBg.setAttribute("id",sId):this.divBg.setAttribute("id","transBackground");
						document.body.insertBefore(DFI.DRAW.divBg,document.body.firstChild);
						//alert(DFI.isIEseven);
						//if(DFI.isIEseven){
									//if(typeof sId != "undefined"){if(sId.style.opacity)sId.style.opacity="0.5";else if(sId.style.filter!=null)sId.style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity="+ 50 + ");";} else {if(document.getElementById('transBackground') && document.getElementById('transBackground').style.opacity)document.getElementById('transBackground').style.opacity="0.5";else if(document.getElementById('transBackground') && document.getElementById('transBackground').style.filter!=null)$document.getElementById('transBackground').style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+ 50 + ");";;}
					//	} else{
									//(typeof sId != "undefined")?new Effect.Opacity(sId, {duration:0.1, from:1.0, to:0.8}):new Effect.Opacity('transBackground', {duration:0.1, from:1.0, to:0.8});
						//}
						if(!(DFI.isIEseven))DFI.DRAW.divBg.style.opacity=""+DFI.bgTransparency / 100;//"0.8"; 	
						if(DFI.isIEseven)DFI.DRAW.divBg.style.background="url(/images/layout/loadingBg.png)";
						DFI.DRAW.divBg.style.filter="alpha(opacity='" + DFI.bgTransparency + "')"; 
						DFI.DRAW.divBg.style.position=(DFI.isIEsix && !(DFI.isIEseven))?"absolute":"fixed"; 
			   if(DFI.isIE)DFI.DRAW.divBg.style.width=DFI.wWidth+"px";
			    DFI.DRAW.divBg.style.height=DFI.wHeight+"px";
      if(DFI.isIEsix && !(DFI.isIEseven))DFI.DRAW.divBg.style.position="absolute";
						if(DFI.isIEsix && !(DFI.isIEseven))DFI.DOM.addScrollEvent(function(){DFI.DRAW.divBg.style.marginTop=document.body.scrollTop+"px";});
						if(DFI.isIEsix && DFI.isIEseven)DFI.DOM.addResizeEvent(function(){DFI.INIT.parseWindowObj();DFI.DRAW.divBg.style.width=DFI.wWidth+'px';DFI.DRAW.divBg.style.height=DFI.wHeight+'px';});
			            if(DFI.isIEsix)DFI.DOM.hideAllSelects();
			            DFI.DRAW.divBg.style.zIndex="999";
			},
				removeLoader:function(){//## PUBLIC
				 if(DFI.isIEsix && !(DFI.isIEseven))DFI.DOM.showAllSelects();
				 this.divImgWrap.style.display = "none";
				 this.divBg.style.visibility = "hidden";
				},
				removeTransBg:function(){DFI.DRAW.divBg.style.display = "none";DFI.hasLoaderBackgroundHidden=true;},
				drawPopUpFromElement:function(domElPop,bDrawBg,bAsyncRemove){
					 //alert("ie7: " + DFI.isIEseven);
					 if(!bAsyncRemove){
								DFI.INIT.parseWindowObj();
								var domPopContent = domElPop.cloneNode(true);
								domPopContent.style.display="block";
								domElPop.style.display = "none";
								//document.body.removeChild(domElPop);
								if (DFI.isIEsix && !(DFI.isIEseven)){domPopContent.style.position="absolute";}else{domPopContent.style.position="fixed";}
								//domPopContent.style.zIndex = "3000";
								//domPopContent.style.top = "200px";
								//domPopContent.style.left = "20%";
								//domPopContent.style.width= "650px";
								//domPopContent.style.fontSize= "0.75em";
								if(bDrawBg)DFI.DRAW.drawTransBg();
								//DFI.DOM.addScrollEvent(function(){domElPop.style.marginTop=document.documentElement.scrollTop+"px"});
								DFI.DRAW.divBg.style.zIndex="2000";
								document.body.insertBefore(domPopContent,document.body.firstChild);
								DFI.DOM.addScrollEvent(function(){domPopContent.style.marginTop=document.body.scrollTop+"px";});
								if (document.compatMode && document.all) {DFI.DOM.addResizeEvent(function(){DFI.INIT.parseWindowObj();	DFI.DRAW.divBg.style.width=DFI.wWidth+'px';	DFI.DRAW.divBg.style.height=DFI.wHeight+'px';})}
						} else {// (bAsyncRemove=true)
						  //alert("ooO");
								domElPop.style.display="none";
								DFI.DRAW.removeTransBg();
								DFI.DOM.showAllSelects();
						}
				}
		},
		INIT:{
			 parseWindowObj:function() {//## PUBLIC
						if( typeof( window.innerWidth ) == 'number' ) {
								//Non-IE
								DFI.wWidth = window.innerWidth;
								DFI.wHeight = window.innerHeight;
						} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
								//IE 6+ in 'standards compliant mode'
								DFI.wWidth = document.documentElement.clientWidth;
								DFI.wHeight = document.documentElement.clientHeight;
						} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
								//IE 4 compatible
								DFI.wWidth = document.body.clientWidth;
								DFI.wHeight = document.body.clientHeight;
						}
				}
		},
		DOM:{
			hideAllSelects:function(){
			  	$A(document.getElementsByTagName('select')).each(function(node){node.style.visibility="hidden"})
			},
			showAllSelects:function(){
			  	$A(document.getElementsByTagName('select')).each(function(node){node.style.visibility="visible"})
			}
			,
			getDocumentWidth: function(){if (document.width) return document.width;if(document.body.offsetWidth) return document.body.offsetWidth;},
			addLoadEvent:function(func){var oldonload = window.onload;if (typeof window.onload != 'function') {window.onload = func;} else {window.onload = function() {if (oldonload) {oldonload();}func();}}},
			addScrollEvent:function(func){var oldonscroll = window.onscroll;if (typeof window.onscroll != 'function') {window.onscroll = func;} else {window.onscroll= function() {if (oldonscroll) {oldonscroll();}func();}}},
			addResizeEvent:function(func){var oldonresize = window.onresize;if (typeof window.onresize != 'function') {window.onresize = func;} else {window.onresize= function() {if (oldonresize) {oldonresize();}func();}}},			swapClasses:function(element,classNameA,classNameB){//## PRIVATE
							var arrTemp = element.className.split(" ");
							for (var i=0;i<arrTemp.length;i++) {if(arrTemp[i]==classNameA)arrTemp[i]=classNameB;};
							//arrTemp.each = function(i,v){};
							element.className = arrTemp.join(" ");
					},
			 insertAfter:function(newElement,targetElement) {//## PRIVATE
      (targetElement.parentNode.lastchild == targetElement)?parent.appendChild(newElement):parent.insertBefore(newElement, targetElement.nextSibling);
				},
			safeGetElById:function(theId){//##//.NET-proof getElementById //## PRIVATE
						var re = new RegExp("_"); 
						if(re.exec(theId)) {
							 $A(document.getElementsByTagName("*")).each(
								  function(v,i){
											 var x = document.getElementsByTagName("*")[i];
										  if((x.getAttribute("id").indexOf(theId))!=-1) 
								      return document.getElementsByTagName("*")[i];
										  }
								   );
						  }else{
							 return document.getElementById(theId);
						}
				}
				
		}
}