function selectRegion(Choice,theForm)
{
  theForm.slCurrency.options.length = 0;
  if(Choice == "1")
  {
    addToCombo1("GBP", "1", theForm.slCurrency);
  }
  if(Choice == "2")
  {
    addToCombo1("GBP", "1", theForm.slCurrency);
    addToCombo1("EUR", "2", theForm.slCurrency);
  }
  if (Choice == "3")
  {
    addToCombo1("GBP", "1", theForm.slCurrency);
    addToCombo1("EUR", "2",  theForm.slCurrency);
    addToCombo1("USD", "3",  theForm.slCurrency);
    addToCombo1("ASD", "4",  theForm.slCurrency);
  }
}

function fnSubscriberLoggedIn(theForm)
{
  theForm.txtUsername.value = "";
  theForm.txtPassword.value = "";
}	

function fnClearLoginDetails(theForm)
{

}	

function selectedCurrency(aValue,theForm)
{
  theForm.hdSelectedCurrency.value = aValue;
}

function fnSelect_Transaction(userId,transactionId,theForm)
{
    	theForm.hdUserId.value = userId;
    	theForm.txtTransactionID.value = transactionId;
	theForm.hdAction.value = "select_transaction";
	theForm.submit();
}	


function fnSelect_Subscriber(subId,aPageContext,theForm)
{
  if(aPageContext == "Reports")
  {
  	theForm.hdCID.value = subId;
        theForm.hdAction.value = "select_report";
        theForm.hdMode.value = "View";
  	
  }
  else if(aPageContext == "BatchReports")
  {
  	theForm.hdCID.value = subId;
        theForm.hdAction.value = "select_report";
        theForm.hdPageContext.value = "BatchReports";
        theForm.hdMode.value = "View";
  	
  }	
  else
  {
	  theForm.hdSubscriberId.value = subId;
	  theForm.hdAction.value = "select_subscriber";
	  theForm.hdMode.value = "View";
  }
  theForm.submit();
}

 function fnLogin(theForm)
 {      
 	if(theForm.txtUsername.value == "")
 	{
 		alert('Please enter the username ');
 		return false;
 	}	
 	else if(theForm.txtPassword.value == "")
 	{
	 	alert('Please enter the password ');
	 	return false;
 	}
 	 return true;
 }
 
function fnEmailInfo(action,theForm)
{
	var valid = true;
	if(theForm.recipientFirstname.value == "")
	{
	   alert('Please enter the recipients firstname. ');
	   valid = false;	
	}
	else if(theForm.recipientEmail.value == "")
	{
	   alert('Please enter the recipients email. ');
	   valid = false;	
	}
	else if(theForm.userFirstname.value == "")
	{
	   alert('Please enter your firstname. ');
	   valid = false;	
	}
	else if(theForm.userEmail.value == "")
	{
	   alert('Please enter your email address. ');
	   valid = false;	
	}
	if(valid == true)buttonClicked(action,theForm);
	
}	

function fnSelectChkBox(action,theFormTn) 
{
    //Options in the multiple combo are selected for submission.
    var aform = eval(theFormIn);
    var totElements = aform.elements.length;
    var i=0;
    var m=0;
    var check = false;
    for(i=0;i<totElements;i++) 
    { 
        if(aform.elements[i].type == "checkbox") 
        {
            if(aform.elements[i].checked == true)
            {
            	check = true;
            }	
            
        }
    }
    if(check == true)
    {	
    	buttonClicked(action,aForm);
    }	
    else
    {
    	alert('Please select the products you wish to trial. ');
    }	
}


function fnSelectItem(action,theForm)
{
  var isChecked = false;
  var len = theForm.chkItemIdList.length;
  if(theForm.chkSelectAll.checked)
  {
    isChecked = true;
  }	
  else if(isChecked == false)
  {
    if(len > 0)
    {
	    for(var i=0; i<len; i++)	
	    {
	      if(theForm.chkItemIdList[i].checked)
	      {
	        isChecked = true;
	
	      }		
	
	}	
   }
   else if( theForm.chkItemIdList.checked)
   {   
       isChecked = true;	
   	
   }	
   	
  }	
  if(isChecked == false)
  {
    alert('Select the content item to be deleted from your marked list.');
  }	
  else
  {
    if(confirm('Selected content item will be deleted from your marked list. Do you want to continue.'))
      buttonClicked(action,theForm);
  }

}	

function fnSelect_SubscriberId(subId,theForm)
{
  theForm.hdSubscriberId.value = subId;
  theForm.hdAction.value = "select_subscriberId";
  theForm.hdMode.value = "View";
  theForm.submit();
}

function fnDeleteList(action,theForm)
{
  if(confirm('Selected Marked List will be deleted. Do you want to continue?'))
    buttonClicked(action,theForm);

}	

function fnDetachUser_Subscriber(theForm)
{
  if(theForm.hdUserIdList.value == "")
  {
    alert('Please select the users to be detached.');
  }	
  else
  {
    theForm.hdAction.value = "button_Detach_Users";
    theForm.submit();
  }	

}

function fnDownload(theForm)
{
  theForm.hdAction.value = "DUMMY_PRINT_MARKEDLIST";
  theForm.submit();

  varlsPopUpURL= SiteUrl + "/au_MarkedLists.do?hdAction=button_download_markedList";
  winpops=window.open(varlsPopUpURL,"","width=500,height=600,left=100,top=100,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes");		


}	

function fnEmail(theForm)
{
  theForm.hdAction.value = "button_EMail";
  theForm.submit();	
}	

function fnPrinthtml(theForm)
{
  theForm.hdAction.value = "DUMMY_PRINT_MARKEDLIST";
  theForm.submit();

  varlsPopUpURL= SiteUrl + "/au_MarkedLists.do?hdAction=button_print_markedList";
  winpops=window.open(varlsPopUpURL,"","width=800,height=600,left=100,top=100,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes");	
}	

function fnAttachSubscriber_popup(theForm)
{
  theForm.hdAction.value = "DUMMY_ATTACH_SUBSCRIBER";
  theForm.submit();

  varlsPopUpURL= SiteUrl + "/au_subscriber.do?hdAction=button_attach_subscriber_popup";
  winpops=window.open(varlsPopUpURL,"","width=500,height=600,left=100,top=100,scrollbars=yes");
}


function fnDettachSubscriber_popup(theForm)
{
  if(theForm.hdUserIdList.value == "")
  {
    alert('Please select the users to be detached.');
  }	
  else
  {
    theForm.hdAction.value = "button_Detach_Subscriber";
    theForm.submit();
  }	

}

function fnAttachSubscriber_closeWindow (asReturn)
{
  lsParentURL = SiteUrl + "/au_subscriber.do?hdAction=select_subscriber_relationships";
  window.opener.location.href = lsParentURL;
  if (window.opener.progressWindow)
  {
    window.opener.progressWindow.close()
  }
  window.close();
}



function fnSelectSubscriberInfo(theForm)
{
  if (theForm.hdMode)
    theForm.hdMode.value="View";

  selectedIndex = theForm.slSubscriber.selectedIndex;
  if (selectedIndex == 0)
    theForm.hdAction.value = "select_subscriber_details";
  if (selectedIndex == 1)
    theForm.hdAction.value = "select_subscriber_subscriptions";
  if (selectedIndex == 2)
    theForm.hdAction.value = "select_subscriber_users";  
  if (selectedIndex == 3)
    theForm.hdAction.value = "select_subscriber_relationships";  
  if (selectedIndex == 4)
    theForm.hdAction.value = "select_subscriber_logons";    
  theForm.submit();
}

function fnSearchJournal(buttonId,currentChar,theForm) 
{
  theForm.hdButtonId.value = buttonId;
  theForm.hdCurrentChar.value = currentChar;
  theForm.hdAction.value = "search_journal";
  theForm.submit(); 
}

function pp_selectJournal(theForm)
{
  selectedIndex = theForm.slJournalList.selectedIndex;
  theForm.hdJournalId.value = theForm.slJournalList.value;
}

function pp_removeJournal(theForm)
{
  selectedIndex = theForm.slSelectJournalList.selectedIndex;
  theForm.hdRemoveJournalId.value = theForm.slSelectJournalList.value;	

}			

function fnUserSearch(userId,theForm)
{
  theForm.hdAction.value = "select_user";
  theForm.hdMode.value = "View";
  theForm.hdUserId.value = userId;
  theForm.submit(); 		
}

function fnMarketingView(messageId,theForm)
{
  theForm.hdAction.value = "viewMessage";
  theForm.hdmessageId.value = messageId;
  theForm.submit(); 		
}

function fnSelectSubscription(Action,theForm)
{
  theForm.hdAction.value = "select_" + Action;
  theForm.submit();	

}	

function fnMessages(buttonId,theForm)
{
  theForm.hdAction.value = "button_" + buttonId;
  theForm.submit();
}

function fnChngUsr(Action,theForm)
{
  if(fnCreateEditCheck(theForm) && fnCheckUser(theForm))
  {

    if(theForm.hdOldUsername.value != stripInitialEndingWhitespace(theForm.txtUsername.value))
    {
      theForm.hdChangeFlag.value="Y"
    }
    if(theForm.hdOldPassword.value != stripInitialEndingWhitespace(theForm.txtPassword.value))
    {
      theForm.hdChangeFlag.value="Y"
    }

    buttonClicked(Action,theForm);
  }
}

function fnView_Subscriber(subId,theForm)
{
  theForm.hdSubscriberId.value = subId;
  theForm.hdMode.value = "View";
  theForm.submit();
  fnChangeSubscriberPopup_CloseWindow();

}

function fnChangeSubscriberPopup_CloseWindow()
{
  lsParentURL = SiteUrl + "/au_subscriber.do?hdAction=select_subscriber";
  window.opener.location.href = lsParentURL;
  if (window.opener.progressWindow)
  {
    window.opener.progressWindow.close()
  }
  window.close();	

}

function fnChangeSubscriber_popup(asContext,theForm)
{
  theForm.hdAction.value = "dummy_change_subscriber";
  theForm.hdContext.value = asContext;
  theForm.submit();

  varlsPopUpURL= SiteUrl + "/au_subscriber.do?hdAction=fwd_change_subscriber_popup";
  winpops=window.open(varlsPopUpURL,"","width=500,height=600,left=100,top=100,scrollbars=yes");
} 	 




function fnSearch_Subscriber(theForm)
{
  var radLength=theForm.rdSearchType.length;
  var selectedValue = "";
  for (var i=0; i<radLength; i++) 
  {
    if (theForm.rdSearchType[i].checked) 
    {
      selectedValue = theForm.rdSearchType[i].value
    }
  }
  if(selectedValue == 1)
  {
    theForm.hdRadioValue.value = "User" ;
  }	
  else 
  {
    theForm.hdRadioValue.value = "Subscriber" ;
  } 	
  theForm.hdAction.value= "button_resetForm";
  theForm.submit();
}


function fnSearch_Advanced()
{
  theForm=document.forms[0];
  var radLength=theForm.searchOptions1.length;
  var selectedValue = "";
  
      selectedValue = theForm.searchOptions1.value
   
  if(selectedValue.equals("Exact match"))
  {
   
  		
  theForm.hdAction.value= "button_resetForm";
  theForm.submit();
  }
}	



function fnEditSavedSearch(Action,theForm)
{
  var isChecked = false;
  var radLength=theForm.rdSvdSrch.length;
  if(radLength >1)
  {	

    for(var i=0;i<radLength;i++)
    {
      if(theForm.rdSvdSrch[i].checked)
      {	
        isChecked = true;
        break;
      }
    }
  }
  else
  {
    if(theForm.rdSvdSrch.checked)
    {
      isChecked = true;
    }
  }

  if (isChecked == false) 
  {
    alert("Please select a saved search for edit")
  }
  else 
  {
    buttonClicked(Action,theForm);
  }
}	 	 


function fnDeleteSavedSearch(Action,theForm)
{
  var isChecked = false;
  var radLength=theForm.rdSvdSrch.length;
  if(radLength >1)
  {	
    for(var i=0;i<radLength;i++)
    {
      if(theForm.rdSvdSrch[i].checked)
      {	
        isChecked = true;
        break;
      }
    }
  }
  else
  {
    if(theForm.rdSvdSrch.checked)
    {
      isChecked = true;
    }
  }

  if (isChecked == false) 
  {
    alert("Please select a saved search for deleting")
  }
  else 
  {
    buttonClicked(Action,theForm);
  }
}	 	 


function fnDeleteMessages(Action,theForm)
{
  var isChecked = false;
  var chxLength=theForm.chkMessage.length;
  if(chxLength >1)
  {	
    for(var i=0;i<chxLength;i++)
    {
      if(theForm.chkMessage[i].checked)
      {	
        isChecked = true;
        break;
      }
    }
  }
  else
  {
    if(theForm.chkMessage.checked)
    {
      isChecked = true;
    }
  }

  if (isChecked == false) 
  {
    alert("Please select a message for deleting")
  }
  else 
  {
    buttonClicked(Action,theForm);
  }
}	 	 

function fnAttachUser_popup(theForm)
{
  theForm.hdAction.value = "DUMMY_ATTACH_USER";
  theForm.submit();

  varlsPopUpURL= SiteUrl + "/au_viewUser.do?hdAction=fwd_attach_user_popup";
  winpops=window.open(varlsPopUpURL,"","width=500,height=600,left=100,top=100,scrollbars=yes");
}


function fnCreateSelectTOCPopup(theForm)
{
  theForm.hdAction.value = "button_Save_Data";
  theForm.submit();
   
  varlsPopUpURL= SiteUrl + "/au_viewUserTOC.do?hdAction=fwd_toc_alert_popup&hdContext=button_CreateUser";
  winpops=window.open(varlsPopUpURL,"","width=650,height=300,left=200,top=200,scrollbars=yes");
}

function fnSelectTOCPopup(theForm)
{
  theForm.hdAction.value = "DUMMY_TOC_ALERT";
  theForm.submit();

  varlsPopUpURL= SiteUrl + "/au_viewUserTOC.do?hdAction=fwd_toc_alert_popup&hdContext=button_TOCAlert";
  winpops=window.open(varlsPopUpURL,"","width=650,height=300,left=200,top=200,scrollbars=yes");
}

function fnSelectJournal_closeWindow(asReturn)
{
  lsParentURL = SiteUrl + "/au_viewUserTOC.do?hdAction=PopUp_Return";
  window.opener.location.href = lsParentURL;
  if (window.opener.progressWindow)
  {
    window.opener.progressWindow.close()
  }
  window.close();
}

function fnAttachUser_closeWindow(asReturn)
{
  lsParentURL = SiteUrl + "/au_subscriber.do?hdAction=select_subscriber_users";
  window.opener.location.href = lsParentURL;
  if (window.opener.progressWindow)
  {
    window.opener.progressWindow.close()
  }
  window.close();
}

function fnRegisterUser(theForm)
{
  var valid = true;
  var password = "";

  if(theForm.slTitle.value == 0)
  {
    alert('Title is mandatory');
    theForm.slTitle.focus();	
    valid = false; 	
  }	
  else if(theForm.txtFirstName.value == "")
  {
    alert('User First Name is mandatory');
    theForm.txtFirstName.focus();	
    valid = false; 		
  }

  // Code commented to fix UAT Bug # 1071

  /*else if (!isEmpty(theForm.txtFirstName.value) && !isAlphanumeric(theForm.txtFirstName.value))
    {
    alert("Please enter only alphanumeric values  in the FirstName field ");
    theForm.txtFirstName.focus();
    valid = false;
    }*/
  else if(theForm.txtLastName.value == "")
  {
    alert('User Last Name is mandatory');
    theForm.txtLastName.focus();	
    valid = false; 		
  }

  /*

     else if (!isEmpty(theForm.txtLastName.value) && !isAlphanumeric(theForm.txtLastName.value))
     {
     alert("Please enter only alphanumeric values  in the LastName field ");
     theForm.txtLastName.focus();
     valid = false;
     }*/

  else if(theForm.txtJobTitle.value == "")
  {
    alert('User Job Title is mandatory');	
    theForm.txtJobTitle.focus();
    valid = false; 		
  }

  else if(theForm.slIndustry.value == 0)
  {
    alert('User Industry is mandatory');
    theForm.slIndustry.focus();	
    valid = false; 		
  }
  else if(theForm.txtOrganisation.value == "")
  {
    alert('User Organisation is mandatory');	
    theForm.txtOrganisation.focus();
    valid = false; 		
  }
  else if (theForm.slCountry.value=="0")
  {
    alert("Country is mandatory");
    theForm.slCountry.focus();
    valid = false;
  }


  /*  Commented for UAT Bug 408
      else if (!isEmpty(theForm.txtOrganisation.value) && !isAlphanumeric(theForm.txtOrganisation.value))
      {
      alert("Please enter only alphanumeric values  in the Organisation field ");
      theForm.txtOrganisation.focus();
      valid = false;
      }
      else if (!isEmpty(theForm.txtDepartment.value) && !checkAddress(theForm.txtDepartment.value))
      {
      alert("Please enter only alphanumeric values  in the Department field ");
      theForm.txtDepartment.focus();
      valid = false;
      }
      else if (!isEmpty(theForm.txtAddressLine1.value) && !checkAddress(theForm.txtAddressLine1.value))
      {
      alert("Invalid characters in the AddressLine1 field ");
      theForm.txtAddressLine1.focus();
      valid = false;
      }
      else if (!isEmpty(theForm.txtAddressLine2.value) && !checkAddress(theForm.txtAddressLine2.value))
      {
      alert("Invalid characters in the AddressLine2 field ");
      theForm.txtAddressLine2.focus();
      valid = false;
      }
      else if (!isEmpty(theForm.txtCityTown.value) && !checkAddress(theForm.txtCityTown.value))
      {
      alert("Invalid characters in the City/Town field ");
      theForm.txtCityTown.focus();
      valid = false;
      }
   */
  else if (!isEmpty(theForm.txtPostCode.value) && !isPostCode(theForm.txtPostCode.value))
  {
    alert("Please enter only alphanumeric values  in the Post Code field ");
    theForm.txtPostCode.focus();
    valid = false;
  }
  else if(theForm.txteMail.value == "")
  {
    alert('User Email address is mandatory');	
    theForm.txteMail.focus();
    valid = false; 		
  }
  else if(!isEmail(theForm.txteMail.value))
  {
    alert('Please enter Email address in correct format');	
    theForm.txteMail.focus();
    valid = false; 		
  }
  else if(theForm.txtConfirmeMail.value == "")
  {
    alert('Confirm email address is mandatory');	
    theForm.txtConfirmeMail.focus();
    valid = false; 		
  }
  else if(!isEmail(theForm.txtConfirmeMail.value))
  {
    alert('Please enter Email address in correct format');	
    theForm.txtConfirmeMail.focus();
    valid = false; 		
  }
  else if (theForm.txteMail.value != theForm.txtConfirmeMail.value)
  {
    alert('Email address and confirm email address must match. Please enter again');
    theForm.txteMail.value="";
    theForm.txtConfirmeMail.value="";
    theForm.txteMail.focus();
    valid  = false;
  }
  /*
     else if (!isEmpty(theForm.txtTelephone.value) && !isHavingAlphabet1(theForm.txtTelephone.value))
     {
     alert("Invalid characters in the Telephone field");
     theForm.txtTelephone.focus();
     valid = false;
     }
     else if (!isEmpty(theForm.txtFax.value) && !isHavingAlphabet1(theForm.txtFax.value))
     {
     alert("Invalid characters in the Fax field ");
     theForm.txtFax.focus();
     valid = false;
     }
   */
  else if(theForm.slInterestArea.value == 0)
  {
    alert('User Area of interest is mandatory');	
    theForm.slInterestArea.focus();
    valid = false; 		
  }
  else if(theForm.slHowFindUs.value == 0)
  {
    alert('How did you find us field is mandatory');	
    theForm.slHowFindUs.focus();
    valid = false; 		
  }
  else if(theForm.txtUsername.value == "")
  {
    alert('Username is mandatory');	
    theForm.txtUsername.focus();
    valid = false; 		
  }
  else if(theForm.txtPassword.value == "")
  {
    alert('User Password is mandatory');	
    theForm.txtPassword.focus();
    valid = false; 		
  }
  else if(theForm.txtPassword.value != "")
  {
    password = theForm.txtPassword.value;
    if(password.length < 6)
    {
      alert('Password should be minimum of 6 Characters');
      valid = false;
    }

  }
  if(valid)
  {
    if(theForm.txtConfirmPassword.value == "")
    {
      alert('Confirm Password is mandatory');	
      theForm.txtConfirmPassword.focus();
      valid = false; 		
    }
    else if (theForm.txtPassword.value != theForm.txtConfirmPassword.value)
    {
      alert('Password and Confirm Password must match. Please enter again');
      theForm.txtPassword.value="";
      theForm.txtConfirmPassword.value="";
      theForm.txtPassword.focus();
      valid  = false;
    }
  }	
  //if (valid == true) buttonClicked(Action,theForm);
  if(valid == false) return false;
  else return true;
}

//function fnUserSubscriber_search(Action,theForm)
//{
//	var valid = true;
//  	if ((theForm.elements[0].checked == false)  && (theForm.elements[1].checked == false))
//  	{
//  		alert('Please select either subscriber or user for search');
//		valid = false;
//	}
//	else if ((theForm.txtCID.value == "") &&  
//  	    (theForm.txtEmeraldId.value == "") &&
//  	    (theForm.txtInstitutionName.value == "") &&
//  	    (theForm.txtFirstName.value == "") &&
//  	    (theForm.txtLastName.value == "") &&
//  	    (theForm.txtUsername .value == "") &&
//  	    (theForm.txtEmailAddress.value == "")) 
//  	{
//  		alert('Please enter value in atleast one field for search');
//  		theForm.txtCID.focus();
//  		valid = false;
//  	}
//  	if (valid == true) buttonClicked(Action,theForm);
//}

function fnAddAthensId(theForm)
{
  if(fnCheckAthensId(theForm))
  {
    var value = theForm.txtAthensLogins.value;
    value = "Athens Id:" + value;
    var lslabel = value;
    moveTextToCombo(value, lslabel, theForm.slAddedLogins);

    theForm.txtAthensLogins.value = '';
  }
}

function fnAddUser_MrktSubsciber(theForm)
{
  var value = theForm.txtAthensLogins.value;
  value = "Athens Id:" + value;
  var lslabel = value;
  moveTextToCombo(value, lslabel, theForm.slAddedLogins);
}	

function fnCheckAthensId(theForm)
{
  if (isEmpty(theForm.txtAthensLogins.value))
  {
    alert("Please enter some value for Athens Login to Add");
    theForm.txtAthensLogins.focus();
    return false;
  }
  /*if (!isEmpty(theForm.txtAthensLogins.value) && !isAlphanumeric(theForm.txtAthensLogins.value))
  {
    alert("Please enter only alphanumeric values  in the Athens Id field ");
    theForm.txtAthensLogins.focus();
    return false;
  }*/
  return true;
}

function fnAddShibbolethId(theForm)
{
  if(fnCheckShibbolethId(theForm))
  {
    var value = theForm.txtShibbolethLogins.value;
    value = "Shibboleth Id:" + value;
    var lslabel = value;
    moveTextToCombo(value, lslabel, theForm.slAddedLogins);

    theForm.txtShibbolethLogins.value = '';
  }
}

function fnCheckShibbolethId(theForm)
{
  if (isEmpty(theForm.txtShibbolethLogins.value))
  {
    alert("Please enter some value for Shibboleth Login to Add");
    theForm.txtShibbolethLogins.focus();
    return false;
  }
  /*if (!isEmpty(theForm.txtShibbolethLogins.value) && !isAlphanumeric(theForm.txtShibbolethLogins.value))
  {
    alert("Please enter only alphanumeric values  in the Shibboleth Id field ");
    theForm.txtShibbolethLogins.focus();
    return false;
  }*/
  return true;
}

function moveTextToCombo(inputValue, inputLabel, destination) 
{
  if(!inputLabel == '') 
  {
    flag=true;
    for(m=0;m<destination.options.length;m++) 
    {
      if(destination.options[m].value == inputValue) 
      {
        flag=false;
        break;
      }
    }
    if(flag == true) 
    {
      var length = 0;
      length = destination.options.length;
      var newEntry = new Option();
      newEntry.value = inputValue;
      newEntry.text  = inputLabel;
      destination[length] = newEntry;
    } 
  }
}

function fnViewSubscription(contractId,theForm)
{
  theForm.hdAction.value = "link_subscription_details";
  theForm.hdMode.value = "View";
  theForm.hdContractId.value = contractId;
  theForm.submit(); 		
}	

function fnEdit_Subscription(theForm)
{
  theForm.hdAction.value = "button_Edit";
  theForm.hdMode.value = "Edit";
  theForm.submit(); 
}	

function fnDeleteShibolethId(Action,theForm)
{
  if(confirm('Selected Shiboleth Id will be lost. Do you want to continue?'))
    buttonClicked(Action,theForm);	
}

function fnDeleteAthensId(Action,theForm)
{
  if(confirm('Selected Athens Id will be lost. Do you want to continue?'))
    buttonClicked(Action,theForm);	
}	


function fnDeleteIPRange(Action,theForm)
{
  if(confirm('Selected IP Range details will be lost. Do you want to continue?'))
    buttonClicked(Action,theForm);
}

function fnDeleteRefURL(Action,theForm)
{
  if(confirm('Selected Referring URL details will be lost. Do you want to continue?'))
    buttonClicked(Action,theForm);
}

function fnDeleteUser(Action,theForm)
{
  if(confirm('Selected Username and Password will be lost. Do you want to continue?'))
    buttonClicked(Action,theForm);
}

function fnEditSubscriber(Action,theForm)
{

  var valid = true;
  setShibbolethMultiple(theForm);
  setAthensMultiple(theForm);
  //setMultiple(theForm);
  if (isEmpty(theForm.txtName.value))
  {
    theForm.txtName.focus();
    alert('Name is mandatory');
    theForm.txtName.focus();
    valid = false;
  }

  /*
     else if (!isEmpty(theForm.txtName.value) && !isAlphanumeric(theForm.txtName.value))
     {
     alert("Please enter only alphanumeric values  in the Name field ");
     theForm.txtName.focus();
     valid = false;
     }*/
  else if (isEmpty(theForm.txtAddressLine1.value))
  {
    alert("Address Line1 is mandatory");
    theForm.txtAddressLine1.focus();
    valid = false;
  }
  else if (!isEmpty(theForm.txtAddressLine1.value) && !checkAddress(theForm.txtAddressLine1.value))
  {
    alert("Invalid characters in the AddressLine1 field ");
    theForm.txtAddressLine1.focus();
    valid = false;
  }
  else if (!isEmpty(theForm.txtAddressLine2.value) && !checkAddress(theForm.txtAddressLine2.value))
  {
    alert("Invalid characters in the AddressLine2 field ");
    theForm.txtAddressLine2.focus();
    valid = false;
  }
  else if (isEmpty(theForm.txtTown.value))
  {
    alert("Town is mandatory");
    theForm.txtTown.focus();
    valid = false;
  }
  else if (!isEmpty(theForm.txtTown.value) && !checkAddress(theForm.txtTown.value))
  {
    alert("Invalid characters in the Town field ");
    theForm.txtTown.focus();
    valid = false;
  }
  else if (!isEmpty(theForm.txtState.value) && !checkAddress(theForm.txtState.value))
  {
    alert("Invalid characters in the State field ");
    theForm.txtState.focus();
    valid = false;
  }
  else if (theForm.slCountry.value=="0")
  {
    alert("Country is mandatory");
    theForm.slCountry.focus();
    valid = false;
  }
  /*else if (isEmpty(theForm.txtPostalCode.value))
    {
    alert("Post Code is mandatory");
    theForm.txtPostalCode.focus();
    valid = false;
    }*/
  else if (!isEmpty(theForm.txtPostalCode.value) && !isPostCode(theForm.txtPostalCode.value))
  {
    alert("Please enter only alphanumeric values  in the PostalCode field ");
    theForm.txtPostalCode.focus();
    valid = false;
  }
  else if (isEmpty(theForm.txtTelephone.value))
  {
    alert("Telephone is mandatory");
    theForm.txtTelephone.focus();
    valid = false;
  }
  /*
     else if (!isEmpty(theForm.txtTelephone.value) && !isHavingAlphabet1(theForm.txtTelephone.value))
     {
     alert("Invalid characters in the Telephone field.");
     theForm.txtTelephone.focus();
     valid = false;
     }
     else if (!isEmpty(theForm.txtFax.value) && !isHavingAlphabet1(theForm.txtFax.value))
     {
     alert("Invalid characters in the Fax field. ");
     theForm.txtFax.focus();
     valid = false;
     }
   */
  else if (isEmpty(theForm.txtEmail.value))
  {
    alert("Email is mandatory");
    theForm.txtEmail.focus();
    valid = false;
  }
  else if (!isEmpty(theForm.txtEmail.value) && !isEmail(theForm.txtEmail.value))
  {
    alert("Please enter email in correct format");
    theForm.txtEmail.focus();
    valid = false;
  }
  //	  else if (!isEmpty(theForm.txtCustIcon.value) && !isAlphanumeric(theForm.txtCustIcon.value))
  //	  {
  //	    alert("Please enter only alphanumeric values  in the Customer Icon field");
  //	    theForm.txtCustIcon.focus();
  //	   	valid = false;
  //	  }
  else if (!isEmpty(theForm.txtDocDeliveryCredits.value) && !isFloat1(theForm.txtDocDeliveryCredits.value))
  {
    alert("Invalid Credits entered ");
    theForm.txtDocDeliveryCredits.focus();
    valid = false;
  }
  else if (!isEmpty(theForm.txtMarketSubscredit.value) && !isFloat1(theForm.txtMarketSubscredit.value))
  {
    alert("Invalid Credits entered ");
    theForm.txtMarketSubscredit.focus();
    valid = false;
  }
  /*else if( theForm.txtIPStartRange1.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPStartRange1.value)))
    {
    alert('Start IP Range must be numeric');
    valid = false;	
    }
    else if( theForm.txtIPStartRange1.value != "" && theForm.txtIPStartRange1.value > 255)
    {

    alert('Start IP Range must be less than 255');
    valid = false;	
    }
    else if( theForm.txtIPStartRange2.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPStartRange2.value)))
    {
    alert('Start IP Range must be numeric');
    valid = false;	
    }
    else if( theForm.txtIPStartRange2.value != "" && theForm.txtIPStartRange2.value > 255)
    {
    alert('Start IP Range must be less than 255');
    valid = false;	
    }
    else if( theForm.txtIPStartRange3.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPStartRange3.value)))
    {
    alert('Start IP Range must be numeric');
    valid = false;	
    }
    else if( theForm.txtIPStartRange3.value != "" && theForm.txtIPStartRange3.value > 255)
    {
    alert('Start IP Range must be less than 255');
    valid = false;	
    }
    else if( theForm.txtIPStartRange4.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPStartRange4.value)))
    {
    alert('Start IP Range must be numeric');
    valid = false;	
    }
    else if( theForm.txtIPStartRange4.value != "" && theForm.txtIPStartRange4.value > 255)
    {
    alert('Start IP Range must be less than 255');
    valid = false;	
    }
    else if( theForm.txtIPLastRange1.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPLastRange1.value)))
    {
    alert('Last IP Range must be numeric');
    valid = false;	
    }
    else if( theForm.txtIPLastRange1.value != "" && theForm.txtIPLastRange1.value > 255)
    {
    alert('Last IP Range must be less than 255');
    valid = false;	
    }
    else if( theForm.txtIPLastRange2.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPLastRange2.value)))
    {
    alert('Last IP Range must be numeric');
    valid = false;	
    }
    else if( theForm.txtIPLastRange2.value != "" && theForm.txtIPLastRange2.value > 255)
    {
    alert('Last IP Range must be less than 255');
    valid = false;	
    }
    else if( theForm.txtIPLastRange3.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPLastRange3.value)))
    {
    alert('Last IP Range must be numeric');
    valid = false;	
    }
    else if( theForm.txtIPLastRange3.value != "" && theForm.txtIPLastRange3.value > 255)
    {
    alert('Last IP Range must be less than 255');
    valid = false;	
    }
    else if( theForm.txtIPLastRange4.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPLastRange4.value)))
  {
    alert('Last IP Range must be numeric');
    valid = false;	
  }
  else if( theForm.txtIPLastRange4.value != "" && theForm.txtIPLastRange4.value > 255)
  {
    alert('Last IP Range must be less than 255');
    valid = false;	
  }*/

  if(valid == true)
  {
    buttonClicked(Action,theForm);	
  }	
}

function fnDone_Subscriber1(theForm)
{
  setShibbolethMultiple(theForm);
  setAthensMultiple(theForm);
  //setMultiple(theForm);
  theForm.hdAction.value = "button_Done";
  //theForm.submit();	
}	

function fnEdit2Check(theForm)
{
  if (!isEmpty(theForm.txtDocDeliveryCredits.value) && !isFloat1(theForm.txtDocDeliveryCredits.value))
  {
    alert("Invalid Credits entered ");
    theForm.txtDocDeliveryCredits.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtMarketSubscredit.value) && !isFloat1(theForm.txtMarketSubscredit.value))
  {
    alert("Invalid Credits entered ");
    theForm.txtMarketSubscredit.focus();
    return false;
  }
  else
  {
    return true;
  }
}

function fnNext_MarketSubscriber(theForm)
{

  if(fnNextPG1Check(theForm))
  {

    setMultiple(theForm);
    theForm.hdAction.value = "button_PG1_NEXT";
    theForm.submit(); 
  }
}

function fnNextPG1Check(theForm)
{

  if (isEmpty(theForm.txtName.value))
  {
    theForm.txtName.focus();
    alert('Name is mandatory');
    theForm.txtName.focus();
    return false;
  }
  /* Commented for UAT Bug 399
     if (!isEmpty(theForm.txtName.value) && isHavingInteger(theForm.txtName.value))
     {
     alert("Integer values not allowed in the Name field ");
     theForm.txtName.focus();
     return false;
     }
   */
  if (isEmpty(theForm.txtAddressLine1.value))
  {
    alert("Address Line1 is mandatory");
    theForm.txtAddressLine1.focus();
    return false;
  }
  if (!isEmpty(theForm.txtAddressLine1.value) && !checkAddress(theForm.txtAddressLine1.value))
  {
    alert("Invalid characters in the AddressLine1 field ");
    theForm.txtAddressLine1.focus();
    return false;
  }
  if (!isEmpty(theForm.txtAddressLine2.value) && !checkAddress(theForm.txtAddressLine2.value))
  {
    alert("Invalid characters in the AddressLine2 field ");
    theForm.txtAddressLine2.focus();
    return false;
  }
  if (isEmpty(theForm.txtTown.value))
  {
    alert("Town is mandatory");
    theForm.txtTown.focus();
    return false;
  }
  if (!isEmpty(theForm.txtTown.value) && !checkAddress(theForm.txtTown.value))
  {
    alert("Invalid characters in the Town field ");
    theForm.txtTown.focus();
    return false;
  }
  if (!isEmpty(theForm.txtState.value) && !checkAddress(theForm.txtState.value))
  {
    alert("Invalid characters in the State field ");
    theForm.txtState.focus();
    return false;
  }
  if (theForm.slCountry.value=="0")
  {
    alert("Country is mandatory");
    theForm.slCountry.focus();
    return false;
  }
  //	  if (isEmpty(theForm.txtPostalCode.value))
  //	  {
  //	    alert("Post Code is mandatory");
  //	    theForm.txtPostalCode.focus();
  //	   	return false;
  //	  }
  if (!isEmpty(theForm.txtPostalCode.value) && !isPostCode(theForm.txtPostalCode.value))
  {
    alert("Please enter only alphanumeric values  in the PostalCode field ");
    theForm.txtPostalCode.focus();
    return false;
  }
  /* Commented for UAT Bug 399
     if (isEmpty(theForm.txtTelephone.value))
     {
     alert("Telephone is mandatory");
     theForm.txtTelephone.focus();
     return false;
     }
     if (!isEmpty(theForm.txtTelephone.value) && !isHavingAlphabet1(theForm.txtTelephone.value))
     {
     alert("Invalid characters in the Telephone field.");
     theForm.txtTelephone.focus();
     return false;
     }
     if (!isEmpty(theForm.txtFax.value) && !isHavingAlphabet1(theForm.txtFax.value))
     {
     alert("Invalid characters in the Fax field. ");
     theForm.txtFax.focus();
     return false;
     }
   */
  /* Commented for UAT Bug 399
     if (isEmpty(theForm.txtEmail.value))
     {
     alert("Email is mandatory");
     theForm.txtEmail.focus();
     return false;
     }
   */
  if (!isEmpty(theForm.txtEmail.value) && !isEmail(theForm.txtEmail.value))
  {
    alert("Please enter email in correct format");
    theForm.txtEmail.focus();
    return false;
  }
  if (!isEmpty(theForm.txtCustIcon.value) && !isAlphanumeric(theForm.txtCustIcon.value))
  {
    alert("Please enter only alphanumeric values  in the Customer Icon field");
    theForm.txtCustIcon.focus();
    return false;
  }

  return true;
}

function fnNext_MarketSubscriber2(Action,theForm)
{
  if(fnNextPG2Check(theForm))
  {       
    selectMultipleUsers(theForm);
    buttonClicked(Action,theForm);
  }
}	

function fnNextPG2Check(theForm)
{
  if (!isEmpty(theForm.txtCredits.value) && !isFloat1(theForm.txtCredits.value))
  {
    alert("Invalid Credits entered ");
    theForm.txtCredits.focus();
    return false;
  }

  else
  {
    return true;
  }
}


function fnCheckAll(theForm)
{
  if(theForm.chkTickAll.checked)
  {
    theForm.chkPref1.checked = "true";
    theForm.chkPref2.checked = "true";
    theForm.chkPref3.checked = "true";
  }
}

function fnSubsAthensId(theForm)
{
  theForm.hdAction.value = "button_Add_Athens_Id";
  theForm.submit();
}

function fnSubsShibolethId(theForm)
{
  theForm.hdAction.value = "button_Add_Shiboleth_Id";
  theForm.submit();
}	

function fnAddSubsIPRange(theForm)
{
  var valid = true;
  if( theForm.txtIPStart1.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPStart1.value)))
  {
    alert('Start IP Range must be numeric');
    valid = false;	
  }
  else if( theForm.txtIPStart1.value != "" && theForm.txtIPStart1.value > 255)
  {

    alert('Start IP Range must be less than 255');
    valid = false;	
  }
  else if( theForm.txtIPStart2.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPStart2.value)))
  {
    alert('Start IP Range must be numeric');
    valid = false;	
  }
  else if( theForm.txtIPStart2.value != "" && theForm.txtIPStart2.value > 255)
  {
    alert('Start IP Range must be less than 255');
    valid = false;	
  }
  else if( theForm.txtIPStart3.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPStart3.value)))
  {
    alert('Start IP Range must be numeric');
    valid = false;	
  }
  else if( theForm.txtIPStart3.value != "" && theForm.txtIPStart3.value > 255)
  {
    alert('Start IP Range must be less than 255');
    valid = false;	
  }
  else if( theForm.txtIPStart4.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPStart4.value)))
  {
    alert('Start IP Range must be numeric');
    valid = false;	
  }
  else if( theForm.txtIPStart4.value != "" && theForm.txtIPStart4.value > 255)
  {
    alert('Start IP Range must be less than 255');
    valid = false;	
  }
  else if( theForm.txtIPLast1.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPLast1.value)))
  {
    alert('Last IP Range must be numeric');
    valid = false;	
  }
  else if( theForm.txtIPLast1.value != "" && theForm.txtIPLast1.value > 255)
  {
    alert('Last IP Range must be less than 255');
    valid = false;	
  }
  else if( theForm.txtIPLast2.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPLast2.value)))
  {
    alert('Last IP Range must be numeric');
    valid = false;	
  }
  else if( theForm.txtIPLast2.value != "" && theForm.txtIPLast2.value > 255)
  {
    alert('Last IP Range must be less than 255');
    valid = false;	
  }
  else if( theForm.txtIPLast3.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPLast3.value)))
  {
    alert('Last IP Range must be numeric');
    valid = false;	
  }
  else if( theForm.txtIPLast3.value != "" && theForm.txtIPLast3.value > 255)
  {
    alert('Last IP Range must be less than 255');
    valid = false;	
  }
  else if( theForm.txtIPLast4.value != "" && !isHavingInteger1(stripInitialAndFinalWhitespace(theForm.txtIPLast4.value)))
  {
    alert('Last IP Range must be numeric');
    valid = false;	
  }
  else if( theForm.txtIPLast4.value != "" && theForm.txtIPLast4.value > 255)
  {
    alert('Last IP Range must be less than 255');
    valid = false;	
  }
  if(valid == true)
  {
    theForm.hdAction.value = "button_Add_IP_Range";
    theForm.submit();
  }	
}	


function fnAddIPRange(theForm)
{
  if(fnCheckIPRange(theForm))
  {
    theForm.hdAction.value = "button_Add_IP_Range";
    theForm.submit();
  }

}	

function fnCheckIPRange(theForm)
{
  if (!isEmpty(theForm.txtIPStart1.value) && !isValidIPAddress(theForm.txtIPStart1.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIPStart1.focus();
    return false;
  }
  if (!isEmpty(theForm.txtIPStart2.value) && !isValidIPAddress(theForm.txtIPStart2.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIPStart2.focus();
    return false;
  }
  if (!isEmpty(theForm.txtIPStart3.value) && !isValidIPAddress(theForm.txtIPStart3.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIPStart3.focus();
    return false;
  }
  if (!isEmpty(theForm.txtIPStart4.value) && !isValidIPAddress(theForm.txtIPStart4.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIPStart4.focus();
    return false;
  }
  if (!isEmpty(theForm.txtIPLast1.value) && !isValidIPAddress(theForm.txtIPLast1.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIPLast1.focus();
    return false;
  }
  if (!isEmpty(theForm.txtIPLast2.value) && !isValidIPAddress(theForm.txtIPLast2.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIPLast2.focus();
    return false;
  }
  if (!isEmpty(theForm.txtIPLast3.value) && !isValidIPAddress(theForm.txtIPLast3.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIPLast3.focus();
    return false;
  }
  if (!isEmpty(theForm.txtIPLast4.value) && !isValidIPAddress(theForm.txtIPLast4.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIPLast4.focus();
    return false;
  }
  if ((theForm.txtIPStart1.value == "") ||
      (theForm.txtIPStart2.value == "") ||
      (theForm.txtIPStart3.value == "") ||
      (theForm.txtIPStart4.value == "") ||
      (theForm.txtIPLast1.value == "")  ||
      (theForm.txtIPLast2.value == "")  ||
      (theForm.txtIPLast3.value == "")	||
      (theForm.txtIPLast4.value == ""))
  {
    alert("Please complete IP start Range and IP Last Range columns");
    theForm.txtIPStart1.focus();
    return false;
  }
  var startRange = theForm.txtIPStart1.value + theForm.txtIPStart2.value + theForm.txtIPStart3.value + theForm.txtIPStart4.value;
  var lastRange = theForm.txtIPLast1.value + theForm.txtIPLast2.value + theForm.txtIPLast3.value + theForm.txtIPLast4.value;
  if(startRange > lastRange)
  {
    alert("IP Last Range has to be greater than the IP Start Range")
      theForm.txtIPStart1.focus();
    return false;
  }

  return true;
}

//function fnAddRefUrl(theForm)
//{
//	var valid = true;
//	if(theForm.txtRefURL.value == " ")
//	{
//	  	alert('Please complete the Referring URL details');
//	  	valid = false;
//	}	
//	else
//	{
//		valid = true;
//	}
//	if (valid == true)
//	{
//		
//		theForm.hdAction.value = "button_Add_Ref_URL";
//		theForm.submit();
//	}	
//}	



function fnAddRefUrl(theForm)
{
  if(fnCheckUrl(theForm))
  {
    theForm.hdAction.value = "button_Add_Ref_URL";
    theForm.submit();
  }

}	

function fnCheckUrl(theForm)
{

  if(isEmpty(theForm.txtRefURL.value))
  {
    alert('Please complete the Referring URL details');
    return false;
  }	
  else
  {
    return true;
  }

}


function fnAddUser(theForm)
{
  //var valid = true;

  if(fnCheckUser(theForm))
  { 
    theForm.hdAction.value = "button_AddUser";
    theForm.submit();
  }

}	

function fnCheckUser(theForm)
{
  var password = theForm.txtPassword.value;

  if (isEmpty(theForm.txtUsername.value))
  {
    alert("Username is mandatory");
    theForm.txtUsername.focus();
    return false;
  }
  /*if (!isEmpty(theForm.txtUsername.value) && !isAlphanumeric(theForm.txtUsername.value))
  {
    alert("Please enter only alphanumeric values  in the Username field ");
    theForm.txtUsername.focus();
    return false;
  }*/
  if (isEmpty(theForm.txtPassword.value))
  {
    alert("Password is mandatory");
    theForm.txtPassword.focus();
    return false;
  }
  /*
     if (!isEmpty(theForm.txtPassword.value) && !isAlphanumeric(theForm.txtPassword.value))
     {
     alert("Please enter only alphanumeric values  in the Password field ");
     theForm.txtPassword.focus();
     return false;
     }
   */
  if(password.length < 6)
  { 
    alert('Password should be minimum of 6 characters.');
    theForm.txtPassword.focus();
    return false;
  }
  return true;
}

function selectMultipleUsers(theForm) {
  //Options in the multiple combo are selected for submission.
  var totElements = theForm.elements.length;
  var i=0;
  var m=0;
  for(i=0;i<totElements;i++) 
  { 
    if(theForm.elements[i].name == "slAssocUsers") 
    {
      var cmb_len = theForm.elements[i].options.length;
      if(cmb_len > 0) 
      {
        for(m=0; m<cmb_len; m++) 
        {
          theForm.elements[i].options[m].selected=true;
        }
      }
    }
  }
}

function setAthensMultiple(theForm) {
  //Options in the multiple combo are selected for submission.
  var totElements = theForm.elements.length;
  var i=0;
  var m=0;
  for(i=0;i<totElements;i++) 
  { 
    if(theForm.elements[i].name == "slAthensId") 
    {
      var cmb_len = theForm.elements[i].options.length;
      if(cmb_len > 0) 
      {
        for(m=0; m<cmb_len; m++) 
        {
          theForm.elements[i].options[m].selected=true;
        }
      }
    }
  }
}

function setShibbolethMultiple(theForm) {
  //Options in the multiple combo are selected for submission.
  var totElements = theForm.elements.length;

  var i=0;
  var m=0;
  for(i=0;i<totElements;i++) 
  { 
    if(theForm.elements[i].name == "slShibbolethId") 
    {
      var cmb_len = aform.elements[i].options.length;
      if(cmb_len > 0) 
      {
        for(m=0; m<cmb_len; m++) 
        {
          theForm.elements[i].options[m].selected=true;
        }
      }
    }
  }
}

function setMultiple(theForm) {
  //Options in the multiple combo are selected for submission.
  var totElements = theForm.elements.length;
  var i=0;
  var m=0;
  for(i=0;i<totElements;i++) 
  { 
    if(theForm.elements[i].name == "slAddedLogins") 
    {
      var cmb_len = theForm.elements[i].options.length;
      if(cmb_len > 0) 
      {
        for(m=0; m<cmb_len; m++) 
        {
          theForm.elements[i].options[m].selected=true;
        }
      }
    }
  }
}

function fnUserSubscriber_search(Action,mode,theForm)
{

  var valid = true;
  if (mode == "BASIC")
  {

    if(fnUserSubscriber_basicCheck(theForm))
    {

      if ((theForm.txtCID.value == "") &&  
          (theForm.txtEmeraldId.value == "") &&
          (theForm.txtInstitutionName.value == "") &&
          (theForm.txtFirstName.value == "") &&
          (theForm.txtLastName.value == "") &&
          (theForm.txtUsername .value == "") &&
          (theForm.txtEmailAddress.value == "")) 
      {
        alert('Please enter value in at least one field for search');
        if (theForm.txtCID.type == "text") theForm.txtCID.focus();
        else theForm.txtFirstName.focus();
        valid = false;
      }
    }
    else
    {
      valid = false
    }

  }
  else if (mode == "ADVANCED")
  {

    if(fnUserSubscriber_basicCheck(theForm) && fnUserSubscriber_extraAdvancedCheck(theForm))
    {
      if ((theForm.txtCID.value == "") &&  
          (theForm.txtEmeraldId.value == "") &&
          (theForm.txtInstitutionName.value == "") &&
          (theForm.txtFirstName.value == "") &&
          (theForm.txtLastName.value == "") &&
          (theForm.txtUsername .value == "") &&
          (theForm.txtEmailAddress.value == "") &&
          (theForm.txtAthensId.value == "") &&
          (theForm.txtShibbolethId.value == "") &&
          (theForm.txtIP1.value == "") &&
          (theForm.txtIP2.value == "") &&
          (theForm.txtIP3 .value == "") &&
          (theForm.txtIP4.value == "") &&
          (theForm.txtCountry.value == "") &&     
          (theForm.txtJournalName.value == "") &&     
          (theForm.txtReferringURL .value == ""))

      {
        alert('Please enter value in at least one field for search');
        theForm.txtCID.focus();
        valid = false;
      }
    }
    else
    {
      valid = false;
    }


  }
  if (valid == true) buttonClicked(Action,theForm);

}

function fnUserSubscriber_basicCheck(theForm)
{
  if (!isEmpty(theForm.txtCID.value) && !isInteger(theForm.txtCID.value))
  {
    alert("Please enter only integer values  in the CID field ");
    theForm.txtCID.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtEmeraldId.value) && !isAlphanumeric(theForm.txtEmeraldId.value))
  {
    alert("Please enter only alphanumeric values  in the EmeraldId field ");
    theForm.txtEmeraldId.focus();
    return false;
  }


  /*
     else if (!isEmpty(theForm.txtFirstName.value) && !isAlphanumeric(theForm.txtFirstName.value))
     {
     alert("Please enter only alphanumeric values  in the FirstName field ");
     theForm.txtFirstName.focus();
     return false;
     }
     else if (!isEmpty(theForm.txtLastName.value) && !isAlphanumeric(theForm.txtLastName.value))
     {
     alert("Please enter only alphanumeric values  in the LastName field ");
     theForm.txtLastName.focus();
     return false;
     }

     else if (!isEmpty(theForm.txtUsername.value) && !isAlphanumeric(theForm.txtUsername.value))
     {
     alert("Please enter only alphanumeric values  in the Username field ");
     theForm.txtUsername.focus();
     return false;
     }
   */
  else if (!isEmpty(theForm.txtEmailAddress.value) && !isEmail(theForm.txtEmailAddress.value))
  {
    alert("Please enter email in correct format");
    theForm.txtEmailAddress.focus();
    return false;
  }
  else
  {
    return true;
  }
}

function fnUserSubscriber_extraAdvancedCheck(theForm)
{
  /*if (!isEmpty(theForm.txtAthensId.value) && !isAlphanumeric(theForm.txtAthensId.value))
  {
    alert("Please enter only alphanumeric values  in the Athens ID field ");
    theForm.txtAthensId.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtShibbolethId.value) && !isAlphanumeric(theForm.txtShibbolethId.value))
  {
    alert("Please enter only alphanumeric values  in the Shibboleth Id field ");
    theForm.txtShibbolethId.focus();
    return false;
  }
  else */
  
  if (!isEmpty(theForm.txtIP1.value) && !isValidIPAddress(theForm.txtIP1.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIP1.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtIP2.value) && !isValidIPAddress(theForm.txtIP2.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIP2.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtIP3.value) && !isValidIPAddress(theForm.txtIP3.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIP3.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtIP4.value) && !isValidIPAddress(theForm.txtIP4.value))
  {
    alert("Please enter valid IP Address");
    theForm.txtIP4.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtCountry.value) && !isAlphanumeric(theForm.txtCountry.value))
  {
    alert("Please enter only alphanumeric values  in the Country field ");
    theForm.txtCountry.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtJournalName.value) && !isAlphanumeric(theForm.txtJournalName.value))
  {
    alert("Please enter only alphanumeric values  in the Journal Name field ");
    theForm.txtJournalName.focus();
    return false;
  }
  else
  {
    return true;
  }
}

function fnCreateMarkedList(asContext,theForm)
{
  theForm.hdAction.value = "menu_marked_list"; theForm.submit();

  varlsPopUpURL= SiteUrl + "/au_MarkedLists.do?hdAction=popup_create_new";
  winpops=window.open(varlsPopUpURL,"","width=250,height=250,left=200,top=200,scrollbars=yes");
}

function fnCreateMarket_closeWindow(asReturn)
{
  lsParentURL = SiteUrl + "/au_MarkedLists.do?hdAction=menu_marked_list";
  //alert("abc = " + lsParentURL);
  window.opener.location.href = lsParentURL;
  if (window.opener.progressWindow)
  {
    window.opener.progressWindow.close()
  }
  window.close();
}	

function fnSelectTab(asTab,theForm)
{
  theForm.hdContentTab.value = "tab_"+asTab;
  theForm.hdAction.value = 'button_view';
  theForm.submit();
}

function fnchkwithResults(theForm)
{
  if(theForm.chkSrchWithinResults.checked)
  {
    theForm.hdChexboxValue.value="true"
  }
  else
  {
    theForm.hdChexboxValue.value="false"
  }
}

function fnLoginProbs(Action,theForm)
{
  //	 if (isEmpty(theForm.txtUsername.value))
  //	 {
  //	 	alert("Please enter UserName to get the forgotten password")
  //	 	theForm.txtUsername.focus();
  //	 }
  //	 else
  //	 {
  //	 	theForm.hdUserName.value = theForm.txtUsername.value
  link(Action)
    // }
}

function fnForgetPswd(Action,theForm)
{
  if (isEmpty(theForm.txteMail.value))
  {
    alert("Email is mandatory")
      theForm.txteMail.focus();
  }
  else if(!isEmail(theForm.txteMail.value))
  {
    alert("Please enter email in correct format");
    theForm.txteMail.focus();
  }
  else
  {
    buttonClicked(Action,theForm)
  }
}



function fnCreateUser(Action,theForm)
{
  if (fnCreateEditCheck(theForm)) buttonClicked(Action,theForm);
}

function fnCreateEditCheck(theForm)
{
  if(theForm.slTitle.value == 0)
  {
    alert('Title is mandatory.');
    theForm.slTitle.focus();	
    return false; 	
  }	
  else if(theForm.txtFirstName.value == "")
  {
    alert('User First Name is mandatory.');
    theForm.txtFirstName.focus();	
    return false; 		
  }
  /*
     else if (!isEmpty(theForm.txtFirstName.value) && !isAlphanumeric(theForm.txtFirstName.value))
     {
     alert("Invalid characters in the FirstName field. ");
     theForm.txtFirstName.focus();
     return false;
     }*/
  else if(theForm.txtLastName.value == "")
  {
    alert('User Surname is mandatory.');
    theForm.txtLastName.focus();	
    return false; 		
  }
  /*
     else if (!isEmpty(theForm.txtLastName.value) && !isAlphanumeric(theForm.txtLastName.value))
     {
     alert("Invalid characters in the LastName field. ");
     theForm.txtLastName.focus();
     return false;
     }*/
  else if(theForm.txtJobTitle.value == "")
  {
    alert('User Job Title is mandatory.');	
    theForm.txtJobTitle.focus();
    return false; 		
  }
  else if (!isEmpty(theForm.txtJobTitle.value) && !isCorrectName(theForm.txtJobTitle.value))
  {
    alert("Invalid characters in the JobTitle field. ");
    theForm.txtJobTitle.focus();
    return false;
  }
  else if(theForm.slIndustry.value == 0)
  {
    alert('User Industry is mandatory');
    theForm.slIndustry.focus();	
    return false; 		
  }
  else if(theForm.txteMail.value == "")
  {
    alert('User Email address is mandatory');	
    theForm.txteMail.focus();
    return false; 		
  }
  else if(!isEmail(theForm.txteMail.value))
  {
    alert('Please enter Email address in correct format');	
    theForm.txteMail.focus();
    return false; 		
  }
  else if(theForm.txtOrganisation.value == "")
  {
    alert('User Organisation is mandatory');	
    theForm.txtOrganisation.focus();
    return false; 		
  }
  else if (!isEmpty(theForm.txtOrganisation.value) && !isCorrectName(theForm.txtOrganisation.value))
  {
    alert("Invalid characters in the Organisation field. ");
    theForm.txtOrganisation.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtDepartment.value) && !isCorrectName(theForm.txtDepartment.value))
  {
    alert("Invalid characters in the Department field. ");
    theForm.txtDepartment.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtAddressLine1.value) && !checkAddress(theForm.txtAddressLine1.value))
  {
    alert("Invalid characters in the AddressLine1 field. ");
    theForm.txtAddressLine1.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtAddressLine2.value) && !checkAddress(theForm.txtAddressLine2.value))
  {
    alert("Invalid characters in the AddressLine2 field. ");
    theForm.txtAddressLine2.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtCityTown.value) && !checkAddress(theForm.txtCityTown.value))
  {
    alert("Invalid characters in the City/Town field. ");
    theForm.txtCityTown.focus();
    return false;
  }
  else if (!isEmpty(theForm.txtPostCode.value) && !isPostCode(theForm.txtPostCode.value))
  {
    alert("Invalid characters in the Post Code field. ");
    theForm.txtPostCode.focus();
    return false;
  }
  /*else if(theForm.txtConfirmeMail.value == "")
    {
    alert('Confirm email address is mandatory');	
    theForm.txtConfirmeMail.focus();
    valid = false; 		
    }
    else if(!isEmail(theForm.txtConfirmeMail.value))
    {
    alert('Please enter Email address in correct format');	
    theForm.txtConfirmeMail.focus();
    valid = false; 		
    }
    else if (theForm.txteMail.value != theForm.txtConfirmeMail.value)
    {
    alert('Email address and confirm email address must match. Please enter again');
    theForm.txteMail.value="";
    theForm.txtConfirmeMail.value="";
    theForm.txteMail.focus();
    valid  = false;
    }
    else if (!isEmpty(theForm.txtTelephone.value) && !isHavingAlphabet1(theForm.txtTelephone.value))
    {
    alert("Invalid characters in the Telephone field.");
    theForm.txtTelephone.focus();
    return false;
    }
    else if (!isEmpty(theForm.txtFax.value) && !isHavingAlphabet1(theForm.txtFax.value))
    {
    alert("Invalid characters in the Fax field. ");
    theForm.txtFax.focus();
    return false;
    }
   */
  else if(theForm.slInterestArea.value == 0)
  {
    alert('User Area of interest is mandatory');	
    theForm.slInterestArea.focus();
    return false; 		
  }
  else if(theForm.slHowFindUs.value == 0)
  {
    alert('How to find us field is mandatory');	
    theForm.slHowFindUs.focus();
    return false; 		
  }
  /*else if(theForm.txtUsername.value == "")
    {
    alert('Username is mandatory');	
    theForm.txtUsername.focus();
    valid = false; 		
    }
    else if(theForm.txtPassword.value == "")
    {
    alert('User Password is mandatory');	
    theForm.txtPassword.focus();
    valid = false; 		
    }
    else if(theForm.txtPassword.value != "")
    {
    password = theForm.txtPassword.value;
    if(password.length < 6)
    {
    alert('Password should be minimum of 6 Characters');
    valid = false;
    }

    }*/
  /*if(valid)
    {
    if(theForm.txtConfirmPassword.value == "")
    {
    alert('Confirm Password is mandatory');	
    theForm.txtConfirmPassword.focus();
    valid = false; 		
    }
    else if (theForm.txtPassword.value != theForm.txtConfirmPassword.value)
    {
    alert('Password and Confirm Password must match. Please enter again');
    theForm.txtPassword.value="";
    theForm.txtConfirmPassword.value="";
    theForm.txtPassword.focus();
    valid  = false;
    }
    }	*/
  return true;
}

function fnFinish_Subscription(Action,theForm)
{
  var valid = true;
  if( (theForm.txtSubscriptionStartDt.value != "" && theForm.txtSubscriptionEndDt.value == "")
      || (theForm.txtSubscriptionStartDt.value == "" && theForm.txtSubscriptionEndDt.value != "") )
  {
    alert("Please enter both Subscription Start and End Dates");
    valid = false;
  }
  else if (theForm.txtSubscriptionStartDt.value != "" && theForm.txtSubscriptionEndDt.value != "")
  {
    if(DateCompare(theForm.txtSubscriptionStartDt.value,theForm.txtSubscriptionEndDt.value)<= 0)
    {
      alert('Subscription End Date is less than or equal to Subscription Start Date');		
      valid = false;
    }
  }
  if(valid)
  {
    if( (theForm.txtTrialStartDt.value != "" && theForm.txtTrialEndDt.value == "")
        || (theForm.txtTrialStartDt.value == "" && theForm.txtTrialEndDt.value != "") )
    {
      alert("Please enter both Trial Start and End Dates");
      valid = false;
    }
    else if (theForm.txtTrialStartDt.value != "" && theForm.txtTrialEndDt.value != "")
    {
      if(DateCompare(theForm.txtTrialStartDt.value,theForm.txtTrialEndDt.value)<= 0)
      {
        alert('Trial End Date is less than or equal to Trial Start Date');		
        valid = false;
      }
    }
  }
  if (valid == true) buttonClicked(Action,theForm);
}	

function fnCreateMarketSubscription(Action,theForm)
{
  var valid = true;
  if( (theForm.txtSubsStartDate.value != "" && theForm.txtSubsEndDate.value == "")
      || (theForm.txtSubsStartDate.value == "" && theForm.txtSubsEndDate.value != "") )
  {
    alert("Please enter both Subscription Start and End Dates");
    valid = false;
  }
  else if (theForm.txtSubsStartDate.value != "" && theForm.txtSubsEndDate.value != "")
  {
    if(DateCompare(theForm.txtSubsStartDate.value,theForm.txtSubsEndDate.value)<= 0)
    {
      alert('Subscription End Date is less than or equal to Subscription Start Date');		
      valid = false;
    }
  }
  if(valid)
  {
    if( (theForm.txtTrialStartDate.value != "" && theForm.txtTrialEndDate.value == "")
        || (theForm.txtTrialStartDate.value == "" && theForm.txtTrialEndDate.value != "") )
    {
      alert("Please enter both Trial Start and End Dates");
      valid = false;
    }
    else if (theForm.txtTrialStartDate.value != "" && theForm.txtTrialEndDate.value != "")
    {
      if(DateCompare(theForm.txtTrialStartDate.value,theForm.txtTrialEndDate.value)<= 0)
      {
        alert('Trial End Date is less than or equal to Trial Start Date');		
        valid = false;
      }
    }
  }
  if (valid == true) buttonClicked(Action,theForm);
}	

