//Programming by Voica Adrian Lucian;
//--------------------------------------------------------------------------------------------------------
function jsTrim (pstring)
{
	return pstring.replace(/(^\s*)|(\s*$)/g,'');
}
//--------------------------------------------------------------------------------------------------------
function jsTrim3 (pstring)
{
	newstring = pstring.replace(/(^\s*)|(\s*$)/g,'');
	if (newstring.match(/[a-zA-Z0-9]{3}/))
	return newstring;
	return "";
}
//--------------------------------------------------------------------------------------------------------
function jsTrimTitle (pstring)
{
	newstring = pstring.replace(/(^\s*)|(\s*$)/g,'');
	if (newstring.match(/[a-zA-Z0-9\s]{10}/))
	return newstring;
	return "";
}
//--------------------------------------------------------------------------------------------------------
function jsTrimDescription (pstring)
{
	newstring = pstring.replace(/(^\s*)|(\s*$)/g,'');
	if (newstring.match(/[a-zA-Z0-9\s]{25}/))
	return newstring;
	return "";
}
//--------------------------------------------------------------------------------------------------------
var ajaxGlobalServerFile = "include/preverify.php";
var ajaxXmlHttp = null;
var ajaxReceiverObjectId = null;
var ajaxIsWorking = 0;
var globalError = 0;
//--------------------------------------------------------------------------------------------------------
function ajaxExec(ajaxServerFile, ajaxRequestString, ajaxResultReceiver)
{
	if (ajaxIsWorking == 1) return;
	if (ajaxRequestString.length == 0) { document.getElementById(ajaxResultReceiver).innerHTML=""; return; }
	ajaxXmlHttp = GetXmlHttpObject(); if (ajaxXmlHttp == null) return;
	if (ajaxServerFile == "") ajaxServerFile = ajaxGlobalServerFile;
	ajaxReceiverObjectId = ajaxResultReceiver;
	ajaxReceiverObjectId.innerHTML = "";
	var url = ajaxServerFile;
	url = url + "?sid=" + Math.random();
	url = url + ajaxRequestString;
	ajaxXmlHttp.open("GET", url, true);
	ajaxXmlHttp.onreadystatechange = function() { if (ajaxXmlHttp.readyState == 4) { document.getElementById(ajaxReceiverObjectId).innerHTML = ajaxXmlHttp.responseText; ajaxIsWorking = 0; } }
	ajaxXmlHttp.send(null);
}
//--------------------------------------------------------------------------------------------------------
function GetXmlHttpObject()
{
	var axmlHttp=null;
	try { axmlHttp = new XMLHttpRequest(); }
	catch (e) { axmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	return axmlHttp;
}
//--------------------------------------------------------------------------------------------------------
var old_content = "";
var arr_old_content = new Array();
//----------------------------------------------------------------------------------------------------
function afiseaza_termeni_si_conditii()
{
	var o = null;
	o = document.getElementById("signupbox");
	if (!o) return;
	old_content = o.innerHTML;
	arr_old_content[0] = document.getElementById("utilizator_utilizator").value;
	arr_old_content[1] = document.getElementById("parola_utilizator").value;
	arr_old_content[2] = document.getElementById("verificare_parola_utilizator").value;
	arr_old_content[3] = document.getElementById("email_utilizator").value;
	arr_old_content[4] = document.getElementById("telefon1_utilizator").value;
	arr_old_content[5] = document.getElementById("telefon2_utilizator").value;
	arr_old_content[6] = document.getElementById("telefon3_utilizator").value;
	arr_old_content[7] = document.getElementById("societate_utilizator").value;
	arr_old_content[8] = document.getElementById("cod_verificare").value;
	arr_old_content[9] = document.getElementById("de_acord").checked;
	arr_old_content[10] = document.getElementById("email_public").checked;
	o.innerHTML = "";
	o.innerHTML = new_content;
}
//----------------------------------------------------------------------------------------------------
function ascunde_termeni_si_conditii()
{
	var o = null;
	o = document.getElementById("signupbox");
	if (!o) return;
	o.innerHTML = "";
	o.innerHTML = old_content;
	document.getElementById("utilizator_utilizator").value = arr_old_content[0];
	document.getElementById("parola_utilizator").value = arr_old_content[1];
	document.getElementById("verificare_parola_utilizator").value = arr_old_content[2];
	document.getElementById("email_utilizator").value = arr_old_content[3];
	document.getElementById("telefon1_utilizator").value = arr_old_content[4];
	document.getElementById("telefon2_utilizator").value = arr_old_content[5];
	document.getElementById("telefon3_utilizator").value = arr_old_content[6];
	document.getElementById("societate_utilizator").value = arr_old_content[7];
	document.getElementById("cod_verificare").value = arr_old_content[8];
	document.getElementById("de_acord").checked = arr_old_content[9];
	document.getElementById("email_public").checked = arr_old_content[10];
}
//----------------------------------------------------------------------------------------------------
function bookmark(url, title)
{
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return; }
}
//-------------------------------------------------------------------------------------------------------
function send_comment()
{
	var o = null;
	o = document.getElementById("ta-comentariu");
	if (!o)
		return false;
	if (o.value == "")
		return showError("comment-err-div", "Nu puteti trimite un comentariu gol!");
	return true;
}
//-------------------------------------------------------------------------------------------------------
function set_stars(stars, img_root)
{
	if (stars == "") stars = 0;
	if (stars == 0)
	{
		for (i=1; i<6; i++)
		{
			var o = null;
			o = document.getElementById("im" + i.toString());
			if (!o) return;
			o.src = img_root + 'star_off.gif';
		}
		document.getElementById("vot").value = stars;
	}
	else
	{
		if (stars > 5) stars = 5;
		for (i=1; i<6; i++)
		{
			var o = null;
			o = document.getElementById("im" + i.toString());
			if (!o) return;
			if (i <= stars)
				o.src = img_root + 'star.gif';
			else
				o.src = img_root + 'star_off.gif';
		}
		document.getElementById("vot").value = stars;
		switch (stars)
		{
			case 1 : showError("info-vote-div", "Slab"); break;
			case 2 : showError("info-vote-div", "Nimic special"); break;
			case 3 : showError("info-vote-div", "Merita vazut"); break;
			case 4 : showError("info-vote-div", "Interesant!"); break;
			case 5 : showError("info-vote-div", "Excelent!"); break;
		}
	}
	return true;
}
//-------------------------------------------------------------------------------------------------------
var toolTipPos = {x:0, y:0};
var toolTipLast = null;
//-------------------------------------------------------------------------------------------------------
function getPosition(e) 
{
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) 
    {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else 
    {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    toolTipPos = cursor;
}
//-------------------------------------------------------------------------------------------------------
function showTip(ts, evt)
{  
    var o = document.getElementById('ToolTip');
    //if ((o) && (evt.srcElement == toolTipLast)) return false;        
    //else 
    if (!o)
    {
        var o = document.createElement('div');
        o.setAttribute("id", "ToolTip");
        o.style.visibility = "hidden";
        o.style.position = "absolute";
        o.style.zIndex = 99;
        o.style.left = "0px";
        o.style.top = "0px";
        o.style.border = "Solid 1px #969696";
        o.style.padding = "2px";
        o.style.backgroundColor = "#FFFFFF";
        o.innerHTML = "";
        document.body.appendChild(o);
    }
    
    if (ts == "")
    {
        o.style.visibility = "hidden";
        o.style.left = "0px";
        o.style.top = "0px";   
        toolTipLast = null;
    }
    else
    {
        getPosition(evt);
        o.style.left = (parseInt(toolTipPos.x) + 10) + "px";
        o.style.top = toolTipPos.y + "px";
        o.style.visibility = "visible";
        o.innerHTML = ts; // + "<br /><div style='position: relative; float: right; font-size: 9px;'></div>";
        toolTipLast = evt.srcElement;
    }
    return true;
}
//-------------------------------------------------------------------------------------------------------
