// JavaScript Document


//the checkVideoTab should run on the page unload

	
function setTabCookie2(){
	//alert("unload");
		}
function checkTabCookie2(){
	//alert("onload");
	}

function setTabCookie(){
	//alert("unload");
	var newsTabState = document.getElementById("theNewsTab").style.display;
	if(newsTabState == ""){
		var newsTabState = "block";
		document.cookie = "pageTabState=news";
		}
	var whyTabState = document.getElementById("theWhyTab").style.display;
	if(whyTabState == ""){
		var whyTabState = "block";
		   document.cookie = "pageTabState=why";
		}
	var videoTabState = document.getElementById("theVideoTab").style.display;
	if(videoTabState == ""){
		var videoTabState = "block";
		 document.cookie = "pageTabState=video";
		}
	var applyTabState = document.getElementById("theApplyTab").style.display;
	if(applyTabState == ""){
		var applyTabState = "block";
		document.cookie = "pageTabState=apply";
		}
	 	//alert(newsTabState + whyTabState + videoTabState +  applyTabState);
	 
	
}



function checkTabCookie(){
	
	// check for url query string and then set tab/cookie
			//create array of url query string
			var firstVar = location.search.substr(1).split("=");
			// set the variable tabRequested to the value of the one from the query string
			var tabRequested = firstVar[1];
			
			// check the name and property of the url query
			if (firstVar != -1){ 
				if (firstVar[0] == "tabRequest"){
					switch (tabRequested)
					{
					case "why":
					  //sets the cookie to the requested tab to make sure the rest of the code makes it visible
					  document.cookie = "pageTabState=why";
					  break;
					case "video":
					  //sets the cookie to the requested tab to make sure the rest of the code makes it visible
					   var videoTabState = "block";
					   document.cookie = "pageTabState=video";
					  //sets the cookie to the requested tab to make sure the rest of the code makes it visible
					  break;
					case "news":
					//sets the cookie to the requested tab to make sure the rest of the code makes it visible
					  document.cookie = "pageTabState=news";
					  break;
					 case "apply":
					  //sets the cookie to the requested tab to make sure the rest of the code makes it visible
					  document.cookie = "pageTabState=apply";
					  break;
					default:
					  //do nothing if the value is not one of the above
					}
					
				}
				//document.cookie = "pageTabState=" + firstVar[1];
				//alert(firstVar[1]);
				 //alert(firstVar[0]);
				// alert(firstVar[1]);
				}
	
var theTabCookie = get_cookie("pageTabState");

if(theTabCookie == "why"){
    // alert(theTabCookie);
     document.getElementById("theWhyTab").style.display = "block";
	  document.getElementById("theVideoTab").style.display = "none";
	   document.getElementById("theApplyTab").style.display = "none";
	   document.getElementById("theNewsTab").style.display = "none";
	   document.getElementById("theEventsTab").style.display = "none";
	    document.getElementById('tab-why').className='current';
		 document.getElementById('tab-news').className='';
		  document.getElementById('tab-video').className='';
		   document.getElementById('tab-apply').className='';
		   
	}else if (theTabCookie == "video"){
		//alert(theTabCookie);
		document.getElementById("theVideoTab").style.display = "block";
		 document.getElementById("theWhyTab").style.display = "none";
		  document.getElementById("theApplyTab").style.display = "none";
		   document.getElementById("theNewsTab").style.display = "none";  
		   document.getElementById("theEventsTab").style.display = "none";
		    document.getElementById('tab-video').className='current';
			 document.getElementById('tab-news').className='';
		  document.getElementById('tab-why').className='';
		   document.getElementById('tab-apply').className='';
}else if (theTabCookie == "apply"){
	//alert(theTabCookie);
	document.getElementById("theApplyTab").style.display = "block";
	 document.getElementById("theVideoTab").style.display = "none";
	  document.getElementById("theWhyTab").style.display = "none";
	   document.getElementById("theNewsTab").style.display = "none";
	     document.getElementById("theEventsTab").style.display = "none";
		  document.getElementById('tab-apply').className='current';
		  	document.getElementById('tab-news').className='';
		  document.getElementById('tab-video').className='';
		   document.getElementById('tab-why').className='';
}else if (theTabCookie == "news"){
		   document.getElementById("theNewsTab").style.display = "block";
	     document.getElementById("theEventsTab").style.display = "block";
		document.getElementById("theApplyTab").style.display = "none";
	 document.getElementById("theVideoTab").style.display = "none";
	  document.getElementById("theWhyTab").style.display = "none";
	 document.getElementById('tab-news').className='current';
	  document.getElementById('tab-why').className='';
		  document.getElementById('tab-video').className='';
		   document.getElementById('tab-apply').className='';

	//do nothing
}
}


	
//this gets the cookie for the page so it can be checked
function get_cookie ( cookie_name ){
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

			  if ( results ){
				return ( unescape ( results[2] ) );
				//alert(cookie_name);
			   } else{
				return null;
			   }
}