/*------------------------------------------------------------*/ 
/*   LoadNavs_V3.js     Jason Pryde     12/3/2006             */
/*   Functions to dynamically populate navbars, righthand box */
/*   banner links and images and other divs on site:          */
/*    www.ksg.harvard.edu/innovations/Management              */
/*------------------------------------------------------------*/ 

	var NominatorFirstNameValue="x";
	var NominatorLastNameValue;
	var NominatorOrganizationValue;
	var NominatorCountryValue;
	var NominatorEmailValue;
	var NominatorPhoneValue;
	
	var NomineeFirstNameValue;
	var NomineeLastNameValue;
	var NomineeOrganizationValue;
	var NominatorCountryValue;
	var NomineeEmailValue;
	var NomineePhoneValue;
	var NomineeInstitutionTypeValue;
	var NomineeOtherInstValue;
	var Question1;
	var Question2;
	var Question3;
	var Question4;


startList = function() 
/*---- This function applys a class to the dropdown menu items on mouseover and mouseout only-- --*/
{
	if (document.all&&document.getElementById) 
	{
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") 
			{
				node.onmouseover=function() 
				{
					this.className+=" over";
				}
				node.onmouseout=function() 
				{
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}



function AddTopNav() {
/*-- fill TopNav Menu with current Menu items that may load new page ---*/
TopNavContent=document.getElementById('TopNav');
TopNavContenttext ="<UL id='nav'>";
TopNavContenttext +="<li id='Home' onclick=\"GoHome()\" >Home&nbsp;</li>";
TopNavContenttext +="<li id='Introduction' onclick='DisplayPage(\"Introduction\")'>&nbsp;Introduction&nbsp;</li>";
TopNavContenttext +="<li id='Eligibility' onclick='DisplayPage(\"Eligibility\")'>&nbsp;Eligibility&nbsp;</li>";
TopNavContenttext +="<li id='SelectionCriteria' onclick='DisplayPage(\"SelectionCriteria\")'>&nbsp;Selection Criteria&nbsp;</li>";
TopNavContenttext +="<li id='SelectionProcess' onclick='DisplayPage(\"SelectionProcess\")'>&nbsp;Selection Process&nbsp;</li>";
TopNavContenttext +="<li id='NominationForm' onclick='DisplayPage(\"NominationForm\")'>&nbsp;Nomination Form</li>";
TopNavContenttext +="</UL>	";
TopNavContent.innerHTML=TopNavContenttext;
startList();
}

function GoHome()  
{
    QryStr = location.search; 	
	HomeURL = location.href.substring(0,location.href.length-QryStr.length);
	location.href = HomeURL;
	
}


function BuildRtColBox()
{
/*--------- Create Righthand box   divisions -----------------------------------------------*/
rtColBoxContent=document.getElementById('RightColBoxContent');
rtColBoxContentText =  "<div id='RtColBox_Intro' class='relatedboxtext'></div>\n";
rtColBoxContentText += "<div id='Announce_Text' class='relatedboxtext'></div>\n";
rtColBoxContentText += "<div id='Tools'         class='relatedboxtext'></div>\n"; 
rtColBoxContent.innerHTML =rtColBoxContentText;
}




function LoadMainPageContent()
{
/*----------Preload Forms Content---------------*/
var ahah_RCBIntro= new DivContent('Form1.html','PageBodyForm1');
ahah_RCBIntro.newreq();

var ahah_RCBIntro= new DivContent('Form2.html','PageBodyForm2');
ahah_RCBIntro.newreq();
var ahah_RCBIntro= new DivContent('Form3Question1.html','Form3Question1');
ahah_RCBIntro.newreq();
var ahah_RCBIntro= new DivContent('Form3Question2.html','Form3Question2');
ahah_RCBIntro.newreq();
var ahah_RCBIntro= new DivContent('Form3Question3.html','Form3Question3');
ahah_RCBIntro.newreq();
var ahah_RCBIntro= new DivContent('Form3Question4.html','Form3Question4');
ahah_RCBIntro.newreq();

var ahah_RCBIntro= new DivContent('Final.html','PageBodyFinal');
ahah_RCBIntro.newreq();




/*-- ---------Preload Initial Main Page Content------------------- ---*/
var ahah_RCBIntro= new DivContent('MainPageBodyContent_PageTitle.html','PageTitle');
ahah_RCBIntro.newreq();

var ahah_RCBIntro= new DivContent('MainPageBodyContent.html','PageBodyContent');
ahah_RCBIntro.newreq();

/*----------Preload Righthand Box Content---------------*/
var ahah_RCBIntro= new DivContent('RtColBox_Intro.html','RtColBox_Intro');
ahah_RCBIntro.newreq(); 
var ahah_RCBIntro= new DivContent('Announcement.html','Announce_Text');
ahah_RCBIntro.newreq();
var ahah_RCBIntro= new DivContent('Tools.html','Tools');
ahah_RCBIntro.newreq();

} 





/*-- ------Scrape Field values from a form------- --*/
function GetFields(PageID)
{ 
   var error_field = "";
   
	switch(PageID)
	{
		case "Form2":
		  
			  	NominatorFirstNameValue=document.getElementById('Nominator_FirstName').value;
				 if (!CheckField('Nominator_FirstName')){error_field="Nominator_FirstName";}

				NominatorLastNameValue=document.getElementById('Nominator_LastName').value;
 				 if (!CheckField('Nominator_LastName')){error_field="Nominator_LastName";}

				NominatorOrganizationValue=document.getElementById('Nominator_Organization').value;
				 if (!CheckField('Nominator_Organization')){error_field="Nominator_Organization";}


				NominatorCountryValue=document.getElementById('Nominator_Country').value;
				/*-- if (!CheckField('Nominator_Country')){error_field="Nominator_Country";}  --*/

				NominatorEmailValue=document.getElementById('Nominator_Email').value;
				 if (!CheckField('Nominator_Email')){error_field="Nominator_Email";} ;

				NominatorPhoneValue=document.getElementById('Nominator_Phone').value;
			/*--	 if (!CheckField('Nominator_Phone')){error_field="Nominator_Phone";}	--*/
				break;
		  
		case "Form3":		  
			  	NomineeFirstNameValue=document.getElementById('Nominee_FirstName').value;
			if (!CheckField('Nominee_FirstName')){error_field="Nominee_FirstName";}
			
				NomineeLastNameValue=document.getElementById('Nominee_LastName').value;
				 	 if (!CheckField('Nominee_LastName')){error_field="Nominee_LastName";}

				NomineeOrganizationValue=document.getElementById('Nominee_Organization').value;
				if (!CheckField('Nominee_Organization')){error_field="Nominee_Organization";}
				
				NomineeCountryValue=document.getElementById('Nominee_Country').value;				 
				 /*-- if (!CheckField('Nominee_Country')){error_field="Nominee_Country";}			  --*/
				
				NomineeEmailValue=document.getElementById('Nominee_Email').value;
			/*--	  if (!CheckField('Nominee_Email')){error_field="Nominee_Email";} ;	--*/
				
				NomineePhoneValue=document.getElementById('Nominee_Phone').value;
			/*--	 if (!CheckField('Nominee_Phone')){error_field="Nominee_Phone";}  --*/

/*--    NomineeInstitutionTypeValue is assigned OnClick of Radio Button	 --*/
				 NomineeOtherInstValue=document.getElementById('Nominee_OtherInst').value;	
				break;
		  
		case "Final":
		  
			  	 Question1Value=document.getElementById('Question1').value;
				 Question2Value=document.getElementById('Question2').value;
				 Question3Value=document.getElementById('Question3').value;
				 Question4Value=document.getElementById('Question4').value;
				break;
		  
	}
	
	
return error_field;	
	
}

//-- ---------Set values of Final Form ---------------------------
function SetFields()
{		 
		document.getElementById('Dsp_Nominator_FirstName').value = NominatorFirstNameValue 		
		document.getElementById('Dsp_Nominator_LastName').value = NominatorLastNameValue 
		document.getElementById('Dsp_Nominator_Organization').value = NominatorOrganizationValue 
		document.getElementById('Dsp_Nominator_Country').value = NominatorCountryValue 
		document.getElementById('Dsp_Nominator_Email').value =NominatorEmailValue 
		document.getElementById('Dsp_Nominator_Phone').value =NominatorPhoneValue

		document.getElementById('Dsp_Nominee_FirstName').value =NomineeFirstNameValue
		document.getElementById('Dsp_Nominee_LastName').value =NomineeLastNameValue
		document.getElementById('Dsp_Nominee_Organization').value =NomineeOrganizationValue
		document.getElementById('Dsp_Nominee_Country').value =NomineeCountryValue
		document.getElementById('Dsp_Nominee_Email').value =NomineeEmailValue
		document.getElementById('Dsp_Nominee_Phone').value =NomineePhoneValue
		document.getElementById('Dsp_Nominee_Institution_Type').value =NomineeInstitutionTypeValue;
		document.getElementById('Dsp_Nominee_OtherInst').value =NomineeOtherInstValue;
				
		document.getElementById('Dsp_Question1').value =Question1Value;
		document.getElementById('Dsp_Question2').value =Question2Value;
		document.getElementById('Dsp_Question3').value =Question3Value;
		document.getElementById('Dsp_Question4').value =Question4Value;
				
}
/*--Initialize form fields to empty string --*/
function InitFields()
{ 				
	    document.getElementById('Question1').value ='';
		document.getElementById('Question2').value ='';
		document.getElementById('Question3').value ='';
		document.getElementById('Question4').value ='';
 
 		NomineeInstitutionTypeValue='';
}




//-- --------Utility Functions----------------------------------------
function DisplayPage(PageID)
{	
/*-- Added Error reporting - jgp 3/26/2007--- --*/	

 
  /*-- ----Check for a query string in URL, override PageID if so. --*/
	QryStr = location.search; 
	$NCResult = QryStr.substring(8, QryStr.length) 
    if ($NCResult.length >0 && PageID == "MainPageBodyContent") 
		{
		  if ($NCResult.indexOf('ERROR')==2)
		  { $NCResult +=  " Field has an error.  Click Home to correct this and try to Submit again."   
			PageID = "NominError";
		  }
		  else
		  { $NCResult += "<br>Click HOME option above to enter another.";  
            PageID = "NominConfirm";
		  }
		}
	
/*--Update PageTitle--*/
	ahah_RCBIntro= new DivContent(PageID+'_PageTitle.html','PageTitle');
	ahah_RCBIntro.newreq();
   

 switch(PageID)
	{
		case "MainPageBodyContent": 
			var ahah_RCBIntro= new DivContent('MainPageBodyContent.html','PageBodyContent');
			ahah_RCBIntro.newreq();
			HideForm();
			ShowDiv('RightColumnBox'); 
			ShowDiv('PageBodyContent');
			break;

		case "Form1": 
			HideDiv('PageBodyForm2');
			HideDiv('PageBodyForm3');
			HideDiv('PageBodyFinal'); 
			HideDiv('PageBodyContent'); 
			HideDiv('RightColumnBox'); 
			ShowDiv('PageBodyForm1');
			break;

		case "Form2": 
			HideDiv('PageBodyFinal'); 
			HideDiv('PageBodyContent'); 
			HideDiv('PageBodyForm3'); 
			var error_result=GetFields(PageID);
			if (error_result != "") 
			{ 
			HideDiv('PageBodyForm2'); 
			ShowDiv('PageBodyForm1');
			}
			else
			{
			HideDiv('PageBodyForm1'); 
			ShowDiv('PageBodyForm2');
			}
			break;
			
		case "Form3": 
			HideDiv('PageBodyFinal'); 
			HideDiv('PageBodyContent'); 
			var error_result=GetFields(PageID);
			if (error_result != "") 
			{ 
			HideDiv('PageBodyForm3'); 
			ShowDiv('PageBodyForm2');
			}
            else			
			{
			HideDiv('PageBodyForm2'); 
			ShowDiv('PageBodyForm3');
			}
			break;
			
		case "Final": 
		    GetFields(PageID);
			HideDiv('PageBodyForm1');
			HideDiv('PageBodyForm2');
			HideDiv('PageBodyContent'); 			
			HideDiv('PageBodyForm3');  
			ShowDiv('PageBodyFinal');
			SetFields();
			break;
		case "Introduction": 
			var ahah_RCBIntro= new DivContent('Introduction.html','PageBodyContent');
			ahah_RCBIntro.newreq();
			HideForm();
			ShowDiv('RightColumnBox'); 
			ShowDiv('PageBodyContent');
			break;
		case "Eligibility": 
			var ahah_RCBIntro= new DivContent('Eligibility.html','PageBodyContent');
			ahah_RCBIntro.newreq();
			HideForm();
			ShowDiv('RightColumnBox'); 
			ShowDiv('PageBodyContent');
			break;
		case "SelectionCriteria": 
			var ahah_RCBIntro= new DivContent('SelectionCriteria.html','PageBodyContent');
			ahah_RCBIntro.newreq();
			HideForm();
			ShowDiv('RightColumnBox'); 
			ShowDiv('PageBodyContent');
			break;
		case "SelectionProcess": 
			var ahah_RCBIntro= new DivContent('SelectionProcess.html','PageBodyContent');
			ahah_RCBIntro.newreq();
			HideForm();
			ShowDiv('RightColumnBox'); 
			ShowDiv('PageBodyContent');
			break;
		case "NominationForm": 
			var ahah_RCBIntro= new DivContent('NominationForm.html','PageBodyContent');
			ahah_RCBIntro.newreq();
			HideForm();
			ShowDiv('RightColumnBox'); 
			ShowDiv('PageBodyContent');
			break;
		case "NominConfirm": 
			var ahah_RCBIntro= new DivContent('NominConfirm.html','PageBodyContent',$NCResult);
			ahah_RCBIntro.newreq();
			HideForm();
			ShowDiv('RightColumnBox'); 
			ShowDiv('PageBodyContent');
			break;
		case "NominError": 
			var ahah_RCBIntro= new DivContent('NominError.html','PageBodyContent',$NCResult);
			ahah_RCBIntro.newreq();
			HideForm();
			HideDiv('RightColumnBox'); 
			ShowDiv('PageBodyContent');
			break;	     
	
	
	}
window.scrollTo(0,0);
}




function HideForm() 
{
			HideDiv('PageBodyForm1');
			HideDiv('PageBodyForm2');
			HideDiv('PageBodyForm3');
			HideDiv('PageBodyFinal'); 
}

function HideDiv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function ShowDiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else 
	{
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}

placeFocus(id)

}




function placeFocus(idx) 
{

  if (document.forms.length > 0) 
  {
   var f;	
	
   switch(idx)
	{
		case "PageBodyForm1": f='Form1'; i=1; break;
		case "PageBodyForm2": f='Form2'; i=0; break;
		case "PageBodyForm3": f='Form3'; i=0; break;
		case "PageBodyFinal": f='PageBodyFinal'; i=18; break;
		default: f=''; i=0;
	}



	if (document.forms[f]) 
	{	
	
/*--	var formid =	document.forms[f].id;	
		var fieldid =	document.forms[f].elements[i].id;
		var fieldqty =	document.forms[f].length;
		alert("f:"+f+"--formid:"+formid+"---fieldid:"+fieldid);   --*/

		document.forms[f].elements[i].focus();
	}

  }  //--endif (document....)

}



/*-- Check Field Validity - General -----*/
function CheckField(FieldName)
{
 	var FieldValue=document.getElementById(FieldName).value; 
	
   	if (FieldValue == "" || FieldValue == null  || FieldValue.charAt(0) == ' ')
    {
    	alert(FieldName+" is a mandatory field.\nPlease amend and retry.\n"+FieldValue)
    	return false;
    }
		
  	/*-----------if (FieldName =="Nominator_Email" || FieldName =="Nominee_Email")	
	{ 
	   if (!isValidEmail(FieldValue))
	    {alert(FieldName + " must be a valid email address.\n"+FieldValue);
		 return false;
		}     
	} -------------------------------*/
	
	
return true;
}



//function to check valid email address
function isValidEmail(strEmail)
{
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  
   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
    { return false; }
	else
    { return true; }
}


