/**
 * 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)
{
//	alert(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();
}
/**
 * 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, thestring)
{
	var ret=new Array();
	
	i=0;
	while (true)
	{
		i++;
		start=0;
		end = thestring.indexOf(separator);
		
		if (end==-1)
		{
			if (thestring.length >0 ) ret.push(thestring);
			break;
		}
		//alert('siru '+thestring.substr(start, end));
		aux = thestring.substr(start, end);
		if (aux.length>0) ret.push(aux);
		thestring = thestring.substr(end+separator.length);
	}
	
	return ret;
}
function in_array(needle, haystack)
{
	for (i=0;i<haystack.length;i++)
	{
		if (haystack[i]==needle) return true;
	}
	return false;
}
function array_search(needle, haystack)
{
	for (i=0;i<haystack.length;i++)
	{
		if (haystack[i]==needle) return i;
	}
	return -1;
}
/**
 * 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));
}
/**
 * arata divul
 */
function showElem(elem_id, display_style)
{
	switch (display_style)
	{
		case 'table-row':
			getElem(elem_id).style.display='block';
			try{
				getElem(elem_id).style.display='table-row';
			}catch (err){}	
		break;
		default:
			getElem(elem_id).style.display='block';
		break;
	}
	
}
/**
 * ascunde divul
 */
function hideElem(elem_id)
{
	getElem(elem_id).style.display='none';
}
/**
 * checks if there is an element with elemID
 * @return boolean  
 */
function elemExists(elemID)
{
	if (getElem(elemID)==null) return false;
	return true;
}
function isEmail(str) {

   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}
