

	var url_archive;
	var latestYears;
	var earliestYears;
//----------------------------js functions of searchOurArchiveViewer.jsp start from here ------------------

	var form_submitted = false;
	var topicids;
function submit_form ( )
{
  if ( form_submitted )
  {
    return false;
  }
  else
  {
    form_submitted = true;
    return true;
  }
}

	function delegateToForm()
	{
		if(submit_form())
		{
				if(doSearch(url_archive + 'keywordsearch.arc'))
				{	
					return true;
				}
				else
				{					
					form_submitted = false;
					return false;
				}
		}
		else
		{
			return false;
		}
	}

	function daysInMonth(iMonth, iYear){    

		return 32 - new Date(iYear, iMonth, 32).getDate();
	}
	
	function checkString(searchFname){		
		var myChar = new Array();
		var totArrLength = 0;
		var isValid
		var isThereValue = 1;
		
		for(i=0;i<26;i++){
			//A to Z
			myChar[totArrLength] = String.fromCharCode(65+i);
			totArrLength = totArrLength+1;
			}
		for(i=0;i<26;i++){
			//a- z
			myChar[totArrLength] = String.fromCharCode(97+i);
			totArrLength = totArrLength+1;
			}
		for(i=0;i<10;i++){
			//0 to 9
			myChar[totArrLength] = String.fromCharCode(48+i);
			totArrLength = totArrLength+1;
			}		
		for(i=0;i<myChar.length;i++){
				isValid = searchFname.indexOf(myChar[i]);				
				// if there is even a single valid (i.e. b/w A to Z,a to z,0 to 9 ) char in keyword string then return 0 els 1
				if(isValid != -1){
					isThereValue = 0;
				}
		}		
		return isThereValue;
	}
	
	function doSearch(targeturl){
		
		document.editionPagination.queryKeywords.value=document.editionPagination.enterKeywords.value;		
		var isValid = isValidDate();		
		
		//Fix for artf678652 start
		document.getElementById("currentPageNumber").value="1";
		//Fix for artf678652 end
		
		
		var isKeywordSplChar = checkString(document.editionPagination.enterKeywords.value);
		if(isKeywordSplChar==0){ 
		
			if(isValid==1 || isValid==2){
					document.editionPagination.fromDate.value = document.editionPagination.selFromYear[document.editionPagination.selFromYear.selectedIndex].value+"-"+document.editionPagination.selFromMonth[document.editionPagination.selFromMonth.selectedIndex].value+"-"+document.editionPagination.selFromDay[document.editionPagination.selFromDay.selectedIndex].value;	
					//var todd = daysInMonth(document.editionPagination.selToMonth[document.editionPagination.selToMonth.selectedIndex].value -1 , document.editionPagination.selToYear[document.editionPagination.selToYear.selectedIndex].value);
					document.editionPagination.toDate.value = document.editionPagination.selToYear[document.editionPagination.selToYear.selectedIndex].value+"-"+document.editionPagination.selToMonth[document.editionPagination.selToMonth.selectedIndex].value+"-"+document.editionPagination.selToDay[document.editionPagination.selToDay.selectedIndex].value;
					document.editionPagination.action=url_archive + 'keywordsearch.arc';
	
					document.editionPagination.addFilters.value=""
					document.editionPagination.removeFilters.value=""
					document.editionPagination.addCat.value=""
					document.editionPagination.addRefineFilters.value=""
					document.editionPagination.removeRefineFilters.value=""
					document.editionPagination.addRefineCat.value=""
					document.editionPagination.method='post';
					
					document.editionPagination.submit();
					return true;
				}
				
				else if(isValid==0)
				{
					alert("Please enter a valid date range.");
					return false;
				}
				/*
				else if(isValid==2)
				{
					alert("Please enter a valid date range. If you're trying to search on a single date, enter that date in the 'From' field and the following day in the 'To' field, e.g. to search on Jan 1 1785, enter Jan 1 1785 in the 'From' field and Jan 2 1785 in the 'To' field.");			
					return false;
				}
				*/
				else if(isValid==3){		
					alert("Please enter a search term.");
					document.keyForm.queryKeywords.focus();
					return false;
				}
			}else{
				alert("Please enter a valid search term.");
				document.editionPagination.enterKeywords.focus();
				return false;
			}
		
	}

	function isValidDate()
	{		
		
		var todd ;
		var toyy ;
		var tomm ;
		var fromdd;		
		var frommm;
		var fromyy;
		var lastFromDayInMth;
		var lastToDayInMth;		
		
		fromdd = eval(document.editionPagination.selFromDay[document.editionPagination.selFromDay.selectedIndex].value);
		frommm = eval(document.editionPagination.selFromMonth[document.editionPagination.selFromMonth.selectedIndex].value);
		fromyy = eval(document.editionPagination.selFromYear[document.editionPagination.selFromYear.selectedIndex].value);
		todd   = eval(document.editionPagination.selToDay[document.editionPagination.selToDay.selectedIndex].value);		
		tomm = eval(document.editionPagination.selToMonth[document.editionPagination.selToMonth.selectedIndex].value);
		toyy = eval(document.editionPagination.selToYear[document.editionPagination.selToYear.selectedIndex].value);							
			
		lastFromDayInMth = daysInMonth(frommm-1,fromyy);
		lastToDayInMth = daysInMonth(tomm-1,toyy);
		
		if(document.editionPagination.enterKeywords.value  == ""){
				return 3;
		}else{
			if(fromdd>lastFromDayInMth){				
				return 0;
			}		
			if(todd>lastToDayInMth){				
				return 0;
			}

			if(fromyy < toyy){
				return 1;				
			}
				
			else if (fromyy == toyy){			
				if (frommm > tomm){					
						return 0;
				}
				else if(frommm == tomm){

					if(fromdd < todd){					
						return 1;							
					}
					else if(fromdd > todd){					
						return 0;							
					}
					else if(fromdd == todd)
						{
							return 2;
						}

					}else if(frommm < tomm){					
						return 1;						
					}			
				}
			else if (fromyy > toyy){			
				return 0;
			}
		}
	}

/*
Fix for Artf623760
@author Elangovan
*/	
function fChangeDropdownValues(eYear, eMonth, eDate, eSelectedDate){

	var nYear=eYear;
	var nMonth=eMonth;	
	var nDaySelect= document.getElementById(eDate);
	var nDaySelectValue= document.getElementById(eDate).value;
	var changeLastDay = daysInMonth(nMonth-1,nYear);
	//nDaySelect.innerHTML = "";
	var fOpts="";
	var nDropDownSelected = eSelectedDate;
	var nDDSelectedDate = changeLastDay;

	if(nDaySelectValue > nDDSelectedDate){
		nDaySelectValue = nDDSelectedDate;
	}
	
	if(nDropDownSelected == 'fromDropdown'){
		nDDSelectedDate = 1;
	}
	//Clearing the dropdown
	 if ( nDaySelect.hasChildNodes() )	{
    	while ( nDaySelect.childNodes.length >= 1 )	{
        	nDaySelect.removeChild( nDaySelect.firstChild );       
    	} 
	}
		
	for(i=1;i<=changeLastDay;i++){
		opt = document.createElement("OPTION");
		
		if(document.all){ //IE
    			nDaySelect.add(opt)
   		}else{
    		nDaySelect.appendChild(opt)
   		}
   		
		if(i==nDaySelectValue){
			if(i<10){	
				opt.value="0"+i;
				opt.selected="selected";
				opt.text=i;
			}	
			else{
				opt.value=i;
				opt.selected="selected";
				opt.text=i;
			}	
		}
		else{
			if(i<10){
				opt.value="0"+i;
				opt.text=i;
			}	
			else{
				opt.value=i;
				opt.text=i;
			}	
		}	
	
	}
}
//------------------------js functions of searchOurArchiveViewer.jsp Ends ------------------------------------------

//-----------------------------js function of articleViewerPagination.jsp starts from here --------------------------------------

function invokeArticleViewerNav(origPgId,origArtId,pageIdvar,articleIdvar,xmlpath,indexvar){
		//changes done owing to Archive without Genreg defect in Release 8.1
		// Author : Rangan Gupta
		// Dated : 08 July, 2008
		var arr = pageIdvar.split("-");
		var newPgid = arr[0]+"-"+arr[1]+"-"+arr[2]+"-"+arr[3]+"-"+arr[4]+"-"+indexvar;
		
		document.editionPagination.pageId.value = newPgid;
		if(newPgid == origPgId){
			
			document.editionPagination.articleId.value = origArtId;
		} else {
			document.editionPagination.articleId.value = newPgid+"-001";
		}
		//end of changes

		document.editionPagination.xmlpath.value =xmlpath;
		document.editionPagination.searchPage.value = "false";
			
		//Artf598438 : Set form attribute in request
		document.editionPagination.fromEditionPagination.value = "true";
		document.editionPagination.action = url_archive + 'viewArticle.arc?articleId='+articleIdvar+'&pageId='+pageIdvar;
		document.editionPagination.method='get';
		document.editionPagination.submit();
}
	
function goBacktoSearchResults(){
	if(document.editionPagination.isDateSearch.value == 'true')
		document.editionPagination.action = url_archive + 'searchOnDay.arc'
	else
		document.editionPagination.action = url_archive + 'keywordsearch.arc'

	document.editionPagination.method='post';
	if(form_submitted != undefined)
	{
		form_submitted = true;
	}
	document.editionPagination.submit()
}

function invokeArticleViewer(pageId,articleId,xmlpath,articlenum){
	if((eval(articlenum) > eval(document.editionPagination.resultsPerPage.value))||(eval(articlenum) == 1)){
		if(eval(articlenum) > eval(document.editionPagination.resultsPerPage.value)){
				var pg = document.editionPagination.currentPageNumber.value
				document.editionPagination.currentPageNumber.value = eval(pg) + 1
				document.editionPagination.resultNumber.value = 1
		}
		
		if(eval(articlenum) == 1){
				var pg = document.editionPagination.currentPageNumber.value
				
				if(eval(pg) <2){										
					document.editionPagination.resultNumber.value = 0;
				}else{
					document.editionPagination.currentPageNumber.value = eval(pg) - 1
					document.editionPagination.resultNumber.value = eval(document.editionPagination.resultsPerPage.value)-1;
				}
		}
		document.editionPagination.pageId.value=''
		document.editionPagination.articleId.value=''
		document.editionPagination.addIndex.value=''


		document.editionPagination.action = url_archive + 'changeArticleRedirect.arc'
	}else{
		document.editionPagination.pageId.value=pageId
		document.editionPagination.articleId.value=articleId
		document.editionPagination.xmlpath.value =xmlpath
		document.editionPagination.resultNumber.value = articlenum
		document.editionPagination.addIndex.value=''
		document.editionPagination.action = url_archive + 'viewArticle.arc'
	}
	//changes done for Archive without Genreg artifact
	// author : Rangan Gupta
	// dated : July 08, 2008
	document.editionPagination.origArticleId.value = document.editionPagination.articleId.value;
	document.editionPagination.origPageId.value = document.editionPagination.pageId.value;
	// end of changes
	document.editionPagination.method='get';
	
	document.editionPagination.submit()
}

function goToArticle(articlenum){
	
	var resultPerPg = document.editionPagination.resultsPerPage.value;
	var totalResults = document.editionPagination.totalResults.value;

	//if(((eval(articlenum) > eval(document.editionPagination.resultsPerPage.value))||(eval(articlenum) == //1))&&(eval(totalResults)>eval(resultPerPg))&&(eval(document.editionPagination.currentPageNumber.value)>1)){
	if(((eval(articlenum) > eval(document.editionPagination.resultsPerPage.value))||(eval(articlenum) == 1))&&(eval(totalResults)>eval(resultPerPg))){	
		if(eval(articlenum) > eval(document.editionPagination.resultsPerPage.value)){
				var pg = document.editionPagination.currentPageNumber.value
				document.editionPagination.currentPageNumber.value = eval(pg) + 1
				document.editionPagination.resultNumber.value = 1
		}
		
		if(eval(articlenum) == 1){
				var pg = document.editionPagination.currentPageNumber.value
				
				if(eval(pg) <2){										
					document.editionPagination.resultNumber.value = 0;
				}else{
					document.editionPagination.currentPageNumber.value = eval(pg) - 1
					document.editionPagination.resultNumber.value = eval(document.editionPagination.resultsPerPage.value)-1
				}
		}
		document.editionPagination.pageId.value=''
		document.editionPagination.articleId.value=''
		document.editionPagination.addIndex.value=''


		document.editionPagination.action = url_archive + 'changeArticleRedirect.arc'
	}else{
		document.editionPagination.pageId.value=''
		document.editionPagination.articleId.value=''
		document.editionPagination.resultNumber.value = articlenum
		document.editionPagination.addIndex.value=''
		document.editionPagination.action = url_archive + 'viewArticleRedirect.arc'
	}
	document.editionPagination.method='get';
	if(form_submitted != undefined)
	{
		form_submitted = true;
	}
	document.editionPagination.submit()
}

function goToTopicPage(topicName,sectionId,toDate,fromDate,introText,topicDesc,topicstate,metaTitle,metaDesc,metaKeywords,query,topicId){
	document.editionPagination.action = url_archive+'archiveTopic/'+topicName+'?aToZSectionId='+sectionId+'&toDate='+toDate+'&fromDate='+fromDate+'&topicIntroTxt='+introText+'&topicName='+topicName+'&topicDesc='+topicDesc+'&topicState='+topicstate+'&metaTitle='+metaTitle+'&metaDesc='+metaDesc+'&metaKeywords='+metaKeywords+'&resultsPerPage=10&offset=0&query='+query+'&topicId='+topicId;
	document.editionPagination.submit();
}
//-----------------------------js functions of articleViewerPagination.jsp Ends ----------------------------------------------------


function setContextURL(cntxUrl){
	url_archive= cntxUrl;
		
}

//-----------------------------js function of articleViewer.jsp starts from here ---------------------------------------------------
	function printPopUp(urls){
	var pageUrl=urls;
	pageUrl = urls+"&print=yes";
	
	return fPopUp(650,650,pageUrl);

}
//-----------------------------js functions of articleViewer.jsp Ends ---------------------------------------------------------------

//-----------------------------js function of topicRelatedArticles.jsp starts from here ---------------------------------------------
function displayArticleViewer(pageIdvar,articleIdvar,resultsPerPagevar,xmlvar){
		document.topicPagearticleViewerForm.xmlpath.value = xmlvar;
		document.topicPagearticleViewerForm.pageId.value = pageIdvar;
		document.topicPagearticleViewerForm.articleId.value = articleIdvar;
		document.topicPagearticleViewerForm.offset.value = resultsPerPagevar;
		document.topicPagearticleViewerForm.topicId.value = topicids;	
		document.topicPagearticleViewerForm.action = url_archive + 'viewArticle.arc'
		document.topicPagearticleViewerForm.method = 'get'
		document.topicPagearticleViewerForm.submit()
	}

//-----------------------------js function of topicRelatedArticles.jsp Ends ----------------------------------------------------------
function setTopicID(id)
{
	topicids=id
}



//-----------------------------js function of relatedTopic.jsp starts ----------------------------------------------------------

	function getTopicPage(toDate , fromDate , introText , topicDesc , state , metatitle , metadesc, metakeyword, query , topicId, topicname){
		document.forms['relatedTopicForm'].action=url_archive+'archiveTopic/' + topicname +'?toDate='+ toDate + '&fromDate=' + fromDate+ '&topicIntroTxt='+ introText+ '&topicName='+ topicname+ '&topicDesc='+topicDesc+'&topicState='+state+'&metaTitle='+metatitle+'&metaDesc='+metadesc+'&metaKeywords='+metakeyword+'&resultsPerPage=10&offset=0&query='+query+'&topicId='+ topicId ;
		document.forms['relatedTopicForm'].submit();
	}
//-----------------------------js function of relatedTopic.jsp Ends ----------------------------------------------------------


//-----------------------------js functions of onMyBirthday.jsp starts ----------------------------------------------------	
	function validateDate(){
		var isValid = isDateValid();		
		if(isValid==true){
			var dayStr = document.siteSearchOnDateForm.getMyBirthDay.value
			var	day=parseInt(dayStr)	
			//day should be two digit
			
			if(day/10<1 && dayStr.length<2){			
				dayStr="0"+dayStr			
			}
			var monthStr = document.siteSearchOnDateForm.getMyBirthMonth.value
			var	month=parseInt(monthStr)		
			//month should be two digit
			if(month/10<1 && monthStr.length<2){			
				monthStr="0"+monthStr			
			}				
			document.siteSearchOnDateForm.myBirthDate.value = document.siteSearchOnDateForm.getMyBirthYear.value+"-"+monthStr+"-"+dayStr						
			document.siteSearchOnDateForm.action = url_archive+"searchOnDay.arc"
			document.siteSearchOnDateForm.submit()
		}
	}

	function clearText(idName){
		document.getElementById(idName).value="";
	}

	function isInteger(s){
		var i;
		for (i = 0; i < s.length; i++){   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}

	function stripCharsInBag(s, bag){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++){   
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}

	function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
		// EXCEPT for centurial years which are not also divisible by 400.
		return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
	   } 
	   return this
	}

	function isDate(dtStr){
		
		var dtCh= "/";
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strMonth=dtStr.substring(0,pos1)
		var strDay=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		var strYr=strYear
		var earliestYearStr =earliestYears;		
		var latestYearStr = latestYears;		
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		var month=parseInt(strMonth)
		var day=parseInt(strDay)
		var year=parseInt(strYr)
		var earliestYear=parseInt(earliestYearStr)
		var latestYear=parseInt(latestYearStr)		

		if (pos1==-1 || pos2==-1){
			alert("Please enter a valid date")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Please enter a valid date")
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert("Please enter a valid date")
			return false
		}
		if (strYear.length != 4 || year==0){
			alert("Please enter a valid date")
			return false
		}else if(year>latestYear || year<earliestYear){
			alert("Please enter a valid date")
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			alert("Please enter a valid date")
			return false
		}
	return true
	}

	function isDateValid(){
		
		var dt = document.siteSearchOnDateForm.getMyBirthMonth.value+"/"+document.siteSearchOnDateForm.getMyBirthDay.value+"/"+document.siteSearchOnDateForm.getMyBirthYear.value		
		//var dt=document.frmSample.txtDate		
		if (isDate(dt)==false){		
			document.siteSearchOnDateForm.getMyBirthDay.focus;
			return false
		}else{
			return true
		}
	 }


function setContextURL(cntxUrl){
	url_archive= cntxUrl;

}
function setEarliestYear(earlier){
	earliestYears= earlier;

}
function setLatestYear(last){
	latestYears= last;
	
}

//-----------------------------js functions of onMyBirthday.jsp Ends ----------------------------------------------------	


//-----------------------------js functions of searchPuff.jsp starts ----------------------------------------------------	
	function fSearchPuffSubmit(sUrl){
		document.searchPuffForm.action=sUrl+"viewSearchResults.arc";
		document.searchPuffForm.submit();
	}
//-----------------------------js functions of searchPuff.jsp Ends ----------------------------------------------------	
