/* top menu */

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; 
	}
}


/* home search tab */

function homeActivateTab(searchIn, submit) {
	
	// update tab outline coloring
	tab = document.getElementById('li' + searchIn);
	var tabs = tab.parentNode.getElementsByTagName('li');

	for (var i = 0; i < tabs.length; i++) {
		if (tabs[i] == tab)
			tabs[i].className = 'liActive';
		else
			tabs[i].className = '';
	}
	document.frmSearch.searchIn.value = searchIn;
	
	var minlength = 2;
	var blank = '[Enter your search term here]';
	if ( document.frmSearch.searchWhat.value == blank )
		document.frmSearch.searchWhat.value = '';
	
	if ( document.frmSearch.searchWhat.value.length < minlength ) {
		if ( searchIn == 'News' ) {
			submit = true;
		}
		else if ( searchIn == 'Blogs' ) {
			submit = true;
		}
		else { // ALL, Wiki, Bizz, People, City 
			document.frmSearch.searchWhat.value = '[Enter your search term here]';
			document.frmSearch.searchWhat.className = 'grey';
		}
	}
	else {
		submit = true;
	}
	
	if (submit)
		document.getElementById('frmSearch').submit();
}

function homeTxtBoxClicked() {
	var obj = document.frmSearch.searchWhat;
	obj.className = '';
	obj.value = '';
}

function homeTxtBoxBlurred() {
	var obj = document.frmSearch.searchWhat;
	if ( obj.value.length == 0 ) {
		document.frmSearch.searchWhat.value = '[Enter your search term here]';
		document.frmSearch.searchWhat.className = 'grey';
	}
}

/* home skins */

function skinSelectContent(index) {
	if(index == null || index == -1) {
		index = iPortal._getCookie('skinIndex');
		if(index == null) 
			index = 0;
	}
	document.getElementById("divSkin").className = "skin" + index
	skinHideList();
	
	cookies = new Array();
	cookies.push( { name: 'skinIndex', value: index } );
	iPortal._setCookie( cookies, 90 );
}

function skinShowList() {
	document.getElementById('divListSkins').style.display='block';
}

function skinHideList() {
	document.getElementById('divListSkins').style.display='none';
}

/* Refine your search functions */

function refineToggleShowMore( src, objid ) {
	var domObj = document.getElementById( objid );
	var domLis = domObj.getElementsByTagName('li');
	var show;
	
	if (src.innerHTML.search('More') == 0) {
		src.innerHTML = src.innerHTML.replace(/More/, 'Top 5');
		show = 'block';
	}
	else {
		src.innerHTML = src.innerHTML.replace(/Top 5/, 'More');
		show = 'none';
	}

	for (var i = 0; i < domLis.length; i++) {
		var domLi = domLis[i];
		if ( domLi.className == 'noTopX' ) {
			domLi.style.display = show;
		}
	}

	return false;
}


/* result page search tab */
function searchActivateTab(searchIn, submit) {
	tab = document.getElementById('li' + searchIn);
	var tabs = tab.parentNode.getElementsByTagName('li');
	
	for (var i = 0; i < tabs.length; i++) {
		if (tabs[i] == tab)
			tabs[i].className = 'liActive';
		else
			tabs[i].className = '';
	}
	
	document.frmSearch.searchIn.value = searchIn;
	if (submit)
		document.frmSearch.submit();
}


/* bizz/people search page functions */
function openPopUp(subscriberid, customerid) {
	w = 788;
	h = 600;
	x = (screen.width - w) / 2;
	y = (screen.height - h) / 2;
	h =window.open(
			"http://www.yellowpages.co.za/subscriber.jsp?id="+subscriberid+"&cid="+customerid,
			"subscriber"+subscriberid,
			"toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+",left="+x+",top="+y);
	//h.moveTo((screen.width-788)/2,(screen.height-600)/2);
}
function clickSaveBizz(link, item) {
	link.innerHTML = 'On "My Bizz Search"';
	link.parentNode.className = "myfavClick";
	appendSavedService(item, 'ssrbizz');
}
function clickSavePeople(link, item) {
	link.innerHTML = 'On "My People Search"';
	link.parentNode.className = "myfavClick";
	appendSavedService(item, 'ssrpeople');
}
function appendSavedService(item, service) {
	var cookie = iPortal._getCookie(service);
	var listingList;
	if(cookie == null || cookie.length == 0) {
		listingList = new Array();
	} else {
		listingList = cookie.split("|");
	}
	listingList.unshift(item);
	
	var i = 1;
	var dupIndex = -1;
	
	// find duplicate index
	for(i = 1; i < listingList.length; i++) {
		if(listingList[i] == item) {
			dupIndex = i;
			break;
		}
	}
	if(dupIndex != -1) {
		listingList.splice(dupIndex, 1);
	}
	
	// limit array length to only 10
	listingList = listingList.slice(0, Math.min(listingList.length, 7) );

	cookies = new Array();
	cookies.push( { name: service, value: listingList.join("|") } );
	iPortal._setCookie( cookies, 360 );
}

