// JavaScript Document
function tabSwitch(active, number, tab_prefix, content_prefix) {
	
	for (var i=1; i < number+1; i++) {
	  document.getElementById(content_prefix+i).style.display = 'none';
	  document.getElementById(tab_prefix+i).className = '';
	}
	document.getElementById(content_prefix+active).style.display = 'block';
	document.getElementById(tab_prefix+active).className = 'active';	
	
}

// show hide mainDet content
function show(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='block';
}
function hide(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='none';
}
function showHide(divID) 
{
	document.getElementById(divID).style.display == 'none' ? document.getElementById(divID).style.display = 'block' : document.getElementById(divID).style.display = 'none';
}

// Checks if a field is empty, and if so, resets the input's content to the default value
function checkField( obj, value )
{
	// Match any amount of white spaces
	if( obj.value == "" )
	{
		obj.value = value;
	}
	
	return false;
}

// Clears an input's content
function clearField( obj, value )
{
	if( obj.value == value )
	{
		obj.value = "";
	}
	
	return false;
}

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 = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function reloadWindow()
{
	window.location=window.location;
	
	return;
}

function viewBox(iid)
{
	if (iid.checked) document.getElementById('altaFactura').style.display = 'block';
	else document.getElementById('altaFactura').style.display = 'none';
}

function orderDetail(oid)
{
	tr = document.getElementById(oid);
	if (tr.style.display == 'none') 
	{
		var browser = navigator.appName;
		view = ((browser == 'Netscape') ? 'table-row' : 'block')
		tr.style.display = view;
	}
	else
	{
		tr.style.display = 'none';
	}
}

function confirma(caz,mes,link,stoc)
{
	switch (caz)
	{
		case 'sterge':
			var sterge = confirm(mes);
			if (sterge) window.location = link;
			break;
		case 'adauga':
			if (stoc != null && stoc != 0)
			{
				window.location = link;
			}
			else alert(mes);
			break;
	}
}
