//Global variable declarations
var globalimgSource='';
var globalCurrentYear='';
var globalimgCount=0;
var counter=0;
var travelpodCityName='';
var travelpodCityCode=''; 
var travelpodCount=0;
var imageFolder = contextPathStatic+'/images/';
var countryCode;
//	Function to get the current year
function getCurrentYear(){
	DWREngine._execute(dwrURL, 'GeocoderServiceDwr', 'CurrentDate',loadCurrentYear);
//	GeocoderServiceDwr.CurrentDate(loadCurrentYear);
}

//	Callback method to get the current year 
 function loadCurrentYear(currentYear){
 	globalCurrentYear = currentYear.substr(0,4);
 }
 
//	Function responsible to Call the travelpod list of entries
//	by calling search method defined in the TravelPodDWR.js file
function getTravelpodList(cityName,cityCode){
	travelpodCityName = cityName;
	travelpodCityCode = cityCode;
	DWREngine._execute(dwrURL, 'GeocoderServiceDwr', 'getColumbusCodeForISOCode', cityCode, callTravelPod);
	
}

function callTravelPod(result){
	if(result != null && result["countryCode"] != null && result["countryCode"] != '' ){
    	countryCode=result["countryCode"];
    }
	getCurrentYear();
	var tpDivObj = document.getElementById("TravelpodLink");
	if(tpDivObj != null){
		if(tpDivObj.className != 'selected'){
			tpDivObj.className = 'selected';
			changeSelectedImageIcon('img_TravelpodLink');
	    }//End Of if
	}//End Of if
	var travelPodObj = document.getElementById("TravelPod");
	travelPodObj.style.display='';
	var travelPodContentObj = document.getElementById("TravelPodEntry");
	travelPodContentObj.style.display='none';
	var travelPodHeadingObj = document.getElementById("TravelPodHeading");
	travelPodHeadingObj.innerHTML = '';
	var travelPodBodyObj = document.getElementById("TravelPodBody");
	travelPodBodyObj.style.display='';
	var travelPodBodyTopObj = document.getElementById("TravelPodBodyTop");
	var travelPodBodyContentObj = document.getElementById("TravelPodBodyContent");
	var travelPodBodyBottomObj = document.getElementById("TravelPodBodyBottom");
	DWREngine._execute(dwrURL, 'TravelPodDWR', 'search', travelpodCityName,countryCode,loadTravelpod);
//	TravelPodDWR.search(loadTravelpod,cityName);
	travelPodBodyContentObj.innerHTML ="<font color='red' ><b>Loading Travel Blog Entries. Please wait </font><img width='50' height='5' src = '"+imageFolder+"searching.gif'></b>";

}

//	CallBack function which inturn calls a function to display the Travelpod content information
function loadTravelpod(result){
		if(result!= null && result != "null" && result.length > 0){
		var travelPodObj = document.getElementById("TravelPod");
		travelPodObj.style.display='';
		var travelPodContentObj = document.getElementById("TravelPodEntry");
		travelPodContentObj.style.display='none';
		var travelPodHeadingObj = document.getElementById("TravelPodHeading");
		travelPodHeadingObj.innerHTML = result[0].city+' | Travel Blogs';
    									 +" <div class='tal fs-09 bgc-04 p-10'>"
    									 +" <a target='_blank' href='http://www.travelpod.com/'><img src='"+contextPath+"/images/travelpod_logo.gif' border='0' alt='Free travel blogs, travel journals, travelogues and travel diaries'></a>"
    									 +" Travel community content is provided in partnership with TravelPod"
    									 +" <div class='pt-10'>"
    									 +" &copy;"+ globalCurrentYear +" TravelPod Inc. All rights reserved.<br />"
    									 +" TravelPod Images. &copy;"+globalCurrentYear+" TravelPod Inc"    									 
    									 +" </div>"
    									 +" <div class='pt-10'>"
    									 +" We and our content providers (\'we\') have tried to make the information" 
    									 +" on this website as accurate as possible, but it is provided \'as is\' and" 
    									 +" we accept no responsibility for any loss, injury or inconvenience sustained by anyone resulting"
    									 +" from this information. You should verify critical information "
    									 +" (like visas, health and safety, customs, and transportation)"
    									 +" with the relevant authorities before you travel."
    									 +" </div>"
    									 +" </div>";
		DWREngine._execute(dwrURL, 'TravelPodDWR', 'getImageCount',travelpodCityName ,countryCode, getCount);
    	count=20;
    	showTravelpodContent(result);
   	}else{
		globalimgCount=0;
		HideShowPreviousNextButtons();
		var travelPodBodyContentObj = document.getElementById("TravelPodBodyContent");			
		travelPodBodyContentObj.innerHTML = "<b>Sorry. We currently do not have blog entries for "+travelpodCityName+"</b>"; 
	}
}

//	CallBack function which inturn calls a function to display the Travelpod content information
function getCount(result){ 
	globalimgCount=result;	
}

//	Function to call the Previous Travelpod Page
function travelPodPreviousPage(){
	DWREngine._execute(dwrURL, 'TravelPodDWR', 'getImageCount',travelpodCityName,countryCode, getCount);
	var travelPodBodyContentObj = document.getElementById("TravelPodBodyContent");
	var travelPodBodyTopObj = document.getElementById("TravelPodBodyTop");
	var travelPodBodyBottomObj = document.getElementById("TravelPodBodyBottom");
	travelpodCount = travelpodCount - 1;
	if(travelpodCount<0)
	travelpodCount=0;
	DWREngine._execute(dwrURL, 'TravelPodDWR', 'nextSearch',travelpodCityName,travelpodCount,countryCode, showTravelpodContent);
	count-=20;
	if(count<0)
	count=0;	
	travelPodBodyContentObj.innerHTML ="<font color='red' ><b>Loading Previous Travel Blog Entries Page. Please wait </font><img width='50' height='5' src = '"+imageFolder+"searching.gif'></b>";
	travelPodBodyTopObj.style.visibility="hidden";
	travelPodBodyBottomObj.style.visibility="hidden";
}

//	Function to call the Next Travelpod Page

function travelPodNextPage(){
	DWREngine._execute(dwrURL, 'TravelPodDWR', 'getImageCount',travelpodCityName,countryCode, getCount);
	var travelPodBodyContentObj = document.getElementById("TravelPodBodyContent");
	var travelPodBodyTopObj = document.getElementById("TravelPodBodyTop");
	var travelPodBodyBottomObj = document.getElementById("TravelPodBodyBottom");
	travelpodCount = travelpodCount + 1;
	DWREngine._execute(dwrURL, 'TravelPodDWR', 'nextSearch',travelpodCityName,travelpodCount,countryCode, showTravelpodContent);
	count+=20;
	travelPodBodyContentObj.innerHTML ="<font color='red' ><b>Loading Next Travel Blog Entries Page. Please wait </font><img width='50' height='5' src = '"+imageFolder+"searching.gif'></b>";
	travelPodBodyTopObj.style.visibility="hidden";
	travelPodBodyBottomObj.style.visibility="hidden";
}

//	Function responsible to Display the list of travelpod entries
//	defined in the TravelPodDWR.js file

function showTravelpodContent(result){
	TravelpodHideError();
	var travelPodBodyContentObj = document.getElementById("TravelPodBodyContent");
	travelPodBodyContentObj.innerHTML='';
	var travelPodBodyContentHTML ='';
	var travelPodBodyTopObj = document.getElementById("TravelPodBodyTop");
	var travelPodBodyBottomObj = document.getElementById("TravelPodBodyBottom");
	
	if(result!=null && result.length > 0){
		travelPodBodyHTML='<div class="">';
		var entryId,tripId,uId,imageSource,entryDate,description,imageTitle,entryTitle,city,country;
		for(var i=0; i<result.length; i++){
			var image = new Array();
			entryId = result[i].id.entryId; 
			tripId = result[i].id.tripId;
			uId = result[i].id.uid;
			imageSource = result[i].imageSource;
			entryDate = result[i].entryDate;
			description = result[i].entryShortDescription;
			imageTitle = result[i].imageTitle;
			entryTitle = result[i].entryTitle;
			city = result[i].city;
			country = result[i].country; 
			image[0]=entryId;
			image[1]=tripId;
			image[2]=uId;
			image[3]=imageSource;
			
	travelPodBodyContentHTML +='<div class="row fs-11" style="padding-top:10px;">'
								+'<table><tr><td><div class="icon" align="left">'
								+'<a href="javascript:getTitleContent('+entryId+',\''+tripId+'\',\''+uId+'\',\''+imageSource+'\');"><img src="'+imageSource+'" alt="'+imageTitle+'" title="'+imageTitle+'" width="75px" height="70px" hspace="2" vspace="2" class="brd-05" /></a>'
								+'</div></td><td></td>&nbsp;<td>'
								+'<div style="width:450px;">'
								+'<q>'+entryDate+' <a href="javascript:getTitleContent('+entryId+',\''+tripId+'\',\''+uId+'\',\''+imageSource+'\');" class="link">'+imageTitle+'</a></q><br />'
								+'<p>By: <a href="javascript:openUserProfileWindow(\''+uId+'\');" class="link">'+uId+'</a> | from a trip to: '+city+', '+country+'</p>'
								+'<p><a href="javascript:openReadExperiences(\''+uId+'\',\''+tripId+'\');" class="link">Read more from this trip</a></p>'
								+'</div></td></tr></table>'
								+'</div>';			
		}
		travelPodBodyContentHTML += '</div'	;
	}
	else{
		TravelpodShowError();
		closeEDpopups();
	}
	setTimeout('HideShowPreviousNextButtons()',3000);	
	travelPodBodyContentObj.innerHTML = travelPodBodyContentHTML;
	travelPodBodyTopObj.style.visibility="visible";
	travelPodBodyBottomObj.style.visibility="visible";
	moveTo();
}
function openUserProfileWindow(userId){
	trackExitLinksHbx("http://www.travelpod.com/");
	var urlUser="http://www.travelpod.com/members/"+userId;
	window.open(urlUser,"Map",'width=900,height=900,left=250,top=100,bottom=50,status=no,resizable=1,scrollbars=1');

}
function openReadExperiences(userId,tripId){
	trackExitLinksHbx("http://www.travelpod.com/");
	var urlReadTrip="http://www.travelpod.com/travel-blog/"+userId+"/"+tripId+"/tpod.html";
	window.open(urlReadTrip,"Map",'width=900,height=900,left=250,top=100,bottom=50,status=no,resizable=1,scrollbars=1');

}


//	Function responsible for Call the getEntry method
//	defined in the TravelPodDWR.js file

function HideShowPreviousNextButtons(){
	
	if (globalimgCount ==0){
		var NextPreviousHTML = '<span id="Previous" style="display:none"><a href="javascript:travelPodPreviousPage();" class="tdnu fc-05"><font face="arial">&#9668;</font></a></span> <span id="Next" style="display:none"><a href="javascript:travelPodNextPage();" class="tdnu fc-05"><font face="arial">&#9658;</font></a></span><br clear="all" />';
		var travelPodBodyTopObj = document.getElementById("TravelPodBodyTop");
    	travelPodBodyTopObj.innerHTML = NextPreviousHTML;
		var travelPodBodyBottomObj = document.getElementById("TravelPodBodyBottom");
    	travelPodBodyBottomObj.innerHTML = NextPreviousHTML;
    	travelPodBodyBottomObj.innerHTML += TravelpodCopyright();
	}
		
	else if(count>20 && count<globalimgCount){

		var NextPreviousHTML = '<span id="Previous"><a href="javascript:travelPodPreviousPage();" class="tdnu fc-05"><font face="arial">&#9668;</font></a></span> <span id="Next"><a href="javascript:travelPodNextPage();" class="tdnu fc-05"><font face="arial">&#9658;</font></a></span><br clear="all" />';
		var travelPodBodyTopObj = document.getElementById("TravelPodBodyTop");
    	travelPodBodyTopObj.innerHTML = NextPreviousHTML;
		var travelPodBodyBottomObj = document.getElementById("TravelPodBodyBottom");
    	travelPodBodyBottomObj.innerHTML = NextPreviousHTML;
    	travelPodBodyBottomObj.innerHTML +=TravelpodCopyright();
    	}
    	else if(count>=globalimgCount){
    	var NextPreviousHTML = '<span id="Previous"><a href="javascript:travelPodPreviousPage();" class="tdnu fc-05"><font face="arial">&#9668;</font></a></span> <span id="Next" style="display:none"><a href="javascript:travelPodNextPage();" class="tdnu fc-05"><font face="arial">&#9658;</font></a></span><br clear="all" />';
		var travelPodBodyTopObj = document.getElementById("TravelPodBodyTop");
    	travelPodBodyTopObj.innerHTML = NextPreviousHTML;
		var travelPodBodyBottomObj = document.getElementById("TravelPodBodyBottom");
    	travelPodBodyBottomObj.innerHTML = NextPreviousHTML;
    	travelPodBodyBottomObj.innerHTML +=TravelpodCopyright();
    	}
    	else if (count<=20){
    	var NextPreviousHTML = '<span id="Previous" style="display:none"><a href="javascript:travelPodPreviousPage();" class="tdnu fc-05"><font face="arial">&#9668;</font></a></span> <span id="Next" ><a href="javascript:travelPodNextPage();" class="tdnu fc-05"><font face="arial">&#9658;</font></a></span><br clear="all" />';
		var travelPodBodyTopObj = document.getElementById("TravelPodBodyTop");
    	travelPodBodyTopObj.innerHTML = NextPreviousHTML;
		var travelPodBodyBottomObj = document.getElementById("TravelPodBodyBottom");
    	travelPodBodyBottomObj.innerHTML = NextPreviousHTML;
    	travelPodBodyBottomObj.innerHTML += TravelpodCopyright();
    	}
 }

//	Function responsible for Call the getEntry method
//	defined in the TravelPodDWR.js file

function getTitleContent(entryId,tripId,uid,imgSource){
trackPageViewsHbx('detail', '/gettingaround/'+travelpodCityCode+'/travelblog'); 
	globalimgSource = imgSource;
	var idEntryId = entryId;
	var idTripId = tripId;
	var idUId = uid;
	DWREngine._execute(dwrURL, 'TravelPodDWR', 'getEntry',idEntryId,idTripId,idUId,loadTravelPodEntry);
}

//	Callback method for load the Entry detals for each entires
//	in the travelpod list of  entires

function loadTravelPodEntry(entryResult){
	if(entryResult==null || entryResult.length==0){
		// error
		return;
	}
	var travelPodBodyObj = document.getElementById("TravelPodBody");
	travelPodBodyObj.style.display='none';
	var travelPodContentObj = document.getElementById("TravelPodEntry");
	travelPodContentObj.style.display='';
	var entry = entryResult.entry;
	var userId=entryResult.id.uid;
	var entryTitle = entryResult.entryTitle;
	entry = entry.replace(/\n/g, '<br />');
	var contentHTML = '';
	contentHTML += '<table border="0" class="fs-11 c-black">'
				+'<tr>'
				+'<td width="75%"><b>'+entryTitle+'</b></td>'
				+'<td width="25%" align="right"><a href="javascript:goBackToTravelPodList();" class="tdnu"><font face="arial">&#9668;</font></a></td>'
				+'</tr>'
				+'<tr>'
				+'<td width="75%"><br />'+entry+'</td>'
				+'<td width="25%" align="right"><br /><img src="'+globalimgSource+'"/></td>'
				+'</tr>'
				+'<tr>'
				+'<td width="75%"><br />By:<b>'+userId+'</b></td>'
				+'<td width="25%" align="right"><br /></td>'
				+'</tr>'
			    +'<td width="75%"><br />'+TravelpodCopyright()+'</td>'   // this diaplays the copy rights information.
				+'</table><br />'				
	travelPodContentObj.innerHTML=contentHTML;
}

//	Function to close the Travelpod
function closeTravelPod(){
	var tpLinkDivObj = document.getElementById("TravelPodLink");
	if(tpLinkDivObj != null){
		tpLinkDivObj.className = '';
		changeSelectedImageIcon('img_TravelpodLink');
	}
	document.getElementById("TravelPod").style.display='none';
	document.getElementById("TravelPodBody").style.display='none';
	document.getElementById("TravelPodBodyTop").innerHTML='';
	document.getElementById("TravelPodBodyContent").innerHTML='';
	document.getElementById("TravelPodBodyBottom").innerHTML='';
	document.getElementById("TravelPodEntry").innerHTML='';		
}

//	Function responsible for switch back to show the list of travelpod entires from entry details
function goBackToTravelPodList(){
	var travelPodContentObj = document.getElementById("TravelPodEntry");
	travelPodContentObj.style.display='none';
	var travelPodBodyObj = document.getElementById("TravelPodBody");
	travelPodBodyObj.style.display='';
}	

//	Function to scroll to the selected travel blog content
function moveTo(){
	var DivToMove= document.getElementById("TravelPod");
	window.scroll(findPosX(DivToMove),findPosY(DivToMove));
}

//	Function used to Hide the Error Massage block for travel blog
function TravelpodHideError(){
	var errorObj = document.getElementById('TravelpoderrorBlock');//errorBlock
	if(errorObj != null){
		errorObj.style.display='none';
		if(globalCalledFor != null && globalCalledFor != ''){
			document.getElementById('errorBlockBackButton').style.display='none';
		}
	}
}

//	Function used to Show the Error Massage block and hide the wait massage block for travel blogs
function TravelpodShowError(){
	exploreDestinationHideWaitMessage();
	var errorObj = document.getElementById('TravelpoderrorBlock');
	if(errorObj != null){
		errorObj.style.display='';
		if(globalCalledFor != null && globalCalledFor != ''){
			document.getElementById('errorBlockBackButton').style.display='';
		}
	}
}

// function to display the travelpodlogo,copright and disclaimer
function TravelpodCopyright(){
	var copyRight =  " <br clear='all'>"
    			 +" <div class='tal fs-09 bgc-04 p-10'>"
    			 +" <a target='_blank' href='http://www.travelpod.com/'><img src='"+contextPath+"/images/travelpod_logo.gif' border='0' alt='Free travel blogs, travel journals, travelogues and travel diaries'></a>"
    			 +" Travel community content is provided in partnership with TravelPod"
    			 +" <div class='pt-10'>"
    			 +" &copy;"+ globalCurrentYear +" TravelPod Inc. All rights reserved.<br />"
    			 +" TravelPod Images. &copy;"+globalCurrentYear+" TravelPod Inc"    									 
    			 +" </div>"
    			 +" <div class='pt-10'>"
    			 +" We and our content providers (\'we\') have tried to make the information" 
    			 +" on this website as accurate as possible, but it is provided \'as is\' and" 
    			 +" we accept no responsibility for any loss, injury or inconvenience sustained by anyone resulting"
    			 +" from this information. You should verify critical information "
    			 +" (like visas, health and safety, customs, and transportation)"
    			 +" with the relevant authorities before you travel."
    			 +" </div>"
    			 +" </div>";
    return copyRight;
}
