
	<!-- Frame Breaker ( should keep those pesky frames away from us -->
	if (window != top) top.location.href = location.href;

	/**
	 * perform Search
	 */
	function Search(type)
	{
		document.getElementById("type").value = type;
		document.getElementById("search").submit();
	}


	function updateStates()
	{
		if (document.getElementById("country").value == 238)
		{
			var newrequest = new AW.HTTP.Request;
			newrequest.setURL("fields.php");

			newrequest.setRequestMethod("POST");
			newrequest.setParameter("id", document.getElementById("country").value);
			newrequest.setParameter("field",'states');

			newrequest.request();

			var doc="NORESPONSE";
			newrequest.response = function(doc)
			{
				document.getElementById("state_holder").innerHTML = doc;
			}
		}
		else
		{
			document.getElementById("state_holder").innerHTML = '<input type="text" class="inp_1" name="state" id="state" value="" />';
			document.getElementById("city_holder").innerHTML = '<input type="text" class="inp_1" name="city" id="city" value="" />';
			document.getElementById("zipcode_holder").innerHTML = '<input type="text" class="inp_1" name="zip" id="zip" value="" />';
		}
	}

	function updateCities()
	{
		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("fields.php");

		newrequest.setRequestMethod("POST");
		newrequest.setParameter("id", document.getElementById("state").value);
		newrequest.setParameter("field",'cities');

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			document.getElementById("city_holder").innerHTML = doc;
			updateZipCodes();
		}
	}

	function updateZipCodes()
	{
		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("fields.php");

		newrequest.setRequestMethod("POST");
		newrequest.setParameter("id", document.getElementById("city").value);
		newrequest.setParameter("field",'zipcode');

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			document.getElementById("zipcode_holder").innerHTML = doc;
			if (!document.getElementById("zip").options.length)
				document.getElementById("zipcode_holder").innerHTML = '<input type="text" class="inp_1" name="zip" id="zip" value="" />';
		}
	}


	function checkValid(id, msg, rule)
	{
		var prefix = "* ";
		var suffix = "\n";

		if (!document.getElementById(id))
			return "";

		switch(rule)
		{
			case 'required':
							if (document.getElementById(id).value=="")
								return prefix+msg+suffix;
					break;
			case 'select':
							if (document.getElementById(id).options[document.getElementById(id).selectedIndex].value=="")
								return prefix+msg+suffix;
					break;
			case 'numeric':
							var validch = "0123456789.";
							var isNumber=true;
							var ch;
							var val = document.getElementById(id).value;

							for (i=0; i<val.length && isNumber == true; i++)
							{
								ch = val.charAt(i);
								if (validch.indexOf(ch) == -1)
									return prefix+msg+suffix;
							}
					break;
			case 'email':
							var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
							if (!filter.test(document.getElementById(id).value.replace(new RegExp("[\\s]+$", "g"), "")))
								return prefix+msg+suffix;
					break;
			case 'integer':
							var filter=/^\d{0,9}$/;
							if (!filter.test(document.getElementById(id).value))
								return prefix+msg+suffix;
					break;
			case 'limitpercent':
							if (document.getElementById(id).value<0 || document.getElementById(id).value>100)
								return prefix+msg+suffix;
					break;
			case 'limitpercentrate':
							if (document.getElementById(id).value<6 || document.getElementById(id).value>60)
								return prefix+msg+suffix;
					break;
		}
		return "";
	}

	function checkIdentical(id1, id2, msg)
	{
		var prefix = "* ";
		var suffix = "\n";

		if (document.getElementById(id1).value != document.getElementById(id2).value)
			return prefix+msg+suffix
		else
			return ''
	}

	function checkLength(id, min, max, msg)
	{
		var prefix = "* ";
		var suffix = "\n";

		if (document.getElementById(id).value.length < min || document.getElementById(id).value.length > max )
			return prefix+msg+suffix
		else
			return ''
	}

	function checkRadio(id,msg)
	{

		var radio_choice = false;
		var prefix = "* ";
		var suffix = "\n";
		radio_obj = document.getElementById(id);

		if (radio_obj.checked)
		{
			radio_choice = true;
		} else
		{
			for (counter = 0; counter < radio_obj.length; counter++)
			{

				if (radio_obj[counter].checked)
				{
					radio_choice = true;
					break;
				}
			}
		}

		if (!radio_choice) {
			return prefix+msg+suffix;
		}
		    return '';
	}

	function checkCheckbox(id,msg)
	{
		var prefix = "* ";
		var suffix = "\n";

		checkbox_obj = document.getElementById(id);

		if (!checkbox_obj.checked) {
			return prefix+msg+suffix;
		}
		    return '';
	}

	function verifyForm(which)
	{
		msg_alert = "______________________________________________________\n\n"
		msg_alert += "Cererea dvs. nu a fost indeplinita din motivele de mai jos.\n";
		msg_alert += "Va rugam corectati erorile si incercati din nou:\n";
		msg_alert += "______________________________________________________\n";
		msg_alert += "\n";
		switch(which)
		{
			case "register":
						msg = "";
						msg += checkValid("username_new", "Trebuie sa introduceti numele asociat contului!", "required");
						msg += checkLength("username_new", 4, 30, "Numele de utilizator trebuie sa aiba cel putin 4 caractere.");
						msg += checkValid("password_new", "Trebuie sa specificati o parola.", "required");
						msg += checkLength("password_new", 5, 16, "Trebuie sa specificati o parola cu o lungime intre 5 si 16 caractere!");
						msg += checkValid("newpassword", "Trebuie sa confirmati parola noua.", "required");
						msg += checkIdentical("password_new","newpassword", "Parolele nu sunt identice.");
						msg += checkValid("email", "Trebuie sa specificati o adresa de e-mail corecta.", "email");
						msg += checkCheckbox("tos","Trebuie sa fiti de acord cu termenii si conditiile de confidentialitate.");
						msg += checkValid("code", "Trebuie sa completati codul de protectie.", "required");
					break;
			case "my_details":
						msg = "";
						msg += checkValid("firstname", "Trebuie sa specificati prenumele dvs.", "required");
						msg += checkValid("lastname", "Trebuie sa specificati numele dvs.", "required");
						msg += checkValid("address", "Trebuie sa specificati adresa dvs.", "required");
						msg += checkValid("country", "Trebuie sa specificati tara dvs.", "select");
						if (document.getElementById('country').value == 238)
						{
							msg += checkValid("state", "Trebuie sa specificati judetul dvs.", "select");
							msg += checkValid("city", "Trebuie sa specificati orasul dvs", "select");
						}
						else
						{
							msg += checkValid("state", "Trebuie sa specificati judetul dvs.", "required");
							msg += checkValid("city", "Trebuie sa specificati orasul dvs", "required");
						}
						msg += checkValid("phone", "Trebuie sa specificati telefonul dvs.", "required");
					break;
			case "company":
						msg = "";
						msg += checkValid("organisation", "Trebuie sa specificati numele firmei ", "required");
						msg += checkValid("cui", "Trebuie sa specificati codul fiscal", "required");
						msg += checkValid("bank", "Trebuie sa specificati banca", "required");
						msg += checkValid("iban", "Trebuie sa specificati contul bancii", "required");
						msg += checkValid("nreg", "Trebuie sa specificati numarul de la registru comertului", "required");
						msg += checkValid("address", "Trebuie sa specificati adresa dvs.", "required");
						msg += checkValid("country", "Trebuie sa specificati tara dvs.", "select");
						if (document.getElementById('country').value == 238)
						{
							msg += checkValid("state", "Trebuie sa specificati judetul dvs.", "select");
							msg += checkValid("city", "Trebuie sa specificati orasul dvs", "select");
						}
						else
						{
							msg += checkValid("state", "Trebuie sa specificati judetul dvs.", "required");
							msg += checkValid("city", "Trebuie sa specificati orasul dvs", "required");
						}

						msg += checkValid("phone", "Trebuie sa specificati telefonul dvs.", "required");
					break;
			case "add_address":
						msg = "";
						msg += checkValid("address", "Trebuie sa specificati adresa dvs.", "required");
						msg += checkValid("country", "Trebuie sa specificati tara dvs.", "select");
						if (document.getElementById('country').value == 238)
						{
							msg += checkValid("state", "Trebuie sa specificati judetul dvs.", "select");
							msg += checkValid("city", "Trebuie sa specificati orasul dvs", "select");
						}
						else
						{
							msg += checkValid("state", "Trebuie sa specificati judetul dvs.", "required");
							msg += checkValid("city", "Trebuie sa specificati orasul dvs", "required");
						}
						msg += checkValid("phone", "Trebuie sa specificati telefonul dvs.", "required");
					break;
			case "modifica_parola":
						msg = "";
						msg += checkValid("pass", "Trebuie sa specificati parola actuala.", "required");
						msg += checkValid("newpass", "Trebuie sa specificati parola noua.", "required");
						msg += checkLength("newpass", 5, 16, "Trebuie sa specificati o parola cu o lungime intre 5 si 16 caractere!");
						msg += checkValid("confirm", "Trebuie sa confirmati parola noua.", "required");
						msg += checkIdentical("newpass","confirm", "Parolele nu sunt identice.");
					break;
			case "modifica_email":
						msg = "";
						msg += checkValid("newmail", "Trebuie sa specificati noua adresa de e-mail.", "required");
						msg += checkValid("newmail", "Trebuie sa specificati o adresa de e-mail corecta.", "email");
						msg += checkValid("confirm", "Trebuie sa confirmati noua adresa de e-mail.", "email");
						msg += checkIdentical("newmail","confirm", "Adresele de e-mail furnizate nu sunt identice.");
					break;
			case "pass_recovery":
						msg = "";
						msg += checkValid("recoverymail", "Trebuie sa specificati noua adresa de e-mail.", "required");
						msg += checkValid("recoverymail", "Trebuie sa specificati o adresa de e-mail corecta.", "email");
					break;
			case "contact":
						msg = "";
						msg += checkValid("name", "Trebuie sa specificati numele dvs.", "required");
						msg += checkValid("email", "Trebuie sa specificati o adresa de e-mail corecta.", "email");
						msg += checkValid("subject", "Trebuie sa completati un subiect", "required");
						msg += checkValid("message", "Trebuie sa completati un mesaj", "required");
					break;
		}
		if (msg != "")
		{
			alert(msg_alert+msg);
			return false;
		}
		return true;
	}


	function updateMyInfo()
	{
		if (verifyForm('my_details'))
		{
			document.getElementById('register').submit();
		}
	}

	function verifyContactMail()
	{
		if (verifyForm('contact'))
		{
			document.getElementById('sendmail').submit();
		}
	}

	function veriEmailChange()
	{
		if (verifyForm('modifica_email'))
		{
			document.getElementById('register').submit();
		}
	}

	function veriPassRecovery()
	{
		if (verifyForm('pass_recovery'))
		{
			document.getElementById('recovery').submit();
		}
	}

	function veriPassChange()
	{
		if (verifyForm('modifica_parola'))
		{
			document.getElementById('register').submit();
		}
	}

	function veriAddAddress()
	{
		if (verifyForm('add_address'))
		{
			document.getElementById('register').submit();
		}
	}

	function veriAddCompany()
	{
		if (verifyForm('company'))
		{
			document.getElementById('register').submit();
		}
	}

	function veriRegister()
	{
		if (verifyForm('register'))
		{
			document.getElementById('register').submit();
		}
	}

	function deleteAddress(id)
	{
		if (confirm("Sunteti sigur că doriti să ștergeţi această adresă?"))
		{
			document.getElementById('delete_addr').value=id;
			document.getElementById('register').submit();
		}
	}

	function deleteCompany(id)
	{
		if (confirm("Sunteti sigur că doriti să ștergeţi această firmă?"))
		{
			document.getElementById('delete_company').value=id;
			document.getElementById('register').submit();
		}
	}

	function selectBilling(id)
	{
		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("fields.php");

		newrequest.setRequestMethod("POST");
		newrequest.setParameter("id", id);
		newrequest.setParameter("field",'billing');

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			document.getElementById("billing").innerHTML = doc;
		}
	}

	function selectDeliveryType(id)
	{
		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("fields.php");

		newrequest.setRequestMethod("POST");
		newrequest.setParameter("same", id);
		newrequest.setParameter("id", 0);
		newrequest.setParameter("field",'delivery');

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			document.getElementById("delivery").innerHTML = doc;
		}
	}

	function selectDelivery(id)
	{
		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("fields.php");

		newrequest.setRequestMethod("POST");
		newrequest.setParameter("id", id);
		newrequest.setParameter("field",'delivery');

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			document.getElementById("delivery").innerHTML = doc;
		}
	}

	function saveDelivery(id)
	{
		var choice = document.getElementById(id).value;

		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("fields.php");

		newrequest.setRequestMethod("POST");

		newrequest.setParameter("id", choice);
		newrequest.setParameter("product", id);
		newrequest.setParameter("field",'delivery');

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			//alert("saved");
		}
	}

	function savePaymentMethod(id)
	{
		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("fields.php");

		newrequest.setRequestMethod("POST");

		newrequest.setParameter("id", id);
		newrequest.setParameter("field",'method');

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			document.getElementById("total").innerHTML = doc;
		}
	}

	function saveObservations()
	{

		var seria = document.getElementById("serie_buletin").value;
		var numar = document.getElementById("numar_buletin").value;
		var observations = document.getElementById("obs").value;

		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("fields.php");

		newrequest.setRequestMethod("POST");

		newrequest.setParameter("id", 0);
		newrequest.setParameter("field",'observations');
		newrequest.setParameter("bi_sr",seria);
		newrequest.setParameter("bi_nr",numar);
		newrequest.setParameter("obs",observations);

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			//alert("saved");
		}
	}

    //helper function to create the form
    function getNewSubmitForm()
    {
        var submitForm = document.createElement("FORM");
        document.body.appendChild(submitForm);
        submitForm.method = "POST";
        return submitForm;
    }

    //helper function to add elements to the form
    function createNewFormElement(inputForm, elementName, elementValue)
    {
        var newElement = document.createElement("input");
        newElement.name = elementName;
        newElement.type = "hidden";
        inputForm.appendChild(newElement);
        newElement.value = elementValue;
        return newElement;
    }

    function checkCode()
    {
		var newrequest = new AW.HTTP.Request;
        newrequest.setURL("fields.php");
        newrequest.setRequestMethod("POST");
        var code = document.getElementById('codsms').value;
        newrequest.setParameter("id", 0);
        newrequest.setParameter("field",'code');
        newrequest.setParameter("code", code);
		newrequest.request();
		var doc="NORESPONSE";
        newrequest.response = function(doc)
        {
        	doc = doc.split("|");
        	code = doc[0];
			if (code == 'ok')
			{
				alert('Felicitari! Contul dumneavoastră a fost încărcat cu ' + doc[1] + ' puncte.');
			}
			if (code == 'bad')
			{
				alert('Codul introdus este invalid!');
			}
		}
    }

    function finalizare()
    {
        var newrequest = new AW.HTTP.Request;
        newrequest.setURL("fields.php");

        newrequest.setRequestMethod("POST");

        newrequest.setParameter("id", 0);
        newrequest.setParameter("field",'payment');
        newrequest.request();

        var doc="NORESPONSE";
        newrequest.response = function(doc)
        {
        	doc = doc.split("|");
        	code = doc[0];
        	if (code != 1)
        	{
        		msg = '';
        		if (code == 2)
        			msg += 'Trebuie sa selectati un cumparator.';
				alert('Eroare: ' + msg);
        	}
        	else
        	{
        		switch(doc[1])
        		{
					case '1': // ePayment
							fields = doc[2].split("#");
        					data = doc[3].split("#");
				            var submitForm = getNewSubmitForm();
				            for (var i = 0; i<fields.length;i++)
				            {
								createNewFormElement(submitForm, fields[i], data[i]);
							}
					        submitForm.action= "https://secure.epayment.ro/order/lu.php";
					        submitForm.submit();
						break;
					case '2': // SMS
							if (doc[2] == 'ok')
							{
								alert('Felicitări. Aţi primit acces la produsele cumpărate!');
							}
							if (doc[2] == 'bad')
							{
								alert('Ne pare rău dar nu aveţi suficiente puncte pentru a putea efectua plata.\nVă rugăm să încărcaţi contul sau să alegeţi altă modalitate de plată.');
							}
							window.location.replace(doc[3]);
						break;
					case '3':
						break;
					case '4':
						break;
        		}
        	}
        }
    }

    function testIPN()
    {
		doc = ipntest.split("|");
        fields = doc[0].split("#");
        data = doc[1].split("#");
        var submitForm = getNewSubmitForm();
        for (var i = 0; i<fields.length;i++)
        {
			createNewFormElement(submitForm, fields[i], data[i]);
		}
	    submitForm.action= "http://editiaonline.com/client/public/ipn.php";
	    submitForm.submit();
    }

	var perpage = 8;
	var start = 0;
	var crtp = 1;
	var pagez = 1;
	var desc = true;
	var ocol = 2;
	var box = 0;
	var destination = 0;

	function printItem(item,last)
	{
		var st = 'style="margin:0px;"';
		if (!last) st = '';
		var theString = '<div class="rev" ' + st + 'onmouseover="document.getElementById(\'rev_' + item[0] + '\').style.background=\'url(img/mask.jpg)\'" onmouseout="document.getElementById(\'rev_' + item[0] + '\').style.background=\'none\'">';
		theString += '<div class="image" id="rev_' + item[0] + '" style="background:none;">';
		theString += '<a href="info.php?bookid=' + item[0] + '"><img src="scripts/mediaGet.php?book=' + item[0] + '&type=5" alt="" /></a>';
		theString += '</div><div class="info">';
		theString += '<strong ><a href="index.php?cmd=filter&filters=mag^'+item[7]+'" class="blue">' + item[1] + '</a></strong><br />';
		theString += 'Nr. ' + item[2] + ' / ' + item[3] + '<br />';
		if (item[8] == 0)
			theString += '<a href="cart.php?add=' + item[9] + '" class="red">Cumpara acum!</a> | <a href="view.php?book=' + item[0] + '">Demo</a>';
		else if (item[8] == 1)
			theString += '<a href="buy.php?pid=' + item[9] + '" class="red">Muta in cont</a> | <a href="view.php?book=' + item[0] + '">Vizualizare</a>';
		else if (item[8] == 2)
			theString += '<a href="buy.php?pid=' + item[9] + '" class="red">Muta in cont</a> | <a href="view.php?book=' + item[0] + '">Demo</a>';

		theString += '</div></div>';
		return theString;
	}

	function render(items)
	{
		var theString = '';
		for ( var i = start;i<Math.min(start+perpage,items.length);i++)
		{
			var last = (i+1) % 4 == 0;
			theString+=printItem(items[i],last);
			if ( last )
				theString += '<div class="clearAll"></div>';
		}
		document.getElementById('reviste').innerHTML = theString;
	}


	function compare(val1, val2, desc)
	{
		return (desc) ? val1 > val2 : val1 < val2;
	}

	function exchange(i, j)
	{
		var tmp= items[i];
		items[i] = items[j];
		items[j] = tmp;
	}

	function get(x,c)
	{
		return items[x][c];
	}

	function quicksort(m,n,column,desc)
	{
		if (n <= m+1) return;
		if ((n - m) == 2)
		{
			if (compare(get(n-1), get(m), desc)) exchange(n-1, m);
			return;
		}
		i = m + 1;
		j = n - 1;
		if (compare(get(m,column), get(i,column), desc)) exchange(i, m);
		if (compare(get(j,column), get(m,column), desc)) exchange(m, j);
		if (compare(get(m,column), get(i,column), desc)) exchange(i, m);
		pivot = get(m,column);
		while (true)
		{
			j--;
			while (compare(pivot, get(j,column), desc)) j--;
			i++;
			while (compare(get(i,column), pivot, desc)) i++;
			if (j <= i) break;
			exchange(i, j);
		}
		exchange(m, j);
		if ((j-m) < (n-j))
		{
			quicksort(  m, j,column, desc);
			quicksort(j+1, n,column, desc);
		}
		else
		{
			quicksort(j+1, n,column, desc);
			quicksort(  m, j,column, desc);
		}
	}


	function drawSortMenu(ncol)
	{
		if ( ocol == 4 )
		document.getElementById('sort_link_' + ocol).className = 'last_link_sort_0';
		else
		document.getElementById('sort_link_' + ocol).className = 'left_link_sort_0';
		switch (ncol)
		{
			case 0:
			case 1:
			case 2:
			case 3:
				if (desc)
					document.getElementById('sort_link_' + ncol).className = 'left_link_sort_3';
				else
					document.getElementById('sort_link_' + ncol).className = 'left_link_sort_2';
				break;
			case 4:
				if (desc)
					document.getElementById('sort_link_' + ncol).className = 'last_link_sort_3';
				else
					document.getElementById('sort_link_' + ncol).className = 'last_link_sort_2';
				break;
		}
		ocol = ncol;
	}

	function sort(col,link)
	{
		if (link == ocol)
		{
			desc = !desc;
		}
		quicksort(0,items.length,col,desc);
		drawSortMenu(link);
		paging();
	}

	function paging()
	{
		var selected = document.getElementById("perpage").selectedIndex;
		switch (selected)
		{
			case 0:
					perpage = 20;
				break;
			case 1:
					perpage = 32;
				break;
			case 2:
					perpage = 48;
				break;
		}
		pagez = Math.ceil( items.length / perpage );
		if ( pagez > 1) document.getElementById("ppg").style.display = 'block';
		start = Math.floor(start / perpage ) * perpage;
		crtp = Math.floor(start / perpage) + 1;
		if ( crtp > pagez ) crtp = pagez;
		drawShortcuts();
		render(items);
	}

	function mysort(col,link)
	{
		if (link == ocol)
		{
			desc = !desc;
		}
		quicksort(0,items.length,col,desc);
		drawSortMenu(link);
		mypaging();
	}

	function mypaging()
	{
		var selected = document.getElementById("perpage").selectedIndex;
		switch (selected)
		{
			case 0:
					perpage = 20;
				break;
			case 1:
					perpage = 32;
				break;
			case 2:
					perpage = 48;
				break;
		}
		pagez = Math.ceil( items.length / perpage );
		if ( pagez > 1) document.getElementById("ppg").style.display = 'block';
		start = Math.floor(start / perpage ) * perpage;
		crtp = Math.floor(start / perpage) + 1;
		if ( crtp > pagez ) crtp = pagez;
		mydrawShortcuts();
		myrender(items);
	}

	function createFolder()
	{
		var name=prompt("Introduceti numele folderului nou","Folder Nou");
		if (name)
		{
			var newrequest = new AW.HTTP.Request;
			newrequest.setURL("mylibrary.php");

			newrequest.setRequestMethod("POST");
			newrequest.setParameter("data", "1^"+ root+ "^" +name);

			newrequest.request();

			var doc="NORESPONSE";
			newrequest.response = function(doc)
			{
				doc = doc.split('^');
				if (doc[0] == 'ok')
				{
					items.pop();
					var item = [doc[1], name, "0", "0", "15", "0", "0"];
					items.push( item );
					var item = [(doc[1]+1), "Creaza Folder Nou", "0", "", "16", "0", "0"];
					items.push( item );
					mypaging();
				}
			}
		}
	}

	function renameFolder(id,name)
	{
		var newname=prompt("Introduceti numele nou:",name);
		if(newname)
		{
			var newrequest = new AW.HTTP.Request;
			newrequest.setURL("mylibrary.php");

			newrequest.setRequestMethod("POST");
			newrequest.setParameter("data", "2^" + id + "^" + newname);

			newrequest.request();

			var doc="NORESPONSE";
			newrequest.response = function(doc)
			{
				doc = doc.split('^');
				if (doc[0] == 'ok')
				{
					for (var i=0;i<items.length;i++)
						{
							if (items[i][0] == doc[1] )
							{
								items[i][1] = doc[2];
								break;
							}
						}
					mypaging();
				}
			}
		}
	}

	function deleteFolder(id,name)
	{
		if (confirm("Sunteti sigur ca doriti sa stergeti folderul " + name + " ?"))
		{
			var newrequest = new AW.HTTP.Request;
			newrequest.setURL("mylibrary.php");

			newrequest.setRequestMethod("POST");
			newrequest.setParameter("data", "3^"+ id);

			newrequest.request();

			var doc="NORESPONSE";
			newrequest.response = function(doc)
			{
				doc = doc.split('^');
				if (doc[0] == 'ok')
				{
					for (var i=0;i<items.length;i++)
					{
						if (items[i][0] == doc[1] )
						{
							items.splice(i,1);
							break;
						}
					}
					mypaging();
				}
			}
		}
	}


	function deleteEditie(id,name)
	{
		if (confirm("Sunteti sigur ca doriti sa stergeti editia " + name + " ?"))
		{
			var newrequest = new AW.HTTP.Request;
			newrequest.setURL("mylibrary.php");

			newrequest.setRequestMethod("POST");
			newrequest.setParameter("data", "7^"+ root+ "^" + id);

			newrequest.request();

			var doc="NORESPONSE";
			newrequest.response = function(doc)
			{
				doc = doc.split('^');
				if (doc[0] == 'ok')
				{
					for (var i=0;i<items.length;i++)
					{
						if (items[i][0] == doc[1] )
						{
							items.splice(i,1);
							break;
						}
					}
					mypaging();
				}
			}
		}
	}

	var sourceID = 0;

	function movetoDialog(id,name)
	{
		sourceID = id;
		document.getElementById("movetoTitle").innerHTML = 'Muta "' + name + '" in folderul:';
		document.getElementById("movetodialog").style.display = 'block';
	}

	function movetoFolder()
	{
		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("mylibrary.php");

		newrequest.setRequestMethod("POST");
		newrequest.setParameter("data", "4^" + sourceID + "^" + selectedIndex);

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			doc = doc.split('^');
			if (doc[0] == 'ok')
			{
				eval ( 'treeView = ' + doc[1]);
				eval ( 'treeText = ' + doc[2]);
				eval ( doc[3] );
				tree2.refresh();
				tree.refresh();
				for (var i=0;i<items.length;i++)
				{
					if (items[i][0] == sourceID )
					{
						items.splice(i,1);
						break;
					}
				}
				mypaging();
				closeMovetoDialog();
			}
		}
	}

	function copytoDialog(id,name)
	{
		sourceID = id;
		document.getElementById("copytoTitle").innerHTML = 'Copiaza "' + name + '" in folderul:';
		document.getElementById("copytodialog").style.display = 'block';
	}

	function copytoFolder()
	{
		var newrequest = new AW.HTTP.Request;
		newrequest.setURL("mylibrary.php");

		newrequest.setRequestMethod("POST");
		newrequest.setParameter("data", "6^" + root + "^" + sourceID + "^" + selectedIndex);

		newrequest.request();

		var doc="NORESPONSE";
		newrequest.response = function(doc)
		{
			doc = doc.split('^');
			if (doc[0] == 'ok')
			{
				closeCopytoDialog();
			}
		}
	}

	function closeCopytoDialog()
	{
		document.getElementById("copytodialog").style.display = 'none';
	}

	function closeMovetoDialog()
	{
		document.getElementById("movetodialog").style.display = 'none';
	}

	function myprintItem(item,last)
	{
		var st = 'style="margin:0px;"';
		if (!last) st = '';
		var theString = '<div class="rev" ' + st + 'onmouseover="document.getElementById(\'rev_' + item[0] + '\').style.background=\'url(img/mask.jpg)\'" onmouseout="document.getElementById(\'rev_' + item[0] + '\').style.background=\'none\'">';
		theString += '<div class="image" id="rev_' + item[0] + '" style="background:none;">';
		if (item[4] == 15 || item[4] == 18)
			theString += '<a href="mylibrary.php?path=' + item[0] + '"><img src="img/myfolder.gif" alt="" /></a>';
		else if(item[4] == 16)
			theString += '<div class="createnew"><a href="javascript:createFolder()"></a></div>';
		else if(item[4] == 17)
			theString += '<a href="mylibrary.php?path=' + item[0] + '"><img src="scripts/mediaGet.php?book=' + item[7] + '&type=5" alt="" /></a>';
		else if(item[4] == 19)
			theString += '<a href="mylibrary.php?path=' + item[0] + '"><img src="img/myfolder.gif" alt="" /></a>';
		else
			theString += '<a href="info.php?bookid=' + item[0] + '"><img src="scripts/mediaGet.php?book=' + item[7] + '&type=5" alt="" /></a>';

		theString += '</div><div class="info">';
		if (item[4] == 15 || item[4] == 18)
			theString += '<strong><a href="mylibrary.php?path='+item[0]+'" class="blue">' + item[1] + '</a></strong><br />';
		else if (item[4] == 16)
			theString += '<strong><a href="javascript:createFolder()" class="blue">' + item[1] + '</a></strong><br />';
		else if (item[4] == 17)
			theString += '<strong><a href="mylibrary.php?path='+item[0]+'" class="blue">' + item[1] + '</a></strong><br />';
		else
			theString += '<strong><a href="info.php?bookid='+item[0]+'" class="blue">' + item[1] + '</a></strong><br />';
		if (item[4] < 15 )
		{
			theString += 'Nr. ' + item[2] + ' / ' + item[3] + '<br />';
			theString += '<div class="copyto"><a href="javascript:copytoDialog('+item[0] + ',\'' + item[1] +'\');"></a></div>';
			if (builtin == 0)
				theString += '<div class="delete"><a href="javascript:deleteEditie('+item[0] + ',\'' + item[1] +'\');"></a></div><br />';
		}

		if (item[4] == 17 )
		{
			theString += 'Contine ' + item[2] + ' editii <br />';
			theString += '<div class="copyto"><a href="javascript:copytoDialog('+item[0] + ',\'' + item[1] +'\');"></a></div><br />';
		}

		if (item[4] == 15 )
		{
			theString += '<div class="copyto"><a href="javascript:movetoDialog('+item[0] + ',\'' + item[1] +'\');"></a></div>';
			theString += '<div class="rename"><a href="javascript:renameFolder('+item[0] + ',\'' + item[1] +'\');"></a></div>';
			theString += '<div class="delete"><a href="javascript:deleteFolder('+item[0] + ',\'' + item[1] +'\');"></a></div><br />';
		}

		theString += '</div></div>';
		return theString;
	}

	function myrender(items)
	{
		var theString = '';
		for ( var i = start;i<Math.min(start+perpage,items.length);i++)
		{
			var last = (i+1) % 4 == 0;
			theString+=myprintItem(items[i],last);
			if ( last )
				theString += '<div class="clearAll"></div>';
		}
		document.getElementById('reviste').innerHTML = theString;
	}


	function shortcuts()
	{
		var theString = '';
		if (crtp != 1)
		{
			theString += '<a href="javascript:gotoPage(1);" onfocus="this.blur()">1</a>';
			theString += '<img src="img/navigare_bull.jpg" alt="" />';
		}
		if (pagez > 6)
		{
			var i = Math.ceil( (crtp-1) / 2);
			if (i != 1 && i != (crtp - 1) )
			{
				theString += '<a href="javascript:gotoPage(' + i + ' );" onfocus="this.blur()">' + i + '</a>';
				theString += '<img src="img/navigare_bull.jpg" alt="" />';
			}
		}
		if (pagez > 2 && crtp - 1 > 1)
		{
			theString += '<a href="javascript:gotoPage(' + ( crtp - 1 ) + ');" onfocus="this.blur()">' + (crtp - 1) + '</a>';
		}
		if ( pagez > 1)
		{
			theString += '<a class="nav_sel" onfocus="this.blur()">' + crtp + '</a>';
		}
		if (pagez > 2 && crtp + 1 < pagez)
		{
			theString += '<a href="javascript:gotoPage(' + ( crtp + 1 ) + ');" onfocus="this.blur()">' + (crtp + 1) + '</a>';
		}
		if (pagez > 6)
		{
			var i = Math.floor((pagez + crtp + 1) / 2);
			if (i != pagez && i != (crtp + 1) )
			{
				theString += '<img src="img/navigare_bulll.jpg" alt="" />';
				theString += '<a href="javascript:gotoPage(' + i + ' );" onfocus="this.blur()">' + i + '</a>';
			}
		}
		if (crtp != pagez)
		{
			theString += '<img src="img/navigare_bulll.jpg" alt="" />';
			theString += '<a href="javascript:gotoPage(' + pagez + ');" onfocus="this.blur()">' + pagez + '</a>';
		}
		theString += '<div class="clearAll"></div>';
		return theString;
	}

	function drawShortcuts()
	{
		var data = shortcuts();
		if (document.getElementById('topsort')) document.getElementById('topsort').innerHTML = data;
		if (document.getElementById('bottomsort')) document.getElementById('bottomsort').innerHTML = data;
	}

	function gotoPage(page)
	{
		crtp = page;
		start = (page-1) * perpage;
		drawShortcuts();
		render(items);
	}

	function myshortcuts()
	{
		var theString = '';
		if (crtp != 1)
		{
			theString += '<a href="javascript:mygotoPage(1);" onfocus="this.blur()">1</a>';
			theString += '<img src="img/navigare_bull.jpg" alt="" />';
		}
		if (pagez > 6)
		{
			var i = Math.ceil( (crtp-1) / 2);
			if (i != 1 && i != (crtp - 1) )
			{
				theString += '<a href="javascript:mygotoPage(' + i + ' );" onfocus="this.blur()">' + i + '</a>';
				theString += '<img src="img/navigare_bull.jpg" alt="" />';
			}
		}
		if (pagez > 2 && crtp - 1 > 1)
		{
			theString += '<a href="javascript:mygotoPage(' + ( crtp - 1 ) + ');" onfocus="this.blur()">' + (crtp - 1) + '</a>';
		}
		if ( pagez > 1)
		{
			theString += '<a class="nav_sel" onfocus="this.blur()">' + crtp + '</a>';
		}
		if (pagez > 2 && crtp + 1 < pagez)
		{
			theString += '<a href="javascript:mygotoPage(' + ( crtp + 1 ) + ');" onfocus="this.blur()">' + (crtp + 1) + '</a>';
		}
		if (pagez > 6)
		{
			var i = Math.floor((pagez + crtp + 1) / 2);
			if (i != pagez && i != (crtp + 1) )
			{
				theString += '<img src="img/navigare_bulll.jpg" alt="" />';
				theString += '<a href="javascript:mygotoPage(' + i + ' );" onfocus="this.blur()">' + i + '</a>';
			}
		}
		if (crtp != pagez)
		{
			theString += '<img src="img/navigare_bulll.jpg" alt="" />';
			theString += '<a href="javascript:mygotoPage(' + pagez + ');" onfocus="this.blur()">' + pagez + '</a>';
		}
		theString += '<div class="clearAll"></div>';
		return theString;
	}

	function mydrawShortcuts()
	{
		var data = myshortcuts();
		if (document.getElementById('topsort')) document.getElementById('topsort').innerHTML = data;
		if (document.getElementById('bottomsort')) document.getElementById('bottomsort').innerHTML = data;
	}

	function mygotoPage(page)
	{
		crtp = page;
		start = (page-1) * perpage;
		mydrawShortcuts();
		myrender(items);
	}

	function applyfilters()
	{

	}

	function hidefilterbox()
	{
		document.getElementById('filters').style.display = 'none';
	}

	function showfilterbox()
	{
		document.getElementById('filters').style.display = 'block';
	}

	function filter(id)
	{
		if ( box ==0 || box != id)
		{
			box = id;
			switch(id)
			{
				case 1:
						var theString = '<table><tr><td><input type="checkbox" id="filter_1"/></td><td>Ziar</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_2"/></td><td>Revista</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_3"/></td><td>Carte</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_4"/></td><td>Brosura</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_5"/></td><td>Prezentare</td></tr>';
						theString += '<tr><td colspan="2" align="center"><a href="javascript:applyfilters();">Aplica</a></td></tr>';
						theString += '</table>';
						document.getElementById('filters').style.width = "90px";
						document.getElementById('filters').style.top = "328px";
					break;
				case 2:
						var theString = '<table><tr><td><input type="checkbox" id="filter_1"/></td><td>cotidian</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_2"/></td><td>saptamanal</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_3"/></td><td>bisaptamanal</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_4"/></td><td>3 aparitii pe saptamana</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_5"/></td><td>bilunar</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_6"/></td><td>lunar</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_7"/></td><td>10 aparitii pe an</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_8"/></td><td>8 aparitii pe an</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_9"/></td><td>6 aparitii pe an</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_10"/></td><td>trimestrial</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_11"/></td><td>bianual</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_12"/></td><td>anual</td></tr>';
						theString += '<tr><td colspan="2" align="center"><a href="javascript:applyfilters();">Aplica</a></td></tr>';
						theString += '</table>';
						document.getElementById('filters').style.width = "160px";
						document.getElementById('filters').style.top = "348px";
					break
				case 3:
						var theString = '<table><tr><td><input type="checkbox" id="filter_1"/></td><td>Ziar</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_2"/></td><td>Revista</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_3"/></td><td>Carte</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_4"/></td><td>Brosura</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_5"/></td><td>Prezentare</td></tr>';
						theString += '<tr><td colspan="2" align="center"><a href="javascript:applyfilters();">Aplica</a></td></tr>';
						theString += '</table>';
					break
				case 4:
						var theString = '<table><tr><td><input type="checkbox" id="filter_1"/></td><td>Ziar</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_2"/></td><td>Revista</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_3"/></td><td>Carte</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_4"/></td><td>Brosura</td></tr>';
						theString += '<tr><td><input type="checkbox" id="filter_5"/></td><td>Prezentare</td></tr>';
						theString += '<tr><td colspan="2" align="center"><a href="javascript:applyfilters();">Aplica</a></td></tr>';
						theString += '</table>';
					break;
			}
			document.getElementById('filters').innerHTML = theString;
			showfilterbox();
		}
		else
		{
			hidefilterbox();
			box = 0;
		}

	}

	function submitenter(myfield,e,verfield)
	{
		var keycode;
		if (window.event)
			keycode = window.event.keyCode;
		else
			if (e)
				keycode = e.which;
		else
			return true;

		if (document.getElementById(verfield).value == '')
			return true;

		if (keycode == 13)
		{
			myfield.form.submit();
			return false;
		}
		else
			return true;
	}

	function submitsearch(e)
	{
		var keycode;

		if (window.event)
			keycode = window.event.keyCode;
		else
			if (e)
				keycode = e.which;
		else
			return true;

		if (keycode == 13)
		{
			Search('1');
			return false;
		}
		else
		{
			return true;
		}

	}