/*
$(document).ready(function() {


    var max = 0;
    var groups = new Array();
    $("[@class^=sameheight]").each(function() {
        var classes = this.className.split(' ');
        for(var i=0;i<classes.length;i++) {
            if (classes[i].substring(0,10) == 'sameheight') {
                if(groups[classes[i]]) {
                    groups[classes[i]] = Math.max($(this).height(),groups[classes[i]]);
                } else {
                    groups[classes[i]] = $(this).height();
                }
            }
        }
        //alert(this.className);
    });

    for(var i in groups) {
        $("."+i).height(groups[i]);
    }

});
*/
		
			
function popWin(source, varW, varH)
{
	var screenWidth = screen.availWidth;
	var screenHeight = screen.availHeight;
	var Left = Math.round((screenWidth - varW) / 2);
	var Top = Math.round((screenHeight - varH) /2);
	
	window.open(source,'_blank','scrollbars=yes,resizable=1,width='+varW+',height='+varH+',left=' + Left +',top=' + Top);
}

function popWin2(varW, varH)
{
	var screenWidth = screen.availWidth;
	var screenHeight = screen.availHeight;
	var Left = Math.round((screenWidth - varW) / 2);
	var Top = Math.round((screenHeight - varH) /2);
	
	window.open(source,'_blank','scrollbars=yes,resizable=1,width='+varW+',height='+varH+',left=' + Left +',top=' + Top);
}

function setValues()
{
	document.getElementById('name').value = document.getElementById('req_name').value
	document.getElementById('email').value = document.getElementById('req_email').value
	document.getElementById('title_comm').value = document.getElementById('title_comm').value
	document.getElementById('comments').value = document.getElementById('comments').value
	document.getElementById('comm_date').value = document.getElementById('comm_date').value
}



function showSetFrom(n, gSection) {

  if (maxItems[gSection] === undefined) return;
  
  
var divContents="";

  for (i=0;i<itemsToShow[gSection];i++)
  {
  	if (itemsToShow[gSection] > maxItems[gSection])
  	{
  		if (maxItems[gSection] == 1)
  		{
        var Id=i+n-2;
  		}
  		else
  		{
        var Id=i+n-1;
  		}
  		
  		
  	}
  	else{
  	 var Id=i+n+1;
    }
   
    
    if (Id >= maxItems[gSection])
    {
        Id=Math.abs(Id-maxItems[gSection]);
    }
     if (divArray[gSection][Id] != undefined)
	    {
	      divContents+=divArray[gSection][Id];
	    }
  }
  document.getElementById('galleryContainer_'+gSection).innerHTML = divContents;

}

function next(gSection){

selected[gSection]+=1;
if (selected[gSection] > maxItems[gSection]) selected[gSection]=1;
showSetFrom(selected[gSection], gSection);
}

function previews(gSection){

selected[gSection]-=1;
if ((selected[gSection] > maxItems[gSection])|| (selected[gSection] < 0)) selected[gSection]=maxItems[gSection]-1;
showSetFrom(selected[gSection], gSection);

}
/*
function validatePoll()
{
	var checkedValue = document.getElementById("pollIdVote").value
	if(checkedValue == 0)
	{
		alert("Va rugam sa votati intai !");
		return false;
	}
	else
	{
		document.forms["pollForm"].submit();
		document.getElementById("poll").innerHTML = "Votul a fost adaugat. Multumim!";
	}
}
*/
/*
function setValue(element)
{
	document.getElementById("fldPollIdSelectedVote").value = element.value;

}

function setValueArtPoll(element)
{
	document.getElementById("fldArticlePollIdSelectedVote").value = element.value;

}

function setValueA(element)
{
	
	document.getElementById("pollIdASelectedVote").value = element.value;
	//alert(element.value);
}
function setValueE(element)
{
	
	document.getElementById("pollIdESelectedVote").value = element.value;
	
}
*/
function showArticlesPage(containerId, page, max)
{
	var container = document.getElementById(containerId);
	$(".pag a").removeClass('selected');
	
	var rowPageFirst = page - 3;
	var rowPageLast = page + 3;
	
	if (rowPageFirst < 1)
	{
		rowPageLast = rowPageLast + (1 - rowPageFirst);
		rowPageFirst = 1;
	}
	
	if (rowPageLast > max)
	{
		rowPageFirst = rowPageFirst - (rowPageLast - max);
		rowPageLast = max;
	}
	
	if (rowPageFirst < 1) {
		rowPageFirst = 1;
	}
	
	
	var rowPageHTML = "<span id=\"pagListLead\">...</span> ";
	
	for(i=rowPageFirst;i<=rowPageLast;i++) {
		rowPageHTML += "<a href=\"#artAll\" id=\"artPg"+i+"\" title=\""+i+"\" onclick=\"javascript:showArticlesPage('artAll', "+i+", "+max+");\">"+i+"</a> "
	}
	
	rowPageHTML += " <span id=\"pagListTrail\">...</span>";
	
	$("#artPg"+page).parent().html(rowPageHTML);
	
	if (rowPageFirst > 1) {
		$("#pagListLead").show();
	} else {
		$("#pagListLead").hide();
	}
	if (rowPageLast < max) {
		$("#pagListTrail").show();
	} else {
		$("#pagListTrail").hide();
	}
	
	$("#artPg"+page).addClass('selected');
	$("#crtArtPage").text(page);
	$(container).load("/ListArticles.php?p="+page);

}

var isScrollSubmenu = false;
var scrollTimeout;
var scrollStep = 15;
var scrollStepDirection;
var scrollCompatibleBrowser = '';
function scrollSubmenu() {
	var newPosLeft = parseInt(document.getElementById('subMenuScrollBox').style.left) + scrollStepDirection;

	if (isNaN(newPosLeft))
	{
		newPosLeft=scrollStepDirection;
	}
	
	var scrollBoxRightOffset = getSubmenuWidth("#subMenuScrollBox") - $("#subMenuScrollBox").parent().width();
	
	if (newPosLeft >= 0) {
		isScrollSubmenu = false;
		$('#subMenuScrollFirst').hide();
	} else {
		$('#subMenuScrollFirst').show();
	}
	
	if ((-1 * newPosLeft) >= scrollBoxRightOffset) {
		$('#subMenuScrollLast').hide();
		isScrollSubmenu = false;
	} else {
		$('#subMenuScrollLast').show();
	}
	
	document.getElementById('subMenuScrollBox').style.left = newPosLeft+'px';
	if (isScrollSubmenu) {
		scrollTimeout = setTimeout("scrollSubmenu()", 100);
		return;
	} else {
		return;
	}
}
function scrollSubmenuInit() {
	if ($("#subMenuScrollBox").length > 0) {
		var scrollBoxRightOffset = getSubmenuWidth("#subMenuScrollBox") - $("#subMenuScrollBox").parent().width() + 100;
		if (0 >= scrollBoxRightOffset) {
			$('#subMenuScrollLast').hide();
		}
	}
}
function scrollSubmenuLeft() {
	scrollSubmenuStart(1);
}
function scrollSubmenuRight() {
	scrollSubmenuStart(-1);
}
function scrollSubmenuStart(direction) {
	scrollStepDirection = direction * scrollStep;
	isScrollSubmenu = true;
	scrollSubmenu();
}
function scrollSubmenuStop() {
	isScrollSubmenu = false;
	clearTimeout(scrollTimeout);
}

function getSubmenuWidth(eid) {
//	var lastChild = $(eid)[0].childNodes[(childNodes.length - 2)];
	var lastChild = $(eid).children('a:last')[0];
	var offsetRight = lastChild.offsetLeft + lastChild.offsetWidth;
	if (navigator.appName == 'Microsoft Internet Explorer') {
		offsetRight += 150;
	}
	return offsetRight;
}
$(document).ready(function(){
	$("#artForm").hide();
	$("#viewForm").click(function() {$("#artForm").fadeIn();});
	$("#viewForm").click(function() {$("#commForm").fadeOut();});
	
	
});
$(document).ready(function(){
	$("#commForm").hide();
	$("#viewCommForm").click(function() {$("#artForm").fadeOut();});
	$("#viewCommForm").click(function() {$("#commForm").fadeIn();});
	$("#ComenteazaTop").click(function() {$("#commForm").fadeIn();});
	$("#ComenteazaBottom").click(function() {$("#commForm").fadeIn();});
	
	
});

$(document).ready(function(){
	$("#commFormImg").hide();
	
	$("#ComenteazaTopImg").click(function() {$("#commFormImg").fadeIn();});
	$("#ComenteazaTopImg").click(function() {$("#ComenteazaTopImg").fadeOut();});
	$("#ComenteazaTopImg").click(function() {$("#ComenteazaBottomImg").fadeOut();});
	
	$("#ComenteazaBottomImg").click(function() {$("#commFormImg").fadeIn();});
	$("#ComenteazaBottomImg").click(function() {$("#ComenteazaBottomImg").fadeOut();});
	$("#ComenteazaBottomImg").click(function() {$("#ComenteazaTopImg").fadeOut();});
	
	
});

$(document).ready(function(){
	$("#commFormPoll").hide();
	
	$("#ComenteazaTopPoll").click(function() {$("#commFormPoll").fadeIn();});
	$("#ComenteazaTopPoll").click(function() {$("#ComenteazaTopPoll").fadeOut();});
	$("#ComenteazaTopPoll").click(function() {$("#ComenteazaBottomPoll").fadeOut();});
	
	$("#ComenteazaBottomPoll").click(function() {$("#commFormPoll").fadeIn();});
	$("#ComenteazaBottomPoll").click(function() {$("#ComenteazaBottomPoll").fadeOut();});
	$("#ComenteazaBottomPoll").click(function() {$("#ComenteazaTopPoll").fadeOut();});
	
	
});

function abNewsletter(){
	alert("Pentru a va abona trebuie mai intati sa va autentificati");
}

function getAvatar() {
	document.getElementById("divAv").innerHTML = "<img src=\"" +document.getElementById("fldAvatar").value+"\" alt=\"\" />";

}
$(document).ready(function(){
	$("#pollRezIntro").hide();
	$("img").each(function() {
		$(this).width($(this).width());
	});
});