//==============================================
// Functions for graphics, rollovers and so on
//==============================================
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//================================================
//
//================================================

function OpenWindow(thePage,theWidth,theHeight,theTop,theLeft,theScroll){
	if(theScroll==""){
		theScroll=0;
	}
	msgWindow=window.open(thePage,'none','toolbar=no,directories=no,menubar=no,scrollbars=' + theScroll + ',resizable=yes,close=no,width=' + theWidth + ',height=' + theHeight + ',top=' + theTop + ',left=' + theLeft);
}

function buildForumSearchQueryString(inOption,inAction,inLocator,inAUTH){
	var sTextValue = document.FrmForumPost.search_text.value;
	var sSearchIn = "";
	var sFid = "";
	
	var lenSearchIn = document.FrmForumPost.search_in.length
	for(i=0;i<lenSearchIn;i++){
		if(document.FrmForumPost.search_in[i].selected){
			sSearchIn = document.FrmForumPost.search_in[i].value;
		}
	}
	var lenFid = document.FrmForumPost.fid.length
	for(i=0;i<lenFid;i++){
		if(document.FrmForumPost.fid[i].selected){
			sFid = document.FrmForumPost.fid[i].value;
		}
	}
	
	if(sTextValue==""){
		alert('Please, enter the text to search for');
	}else{
		var sPage = "LevelOne.asp?page=" + inOption + "&search_text=" + sTextValue + "&search_in=" + sSearchIn + "&fid=" + sFid + "&action=" + inAction + "&Locator=" + inLocator + inAUTH;
		//alert(sPage);
		document.location.href = sPage;
	}
}


function SubmitSearch(inChosenSection,inFiltersShown,inSectionTitle){

	var vFullText = document.FrmSearch.FullText.value;
	vFullText = trim(vFullText);
	
	//Advanced Search
	if((inChosenSection=="Advanced Search")||(inChosenSection=="Advanced Search Result")){			
		checkAdvancedSearchFilters(inChosenSection,inFiltersShown,vFullText);
	//Section Search
	}else{
		checkSectionSearchFilters(inChosenSection,inFiltersShown,inSectionTitle,vFullText);	
	}
}
function checkSectionSearchFilters(inChosenSection,inFiltersShown,inSectionTitle,vFullText){
	var bSubmitSingleSearch = true;

	if(vFullText==""){
		if(inSectionTitle=="Awards"){
			nAwardYearFrom = document.FrmSearch.cboAwardYearFrom.length;
			nAwardYearTo = document.FrmSearch.cboAwardYearTo.length;
			var bAwardYearFromSelected = false;
			var bAwardYearToSelected = false;
			
			for(i=0;i<nAwardYearFrom;i++){
				if((document.FrmSearch.cboAwardYearFrom[i].selected)&&(document.FrmSearch.cboAwardYearFrom[i].value!='')){
					bAwardYearFromSelected = true;
				}
			}		
			for(i=0;i<nAwardYearTo;i++){
				if((document.FrmSearch.cboAwardYearTo[i].selected)&&(document.FrmSearch.cboAwardYearTo[i].value!='')){
					bAwardYearToSelected = true;
				}
			}		
			if(bAwardYearFromSelected||bAwardYearToSelected){
			
			}else{
				bSubmitSingleSearch = false;
				alert('Please enter the word(s) or date(s) to do a search on');			
			}		
		}else{
			bSubmitSingleSearch = false;
			alert('Please enter the word(s) to do a search on');
		}
	}else if((vFullText.length==1)&&((vFullText==",")||(vFullText=="-")||(vFullText=="+")||(vFullText=="|")||(vFullText==">")||(vFullText=="<")||(vFullText=="*")||(vFullText=="[")||(vFullText=="]")||(vFullText=="(")||(vFullText==")")||(vFullText=="{")||(vFullText=="}")||(vFullText=="/")||(vFullText=="\\"))){
		bSubmitSingleSearch = false;
		alert("Sorry, '" + vFullText + "' is not a valid Search criteria");		
	}		
	
	if(bSubmitSingleSearch == true){	
		//IF THERE IS AMPERSAND REPLACE IT OTHEWISE IT WON'T BE POSTED!
		document.FrmSearch.FullText.value = vFullText.replace("&","_AMP_")
		document.FrmSearch.submit();		
	}
}

function checkAdvancedSearchFilters(inChosenSection,inFiltersShown,vFullText){

	document.FrmAdvSearch.FullText.value = vFullText.replace("&","_AMP_");
	for(i=0;i<document.FrmSearch.rdoLanguageFilter.length;i++){
		if(document.FrmSearch.rdoLanguageFilter[i].checked)
			document.FrmAdvSearch.rdoLanguageFilter.value = document.FrmSearch.rdoLanguageFilter[i].value;						
	}					

	if(inFiltersShown=='yes'){
		var nMonthFrom = document.FrmAdvSearch.cboMonthFrom.length;
		var nYearFrom = document.FrmAdvSearch.cboYearFrom.length;
		var nMonthTo = document.FrmAdvSearch.cboMonthTo.length;
		var nYearTo = document.FrmAdvSearch.cboYearTo.length;

		var bMonthFromSelected = false;
		var bYearFromSelected = false;
		var bMonthToSelected = false;
		var bYearToSelected = false;
	
		for(i=0;i<nMonthFrom;i++){
			if((document.FrmAdvSearch.cboMonthFrom[i].selected)&&(document.FrmAdvSearch.cboMonthFrom[i].value!='0')){
				bMonthFromSelected = true;
				//alert("bMonthFromSelected = " + bMonthFromSelected);
			}
		}	
		for(i=0;i<nYearFrom;i++){
			if((document.FrmAdvSearch.cboYearFrom[i].selected)&&(document.FrmAdvSearch.cboYearFrom[i].value!='')){
				bYearFromSelected = true;
				//alert("bYearFromSelected = " + bYearFromSelected);					
			}
		}	
		for(i=0;i<nMonthTo;i++){
			if((document.FrmAdvSearch.cboMonthTo[i].selected)&&(document.FrmAdvSearch.cboMonthTo[i].value!='0')){
				bMonthToSelected = true;
				//alert("bMonthToSelected = " + bMonthToSelected);
			}
		}	
		for(i=0;i<nYearTo;i++){
			if((document.FrmAdvSearch.cboYearTo[i].selected)&&(document.FrmAdvSearch.cboYearTo[i].value!='')){
				bYearToSelected = true;
				//alert("bYearToSelected = " + bYearToSelected);
			}
		}		
		if(((bMonthFromSelected==true)&&(bYearFromSelected==false))||((bMonthToSelected==true)&&(bYearToSelected==false))){
				alert('Sorry, you cannot search by month only, deselect it or select year too');
		}else if(((bMonthFromSelected==true)&&(bYearFromSelected==true)&&(bYearToSelected==true)&&(bMonthToSelected==false))||
		((bYearToSelected==true)&&(bMonthToSelected==true)&&(bMonthFromSelected==false)&&(bYearFromSelected==true))){
			alert('Sorry, query is not valid, all months or none should be selected');
		}else{	
			var bAnyOtherChecked = isAnyChecked(inChosenSection,inFiltersShown);
			if(!bAnyOtherChecked)
			{
				alert("Please, select the content you would like to do a search on");
				return ;
			}else{	
				if((vFullText=="")&&(bYearFromSelected==false)&&(bYearToSelected==false)){
					alert('Please enter the word(s) or date(s) to do a search on');	
				}else if((vFullText.length==1)&&((vFullText==",")||(vFullText=="-")||(vFullText=="+")||(vFullText=="|")||(vFullText==">")||(vFullText=="<")||(vFullText=="*")||(vFullText=="[")||(vFullText=="]")||(vFullText=="(")||(vFullText==")")||(vFullText=="{")||(vFullText=="}")||(vFullText=="/")||(vFullText=="\\"))){		
					alert("Sorry, '" + vFullText + "' is not a valid Search criteria");						
				}else{	
					document.FrmAdvSearch.submit();	
				}
			}	
		}	
	}else{
		document.FrmAdvSearch.submit();	
	}
}
function isAnyChecked(inChosenSection,inFiltersShown){
	var str = "";
	var bAnyOtherChecked = false;
	var elementName = "";
	
	for(i=0;i<document.FrmAdvSearch.elements.length-1;i++)
	{
		//if any checkbox checked which is not chkContext
		elementName = document.FrmAdvSearch.elements[i].name;
		if((elementName.substring(0,14)=="CHK_ADVSEARCH_")&&(elementName!="chkContext")&&(document.FrmAdvSearch.elements[i].checked))
		{
			bAnyOtherChecked = true;
		}		
	
	}
	return bAnyOtherChecked;

}
function trim(string)
{
	var re= /^\s|\s$/g;
	return string.replace(re,"");
}


// determines whether Netscape or Internet Explorer
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");
function keyPressed(inOption,inAction,inLocator,inAUTH){
	//k = (netscape) ? DnEvents.which : window.event.keyCode;
	k =  window.event.keyCode;
	if (k == 13) { // enter key pressed
		buildForumSearchQueryString(inOption,inAction,inLocator,inAUTH);
	}
}
//document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);

function keyNewFolderPressed(inType,inLinkToAppend){
	k =  window.event.keyCode;
	if (k == 13) { // enter key pressed
		createNewFolder(inType,inLinkToAppend);
	}
}

function createNewFolder(inType,inLinkToAppend){

	if(document.FrmMyDRL.txtNewFolderName.value==""){
		alert('Please enter a name for the new folder');
		document.FrmMyDRL.txtNewFolderName.focus();
	}else{
		var sPage = "myDRL_ManageProfile.asp?ItemName=" + document.FrmMyDRL.txtNewFolderName.value + "&Action=ADD" + "&ItemType=" + inType + inLinkToAppend;
		document.location.href = sPage ;
	}

}
function removeFolderOrDoc(inFolder,inName,inType,inLinkToAppend){



	
	var sConfirmMsg = "Are you sure you want to remove the " + inType + " \<<" + inName + "\>>";
	if(inType!="folder"){
		sConfirmMsg = sConfirmMsg + " from \<<" + inFolder + "\>>";
	}
	sConfirmMsg = sConfirmMsg + "?";
	var sConfirm = confirm(sConfirmMsg)
	
	if (sConfirm== true){
		var sPage = "myDRL_ManageProfile.asp?ItemName=" + inName + "&Action=DELETE" + "&ItemType=" + inType + "&FolderName=" + inFolder + inLinkToAppend;
		document.location.href = sPage ;   
	}
}
function closeNotesWindow(){
	var sHasItChanged = document.FrmMyNotes.hiHasChanged.value;
	if(sHasItChanged=='true'){
		sConfirmMsg = "The notes have been modified, would you like to save the changes before leaving? "
		var sConfirm = confirm(sConfirmMsg)
		if (sConfirm== true){
			document.FrmMyNotes.submit();
			window.close();
		}else{
			window.close();
		}
	}else{
		window.close();
	}
}

function fncUnderConstruction(){
	alert('Sorry, not implemented yet');
}

function populateDescription(inArray){
	var sNrOfFolders = document.FrmSaveDoc.cboListFolders.length;
	
	for(i=0;i<sNrOfFolders;i++){
	var nValue = -1;
		if((document.FrmSaveDoc.cboListFolders[i].selected)&&(document.FrmSaveDoc.cboListFolders[i].value!='none')){
			nValue = i;
			alert(document.FrmSaveDoc.cboListFolders[i].value);
		}
	}
	if(nValue!=-1){
		document.FrmSaveDoc.txtFolderDesc.value = inArray[nValue];
	}else{
		document.FrmSaveDoc.txtFolderDesc.value = "";
	}
}
function FncSaveDoc(){
	var sNrOfFolders = document.FrmSaveDoc.cboListFolders.length;
	var bThereIsValueInCbo = false;
	for(i=0;i<sNrOfFolders;i++){
		if((document.FrmSaveDoc.cboListFolders[i].selected)&&(document.FrmSaveDoc.cboListFolders[i].value!='none')){
			bThereIsValueInCbo = true;
		}
	}
	
	//document.FrmSaveDoc.txtName.value = parent.opener.FrmParentDocumentToSave.txtName.value;
	//document.FrmSaveDoc.txtpage.value = parent.opener.FrmParentDocumentToSave.txtpage.value;
	//document.FrmSaveDoc.txtContentxml.value = parent.opener.FrmParentDocumentToSave.txtContentxml.value;	
	
	document.FrmSaveDoc.txtName.value = window.opener.document.FrmParentDocumentToSave.txtName.value;
	document.FrmSaveDoc.txtDocSection.value = window.opener.document.FrmParentDocumentToSave.txtDocSection.value;
	document.FrmSaveDoc.txtContentxml.value = window.opener.document.FrmParentDocumentToSave.txtContentxml.value;

	
	var sNewFolder = document.FrmSaveDoc.txtNewFolder.value;
	if((bThereIsValueInCbo==false)&&((sNewFolder=="Folder")||(sNewFolder==""))){
		alert('Please, select existing or new folder');
	}else if((bThereIsValueInCbo==true)&&((sNewFolder!="Folder")&&(sNewFolder!=""))){
		alert('Please, select only one folder');
	}else{
		document.FrmSaveDoc.submit();
	}
}
/*function FncSaveDoc(inFolderName){
	document.FrmDocumentToSave.txtFolderName.value = inFolderName ;
	document.FrmDocumentToSave.submit();
}*/
function FncNewFolder(){
	
	var sNewFolder = document.FrmDocumentToSave.txtNewFolder.value;
	if(sNewFolder==""){
		alert('Please, enter a name for the new folder');
	}else{
		document.FrmDocumentToSave.submit();
	}
}


//--------------------------------------------------------------------------------
// TreeView functions
//---------------------------------------------------------------------------------

function ToggleDisplay(oButton, oItems) {
	if ((oItems.style.display == "") || (oItems.style.display == "none")) {
		oItems.style.display = "block";
		oButton.src = "dcpro_f_graphics/minus.gif";
	}	else {
		oItems.style.display = "none";
		oButton.src = "dcpro_f_graphics/plus.gif";
	}

	return false;

}

function HideDisplay(oItems) {

	//oItems.style.display = "none";
}

function ShowDisplay(oItems) {

	//oItems.style.display = "block";
	oItems.style.display = "none";

}
function hasMaxLength(obj,nMaxLen)
{
	bValid = true;
	if (obj.value.length > nMaxLen)
	{
		bValid=false;
		alert("Field contains " + obj.value.length + " characters.\n" + "Maximum of " + nMaxLen + " characters permitted.");
		obj.focus();
		//obj.value="";
	}
}
function fncLocationParent(inFolder,inPage,inLocator,inLinkToAppend){
	var sNewLocation = "";
	sNewLocation = "LevelOne.asp?page=" + inPage + "&Locator=" + inLocator + "&contentxsl=MyFolder.xsl&Folder=" + inFolder + inLinkToAppend;
	opener.document.location = sNewLocation;
	window.close();
}

//-------------------------------------------------------------------------------------------------
// determines whether Netscape or Internet Explorer
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");
function keyDown(){
	k = (netscape) ? DnEvents.which : window.event.keyCode;
	if (k == 13) { // enter key pressed
		CheckNoEmpty();
	}
}
//document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
		
function CheckNoEmpty(){
	if((document.frmLogin.username.value=="")||(document.frmLogin.username.value=="")){
		alert("Sorry, username and password are required");
	}else{
		document.frmLogin.submit();
	}
}

function getLockedMessage(){
	alert('Please, log in to have access to content');
}
function showIntervalBits(inState){
	if(inState==true){
		sVisibility = "visible";
		sSentence = "<font class='searchGUIFont'>From</font>";
	}else{
		sVisibility = "hidden";
		sSentence = "<font class='searchGUIFont'>Date</font>";
	}
	
	
	document.getElementById('divFrom').innerHTML = sSentence;	
	//document.getElementById('divFrom').style.visibility = sVisibility;
	document.getElementById('divTo').style.visibility = sVisibility;
	document.getElementById('divYear').style.visibility = sVisibility;

	document.FrmSearch.cboAwardYearTo.selected=false;
	document.FrmSearch.cboAwardYearTo.value="";
	
}
function setContentchkboxes(inValue){

	var nrContentChecks = document.FrmAdvSearch.checkFieldNames.length;
	
	for(i=0;i<nrContentChecks;i++){
		var auxField = 	eval("document.FrmAdvSearch." + document.FrmAdvSearch.checkFieldNames[i].value);
		auxField.checked = inValue;
	
	}


}
function SortBy(inField,inSortOrder){
	document.FrmBibliography.hiSortKey.value = inField;
	document.FrmBibliography.hiSortOrder.value = inSortOrder;
	document.FrmBibliography.submit();
}

function isValidEmail(s){
	//Email address must be of form a@b.c..in other words:
	//* there must be at least one character before the @
	//* there must be at least one character before and after the .
	//* the characters @ and . are both required
	//
	//there must be >=1 character before @, so we
	//start looking at character position 1
	//(i.e.secont character)
	//////comment this part

	var bo,ba;
	var counter=0;
	bo=false;
	ba=false;
	var slength=s.length;
	for (i=0;i<s.length-1;i++){
		if (s.charAt(i)=="@" && (i!=0)){
			counter++;
			ba=true;
		}
		if ((s.charAt(i)==".") && (s.length-1>=i+1)&&(s.length-1<=i+3)){
			bo=true;
		}	
	}
	if (bo==true && ba==true && s.length!=0){
		return true;
	}else{
		alert('That is not a valid e-mail address');	
		return false;
	}
}
