
function activateTab(secao)
{	
	syncTxtSearch({value: ''});
	document.frmHome.searchType.value = secao;
	document.frmHome.navigatorStr.value = '';
	document.frmHome.submit();
}
function syncTxtSearch(txtSearch) {
	document.frmHome.txtSearch.value = txtSearch.value;
}
function setLocation(cityName){
	iVentekCore.setCookie( {'name': 'city', 'value':cityName}, 90 );
}
function setLocationAndSubmit(cityName){
	iVentekCore.setCookie( {'name': 'city', 'value':cityName}, 90 );
	window.location.href = "home.htm";
}
function newLocationSubmit(){
	//document.newLocation.txtSearch.value = document.frmHome.txtSearch.value;
	document.newLocation.txtSearch.value = '';
	document.newLocation.searchType.value = document.frmHome.searchType.value;
	iVentekCore.setCookie( {'name': 'city', 'value': document.getElementById('new-location').value}, 90 );
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	// i am not sure if you can set the cookie set under /portal when you are at /citysearch
	document.cookie = name + "=" + escape(value) + expires + "; path=/portal";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
function getCookie (name) {
	var dc = document.cookie;
	var cname = name + "=";

	if (dc.length > 0) {
	  begin = dc.indexOf(cname);
	  if (begin != -1) {
		begin += cname.length;
		end = dc.indexOf(";", begin);
		if (end == -1) end = dc.length;
		return unescape(dc.substring(begin, end));
		}
	  }
	return null;
}
function addCookie(listing, cookieName) {
	var cookie = getCookie(cookieName);
	var listingList;
	if(cookie == null || cookie.length == 0) {
		listingList = new Array();
	} else {
		listingList = cookie.split("|");
	}
	listingList.unshift(listing);
	
	var i = 1;
	var dupIndex = -1;
	// find duplicate index
	for(i = 1; i < listingList.length; i++) {
		if(listingList[i] == listing) {
			dupIndex = i;
			break;
		}
	}
	if(dupIndex != -1) {
		listingList.splice(dupIndex, 1);
	}
	
	// limit array length to only 10
	listingList = listingList.slice(0, Math.min(listingList.length, 10) );

	createCookie(cookieName,listingList.join("|"), 360);
}
function showHideBoxCityWeather(elem, action) {
	var v_principal = document.getElementById("wrap");
	var v_divWeather = document.getElementById("forecast");
	var v_elem = document.getElementById(elem);
	
	v_elem.style.display = action;			

}
function showHideBox(elem, action, elem1, action1) {
	var v_elem = document.getElementById(elem);
	var v_elem1 = document.getElementById(elem1);
	
	v_elem.style.display = action;
	v_elem1.style.display = action1;
	
}
function popup(p, n, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',scrollbars='+scroll+',top='+wint+',left='+winl+',non-resizable';
	win = window.open(p, n, winprops);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function submitWeather(obj){
	var cityobj = document.getElementById("city");
	if (cityobj.value=="") alert("Please select a city/town");
	else document.weatherForm.submit();	
}

function toprateAddToPlanner( src, id, cid ) {

	iPlanner.add( id, cid );
	src.innerHTML = 'Added';
	src.parentNode.className = "add-planner-added";	
	
}

function listingAddToPlanner( src, id, cid ) {

	iPlanner.add( id, cid );
	src.innerHTML = 'Added';
	src.parentNode.className = "add-planner-added";	
	
}

function plannerRemove( src, id, cid ) {
	
	iPlanner.remove( id, cid );
	src.parentNode.parentNode.parentNode.parentNode.removeChild( src.parentNode.parentNode.parentNode );
	
}
function createBookmarkLink() {
	title = document.title;
	url = location.href;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}

function showPhone(id) {
	document.getElementById(id).style.display='none';
	document.getElementById('show'+id).style.display='block';
}
/* for Agendize */
var newWindow = null;
function openWin (Url, Nom,largeur, hauteur, menu, status, scroll) {
	var win_opt= "left=50,top=50,titlebar=no,";
	if (newWindow != null&& !newWindow.closed)
	{ 
		newWindow.close()
	}
	win_opt += "width=" + largeur + ",height=" + hauteur+ ",menubar = no,resizable=no, status=no, scrollbars=no" ;
	newWindow = window.open('',Nom,win_opt);
	if (newWindow != null) {
		if (newWindow.opener == null)
		{ 
			newWindow.opener = self;
		}
		newWindow.location.href = Url;
		if (newWindow.focus) newWindow.focus();
	}
}
function openFreeCall(id) {
	openWin('http://o1.agendize.com/w1/inserter/box?virtual=true&type=xml&mapping=tdsxml&author=tds&id='+id+'&btype=contact&default=call','default','680','570');
}
function openShareIt(id) {
	openWin('http://o1.agendize.com/w1/inserter/box?virtual=true&type=xml&mapping=tdsxml&author=tds&id='+id+'&btype=contact&medias=email,sms,messengers,blog,online&default=sms','default','680','570');
}
function openAddRating(id) {
	window.open('http://ondemand-1.agendize.com/agendize/webservices/reviews/review?virtual=true&type=xml&mapping=tdsxml&author=tds&btype=contact&id='+id+'&template=reviews&new=true', 'comments', 'resizable=yes,scrollbars=yes,titlebar=no,width=380,height=620');
}
function openViewRating(id) {
	window.open('http://ondemand-1.agendize.com/agendize/webservices/reviews/review?virtual=true&mapping=tdsxml&type=xml&author=tds&btype=contact&template=reviews&id='+id, 'comments', 'resizable=yes,scrollbars=yes,titlebar=no,width=380,height=650');
}
function loadAllRatings(idList) {
	var script = document.createElement('script'); 
	script.type = 'text/javascript'; 
	script.src = 'http://ondemand-1.agendize.com/agendize/web/templates/tds/counts.jsp?virtual=true&mapping=tdsxml&type=xml&author=tds&lang=en&btype=contact&template=reviews&id='+idList; 
	document.getElementsByTagName('head')[0].appendChild(script);
}
/* end for Angendize */

function toggleShowMore( obj ) {
	var Y = YAHOO,
	Dom = Y.util.Dom,
	Event = Y.util.Event;

	var className = 'show-all';
	var oDiv = Dom.getAncestorByTagName(obj, 'div');
	
	if (Dom.hasClass(oDiv, className)) {
		obj.innerHTML = 'More keywords';
		Dom.removeClass(oDiv, className);
	} else {
		obj.innerHTML = 'Top 5 keywords';
		Dom.addClass(oDiv, className);
	}
	
}
