var SiteUrl = "/Insight";

function selectContainerAttributes(theForm)
{
  var selectedIndex = theForm.slContainerType.selectedIndex;
  var ContainerType = theForm.slContainerType.options[selectedIndex].value;

  theForm.hdContainerType.value = ContainerType;

  theForm.hdAction.value = "SelectContainerType";
  theForm.submit();
}

function setContentItemId(contentItemId,theForm)
{
  theForm.contentItemId.value = contentItemId;
}

function fnAddTrialsListExists()
{
	alert('The trials you have selected have been added to your Free Trials list. ');
	
}	

function fnRemoveOwner(theForm)
{
	theForm.txtAssociatedOwnerName.value = "";
	theForm.hdAssociatedOwnerId.value = "";
	theForm.submit();
}	


function fnFreeTrailExists()
{
	alert('Free Trial for this period already exists.');
}	

function fnAddMarkedListExists()
{
	alert('The items you have selected have been added to your marked list. \n Select "Marked List" within "My Profile" to view your lists.');
}	

function setSavedSearchId(searchId,theForm)
{
  theForm.savedSearchId.value =  searchId;
}

function validateLogin(Action,theForm){
	var userName=theForm.userName.value;
	var password=theForm.password.value;
	var valid = true;
	if(userName=="" || userName==null){
		if(password=="" || password==null){
			alert("Please enter Username and password")	;
			valid = false;
		}else{
			alert("Please enter Username")	;
			valid = false;
		}	
	}else if(password=="" || password==null){
			alert("Please enter password")	;
			valid = false;
	}
	if(valid == true)	buttonClicked(Action,theForm);
}

function validateSavedSearch(theForm)
{
  var searchName=theForm.searchName.value;
  var searchExp=theForm.searchExpression.value;
  
  if(searchName== "" || searchName == null)
  {
    alert("Please enter the search Name");
    return false;
  }
  if(searchExp== "" || searchExp == null)
  {
    alert("Search Expression is mandatory ");
    return false;
  }
  return true;
}

function setSavedSearchData(searchName,searchEx,maxHits,searchId,theForm)
{
  theForm.searchName.value =searchName;
  theForm.searchExpression.value =searchEx;
  theForm.maxHits.value =maxHits;
  theForm.savedSearchId.value =searchId;
}

function checkSelection(buttonId,theForm)
{
	lsSelected = false;
	for (i=0; i< theForm.rdSelectJournal.length; i++)
	{
		if (theForm.rdSelectJournal[i].checked)
		{
			lsSelected = true;
			break;
		}
	}
	if (lsSelected == false)
	{
		alert("Please search/select a Journal to subscribe.");
		return;
	}
	else
	  	buttonClicked(buttonId,theForm);
}

function buttonClicked(buttonId,theForm)
{
  theForm.hdAction.value = "button_" + buttonId;
  theForm.submit();
}

function getPublishedContainers(aThis,theForm)
{
  theForm.hdContentContainerId.value = aThis;
  theForm.hdAction.value = "link_contentContainer";
  theForm.submit();
}

function getDuplicateItems(aThis,title,contentItemTypeName,createDate,filename,theForm)
{
 // alert(aThis + ':' +title + ':' +contentItemTypeName+ ':' +createDate+ ':' +filename);
  theForm.contentItemId.value = aThis;
  theForm.title.value = title;
  theForm.filename.value = filename;
  theForm.createDate.value =createDate ;
  theForm.contentItemTypeName.value = contentItemTypeName;
  theForm.hdAction.value = "get_duplicateItems";
  theForm.submit();
}

function linkClicked(linkId,theForm)
{
  theForm.hdAction.value = "tab_" + linkId;
  theForm.submit();
}

function link(linkId,theForm)
{
  theForm.hdAction.value = "link_" + linkId;
  theForm.submit();
}


function menuClicked(menuId,theForm)
{
  if (theForm)
  {
    theForm.hdAction.value = "menu_" + menuId;
    theForm.submit();
  }
  else
    document.location.href = SiteUrl + "/menuNavigation.do?hdAction=menu_"+menuId;
}

function menuClickedDetails(menuId,theForm)
{
  if (theForm)
  {
    theForm.hdAction.value = "menu_" + menuId;
    theForm.hdMode.value = "Login";
    theForm.submit();
  }
  else
    document.location.href = SiteUrl + "/menuNavigation.do?hdAction=menu_"+menuId;	
}	

function getTree(ContainerId, ContainerName,theForm)
{
  theForm.hdAction.value = "link_getContainerTree";
  theForm.hdContainerId.value = ContainerId;
  theForm.hdContainerName.value = ContainerName;
  theForm.submit();
}

function browseTree(ContainerId)
{
  document.forms[0].hdAction.value = "link_browseContainerTree";
   document.forms[0].hdContainerId.value = ContainerId;
   document.forms[0].submit();
}

/*function browseTree(ContainerId,theForm)
{
  theForm.hdAction.value = "link_browseContainerTree";
  theForm.hdContainerId.value = ContainerId;
  theForm.submit();
}*/

function deleteFT(idx,theForm)
{
  theForm.hdDeleteIdx.value = idx * (-1);
}

function pp_setcontainer(theForm)
{
  selectedIndex = theForm.slScrollList.selectedIndex;
  theForm.hdContainerId.value = theForm.slScrollList.value;

  theForm.hdContainerName.value =
    theForm.slScrollList.options[selectedIndex].text;

  theForm.hdAction.value="frm_container_tree";
  theForm.submit();
}

function pp_setcontentitem(theForm)
{
  selectedIndex = theForm.slScrollList.selectedIndex;
  theForm.hdContentItemId.value = theForm.slScrollList.value;

  theForm.hdContentItemName.value =
    theForm.slScrollList.options[selectedIndex].text;
}

function pp_setRemoved(theForm)
{
  selectedIndex = theForm.slSelectedList.selectedIndex;
  theForm.hdRemoveContainerId.value = theForm.slSelectedList.value;
}

function pp_setRemovedItem(theForm)
{
  selectedIndex = theForm.slSelectedItemList.selectedIndex;
  theForm.hdRemoveItemId.value = theForm.slSelectedItemList.value;
}

function fnSelectCC_popup(asContext, abMulti,theForm)
{
  theForm.hdAction.value = asContext; theForm.submit();
  varlsPopUpURL= SiteUrl + "/searchContainer.do?hdAction=fwd_select_popup&hdMulti="+abMulti+"&hdContext="+asContext;
  winpops=window.open(varlsPopUpURL,"","width=750,height=300,left=200,top=200,scrollbars=yes");
}

function fnAttachContentItem_closeWindow (asReturn)
{
  lsParentURL = SiteUrl + "/createContainer.do?hdAction=PopUp_Return";
  window.opener.location.href = lsParentURL;
  if (window.opener.progressWindow)
  {
    window.opener.progressWindow.close()
  }
  window.close();
}

function fnSearchContainer_closeWindow(asReturn)
{
  lsParentURL = SiteUrl + "/createContainer.do?hdAction=PopUp_Return";
  window.opener.location.href = lsParentURL;
  if (window.opener.progressWindow)
  {
    window.opener.progressWindow.close()
  }
  window.close();
}


function move(fbox, tbox)
{
  var arrFbox = new Array();
  var arrTbox = new Array();
  var arrLookup = new Array();
  var arrLookup1 = new Array(); //Stores value for From box
  var arrLookup2 = new Array(); //Stores values for To Box
  var i;
  for (i = 0; i < tbox.options.length; i++)
  {
    arrLookup[tbox.options[i].text] = tbox.options[i].value;
    arrTbox[i] = tbox.options[i].text;
    arrLookup2[i] = tbox.options[i].value;
  }
  var fLength = 0;
  var tLength = arrTbox.length;
  for(i = 0; i < fbox.options.length; i++)
  {
    arrLookup[fbox.options[i].text] = fbox.options[i].value;

    //We come into this loop only if something is selected and the button is pressed
    if (fbox.options[i].selected && fbox.options[i].value != "")
    {
      arrTbox[tLength] = fbox.options[i].text;
      arrLookup2[tLength] = fbox.options[i].value;
      tLength++;
    }
    else
    {
      arrFbox[fLength] = fbox.options[i].text;
      arrLookup1[fLength] = fbox.options[i].value;
      fLength++;
    }
  }
  arrFbox.sort();
  arrTbox.sort();
  fbox.selectedIndex = -1;
  tbox.selectedIndex = -1;
  fbox.length = 0;
  tbox.length = 0;
  var c;
  for(c = 0; c < arrFbox.length; c++)
  {
    var no = new Option();
    no.value = arrLookup[arrFbox[c]];
    no.text =  arrFbox[c];
    fbox[c] = no;
  }
  for(c = 0; c < arrTbox.length; c++)
  {
    var no = new Option();
    no.value = arrLookup[arrTbox[c]];
    no.text = arrTbox[c];
    tbox[c] = no;
  }


}

//Function which passes the text and values to and fro from multiple choice boxes
function moveAll(fbox, tbox)
{
  var arrFbox = new Array();
  var arrTbox = new Array();
  var arrLookup = new Array();
  var arrLookup1 = new Array(); //Stores value for From box
  var arrLookup2 = new Array(); //Stores values for To Box
  var i;
  for (i = 0; i < tbox.options.length; i++)
  {
    arrLookup[tbox.options[i].text] = tbox.options[i].value;
    arrTbox[i] = tbox.options[i].text;
    arrLookup2[i] = tbox.options[i].value;
  }
  var fLength = 0;
  var tLength = arrTbox.length;
  for(i = 0; i < fbox.options.length; i++)
  {
    arrLookup[fbox.options[i].text] = fbox.options[i].value;

    //We come into this loop only if something is selected and the button is pressed
    if (fbox.options[i].value != "")
    {
      arrTbox[tLength] = fbox.options[i].text;
      arrLookup2[tLength] = fbox.options[i].value;
      tLength++;
    }
    else
    {
      arrFbox[fLength] = fbox.options[i].text;
      arrLookup1[fLength] = fbox.options[i].value;
      fLength++;
    }
  }
  arrFbox.sort();
  arrTbox.sort();
  fbox.selectedIndex = -1;
  tbox.selectedIndex = -1;
  fbox.length = 0;
  tbox.length = 0;
  var c;
  for(c = 0; c < arrFbox.length; c++)
  {
    var no = new Option();
    no.value = arrLookup[arrFbox[c]];
    no.text =  arrFbox[c];
    fbox[c] = no;
  }
  for(c = 0; c < arrTbox.length; c++)
  {
    var no = new Option();
    no.value = arrLookup[arrTbox[c]];
    no.text = arrTbox[c];
    tbox[c] = no;
  }

}

/*
   function fnSelectOwnerCC_popup()
   {
   varlsPopUpURL="/Insight/searchContainer.do?hdAction=fwd_select_popup&hdMulti=false&hdContext=button_SelectAssociatedOwner";
   winpops=window.open(varlsPopUpURL,"","width=650,height=300,left=200,top=200,scrollbars=yes");
   }

   function fnSelectEditContainer_Popup()
   {
   varlsPopUpURL="/Insight/searchContainer.do?hdAction=fwd_select_popup&hdMulti=false&hdContext=button_SelectEditContainer";
   winpops=window.open(varlsPopUpURL,"","width=650,height=300,left=200,top=200,scrollbars=yes");
   }

   function fnSelectAssocCC_popup()
   {
   varlsPopUpURL="/Insight/searchContainer.do?hdAction=fwd_select_popup&hdMulti=true&hdContext=button_SelectAssociatedCC";
   winpops=window.open(varlsPopUpURL,"","width=650,height=300,left=200,top=200,scrollbars=yes");
   }

   function fnSelectAssocCI_popup()
   {
   varlsPopUpURL="/Insight/searchContainer.do?hdAction=fwd_select_ci_popup&hdMulti=true&hdContext=button_SelectAssociatedCI";
   winpops=window.open(varlsPopUpURL,"","width=650,height=300,left=200,top=200,scrollbars=yes");
   }
 */

function moveToCombo(inputText, destination) 
{
  if(!inputText.value == '') 
  {
    flag=true;
    for(m=0;m<destination.options.length;m++) 
    {
      if(destination.options[m].text==inputText.value) 
      {
        flag=false;
        break;
      }
    }
    if(flag == true) 
    {
      var length = 0;
      length = destination.options.length;
      var newEntry = new Option();
      newEntry.value = inputText.value;
      newEntry.text  = inputText.value;
      destination[length] = newEntry;
      inputText.value='';
    } 
  }
}

function removeFromCombo(source) {
  SelectedValue = new Array();
  SelectedText = new Array();
  ExistingValue = new Array();
  ExistingText = new Array();

  var j=0,k=0;
  for(i=0;i<source.options.length;i++)
  {
    if(source.options[i].selected==true)
    {
      SelectedValue[j]=source.options[i].value;
      SelectedText[j++]=source.options[i].text;
    }
    else
    {
      ExistingValue[k]=source.options[i].value;
      ExistingText[k++]=source.options[i].text;
    }
  }
  source.options.length=ExistingValue.length;
  for(i=0;i<ExistingValue.length;i++)
  {
    source.options[i].value = ExistingValue[i];
    source.options[i].text  = ExistingText[i];
  }
}

function fnEditPromotion(PromotionId,theForm)
{
  theForm.hdAction.value = "button_EditPromotion";
  theForm.hdPromotionId.value = PromotionId;
  theForm.submit();
}

function fnSelectPromotionType(theForm)
{
  selectedIndex = theForm.slPromotionType.selectedIndex;
  if (selectedIndex == 0)
    theForm.hdValidType.value = "True";
  else
    theForm.hdValidType.value = "False";
    theForm.hdAction.value = "";
    theForm.submit();
}

function fnDone_Promotion(Action,theForm)
{
  var valid = true;
  
  if(theForm.txtPromotionName.value == "")
  {
    alert('Promotion Name is mandatory');	
    valid = false; 	
  }	
  
  else if(theForm.tdPRO_FromDate.value == "")
  {
    alert('Promotion From Date is mandatory');	
    valid = false; 	
  }	
  else if(theForm.tdPRO_ToDate.value == "")
  {
    alert('Promotion To Date is mandatory');	
    valid = false; 		
  }	
  else if(theForm.tdPRO_FromDate.value != "" && theForm.tdPRO_ToDate.value != "")
  {
    if(DateCompare(theForm.tdPRO_FromDate.value,theForm.tdPRO_ToDate.value)< 0)
    {
      alert('Promotion ToDate is less than Promotion FromDate');		
      valid = false;
    }

 }
if(theForm.hdValidType.value == "False" && !theForm.hdValidOwnerType.value == "")
{
   alert('For Non Journals, Promotion Components must be Content Items.');
   valid = false;		
}
else if(theForm.hdValidType.value == "False" && theForm.hdValidItemType.value == "")
{
   alert('For Non Journals, Promotion Components must be Content Items.');
   valid = false;		
}	
else if((theForm.hdValidType.value == "" || theForm.hdValidType.value == "True") && theForm.hdValidOwnerType.value == ""  && theForm.hdValidItemType.value == "")
{
  alert('For Journals, Promotion Components must be either Content Container of type JOURNAL or Content Items.');		
  valid = false;	
}	
else if((theForm.hdValidType.value == "True" || theForm.hdValidType.value == "")  && theForm.hdValidOwnerType.value != "" && theForm.hdValidOwnerType.value == "False" )
{
  alert('For Journals, Promotion Components must be either Content Container of type JOURNAL or Content Items.');		
  valid = false;
}	
else if(theForm.hdValidOwnerType.value == "True" && theForm.hdValidItemType.value == "True")
{
  alert('For Journals, Promotion Components must be either Content Container of type JOURNAL or Content Items.');		
  valid = false;
}  
if (valid == true) buttonClicked(Action,theForm);

}

function fnDeleteFT(Action,theForm)
{
  if(confirm('Selected Free Trial details will be lost. Do you want to continue?'))
    buttonClicked(Action,theForm);
}

function fnDeleteRC(Action,theForm)
{
  if(confirm('Selected Research Contact details will be lost. Do you want to continue?'))
    buttonClicked(Action,theForm);
}

function fnDeletePD(Action,theForm)
{
  if(confirm('Selected Publication details will be lost. Do you want to continue?'))
    buttonClicked(Action,theForm);
}


function isYear(dateString,theForm)
{
  alert('dateString --- '+dateString);
  var date1 = dateString.substring(6,10);
  alert('year(yyyy): '+date1);
  theForm.tdPublicationYear.value = date1;	
}	


function DateCompare(dateString1,dateString2)
{
  var date1  = new Date(dateString1.substring(6,10),
      dateString1.substring(3,5)-1,
      dateString1.substring(0,2)
      );

  var date2 = new Date(dateString2.substring(6,10),
      dateString2.substring(3,5)-1,
      dateString2.substring(0,2)
      );

  if (date2 < date1)
  {
    return -1;
  }
  else if (date2 > date1)
  {
    return 1;
  }
  else
  {
    return 0;
  }
}

function configureCC(ccType,theForm)
{
  theForm.hdContainerType.value = ccType;
}

function configureCI(ciType,theForm)
{
  theForm.hdContentItemType.value = ciType;
}

function fnEditBanner(BannerId,theForm)
{
  theForm.hdAction.value = "button_EditBanner";
  theForm.hdMode.value = "Edit";
  theForm.hdBannerId.value = BannerId;
  theForm.submit(); 	
}



function fnNext_Banner(Action,theForm)	
{
  var valid = true;	
   if(theForm.txtBannerName.value == "")
  {
    alert('Banner Name is mandatory');	
    valid = false; 	
  }	
  else if(theForm.tdBA_FromDate.value == "")
  {
    alert('BannerAdvertisement From Date is mandatory');	
    valid = false; 	
  }	
//  else if(theForm.tdBA_ToDate.value == "")
//  {
//    alert('BannerAdvertisement To Date is mandatory');	
//    valid = false; 		
//  }	
  else if(theForm.tdBA_FromDate.value != "" && theForm.tdBA_ToDate.value != "")
  {
    if(DateCompare(theForm.tdBA_FromDate.value,theForm.tdBA_ToDate.value)<= 0)
    {
      alert('BannerAdvertisement ToDate is less than or equal to BannerAdvertisement FromDate');		
      valid = false;
    }

  }
  if (valid == true) buttonClicked(Action,theForm);	
}

function fnDone_Banner(Action,theForm)
{
  valid = true;

  if (theForm.txtLinkURL.value == "") 
  { 
    alert("Link URL is Mandatory");
    valid = false; 
  } 
  else if (!isURL(theForm.txtLinkURL.value)) 
  {
    alert('Please enter well formed Link URL!');
    valid = false;
  }
  else if (theForm.txtGraphicLabel.value == "") 
  { 
    alert("Graphic Label is Mandatory"); 
    valid = false; 
  }
  else if (theForm.txtImageAddress.value == "") 
  { 
    alert("Image Address is Mandatory");
    valid = false; 
  }
  else if (!isURI(theForm.txtImageAddress.value)) 
  {
    alert('Please enter well formed Image Address!');
    valid = false;
  }

  if (valid == true) buttonClicked(Action,theForm);	
}

function fnCancel(Action,theForm)
{
  if(confirm('All your changes will be lost. Do you want to continue?'))
    buttonClicked(Action,theForm);


}

function fnClearDates(Action,theForm)
{
  //if(confirm('Dates selected by you will be lost. Do you want to continue?'))
  //{
  	theForm.txtSubsStartDate.value = "";
  	theForm.txtSubsEndDate.value = "";
  	theForm.txtTrialStartDate.value = "";	
  	theForm.txtTrialEndDate.value = "";
  //}	
}

function fnRemove(Action,theForm) // Bug 3005 Vijaya
{
  if(confirm('The data selected by you will be removed. Do you want to continue?'))
    buttonClicked(Action,theForm);
}	

function fnMenuClicked(menuId,theForm)
{
  if(confirm('All your changes will be lost. Do you want to continue?'))
    theForm.hdAction.value = "menu_" + menuId;
  theForm.submit();	
}	

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}


function isFloat1(s)
{   
   var i;
  var seenDecimalPoint = false;
  if (isEmpty(s))
    if (isFloat.arguments.length == 1) return defaultEmptyOK;
    else return (isFloat.arguments[1] == true);

    if (s == ".") return false;

    for (i = 0; i < s.length; i++)
    {
      // Check that current character is number.
      var c = s.charAt(i);
      if ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
      else if (!isDigit(c)) return false;
    }

    return true;
}

function fnNext_Container(Action,theForm)
{
  var valid = true;	
  if (theForm.txtSI_Price.value == "" && theForm.tdSI_FromDate.value == "" && theForm.tdSI_ToDate.value == "")
    valid = true; 
  else 
  {
    if( (theForm.tdSI_FromDate.value != "" && theForm.tdSI_ToDate.value == "")
        || (theForm.tdSI_FromDate.value == "" && theForm.tdSI_ToDate.value != "") )
    {
      alert("Please enter both From and To Dates");
      valid = false;
    }
    else if (theForm.tdSI_FromDate.value != "" && theForm.tdSI_ToDate.value != "")
    {
      if(DateCompare(theForm.tdSI_FromDate.value,theForm.tdSI_ToDate.value)<= 0)
      {
        alert('ShopItem ToDate is less than or equal to ShopItem FromDate');		
        valid = false;
      }
    }

    if (valid)
    {
      if(theForm.txtSI_Price.value == "")
      {
        alert('Price for ShopItem is mandatory');
        valid = false;
      }
      else
      {
      	 var s = theForm.txtSI_Price.value;
      	 if(!isFloat1(s))
        {
          alert('Price value entered is not correct.');
          valid = false;
        }  
      }	
      
//      else 
//      {
//        var s = theForm.txtSI_Price.value;
//        alert('s :: '+s);
//        isFloat(s);
//        //if(isFloat(s))
//        //{
//          //alert('Price value entered is not correct.');
//          //valid = false;
//        //}  
////        else
////        {
////          prec = s.substring(s.indexOf('.')+1, s.length);
////          if (prec.length > 2) 
////          {
////            alert("Please enter price upto 2 places of decimal");
////            valid = false;
////          }
////        }
//      }
    }
  }
  if (valid == true) buttonClicked(Action,theForm);
}

function fnFreeTrial(Action,theForm)
{
  var valid = true;

  if( (theForm.tdFT_FromDate.value != "" && theForm.tdFT_ToDate.value == "")
      || (theForm.tdFT_FromDate.value == "" && theForm.tdFT_ToDate.value != "") )
  {
    alert("Please enter both From and To Dates");
    valid = false;
  }
  else if(theForm.tdFT_FromDate.value != "" && theForm.tdFT_ToDate.value != "")
  {
    if(DateCompare(theForm.tdFT_FromDate.value,theForm.tdFT_ToDate.value)<= 0)
    {
      alert('FreeTrial ToDate is less than or equal to FreeTrial FromDate');		
      valid = false;
    }
  }		
  if (valid == true) buttonClicked(Action,theForm);	
}	



function isInteger (s)
{
  var i;
  if (isEmpty(s))
    if (isInteger.arguments.length == 1) return defaultEmptyOK;
    else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {
      var c = s.charAt(i);
      if (!isDigit(c)) return false;
    }

    return true;
}	


function AddToList(resultCount,theForm){

  var SelectedItemsList ='';
  var size = resultCount - 1;

  for(var i = 0; i <size ; i++){
    if(theForm.SelectContentItem(i).checked)
      SelectedItemsList = SelectedItemsList +  ', ' + theForm.SelectContentItem(i).value;
  }
  theForm.SelectedItemsList.value = SelectedItemsList;
  theForm.submit();
}

function ValidateFields(theForm)
{

  // alert(theForm.AllFields.checked);
  if(theForm.AllFields.checked)
  { 
    theForm.AllFieldsXFT.checked = false;
    theForm.JournalTitle.checked = false;
    theForm.CompanyName.checked = false;
    theForm.ReferenceNum.checked = false;
    theForm.Abstract.checked = false;
    theForm.Author.checked = false;
    theForm.Keywords.checked = false;
    theForm.ArticleTitle.checked = false;
  }
  if(theForm.AllFieldsXFT.checked)
  { 
    theForm.AllFields.checked = false;
    theForm.JournalTitle.checked = false;
    theForm.CompanyName.checked = false;
    theForm.ReferenceNum.checked = false;
    theForm.Abstract.checked = false;
    theForm.Author.checked = false;
    theForm.Keywords.checked = false;
    theForm.ArticleTitle.checked = false;
  }
}



function fnHelpSearchOptions_popup(PopUpURL)
{
  winpops=window.open(PopUpURL,"","width=500,height=250,left=200,top=200,scrollbars=no");
}


function jumpToPage(pgno,theForm)
{
  theForm.hdCurrPage.value = pgno;
  theForm.hdAction.value = "select_pageNo";
  theForm.submit();
}

function searchResearch(Action,theForm)
{
  var valid = true;
  /*if(theForm.txtProjectTitle.value == "" && theForm.txtResName.value== "")
  {
    alert('Please enter either Project Title or Researcher Name to continue');
    theForm.txtProjectTitle.focus();	
    valid = false; 
  }*/
  if (valid == true) buttonClicked(Action,theForm);		
}
function submitResearch(Action,theForm)
{
  var valid = true;
  var output = '';
  //var length=theForm.chkSelectMeth.length;
  var prjStartDate="01" + "." + theForm.slPrjStartMonth.value + "." + theForm.slPrjStartYear.value;
  var prjCompDate="01" + "." + theForm.slPrjCompMonth.value + "." + theForm.slPrjCompYear.value;
  
  var selectedIndex = theForm.slResRegSub.selectedIndex;
  var ResRegSub = theForm.slResRegSub.options[selectedIndex].value;
  
  var selectedIndex1 = theForm.slPrjStatus.selectedIndex;
  var PrjStatus = theForm.slPrjStatus.options[selectedIndex1].value;

  //  for(var i=0;i<length;i++)
  //  {
  //  	if(theForm.chkSelectMeth[i].checked)
  //  	{
  //  		output = output + ', ' + theForm.chkSelectMeth[i].value;
  //  	}
  //  	
  //  }
  // theForm.hdSelMeth.value = output;
  
  if(ResRegSub == "0")
  {
    alert('Research Register Subject is mandatory');
    theForm.slResRegSub.focus();	
    valid = false; 	
  }
  else if(theForm.txtProjectTitle.value == "")
  {
    alert('Project Title is mandatory');
    theForm.txtProjectTitle.focus();	
    valid = false; 	
  }
  else if(DateCompare(prjStartDate,prjCompDate) == -1)
  {
    alert('Project Start Date must be less than or equal to Project Completion Date');
    theForm.slPrjStartMonth.focus();	
    valid = false; 	
  }	
  else if((theForm.txtBudget.value != "") && (!isFloat(theForm.txtBudget.value)))
  {
    alert('Please enter decimal value for Budget');
    theForm.txtBudget.value = "";
    theForm.txtBudget.focus();	
    valid = false; 		
  }
  else if(theForm.taKeywords.value == "")
  {
    alert('Please enter Keywords');
    theForm.taKeywords.focus();	
    valid = false; 		
  }
  else if(PrjStatus == "0")
  {
    alert('Project Status is mandatory');
    theForm.slPrjStatus.focus();	
    valid = false; 	
  }
  //  else if(theForm.hdSelMeth.value == "") 	
  //  {
  //    alert('Please select atleast one methodology');
  //    theForm.chkSelectMeth[0].focus();	
  //    valid = false; 		
  //  }
  else if(theForm.taDescription.value == "")
  {
    alert('Description of Research Item is mandatory');
    theForm.taDescription.focus();	
    valid = false; 		
  }	
  else if(theForm.hdResConSize.value == "0")
  {
    alert('Please enter research contact details');
    theForm.txtResName.focus();	
    valid = false; 		
  }
  /*else if(theForm.hdPubDetSize.value == "0")
  {
    alert('Please enter publication details');
    theForm.txtJournalConfTitle.focus();	
    valid = false; 		
  }*/	


  if (valid == true) buttonClicked(Action,theForm);

}


function searchResearchItem(buttonId,theForm)
{
  theForm.hdAction.value = "button_" + buttonId;
  theForm.hdMode.value = "View";
  theForm.submit();
}

function addContributor(Action,theForm)
{
  var valid = true;
  
  
  if(theForm.txtResName.value == "")
	{
		alert('Researcher Name is mandatory');
		theForm.txtResName.focus();	
		valid = false; 		
	}
  /*else if (!isEmpty(theForm.txtResName.value) && !isAlphanumeric(theForm.txtResName.value))
        {
                alert("Please enter only alphanumeric values  in the Researcher Name field ");
                theForm.txtResName.focus();
   	        valid = false;
        }*/	
  else if(theForm.txtOrg.value == "")
	{
		alert('Researcher Affliation is mandatory');
		theForm.txtOrg.focus();	
		valid = false; 		
	}
  else if(theForm.txtEmail.value == "")
	{
		alert('Researcher E-mail address is mandatory');
		theForm.txtEmail.focus();	
		valid = false; 		
	}
  else if(!isEmail(theForm.txtEmail.value))
	{
		alert('Please enter E-mail address in correct format');	
		theForm.txtEmail.focus();
		valid = false; 		
	}
	
  if (valid == true) buttonClicked(Action,theForm);
  
}

function addPubDetails(Action,theForm)
{
  var valid = true;
  
  
  if(theForm.txtJournalConfTitle.value == "")
	{
		alert('Journal/Conference Title is mandatory');
		theForm.txtJournalConfTitle.focus();	
		valid = false; 		
	}
  
  else if(theForm.txtArticleTitle.value == "")
	{
		alert('Article Title is mandatory');
		theForm.txtArticleTitle.focus();	
		valid = false; 		
	}
  else if(theForm.txtVolYear.value == "")
	{
		alert('Volume/Year is mandatory');
		theForm.txtVolYear.focus();	
		valid = false; 		
	}
  else if(theForm.txtIssueConfVenue.value == "")
	{
		alert('Issue/Conference Venue is mandatory');
		theForm.txtIssueConfVenue.focus();	
		valid = false; 		
	}
  else if(theForm.txtPub.value == "")
	{
		alert('Publisher Name is mandatory');
		theForm.txtPub.focus();	
		valid = false; 		
	}
  else if(theForm.txtPubConfWebsite.value == "")
	{
		alert('Publisher/Conference Website is mandatory');
		theForm.txtPubConfWebsite.focus();	
		valid = false; 		
	}				
	
  if (valid == true) buttonClicked(Action,theForm);
  
}

function setAppContentItemId(lContentItemId, lContentItemName,theForm)
{
  theForm.hdContentItemId.value = lContentItemId;
  theForm.hdContentItemName.value = lContentItemName;
}	

function setUnappContentItemId(lContentItemId, lContentItemName,theForm)
{
  theForm.hdUnappContentItemId.value = lContentItemId;
  theForm.hdUnappContentItemName.value = lContentItemName;
}

function AppResearchItem(Action,theForm)
{
  theForm.hdItemType.value = 'APPROVED';
  buttonClicked(Action,theForm);
}

function UnappResearchItem(Action,theForm)
{
  theForm.hdItemType.value = 'UNAPPROVED';
  buttonClicked(Action,theForm);
}

function getListBySubjectId(subId, subDesc,theForm){
  theForm.hdsubjectCode.value = subId;
  theForm.hdsubjectDesc.value = subDesc;
  theForm.hdAction.value = "button_SubjectTitle";
  theForm.submit();
}

function checkLength(theForm)
{
  if (theForm.taDescription.value.length  > 5000)
  {
    var lsValue = new String(theForm.taDescription.value);
    theForm.taDescription.value = lsValue.substring(0,5000);
  }
}

function validateSearchQuick(Action,theForm)
{
  var valid = true;
  
  if(theForm.searchTerm.value == "")
	{
		alert('Please enter the term to search');
		theForm.searchTerm.focus();	
		valid = false; 		
	}

  return valid;
}

function validateSearchQuickOptions(Action,theForm)
{
  var valid = true;
  
  if(theForm.searchTerm.value == "")
	{
		alert('Please enter the term to search');
		theForm.searchTerm.focus();	
		valid = false; 		
	}
  else if(!(theForm.AllFields[0].checked || theForm.AllFieldsXFT[0].checked || 
            theForm.JournalTitle[0].checked || theForm.CompanyName[0].checked || 
            theForm.ReferenceNum[0].checked || theForm.Abstract[0].checked || 
            theForm.Author[0].checked || theForm.Keywords[0].checked ||
            theForm.ArticleTitle[0].checked))
        {
        	alert('Please select fields to search');
		valid = false;
        }
        
  return valid;
  
}

function validateSearchAdvanced(Action,theForm)
{
  var valid = true;
  
  if(theForm.searchTerm1.value == "" && theForm.searchTerm2.value == "" && theForm.searchTerm3.value == "")
	{
		alert('Please enter the term to search');
		theForm.searchTerm1.focus();	
		valid = false; 		
	}
        
 return valid;
  
}



