function confirmareStergere(adress) {
	if(confirm('Doriţi ştergerea acestei înregistrări?')) {
		javascript:window.location.href=adress;
	}
}

function getCookie(NameOfCookie){
if (document.cookie.length > 0) {
begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1) {
begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end));}}
return null;
}

function setCookie(NameOfCookie, value, expirehours) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expirehours * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) +
	((expirehours == null) ? "" : "; expires=" + ExpireDate.toGMTString()+"; path=/");
}

function delCookie (NameOfCookie) {
	if (getCookie(NameOfCookie)) {
	document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/";
	}
}


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 Populating(form) 
  {  for(var i=0; i<arrMainCat.length; i++)
	   {if(i%2){
      var xx = new Option(arrMainCat[i],arrMainCat[i-1], false, false);
      form.selectCategory.options[(i-1)/2+1]=xx;
               }
      }
  }
  
 


 
  
  function PopulateSubcats(selectedCat, whereTo) {  
	
	//alert("populate subcats");
	//alert("selected= "+selectedCat);
	//alert("where "+whereTo);
	var id=selectedCat;   
	whereTo=whereTo.replace("grupa","cat");
	
	//alert("where value "+document.getElementById(whereTo).value);
	var ob_categ=document.getElementById(whereTo);	
	//alert(ob_categ.innerHTML);		
	ob_categ.options[0]=new Option("alegeţi o categorie","0", false, true);
	//alert(ob_categ.options.value);
	var tot=ob_categ.options.length+1;
	//alert("total "+tot);
	for(var i=1; i<tot; i++) {
		//alert("fac nul"+i+" "+ob_categ.options[i]);
		ob_categ.options[i]=null;		
	}

	
	if(arrSubCat[id]!=null){
	//alert("lungime "+arrSubCat[id].length);
	
		for(var i=0; i<arrSubCat[id].length; i++) { 
			//alert("i :  "+i );
			//alert("optiune "+arrSubCat[id][i]);
			if(i%2) {
			  /*
				if(categoria_veche==arrSubCat[id][i-1]) {					
					var xx = new Option(arrSubCat[id][i],arrSubCat[id][i-1], false, true)
					//alert('true');
				} else {
					var xx = new Option(arrSubCat[id][i],arrSubCat[id][i-1], false, false);
					//alert('false');
				}
				
				*/
				var xx = new Option(arrSubCat[id][i],arrSubCat[id][i-1], false, false);
				ob_categ.options[(i-1)/2+1]=xx;
				ind=(i-1)/2+1;
				//alert("index options:  "+ind);
				//alert(xx);
				//ob_categ.options[(i-1)/2+1]=xx;
				}
			}
			ob_categ.options.length=arrSubCat[id].length/2+1;
			//alert("final "+ob_categ.options.length);
			
			/*
		k=0;
		while(k<arrSubCat[id].length)
		{
			alert("optiune 1"+arrSubCat[id][k]);
			alert("optiune 2"+arrSubCat[id][k+1]);
			var xx = new Option(arrSubCat[id][k+1],arrSubCat[id][k], false, false);
			ob_categ.options[arrSubCat[id][k]]=xx;
			k=k+2;
			
		}
					*/

			
	}
	//alert(ob_categ.innerHTML);		
	$.jNice.SelectRemove($("#"+whereTo));
	$("#"+whereTo).parents(".AAddMainFSelDiv").jNice();
	
	
  }

    function PopulateSubcatsAdmin(selectedCat, whereTo,categoria_veche)
  {  
	//alert('admin');
  var id=selectedCat; 
  //alert(selectedCat);
  
  var ob_categ=document.getElementById(whereTo);
	{
	ob_categ.options[0]=new Option("alegeţi o categorie","0", false, true);

	for(var i=1; i<ob_categ.options.length+1; i++)
		{
		ob_categ.options[i]=null;
		}
	
	if(arrSubCat[id]!=null){
		for(var i=0; i<arrSubCat[id].length; i++)
			{ 
			if(i%2)
				{
				if(categoria_veche==arrSubCat[id][i-1]) {					
					var xx = new Option(arrSubCat[id][i],arrSubCat[id][i-1], false, true)
					//alert('true');
				} else {
					var xx = new Option(arrSubCat[id][i],arrSubCat[id][i-1], false, false);
				}
				ob_categ.options[(i-1)/2+1]=xx;
				
				//alert(ob_categ.options[(i-1)/2+1].value);
				}
			}
	}
	}
	$("#"+whereTo).parent().parent().jNice();
	//alert(ob_categ.innerHTML);	
  }
  
 function AdaugaNote(formId,index_selected) {
	var tbodyLen = document.getElementById("tblmain").getElementsByTagName("tbody").length;	
 	var toateCategoriile = document.anuntUniversal.id_grupa_obiect;
 	var toateSubCategoriile = document.anuntUniversal.id_cat_obiect;
 	var toateCatSelected = document.anuntUniversal.id_grupa_obiect.selectedIndex;
 	var categSubcategLista = new Array();
 	var nota_0,nota_1,nota_2;
 	categSubcategLista['Gastronomie'] = new Array();
 	categSubcategLista['Gastronomie']['Restaurante'] = new Array ('Mancare','Servire','Preturi');
 	categSubcategLista['Gastronomie']['Pizzerii,fast-food'] = new Array ('Mancare','Servire','Preturi');
 	categSubcategLista['Gastronomie']['Cantine'] = new Array ('Mancare','Servire','Preturi');
 	categSubcategLista['Gastronomie']['Cofetarii'] = new Array ('Mancare','Servire','Preturi');
 	categSubcategLista['Gastronomie']['Catering'] = new Array ('Mancare','Servire','Preturi');
 	categSubcategLista['Divertisment'] = new Array();
 	categSubcategLista['Divertisment']['Cluburi si baruri'] = new Array ('Atmosfera','Servire','Preturi');
 	categSubcategLista['Divertisment']['Cluburi de noapte'] = new Array ('Atmosfera','Servire','Preturi');
 
 	if (document.getElementById('created') == null)
 	{
 		var xx='blah';
 	} else {
 		var to_remove = document.getElementById('created');
 		var remLen=to_remove.childNodes.length;  
 		for (i = 0;i < remLen;i++)
 			to_remove.removeChild(to_remove.childNodes[0]);
 	}
 	if (categSubcategLista[toateCategoriile.options[toateCatSelected].text][toateSubCategoriile.options[index_selected].text])	
	{
		var arrLength = categSubcategLista[toateCategoriile.options[toateCatSelected].text][toateSubCategoriile.options[index_selected].text].length;
		// creaza o noua linie in table
		var newRow = document.createElement('tr');
		newRow.id = "created";
		// prima coloana (care contine titlul categoriei)
		var cell_1 = document.createElement('td');
		var text_1 =  document.createTextNode('Votul tau:');
		cell_1.vAlign = 'top';
		cell_1.className = "text";
		// adauga textull
		cell_1.appendChild(text_1);
		
		// urmeaza a doua coloana in care va fi inserat un tabel ce contine in posib de a da note:
		var cell_2 = document.createElement('td');
		cell_2.vAlign = 'top';
		// creez tabelul:
		var newTable_row_1,newTable_row_2, newTable_row_3;
		var table_1 = document.createElement('table');
		table_1.cellPadding = 5;
		table_1.border = 0;
		table_1.cellSpacing = 5;
		table_1.width = "100%";
		table_1.className = "text";
		var tbody = document.createElement('tbody');
		table_1.appendChild (tbody);
		var t_row = new Array();
		var t_cell0 = new Array();
		var t_cell1 = new Array();
		for (var i=0;i<arrLength;i++)	
		{
			t_row[i] = document.createElement ('tr');
			t_cell0[i] = document.createElement ('td');
			t_cell0[i].className='text';
			t_cell1[i] = document.createElement ('td');
			t_cell1[i].className='text';
			t_row[i].appendChild(t_cell0[i]);
			t_row[i].appendChild(t_cell1[i]);
			t_row[i].vAlign='top';
			tbody.appendChild(t_row[i]);
		}
			newRow.appendChild (cell_1);
			newRow.appendChild (cell_2);
			
			for (var i=0;i<arrLength;i++) {
				t_cell0[i].appendChild( document.createTextNode( categSubcategLista[toateCategoriile.options[toateCatSelected].text][toateSubCategoriile.options[index_selected].text][i] ) );
				t_cell1[i].appendChild( CreateSelect ( eval ('nota_'+i)));
			}
		
		// insereaza nota globala !!!
		var newRow_2 = tbody.insertRow(3);
		newRow_2.id = "nota";
		// prima coloana (care contine titlul categoriei)
		var cell_21 = document.createElement('td');
		var text_21 =  document.createTextNode('Nota globala:');
		cell_21.vAlign = 'top';
		cell_21.className = "text";
		// adauga textull
		cell_21.appendChild(text_21);
		
		// urmeaza a doua coloana in care va fi inserat un tabel ce contine in posib de a da note:
		var cell_22 = document.createElement('td');
		cell_22.vAlign = 'top';
		cell_22.className = "text";
		cell_22.id = 'notaGlobala';
		var text_22 =  document.createTextNode('10');
		cell_22.appendChild(text_22);
		newRow_2.appendChild(cell_21);
		newRow_2.appendChild(cell_22);
		
		cell_2.appendChild (table_1);
		var insert_here = document.getElementById("here");
		insert_here.parentNode.insertBefore(newRow,insert_here);
	
		
		
		//var tbody = document.getElementById("tblmain").getElementsByTagName("tbody")[0]; 	
		
		//insert_here_2.parentNode.insertBefore(newRow_2,insert_here_2);
	}
 }
 
function CreateSelect (sel_name) {
	var select = document.createElement ("select");
	select.name = sel_name;
	var n;
	for (var i = 1;i <= 10; i++ )
	{
		if (i == 10)
			n = new Option(i,i,false,true);
		else
			n = new Option(i,i,true,false);
		select.appendChild(n);
	}
	return select;
}
function CalculeazaNotaGlobala(formId) {
	var nota1 = formId.nota_0.value;
	var nota2 = formId.nota_1.value;
	var nota3 = formId.nota_2.value;
	var media = (nota1+nota2+nota3)/3;
	var loc = document.getElementById ('notaGlobala');
	var text =  document.createTextNode(media);
	loc.appendElement (text);
}
function go(){
  if (document.jumpto.pids.options[document.jumpto.pids.selectedIndex].value != "none") {
	location = document.jumpto.pids.options[document.jumpto.pids.selectedIndex].value;
  }
}

function confirmAlbum(stuffid)
{
    var is_confirmed = confirm("Are you sure you want to DELETE this album? (id: " + stuffid + ") \n\nWARNING: All the pictures and comments in this album will \nalso be deleted!");
    if (is_confirmed) {
        // Do nothing...
    }
    return is_confirmed;
}

function confirmPicture(stuffid)
{
    var is_confirmed = confirm("Are you sure you want to DELETE this picture? (id: " + stuffid + ") \nComments will also be deleted.");
    if (is_confirmed) {
        // Do nothing...
    }
    return is_confirmed;
}

function confirmComment(stuffid)
{
    var is_confirmed = confirm("Are you sure you want to DELETE this comment? (id: " + stuffid + ")");
    if (is_confirmed) {
        // Do nothing...
    }

    return is_confirmed;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function writeCookie(name, data, noDays){
  var cookieStr = name + "="+ data
  if (writeCookie.arguments.length > 2){
    cookieStr += "; expires=" + getCookieExpireDate(noDays)
    }
  document.cookie = cookieStr
}

function readCookie(cookieName){
   var searchName = cookieName + "="
   var cookies = document.cookie
   var start = cookies.indexOf(cookieName)
   if (start == -1){ // cookie not found
     return ""
     }
   start += searchName.length //start of the cookie data
   var end = cookies.indexOf(";", start)
   if (end == -1){
     end = cookies.length
     }
   return cookies.substring(start, end)
}

function blocking(nr, cookie, vis_state)
{
	if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? vis_state : 'none';
		if (cookie != '')
			writeCookie(nr, current);
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		current = (document.all[nr].style.display == 'none') ? vis_state : 'none';
		if (cookie != '')
			writeCookie(nr, current);
		document.all[nr].style.display = current;
	}
	else if (document.getElementById)
	{
		display = (document.getElementById(nr).style.display == 'none') ? vis_state : 'none';
		if (cookie != '')
			writeCookie(nr, display);
		document.getElementById(nr).style.display = display;
	}
}


function adjust_popup()
{
	var w, h, fixedW, fixedH, diffW, diffH;
	
	if (document.all) {
		fixedW = document.body.clientWidth;
		fixedH = document.body.clientHeight;
		window.resizeTo(fixedW, fixedH);
		diffW = fixedW - document.body.clientWidth;
		diffH = fixedH - document.body.clientHeight;
	} else {
		fixedW = window.innerWidth;
		fixedH = window.innerHeight;
		window.resizeTo(fixedW, fixedH);
		diffW = fixedW - window.innerWidth;
		diffH = fixedH - window.innerHeight;
	}
	w = fixedW + diffW;
	h = fixedH + diffH;
	if (h >= screen.availHeight) w += 16;
	if (w >= screen.availWidth)  h += 16;
	w = Math.min(w,screen.availWidth);
	h = Math.min(h,screen.availHeight);
	window.resizeTo(w,h);
	window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}

//FUNCTII PT BANNERELE VERTICALE SUSPENDATE
function openAd() {
		on.style.posTop=0;
		on.style.posLeft=x;
		on.style.display = "block";
		on.style.visibility = "visible";
		setTimeout("closeAd()", 60000); //tine activ layerul on 30 secunde
}

function closeAd() {
		on.style.visibility = "hidden";
		on.style.display = "none";
}
function clickAd() {
		//setCookie('<? echo $cookie_name ?>', "da", 2);
		on.style.visibility = "hidden";
		on.style.display = "none";
}

function popupWin(url) {
    
	win=window.open(url,'windowViewer','screenX=0,screenY=0,left=150,top=150,status=no,menubar=no,scrollbars=yes,width=400,height=500');
	win.focus();

}
