﻿function GCHideDiv(DivId)
{
	var e=document.getElementById(DivId);
	if(e!=null)
	{
		e.style.display = 'none';
	}
}

function GCShowDiv(DivId)
{
	var e=document.getElementById(DivId);
	if(e!=null)
	{
		e.style.display = '';
	}
}
function SetHtml(DivId,hdnId,HeaderDivId)
{
	GCHideDiv(DivId);
	GCHideDiv(HeaderDivId);
	
	var e=document.getElementById(DivId);
	var hdn="document.forms[0]."+hdnId
	var hdnObject=eval(hdn);
	if(e!=null && hdnObject!=null && hdnObject.value!='' )
	{
		var val=hdnObject.value;
		if(hdnId=='hdnProjectDiseasePriority' || hdnId=='hdnProjectTechnology')
		{
			val=val.replace(/;/g,", ");
		}
		e.innerHTML=val;
		GCShowDiv(DivId);
		GCShowDiv(HeaderDivId);
	}
}

function SetHtmlMulti(DivId,hdnId1,hdnId2,concat)
{
	GCHideDiv(DivId);
	var e=document.getElementById(DivId);
	
	if(e!=null )
	{
		var val="";
		var hdn1="document.forms[0]."+hdnId1
		var hdnObject1=eval(hdn1);
		
		if(hdnObject1!=null )
		{
			val=hdnObject1.value;
		}
		var hdn2="document.forms[0]."+hdnId2
		var hdnObject2=eval(hdn2);
		if(hdnObject2!=null )
		{
			if(val!="")
			{
				val=val+concat+hdnObject2.value;
			}
			else
			{
				val=hdnObject2.value;
			}
		}
		e.innerHTML=val;
		GCShowDiv(DivId);
	}
}

function RandomProjectSpotlight(upperLimit)
{
	var div="gc_pro_";
	var randomnumber=Math.floor(Math.random()*upperLimit)
	if(randomnumber<=upperLimit)
	{
		var e=document.getElementById(div+randomnumber);
		if(e!=null)
		{
			GCHideDiv(div+"1");
			GCShowDiv(div+randomnumber);
		}
	}
}

function RandomHero()
{
	var img=new Array("hero_e2.jpg", "hero_g1.jpg","hero_g2a.jpg", "hero_g3.jpg", "hero_g4.jpg","hero_g5.jpg","hero_g6.jpg", "hero_g7a.jpg");
	var upperLimit=img.length;

	var randomnumber=Math.floor(Math.random()*upperLimit)
//alert(randomnumber);
	var displayImgIndex=0;
	if(randomnumber<=upperLimit)
	{
		displayImgIndex=randomnumber;
		
	}
	//alert(upperLimit + " " + displayImgIndex);
	var e=document.getElementById("HomeHeroDiv");
	if(e!=null)
	{
		e.style.backgroundImage="url('/SiteCollectionImages/"+img[randomnumber]+"')";
	}
	
}

function NavHero(direction)
{
	var img=new Array("hero_e2.jpg", "hero_g1.jpg","hero_g2a.jpg", "hero_g3.jpg", "hero_g4.jpg","hero_g5.jpg","hero_g6.jpg", "hero_g7a.jpg");
	
	var lastIndex=img.length-1;
	var current = "";
	var currentIndex = 0;
	var requestedIndex = 0;
	
	var e=document.getElementById("HomeHeroDiv");
	if(e!=null)
	{
		current = e.style.backgroundImage;
	}
	current = current.substring(current.lastIndexOf('/')+1,current.length-1).toLowerCase();

	// get index of current hero
	for(i=0; i<=lastIndex; i++) {
		if (img[i] == current) {
			currentIndex = i;
		}
	}
	// calculate index of requested hero
	switch(direction) {
		case "previous":
			requestedIndex = currentIndex - 1;
			if (requestedIndex < 0)
				requestedIndex = lastIndex;
			break;
		case "next":
			requestedIndex = currentIndex + 1;
			if (requestedIndex > lastIndex)
				requestedIndex = 0;
			break;			
	}
	// set background image for new hero
	e.style.backgroundImage="url('/SiteCollectionImages/"+img[requestedIndex]+"')";
}

function GCGHFAQToggle(divId)
{
	var e=document.getElementById(divId);

	if(e!=null)
	{
		if(e.className == 'gc_FaqAShow')
	    {
	        e.className  = 'gc_FaqA';
	    }
	    else
	    {
	        e.className  = 'gc_FaqAShow';
	    }		
	}					
}

function GCGHToggle(divId)
{
	var e=document.getElementById(divId);
	if(e!=null)
	{
		if(e.style.display == '')
	    {
	        e.style.display = 'none';
	    }
	    else
	    {
	        e.style.display = '';
	    }		
	}					
}
function GoalsToggle(divId,goalDivId)
{
	var e=document.getElementById(divId);
	//alert(e.className);
	var egoal=document.getElementById(goalDivId);
	if(e!=null && egoal!=null)
	{
		if(e.className == 'gc_Show')
	    {
	    	//alert("set hide " + e.className);
	        e.className = 'gc_Hide';
	        egoal.className='gc_NewGoalListingPlus'
	    }
	    else
	    {
	    	//alert("set show " + e.className);
	        egoal.className='gc_NewGoalListingMinus';
	        e.className= 'gc_Show';
	    }		
	}					

}

function ResearchMapClick()
{
	//window.location.href="/Pages/WhereWeWork.aspx";
	window.open("/Pages/WhereWeWork.aspx");
}

function ExplorationsApplyNow()
{

}

//Redirect

function Custom404Redirect()
{
	var oldUrl=queryString("Url");
	if(oldUrl.toLowerCase() =='/emailsignup/default.aspx')
	{
		window.location.href='/about/Pages/StayUpdated.aspx?Source=ThankYou.aspx';
	}
	if(oldUrl.toLowerCase() =='/explorations/faq/' || oldUrl.toLowerCase() =='/explorations/faq')
	{
		window.location.href='/Explorations/Pages/FAQ.aspx';
	}

}
//End Redirect


//start  Print 
function queryString(Name) 
{
	var url=window.location.href;
	var query = url.substring(url.indexOf('?'));
	query =query.substring(1);
	//alert(query );
	
	var gs = query.split("&");
	for (i=0;i<gs.length;i++) 
	{
		nv = gs[i].split("=");
		if (nv[0].toLowerCase() == Name.toLowerCase()) 
		{
			return nv[1];
		}
	}
}
function OpenPrinterFriendlyPage()
{
	
	var url=window.location.href;
	//alert(url);
	if(url.indexOf('?')!=-1)
	{
		url=url+"&print=1";
	}
	else
	{
		if(url.indexOf('#')==-1)
		{
			url=url+"?print=1";
		}
		else
		{
			url=url.replace('#','?#');
			url=url+"&print=1";
		}
	}
	//alert(url);
	window.open(url);
}
//End print
function MakePrivacyPolicyConfirmationClickable()
{
	//alert('hi');
	var e=document.getElementById("gc_PrivacyPolicyConfirmationId");
	//alert(e);
	if(e!=null)
	{
		var l=e.getElementsByTagName("LABEL");
		//alert(l.length);
		if(l!=null && l.length>0)
		{
			var label=l[0];
			//alert(label.innerHTML);
			label.innerHTML="I have read and agree to the terms of the <a href='/about/Pages/PrivacyPolicy.aspx'>privacy policy</a>";
		}
	}
}


/*
function ResearchMapClickOld()
{
	var noFlash="It appears that you do not have the Adobe Flash Player installed.<p> To take full advantage of the Flash navigation and map features of this site, we recommend that you install it now from the <a href='http://www.adobe.com/' target='_blank'>Adobe site</a>.</p><p>If you decide to install Flash later, you can switch from the HTML version that you are currently viewing to the Flash version of the site.</p>"
	var flashOff="To take full advantage of the Flash navigation and map features of this site, switch from the HTML version that you are currently viewing to the Flash version of the site.";
	var msg="";
	//gcgh= document.getElementById("gcgh");
	//for(var x in gcgh)
	//{
	//	msg+=" | " + x +"="+gcgh[x];
	
	//}
	//alert(gcghNavType);
	if(gcgh!=null && gcghNavType =="Flash")
	{
		gcgh.openMap();
	}
	if(gcghNavType =="NoFlash")
	{
		FlashErrorDisplay(noFlash,300,240);
	}
	
	if(gcghNavType =="Html")
	{
		FlashErrorDisplay(flashOff,300,150);
	}

}
function FlashErrorDisplay(message,width,height)
{
	//alert(message);
	var msgPrefix="<style> td{font-size:12px;font-family:arial,helvetica,sans-serif;}</style><title>Flash Message</title><body><hr><table style='margin:5px'><tr><td>";
	var msgSuffix="</td></tr><tr><td><a href='' onclick='window.close();'>Close</a></td></tr></table><hr></body>";
	message=msgPrefix+message+msgSuffix;
	var properties="height="+height+",width="+width+",toolbar=no, scrollbars=no, menubar=no, status=no, resize=yes"
	var FlashMsgWindow = window.open("", "FlashMsgWindow", properties) ;
	FlashMsgWindow.document.close();
    FlashMsgWindow.document.write(message);
    FlashMsgWindow.document.close();
    FlashMsgWindow.focus();

}


function ToggleFlash()
{
	var divId="ToggleFlash";
	var e=document.getElementById(divId);
	if(e!=null)
	{
		var text=e.innerHTML;

		if(text=="Switch To Flash Version" || text=="<a>Switch To Flash Version</a>")
		{
			createCookie("GCNavType","Flash",10);
			location.reload(true);
		}
		else
		{
			 createCookie("GCNavType","Html",10);
			 location.reload(true);
		}
	}

}
*/
/*
function ToggleShowFlash(e)
{
	if(e!=null)
	{
		var flashDiv = document.getElementById('gcgh1');
		if(flashDiv !=null)
		{
			flashDiv.className="gc_globalNavFlashShow";
			createCookie("GCNavType","Flash",10);
			e.innerHTML="Show Html Version";
		}
		var  globalNavHtml= document.getElementById('globalNavHtml');
		if(globalNavHtml!=null)
		{
			globalNavHtml.className="gc_globalNavHtmlHide";
	
		}
	}

}

function ToggleHideFlash(e)
{
	if(e!=null)
	{

		e.innerHTML="Show Flash Version";
		var  globalNavHtml= document.getElementById('globalNavHtml');
		var flashDiv = document.getElementById('gcgh1');
		if(globalNavHtml!=null)
		{
			globalNavHtml.className="gc_globalNavHtmlShow";
			e.innerHTML="Show Flash Version";
			createCookie("GCNavType","Html",10);
	
		}
		if(flashDiv !=null)
		{
			flashDiv.className="gc_globalNavFlashHide";
		}
	}
}
*/
/*
function SetToggleNavText(text)
{
	var flashToggleDiv=document.getElementById("ToggleFlash");
	if(flashToggleDiv!=null)
	{
		flashToggleDiv.innerHTML=text;
	}
}

function createCookie(name,value,days) {
	//alert("Create Cookie:" + name + " = " + value);
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
*/


//Search Grant
function ResetSearch()
{
	var url=window.location.pathname;
	//alert(url);
	window.location.href=url;
}
function ProcessSearch()
{
	var url=window.location.pathname;
	var query="";
	if(document.forms[0]._topic[document.forms[0]._topic.selectedIndex].value!='')
	{
		query="Topic="+document.forms[0]._topic[document.forms[0]._topic.selectedIndex].value
	}
	//alert(query);
	if(document.forms[0]._technologies[document.forms[0]._technologies.selectedIndex].value!='')
	{
		if(query=="")
		{
			query="Technologies="+document.forms[0]._technologies[document.forms[0]._technologies.selectedIndex].value;
		}
		else
		{
			query=query+"&Technologies="+document.forms[0]._technologies[document.forms[0]._technologies.selectedIndex].value;
		}
	}
	//alert(query);
	if(document.forms[0]._rounds[document.forms[0]._rounds.selectedIndex].value!='')
	{
		if(query=="")
		{
			query="Round="+document.forms[0]._rounds[document.forms[0]._rounds.selectedIndex].value;
		}
		else
		{
			query=query+"&Round="+document.forms[0]._rounds[document.forms[0]._rounds.selectedIndex].value;
		}
	}
    if (document.forms[0]._phases[document.forms[0]._phases.selectedIndex].value != '') {
        if (query == "") {
            query = "Phase=" + document.forms[0]._phases[document.forms[0]._phases.selectedIndex].value;
        }
        else {
            query = query + "&Phase=" + document.forms[0]._phases[document.forms[0]._phases.selectedIndex].value;
        }
    }
    //alert(query);
     if(query!="")
     {
	   window.location.href=url+"?"+query;
	 }
	 else
	 {
	 	window.location.href=url;
	 }
}
//end search grant
