var bolChange = false;

// browser variables
var ns6 = (navigator.userAgent.substring(0,9) == 'Mozilla/5');
var ns4 = (document.layers) && (navigator.userAgent.substring(0,9) == 'Mozilla/4');
var ns = (ns4 || ns6)? true:false;
var ie4 = (navigator.appVersion.indexOf('Windows') != -1) && (navigator.appVersion.substring(17,23) == 'MSIE 4')? true:false;
var ie5 = (document.all) && (navigator.appVersion.substring(17,23) == 'MSIE 5')? true:false;
var ie6 = (document.all) && (navigator.appVersion.substring(17,23) == 'MSIE 6')? true:false;
var ie7 = (document.all) && (navigator.appVersion.substring(17,23) == 'MSIE 7')? true:false;
var ieMac = (document.all) && (navigator.userAgent.indexOf('Mac')!=-1)? true:false;
var ie = (document.all) && (navigator.appVersion.substring(17,21) == 'MSIE')? true:false;
//var ie = (ie4 || ie5 || ie6 || ie7 || ieMac)? true:false;
var ie5Mac = (ie5 && ieMac)? true:false;
var strConfirmation = "You have made a change and did not SAVE your work.\n\n" + 
				"Select OK to discard the changes and move to the next screen.\n\n" + 
				"Select CANCEL to return to the screen and click on the SAVE button to save your work.\n\n" +
		        "Note: Using the \"Back\" navigation in your browser after leaving\n" +
		        "this screen will make it appear that you have saved your information. However,\n" +
		        "unless you have actually pressed the SAVE button your work will be lost.";

if (ie)
	document.write('<link href="/style/ie.css" type=text/css rel=stylesheet>');
else
	document.write('<link href="/style/ff.css" type=text/css rel=stylesheet>');

function LimitSize(TheObject, Size)
{
   var theText = TheObject.value;

   if(theText.length < Size)
   {
      return true;
   }// End If
   else
   {
      TheObject.value = theText.substr(0, Size);
      return false;
   }// End Else
}// Close LimitSize

function Confirm(NextLocation)
{
   if(bolChange)
   {
     if(confirm(strConfirmation))
     {
        location.href = NextLocation;
     }// End If
   }//End If
   else
   {
      location.href = NextLocation;
   }// End If  
}// Close Confirm

function doChange(TheElement)
{
   bolChange = true;
   switch(TheElement.name)
   {
		case "ddlcitizen_us":
			doDisable();
			break;
		case "ddlcitizen_country_id":
			doDisable();
			break;
		case "txtAgreeFullName":
			doDisable();
			break;
   }// Close Switch
}// Close doChange

function Init()
{
    for(i = 0; i < document.forms[0].elements.length; i++)
    {
		eval('document.forms[0].elements[i].onchange = new Function("doChange(this)")');
    }// End For
}// Close Init

function checkMaxLength(textarea, evt, maxLength)
{
  if (textarea.selected && evt.shiftKey)
  { 
    // ignore shift click for select
    return true;
  }// End If

  var allowKey = false;

  if (textarea.selected && textarea.selectedLength > 0)
  {
    allowKey = true;
  }// End If
  else
  {
    var keyCode = document.layers ? evt.which : evt.keyCode;
    
    if (keyCode < 41 && keyCode != 13 && keyCode != 32)
    {
      allowKey = true;
    }// End If
    else
    {
      allowKey = textarea.value.length < maxLength;
    }// End Else
  }// End Else

  textarea.selected = false;
  return allowKey;

}// Close checkMaxLength

function storeSelection (field)
{
  if (document.all)
  {
    field.selected = true;
    field.selectedLength = field.createTextRange ? document.selection.createRange().text.length : 1;
  }// End If
}// Close storeSelection

function customWindow(name, URL)
{
	var sH = screen.availHeight - 250;
	var sW = screen.availWidth - 350;
	
	var win = window.open(URL, name,'height=' + sH + ',width=' + sW + ',scrollbars=yes,status=no,toolbar=no,menubar=yes,location=no,resizable=yes');
	
	if(win)
	{
		win.focus();
		win.moveTo(10,10);
	}// End If
}// Close customWindow

function openInstitution(QueryString, WindowName)
{
	var sH = screen.availHeight - 250;
	var sW = screen.availWidth - 350;
	
	var win = window.open('/programs/list/?' + QueryString, WindowName,'height=' + sH + ',width=' + sW + ',scrollbars=yes,status=no,toolbar=no,menubar=yes,location=no,resizable=yes');
	
	if(win)
	{
		win.focus();
		win.moveTo(10,10);
	}// End If
}// Close openInstitution

function openReferee(QueryString, WindowName, Height)
{
	var sW = 600;
	var sH = 560;
	if(Height == 2)
		sH = 175
	
	var win = window.open('/programs/referee/?' + QueryString, WindowName,'height=' + sH + ',width=' + sW + ',scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	//var win = window.open('/programs/referee/edit.aspx?' + QueryString, WindowName,'height=' + sH + ',width=' + sW + ',scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	
	if(win)
	{
		win.focus();
		win.moveTo(10,10);
	}// End If
}// Close openReferee

function openLanguage(QueryString, WindowName, Height)
{
	var sW = 600;
	var sH = 560;
	if(Height == 2)
		sH = 175
	
	var win = window.open('/programs/referee/language.aspx?' + QueryString, WindowName,'height=' + sH + ',width=' + sW + ',scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	
	if(win)
	{
		win.focus();
		win.moveTo(10,10);
	}// End If
}// Close openReferee

function editEmail(QueryString, WindowName)
{
	var sW = 600;
	var sH = 500;
	
	var win = window.open('/programs/referee/edit.aspx?' + QueryString, WindowName,'height=' + sH + ',width=' + sW + ',scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	
	if(win)
	{
		win.focus();
		win.moveTo(10,10);
	}// End If
}// Close editEmail

function closeList()
{
	if(window.opener && !self.opener.closed)
		self.opener.focus();

	self.window.close();
}// Close closeList

function openOSXWindow()
{
	var strURL = "/programs/faq/mac_osx.htm";
	
	var win = window.open(strURL, 'OSXWindow', 'height=400,width=450,scrollbars=yes,status=no,toolbar=no,menubar=yes,location=no,resizable=yes');
	
	if(win)
	{
		win.focus();
		win.moveTo(10,10);
	}// End If
}// Close openOSXWindow

function checkHelp()
{
	if (document.forms[0].txaproblem.value == "")
	{
		alert('Please describe the problem that you are having!');
	}
	else
	{
		document.forms[0].submit();
	}
}// Close checkHelp

function confirmSubmit()
{
	var msg = "By clicking 'OK' you will submit your application. At that point you will be unable to make any further revisions." +
				"\n\nDo you wish to continue?";
	if(confirm(msg))
	{
		document.forms[0].submit();
	}// End If
}// Close confirmSubmit

function confirmWithoutUpload()
{
	var msg = "Your proposal has not been uploaded.  Please make sure to upload your proposal following the instructions on the \"Proposal Upload\" page.\n\n" + 
				"If you experience difficulty with your upload, please contact us using the HELP button on the top right of any page.\n\n" +
				"If you click \"OK\" and submit your application now, it will be incomplete. No further revisions may be made after submission.";
	if(confirm(msg))
	{
		document.forms[0].submit();
	}// End If
}// Close confirmWithoutUpload

function alertRequirements(upload, reference, subfield)
{
	var msg = "";
	
	switch (subfield)
	{
		case 1:
			msg += "- Enter a discipline subfield on the \"General Information\" page.\n";
			break;
	}

	switch (upload)
	{
		case 1: 
			msg += "- Upload your supporting material following the instructions on the \"Supporting Material Upload\" page .\n";
			break;
	}
	
	switch (reference)
	{
		case 1:
			msg += "- Enter the required number of recommenders on the \"List of Recommenders\" page .\n";
			break;
	}

	msg = "All requirements have not been met.\n\n" +
			msg + 
			"\nIf you experience any difficulty and need assistance, please contact SSRC using the HELP button on the top right of any page.\n\n";
	alert(msg);
}// Close alertRequirements

function alertUploads()
{
	var msg =	"You cannot submit your application because all requirements have not been met.\n\n" +
				"Please make sure to upload your supporting material following the instructions on the \"Supporting Material Upload\" page before submitting your application.\n\n" + 
				"If you experience any difficulty and need assistance, please contact the Radcliffe Institute Fellowships Office using the HELP button on the top right of any page.\n\n";
	alert(msg);
}// Close alertUploads

function alertReferences()
{
	var msg =	"You cannot submit your application because all requirements have not been met.\n\n" +
				"Please make sure to enter the required number of recommenders on the \"List of Recommenders\" page before submitting your application.\n\n" + 
				"If you experience any difficulty and need assistance, please contact the Radcliffe Institute Fellowships Office using the HELP button on the top right of any page.\n\n";
	alert(msg);
}// Close alertReferences

function alertReferenceAssessment()
{
	var msg = "Please select an option for the Assessment question before submitting this evaluation.";
	
	alert(msg);
}// Close alertReferenceAssessment


function alertReferenceAssessmentOther()
{
	var msg = "Please enter some comments on why you've chosen 'Other' for the Assessment question for this applicant.";
	
	alert(msg);
}// Close alertReferenceAssessment

function submitReferenceLetter()
{
	var msg = "Please enter your letter for this applicant before submitting your recommendation.";
	
	alert(msg);
}// Close alertReferenceAssessment

function confirmReferenceLetterSubmit()
{
	var msg = "By clicking 'OK' you will submit this recommendation. At that point you will be unable to make any further revisions." +
				"\n\nDo you wish to continue?";
	if(confirm(msg))
	{
		document.forms[0].submit();
	}// End If
}// Close confirmReferenceLetterSubmit




