/**
 * general.js
 *
 * Copyright (c) 2004-2008 VTeX EJMS
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * Site-wide common JavaScript functions. 
 *
 * $Id$
 */

/**
 * Prompt user for confirmation prior to loading a URL.
 */
function confirmAction(url, msg) {
	if (url && msg && confirm(msg)) {
		document.location.href=url;
	}
	return false;
}
function newWindow( url, title ){
	window.open(
		url,
		'myNewWindow',
		'dependent,directories=0,menubar=1,width=700,height=500,resizable,scrollbars,toolbar=0'
	);
}
/**
 *
 * opens/closes block of given Id and
 * shows/hides open/close sign "[+]/[-]" iddentified by 
 * given Id plus suffix "_open/_close"
 *
 */
function showHideById(id) {

	var elem, elemOpen, elemClose;
	if (elem = document.getElementById(id)) {
		
		className = elem.className;
	} else {
		return(0);
	}

	elemClose = document.getElementById(id + "_close");
	elemOpen = document.getElementById(id + "_open");

	if ( className.indexOf('hide') > -1) {
		elem.className = className.replace('hide','show');

		if (elemClose) {
			elemClose.className = elemClose.className.replace('hide','show');
		}
		if (elemOpen) {
			elemOpen.className = elemOpen.className.replace('show', ' hide ');
		}
	} else {
		elem.className = elem.className.replace('show',' hide ');

		if (elemClose) {
			elemClose.className = elemClose.className.replace('show',' hide ');
		}
		if (elemOpen) {
			elemOpen.className = elemOpen.className.replace('hide', ' show ');
		}
	}
}
function hideById(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).className = 'hide';
	}
}
function showById(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).className = 'show';
	}
}

/**
 * expands/shrinks block element with a given Id
 *
 * @param id ID of element 
 *
 */
function expandShrinkById(id) {

	var el = document.getElementById(id);
	var el_l = document.getElementById(id + "-line");
	var el_f = document.getElementById(id + "-full");

	if (! ( el && el_l && el_f) ) {
		return(0);
	}

	if ( el.className.indexOf('partView') > -1 ) {
		el.className = el.className.replace('partView', 'fullView');
		show_el = el_f;
		hide_el = el_l;
	} else {
		el.className = el.className.replace('fullView', 'partView');
		show_el = el_l;
		hide_el = el_f;
	}

	hide_el.className = hide_el.className.replace('show', 'hide');
	show_el.className = show_el.className.replace('hide', 'show');
}

/** 
 * From group of tabs shows selected and hide others
 * @param activeTabNo tab's to show No
 * @param numberOfTabes how many tabs
 * @param tabsIdPrefix prefix of tab's IDs
 */

function showOneTabHideOthers( activeTabNo, numberOfTabs, tabsIdPrefix){
	for ( i=1; i<=numberOfTabs; i++){

		tab = document.getElementById(tabsIdPrefix+i);
		if (!tab) continue;

		if ( i == activeTabNo ){
			tab.className = 'show';
		}else{
			tab.className = 'hide';
		}
	}
}

/**
 * Redirects to url
 * @param url 
 */
function go2(url){
	if (url) document.location.href=url;
}

/**
 * Clear value of form's field
 * @param id fields ID
 */
function clearValue(fieldId){
	f = document.getElementById(fieldId);
	if (f){
		f.value=null;
		f.focus();
	}
}

