/*********************************************************************************************************************
.js file for the Search, containing the following functions.
	
	1.  jsChangeDay					- 
	2.  jsShowImage					- 
	3.  jsArchives					- 
	4.  jsShowBorder				- 
	5.  jsSlideShow					- 
	6.  jsASSearch					- 
	7.  jsAdvanceSearch				-
	8.	jsReset						-
	9.	jsASNext					-	
	10.	jsASPrevious				-
	11.	jsSearch					-
	12. jsNewSearch					-
	13.	jsShowNext					-
	14.	jsShowPrevious				-
**********************************************************************************************************************/

function jsChangeDay(ToDID) {
	window.location.href= "login.aspx" ;
	return false;
}
function jsShowImage(ImageType,ImageName,ImageWidth ,ImageHeight){
	if (ImageType == 'picture') openArticle("ArticleImageEx.aspx",ImageName,ImageWidth,ImageHeight,2)
	else openArticle("ArticleImageEx.aspx",ImageName,ImageWidth,ImageHeight,1)
}
function jsArchives(){
	alert("Archives Coming soon...");
}
function jsShowBorder(ctl,status){
	if (status == 1)
		ctl.border=1
	else if (status ==0)
		ctl.border=0
}
function jsSlideShow(ShowFor){
	window.open("viewslideshow.aspx?SlideShowFor=" + ShowFor + "&CurrentDay=" + sCurrentPage,"vss","fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,height=700,width=650");
}
// Advance search BEGIN
/* Advance search article - called on the submit button	*/
function jsASSearch(SearchFor,sNPQS) {
	var iSearch = 0;
	var sKeyWord = "";
	var sAuthor="";
	var sPageNumber="";
	var sLocation="";
	var sColumnTitle="";
	var sStartDate="";
	var sEndDate="";
	var perUrl="";
		
	//validate the control and send the search
	if (sNPQS == undefined)
		sNPQS="";
		
	if (document.getElementById('rdAll').checked == true)
		iSearch = 0;
	else
		iSearch = 1;
			
	sKeyWord = document.getElementById('txtASKeyWord').value;
	sAuthor=document.getElementById('txtASAuthor').value;
	sPageNumber=document.getElementById('txtASPageNumber').value;
	sLocation=document.getElementById('txtASLocation').value;
	sColumnTitle =document.getElementById('txtASColumnTitle').value;
	sStartDate=document.getElementById('selFrom').options[document.getElementById('selFrom').selectedIndex].value;
	sEndDate=document.getElementById('selFrom').options[document.getElementById('selTo').selectedIndex].value;
		
	if (sKeyWord=="" && sAuthor=="" && sPageNumber=="" && sLocation=="" && sColumnTitle=="" && sStartDate=="" && sEndDate=="") {
		alert("Enter one or more search options");
		return;
	}
		
	if (SearchFor == 'article'){
		perUrl = "AdvanceSearch.aspx?Show=RESULT&SearchFor=" + SearchFor + "&KeyWords=" + sKeyWord + "&Author=" + sAuthor 
			+ "&PageNumber=" + sPageNumber + "&Location=" + sLocation + "&ColumnTitle=" + sColumnTitle + "&StartDate=" + sStartDate
			+ "&EndDate=" + sEndDate + "&SearchType=" + iSearch + sNPQS;
	}
	displayLoading();
	jsRemoteCallOthers(perUrl);
}
	
/* called to show the advance search UI option for article,image,advertisement */
function jsAdvanceSearch(SearchFor){
	if (chck == "False") {
		window.location.href = "Login.aspx";
		return false;
	}
	var perUrl="";
	perUrl = "AdvanceSearch.aspx?Show=UI&SearchFor=" + SearchFor
	displayLoading();
	jsRemoteCallOthers(perUrl);
}	
function jsReset(){
	document.getElementById('txtASKeyWord').value = "";
	document.getElementById('txtASAuthor').value ="";
	document.getElementById('txtASPageNumber').value="";
	document.getElementById('txtASLocation').value="";
	document.getElementById('txtASColumnTitle').value="";
	document.getElementById('selFrom').selectedIndex=0;
	document.getElementById('selTo').selectedIndex=document.getElementById('selTo').length -1;
}
function jsASNext() {
	var iPrevious=0;
	var iNoOfRecords=0;
	var iLastEndID=0;
	var iLastStartID=0;
	var iStartID=0;
	var iRecShown=0;
	var iCurrentPage="0";
		
	if (document.getElementById('hidNoOfRecords'))
		iNoOfRecords=hidNoOfRecords.value;
	if (document.getElementById('hidLastEndID'))
		iLastEndID=hidLastEndID.value;			
	if (document.getElementById('hidLastStartID'))
		iLastStartID=hidLastStartID.value;
	if (document.getElementById('hidStartID'))
		iStartID=hidStartID.value;
	if (document.getElementById('hidRecsShown'))
		iRecShown = hidRecsShown.value;
	if (iLastEndID.split(",").length == iRecShown){
		return;
	}
	if (document.getElementById('hidCurrentPage'))
		iCurrentPage = parseInt(hidCurrentPage.value) + 1;	
	var QS =  "&NoOfRecords=" + iNoOfRecords + "&Previous=" + iPrevious + "&StartID=" + iStartID + "&RecsShown=" + iRecShown + "&LastEndID=" + iLastEndID + "&LastStartID=" + iLastStartID + "&CurrentPage=" + iCurrentPage		
	jsASSearch('article',QS) ;
}
	
function jsASPrevious() {
	var iPrevious=1;
	var iNoOfRecords=0;
	var iLastEndID=0;
	var iLastStartID=0;
	var iStartID=0;
	var iRecShown=0;
	var iCurrentPage="0";
		
	if (document.getElementById('hidNoOfRecords'))
		iNoOfRecords=hidNoOfRecords.value;
	if (document.getElementById('hidLastEndID'))
		iLastEndID=hidLastEndID.value;			
	if (document.getElementById('hidLastStartID'))
		iLastStartID=hidLastStartID.value;
	if (document.getElementById('hidStartID'))
		iStartID=hidStartID.value;
	if (document.getElementById('hidRecsShown'))
		iRecShown = hidRecsShown.value;
	if (iLastEndID.split(",").length == 1)
		return;
	if (document.getElementById('hidCurrentPage'))
		iCurrentPage = hidCurrentPage.value - 1;
			
	var QS =  "&NoOfRecords=" + iNoOfRecords + "&Previous=" + iPrevious + "&StartID=" + iStartID + "&RecsShown=" + iRecShown + "&LastEndID=" + iLastEndID + "&LastStartID=" + iLastStartID + "&CurrentPage=" + iCurrentPage		
	jsASSearch('article',QS) ;
}
	
// Advance Search END

// General & New Search Begin 
function jsSearch(SearchFor,remotPage,sPage) {
	if (chck == "False") {
		window.location.href = "Login.aspx"
		return false;
	}
	var sKeyword="";
	if (SearchFor == "article")	{
		sKeyword = document.getElementById('txtArticleKeyword').value;	
		if (sKeyword == ""){
			alert("Enter a keyword to seach");
			return;
		}
	}
	else if (SearchFor == "picture"){	
		sKeyword = document.getElementById('txtPictureKeyword').value;
		if (sKeyword == ""){
			alert("Enter a keyword to seach");
			return;
		}
	}
	else if (SearchFor == "picturegallarey"){
		document.getElementById('txtPictureKeyword').value="";	
		sKeyword ="";
	}
	else if (SearchFor == 'advertisement'){
		sKeyword = document.getElementById('txtAdKeyword').value;
		if (sKeyword == ""){
			alert("Enter a keyword to seach");
			return;
		}
	}
	else if (SearchFor =='advertismentgallery'){
		document.getElementById('txtAdKeyword').value="";
		sKeyword="";
	}
	if (sPage == "")
		sPage = sCurrentPage;
	var perUrl =   remotPage + "?keyWords=" + sKeyword + "&SearchDate=" + sPage ;
	displayLoading();
	jsRemoteCallOthers(perUrl);
}

	
function jsNewSearch(SearchFor,remotePage){
		
	if (chck == "False") {
		window.location.href = "Login.aspx";
		return false;
	}
	var sKeyword="";
	if (SearchFor == 'article'){
		sKeyword = document.getElementById('txtNewSearch').value;
		if (sKeyword == ""){
			alert("Enter a keyword to seach");
			return;
		}
		document.getElementById('txtArticleKeyword').value =sKeyword; 
	}
	else if (SearchFor == 'picture'){
		sKeyword = document.getElementById('txtNewSearch').value;
		if (sKeyword == ""){
			alert("Enter a keyword to seach");
			return;
		}
		document.getElementById('txtPictureKeyword').value =sKeyword;
	}
	else if (SearchFor == 'advertisement') {
		sKeyword = document.getElementById('txtNewSearch').value;
		if (sKeyword == "") {
			alert("Enter a keyword to seach");
			return;
		}
		document.getElementById('txtAdKeyword').value =sKeyword;
	}
	var perUrl =  remotePage + "?keyWords=" + sKeyword + "&SearchDate=" + selFrom.options[selFrom.selectedIndex].value + "&SearchToDate=" + selTo.options[selTo.selectedIndex].value ;
	displayLoading();
	jsRemoteCallOthers(perUrl);
}
	
function jsShowNext(SearchFor,remotePage){
	var iPrevious=0;
	var iNoOfRecords=0;
	var iLastEndID=0;
	var iLastStartID=0;
	var iStartID=0;
	var iRecShown=0;
	var iCurrentPage="0";
		
	var dSearchDate="";
	var dSearchToDate="";
	var sKeyword="";
	var perUrl="";
		
	if (SearchFor == "article")
		sKeyword = document.getElementById('txtArticleKeyword').value;	
	else if (SearchFor == "picture")
		sKeyword = document.getElementById('txtPictureKeyword').value;
	else if (SearchFor == "advertisement")
		sKeyword = document.getElementById('txtAdKeyword').value;

	if (document.getElementById('hidNoOfRecords'))
		iNoOfRecords=document.getElementById('hidNoOfRecords').value;
			
	if (document.getElementById('hidStartID'))
		iStartID=document.getElementById('hidStartID').value;
			
	if (document.getElementById('hidLastStartID'))
		iLastStartID=document.getElementById('hidLastStartID').value;
			
	if (document.getElementById('hidLastEndID'))
		iLastEndID=document.getElementById('hidLastEndID').value;
			
	if (document.getElementById('hidRecsShown'))
		iRecShown = document.getElementById('hidRecsShown').value;
			
	if (document.getElementById('hidSearchDate'))
		dSearchDate=document.getElementById('hidSearchDate').value;
			
	if (iLastEndID.split(",").length == iRecShown){
		return;
	}
	if (document.getElementById('hidCurrentPage'))
		iCurrentPage = parseInt(document.getElementById('hidCurrentPage').value) + 1;
			
	perUrl = remotePage + "?keyWords=" + sKeyword + "&NoOfRecords=" + iNoOfRecords + "&Previous=" + iPrevious + "&StartID=" + iStartID + "&RecsShown=" + iRecShown + "&LastEndID=" + iLastEndID + "&LastStartID=" + iLastStartID + "&SearchDate=" + dSearchDate + "&CurrentPage=" + iCurrentPage + "&SearchToDate=" + selTo.options[selTo.selectedIndex].value;
	displayLoading();
	jsRemoteCallOthers(perUrl);
		
}
	
function jsShowPrevious(SearchFor,remotePage){
	var iPrevious=1;
	var iNoOfRecords=0;
	var iLastEndID=0;
	var iLastStartID=0;
	var iStartID=0;
	var iRecShown=0;
	var iCurrentPage="0";
	var dSearchDate="";
	var sKeyword="";
	var perUrl="";
		
	if (SearchFor == "article")
		sKeyword = document.getElementById('txtArticleKeyword').value;	
	else if (SearchFor == "picture")
		sKeyword = document.getElementById('txtPictureKeyword').value;
	else if (SearchFor == "advertisement")
		sKeyword = document.getElementById('txtAdKeyword').value;
			
	if (document.getElementById('hidNoOfRecords'))
		iNoOfRecords=document.getElementById('hidNoOfRecords').value;
			
	if (document.getElementById('hidStartID'))
		iStartID=document.getElementById('hidStartID').value;
			
	if (document.getElementById('hidLastStartID'))
		iLastStartID=document.getElementById('hidLastStartID').value;
			
	if (document.getElementById('hidLastEndID'))
		iLastEndID=document.getElementById('hidLastEndID').value;
			
	if (document.getElementById('hidRecsShown'))
		iRecShown = document.getElementById('hidRecsShown').value;
			
	if (document.getElementById('hidSearchDate'))
		dSearchDate=document.getElementById('hidSearchDate').value;
		
	if (iLastEndID.split(",").length == 1){
		return;
	}
	if (document.getElementById('hidCurrentPage'))
		iCurrentPage = document.getElementById('hidCurrentPage').value - 1;
		
	perUrl = remotePage + "?keyWords=" + sKeyword + "&NoOfRecords=" + iNoOfRecords + "&Previous=" + iPrevious + "&StartID=" + iStartID + "&RecsShown=" + iRecShown + "&LastEndID=" + iLastEndID + "&LastStartID=" + iLastStartID + "&SearchDate=" + dSearchDate + "&CurrentPage=" + iCurrentPage + "&SearchToDate=" + selTo.options[selTo.selectedIndex].value;
	displayLoading();
	jsRemoteCallOthers(perUrl);
}