/**
 * 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);
}
/**
 * Presupune existenta unui caz foarte specializat dar foarte des intalnit
 * seteaza valoarea elementului cu id-ul action la valoarea val
 */
function setAction2(val)
{
	setValue('action2',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();
}

/**
 * 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 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;
		case 'inline':
			getElem(elem_id).style.display='inline';
		break;		
		default:
			getElem(elem_id).style.display='block';
		break;
	}
	
}
/**
 * ascunde divul
 */
function hideElem(elem_id)
{
	getElem(elem_id).style.display='none';
}
/**
 * 
 */
function isElemHidden(elem_id)
{
	return getElem(elem_id).style.display=='none';
}
function showHideElem(elem_id, display_style)
{
	if (isElemHidden(elem_id)) showElem(elem_id, display_style);
	else hideElem(elem_id);	
}
function showHideRootCat(id_category)
{
	showHideElem('rootcat_body_'+id_category);
	showHideElem('rootcat_footer_'+id_category);
	if (isElemHidden('rootcat_body_'+id_category))
	{
		getElem('rootcat_showhide_'+id_category).innerHTML = 'View all';
		getElem('rootcat_'+id_category).className = 'rootcat';
	}
	else
	{
		getElem('rootcat_showhide_'+id_category).innerHTML = 'Close';
		getElem('rootcat_'+id_category).className = 'rootcat_open';
	}
}
/**
 * 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.html';//setez poza 
	}
	else //ma duc pe unul selectat ( deci anulez )
	{
		setValue(select_id,'0');//setez starea
		getElem(imgitem_id).src='images/design/tree/item.html';//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 updateDiv(sDiv_id, sUrl, sMethod)
{
	var method = sMethod;
	if (method==null) method = 'GET';
	var div = getElem(sDiv_id);

	
	var handleSuccess = function(o){
		if(o.responseText !== undefined){
			div.innerHTML = o.responseText;
		}
	}
	
	var handleFailure = function(o){
		if(o.responseText !== undefined){
			div.innerHTML = "Ajax error";
		}
	}
	
	var handleUpload = function(o){
		if(o.responseText !== undefined){
			div.innerHTML = o.responseText;
		}
	}
	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure,
	  upload: handleUpload
	};
	var request = YAHOO.util.Connect.asyncRequest(method, sUrl, callback); 
}
function toggleTextareaHeight(elem, h1, h2)
{
	if (elem.style.height==(''+h1+'px')) elem.style.height = ''+h2+'px';
	else if (elem.style.height==(''+h2+'px')) elem.style.height = ''+h1+'px';
}
function inject(aElem, url)
{
	var text = aElem.innerHTML;
	if (text.indexOf('span')==-1)
	{
		aElem.innerHTML = aElem.innerHTML + '<span><img src="'+url+'"></span>';
	}
}
function hoout(url)
{
	
}
function wait()
{
	
}
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
var pt_popups = new Array();
function pt_popup(username, password, remove_header)
{
	winname = 'exercises_'+username;
	url = 'https://www.physiotec.org/?do=login';
	url = CLIENTMAIN_URL+'exercises.php';
	
	url += '?username='+username;
	url += '&password='+password;
	if (remove_header!=null) url += '&remove_header='+remove_header;
//	alert(url);
	pt_popups.push(window.open(url, winname, 'width=1000, height=700, left=0, top=0, resizable=no, status=yes, toolbar=no, menubar=no, location=no, scrollbars=yes', winname));
	pt_popups[pt_popups.length-1].focus();
}
