/**
 * aduce valoarea elementului cu id-ul id . se presupune ca exista un asemenea element in documentul curent 
 * si ca i se poate intoarce valoarea
 */
function getValue(id)
{
	return getElem(id).value;
}
/**
 * seteaza valoarea elementului cu id-ul id la valoarea val
 * si ca i se poate intoarce valoarea
 */
function setValue(id, val)
{
	getElem(id).value=val;
}
/**
 * Presupune existenta unui caz foarte specializat dar foarte des intalnit
 * seteaza valoarea elementului cu id-ul action la valoarea val
 */
function setAction(val)
{
	setValue('action',val);
}
/**
 * aduce elementul cu id-ul id . se presupune ca exista un asemenea element in documentul curent 
 */
function getElem(id)
{
	return document.getElementById(id);
}
/**
 * aduce elementul cu id-ul id . se presupune ca exista un asemenea element in documentul ferestrei parinte
 */
function getParentElem(id)
{
	return window.parent.document.getElementById(id);
}
/**
 * aduce elementul cu id-ul id . se presupune ca exista un asemenea element in documentul ferestrei parinte
 */
function getOpenerElem(id)
{
	return window.opener.document.getElementById(id);
}
/**
 * face submit la elementul cu id-ul id . Se presupune ca e vorba de un formular
 */
function doSubmit(id)
{
	getElem(id).submit();
}
/**
 * face elementul cu id-ul id vizibil
 */
function showElem(id)
{
	getElem(id).style.display='block';
}
/**
 * face elementul cu id-ul id invizibil
 */
function hideElem(id)
{
	getElem(id).style.display='none';
}
/**
 * Concateneaza toate bucatile si intre ele baga glue
 * @param String glue
 * @param Array pieces array de stringuri
 * @return String 
 */
function implode(glue,pieces)
{
	var ret=new String();
	
	for (i=0;i<pieces.length;i++)
	{
		if (i>0) ret = ret.concat(glue);
		ret = ret.concat(pieces[i]);
	}
	return ret;
}

/**
 * Sparge stringul in bucati dupa separator si intoarce un array cu bucatile
 * @param String separator
 * @param String stringul de explodat
 * @return Array bucatile rezultate dupa explozie
 */
function explode(separator, string)
{
	var ret=new Array();
	
	//de scris 
	
	return ret;
}
/**
 * arata divul
 */
function showDiv(div_id, display_style)
{
	switch (display_style)
	{
		case 'table-row':
			getElem(div_id).style.display='block';
			try{
				getElem(div_id).style.display='table-row';
			}catch (err){}	
		break;
		default:
			getElem(div_id).style.display='block';
		break;
	}
	
}
/**
 * ascunde divul
 */
function hideDiv(div_id)
{
	getElem(div_id).style.display='none';
}
/**
 * arata divul si incrementeaza newi
 */
function showNewDiv(newi, div_new, limit)
{
	if (getValue(newi)==limit) return true;
	
	setValue(newi, parseInt(getValue(newi))+1);
	showDiv(div_new+getValue(newi),'table-row');
}
/**
 * schimba imaginea pozei img_id, si a hiddenului select_id
 */
function selUnselItem(select_id, imgitem_id)
{
	if (getValue(select_id)==0)//ma duc pe un item neselectat ( deci bifez prima data)
	{
		setValue(select_id,'1');//setez starea
		getElem(imgitem_id).src='images/design/tree/itemsel.gif';//setez poza 
	}
	else //ma duc pe unul selectat ( deci anulez )
	{
		setValue(select_id,'0');//setez starea
		getElem(imgitem_id).src='images/design/tree/item.gif';//setez poza 
	}	
}
function isEmail(str) 
{
	var lastdot = str.lastIndexOf(".");
	var at = str.indexOf("@");
	var lastat = str.lastIndexOf("@");
	
	return (at>0 && at==lastat && lastdot > 2 && lastdot<(str.length-2));
}
/**
 * Trims the leading spaces of a string 
 * @param String thestring
 * @return String trimmed
 */
function ltrim(thestring)
{
	return thestring.replace(/^\s+/,'');
}
/**
 * Trims the ending spaces of a string 
 * @param String thestring
 * @return String trimmed
 */
function rtrim(thestring)
{
	return thestring.replace(/\s+$/,'');
}
/**
 * Trims both the leading and the ending spaces
 * @param String thestring
 * @return String
 */
function trim(thestring)
{
	return ltrim(rtrim(thestring));
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function setOpacity(obj) {
	if(obj.xOpacity>.99) {
		obj.xOpacity = .99;
		return;
	}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}

function fadeImage()
{
	var curelem = getElem('img_'+getValue('cur'));
	var nextelem = getElem('img_'+getValue('next'));
	
	if (imgelem.xOpacity <= 0) return;
	imgelem.xOpacity -= 0.1;
	setOpacity(imgelem);
	
	setTimeout(fadeImage, 500);	
}
function startFading(nr)
{
	for (i=1;i<nr;i++)
	{
		setValue('cur')=i;
		setValue('next')=i+1;
	}
}
