function pollVote(box_id, poll_id) {
	var str_text = '';
	var str = ''
	if($('#members_only').val() == 1)
	{
		str = $("input[id=opt]:checked").val(); 
		if(typeof str == 'undefined')
		{
			var currentPage = $('#curent_page').val();
			if(typeof currentPage == 'undefined') currentPage = 1;
			str_text = $("#opt"+currentPage).val();
			if(str_text > '')
			{
			}
			else
			{
				alert("Pentru a putea participa la concurs trebuie sa alegeti/introduceti un raspuns!");
				return false;
			}
		}
	}
	else
	{
		str = $("input[id=opt]:checked").val();
	}
		
	   var url = 'http://www.elle.ro';
	    if($('#members_only').val() == 1)
		{
			if(getCookie('user_name') > "")
			{
				if($('#refresh').val() == 'yes')
				{
					if($('#curent_page').val() < $('#count_pages').val())
					{
						var next = parseInt($('#curent_page').val()) + 1;
						$.ajax({
							type: "POST",
							url: "/contest_submit.php",
							data: "page="+$('#curent_page').val()+"&itemId="+poll_id+"&opt="+str,
							 async: false,
							success: function(msg){
								if(msg==1)
								{
									window.location = url+$('#cms_url').val()+'?p='+next+'#concurs';
								}
								else
								{
									alert("Pentru a putea participa la concurs trebuie sa alegeti/introduceti un raspuns!");
								}
						   }
						 });
						
					}
				}
			}
		}
		else
		{
			if($('#refresh').val() == 'yes')
			{
				if(parseInt($('#curent_page').val()) <= parseInt($('#count_pages').val()))
				{
					var next = parseInt($('#curent_page').val()) + 1;
					$.ajax({
							type: "POST",
							url: "/contest_submit.php",
							data: "page="+$('#curent_page').val()+"&itemId="+poll_id+"&opt="+str,
							 async: false,
							success: function(msg){
								if(msg==1)
								{
									window.location = url+$('#cms_url').val()+'?p='+next+'#concurs';
								}
								else
								{
									alert("Pentru a putea participa la concurs trebuie sa alegeti/introduceti un raspuns!");
								}
						   }
					 });
				}
			}
		}
		if($('#refresh').val() == 'yes')
		{
			//if(($('#members_only').val() == 1 && parseInt($('#curent_page').val()) == parseInt($('#count_pages').val())) || ($('#members_only').val() == 0 && parseInt($('#curent_page').val()) == parseInt($('#count_pages').val())))
			if(parseInt($('#curent_page').val()) == parseInt($('#count_pages').val()))
			{
				if($('#members_only').val() == 0)
				{
					name = $('#name').val();
					email = $('#email').val();
					xmlAsyncRequestText ('/ajax?'+box_id+'&submit=1&name='+name+'&email='+email+'&itemID='+poll_id+'&service_type=PollContest'+'&rnd='+Math.random(), Form_MakeQueryString('fp'+poll_id), 'dinamicContent'+box_id+'_'+poll_id);
				}
				else
				{
					xmlAsyncRequestText ('/ajax?'+box_id+'&submit=1&itemID='+poll_id+'&service_type=PollContest'+'&rnd='+Math.random(), Form_MakeQueryString('fp'+poll_id), 'dinamicContent'+box_id+'_'+poll_id);
				}
			}
		}
		else
		{
			xmlAsyncRequestText ('/ajax?'+box_id+'&submit=1&itemID='+poll_id+'&service_type=PollContest'+'&rnd='+Math.random(), Form_MakeQueryString('fp'+poll_id), 'dinamicContent'+box_id+'_'+poll_id);
		}
	return false;
}
function pollShowResults(box_id, poll_id) {
	xmlAsyncRequestText ('/ajax?'+box_id+'&submit=1&itemID='+poll_id+'&service_type=PollContest&output=results'
		+'&rnd='+Math.random()
		, ''
		, 'dinamicContent'+box_id+'_'+poll_id);
	return false;
}

function submitRegister() 
{
	//document.register_form.submit();
	if(document.register_form.agree.checked != true)
	{
		alert('Pentru a fi inregistrat pe acest site trebuie sa fiti de acord cu termeni si conditiile acestui site!')
		return false;
	}
	else
	{
		document.register_form.submit();
	}
}

function searchDesigner()
{
	var submit_search_url = '/cautare-designer/';
	var keywords = $('input[name=q]').val();
	var keywords2 = $('input[name=q2]').val();
	if(keywords != '' || keywords2 != '')
	{
		if(keywords != '') submit_search_url = submit_search_url + keywords;
		else  submit_search_url = submit_search_url + keywords2;
		window.location = submit_search_url;
	}
	else
	{
		alert("Cautare invalida!");
	}
	return false;
}
function searchSite()
{
	var submit_search_url = '/cautare/';
	var keywords = $('input[name=q]').val();
	if(keywords != '')
	{
		if(keywords != '') submit_search_url = submit_search_url + keywords;
		window.location = submit_search_url;
	}
	else
	{
		alert("Cautare invalida!");
	}
	return false;
}
function searchTravel()
{
	var submit_search_url = '/cautare-travel/';
	var keywords = $('input[name=q]').val();
	if(keywords != '')
	{
		if(keywords != '') submit_search_url = submit_search_url + keywords;
		window.location = submit_search_url;
	}
	else
	{
		alert("Cautare invalida!");
	}
	return false;
}
function openPopup (url, name, w, h) 
{
	pictures = window.open(url, name, 'width='+ w +',height='+ h +',top='+ (screen.height/2-h/2) +',left='+ (screen.width/2-w/2) +',toolbar=0,resizable=1,scrollbars=yes');
}

function resizeImagePopup2() {
        var img = document.getElementById('popImg');
        var width = img.width;                                                                                                                                       
		var height = img.height;

		window.moveTo(0,0);
		//console.error("Widtd: "+img.width+" Height: "+img.height);
        if (0 == img.width || 0 == img.height || img.width < 100) {
                var toWidth = 1130;
                var toHeight = 900;
        }
        else {
				var plusSize = document.getElementById('plusSize').innerHTML; 
				//console.error("plus: "+plusSize);
                var toWidth = parseInt(plusSize) + img.width; 
				//console.error("twidth: "+toWidth);
                var toHeight = 250 + img.height;
                if (toWidth > screen.width) {
                        toWidth = screen.width;
                }
                if (toHeight > screen.height) {
                        toHeight = screen.height;
                }
        }
        top.resizeTo(toWidth, toHeight);
	
		x = (screen.height -  toHeight)/2;
		y = (screen.width - toWidth)/2;

		window.moveTo(x,y);
}
function checkit() 
{
  var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
  if (!(document.getElementById('nume_d').value > '')) {alert('Numele destinatarului nu este completat!');return false;}
  if (!(document.getElementById('nume_e').value > '')) {alert('Numele expeditorului nu este completat'); return false;}
  if (!pattern.test(document.getElementById('email_d').value)) {alert('Email-ul destinatarului nu este completat!');return false;}
  if (!pattern.test(document.getElementById('email_e').value)) {alert('Email-ul  expeditorului nu este completat'); return false;}
  return true;
}

function change_article(total_cover_story)
{
    if (getNextStory == 1)
    {
		nextCoverStory = (currentCoverStory + 1) >= total_cover_story ? 1 : (currentCoverStory + 1);
		select_cover_story(nextCoverStory, total_cover_story);
    }
    window.clearTimeout(timeoutId);
    timeoutId = window.setTimeout('change_article(' + total_cover_story + ')', time);
}

function select_cover_story(current_cover_story, total_cover_story)
{
    for (var i = 0; i < total_cover_story; i++)
    {
		document.getElementById('main_' + i).style.display = 'none';
    }
    document.getElementById('main_' + current_cover_story).style.display = 'block';
    currentCoverStory = current_cover_story;
    if (total_cover_story > 1)
    {
	window.clearTimeout(timeoutId);
	timeoutId = window.setTimeout('change_article(' + total_cover_story + ')', time);
    }
}
var showRegisterVar = 0;
function showRegister()
{
	if(showRegisterVar == 1)
	{
		document.getElementById('login').style.display='none';
		document.getElementById('preRegister').style.display='none';
		document.getElementById('register').style.display='block';
	}
}
function validate_form_pic()
{
	$pics = 0;
	for(i=1;i<=count;i++)
	{
		if (document.getElementById('1_attachments_1').value==null || document.getElementById('1_attachments_1').value=="")
		{ 
		}
		else
		{
			$pics++;
		}
	}
	if($pics == 0)
	{
		document.getElementById("error_pic").innerHTML="Trebuie sa introduci cel putin o poza!"; 
		return false;
	}
	return true;
}

function popup_idee()
{
	window.open('/trimite-idee', '_blank', 'height=700,width=550,resizable=yes,scrollbars=yes');
}
function popup_idee_street()
{
	window.open('/trimite-idee-street', '_blank', 'height=700,width=550,resizable=yes,scrollbars=yes');
}
function popup_question()
{
	window.open('/trimite-intrebare', '_blank', 'height=450,width=550,resizable=yes,scrollbars=yes');
}

 function pollVoteSpecial(box_id, poll_id) {
        var str_text = '';
        if($('#members_only').val() == 1)
        {
                str_text = '';
                var i=0;
                $("input:checkbox[id=opt]:checked").each(
                        function(){
                                str_text = str_text+","+$(this).val();
                                i++;
                        }
                );

                if(i==0)
                {
                        var str = $("input:radio[id=opt]:checked").val();
                }
                else
                {
                        str_text = str_text.substr(1);
                        var str = str_text;
                }
                if(typeof str == 'undefined')
                {
                        str_text = $("#opt"+$('#curent_page').val()).val();
                        if(str_text > '')
                        {
                        }
                        else
                        {
                                alert("Pentru a putea participa la concurs trebuie sa alegeti/introduceti un raspuns!");
                                return false;
                        }
                }
        }

           var url = 'http://www.elle.ro';
            if($('#members_only').val() == 1)
                {
                        if(getCookie('user_name') > "")
                        {
                                if($('#curent_page').val() < $('#count_pages').val())
                                        {
                                                var next = parseInt($('#curent_page').val()) + 1;
                                                $.ajax({
                                                        type: "POST",
                                                        url: "/contest_submit.php",
                                                        data: "page="+$('#curent_page').val()+"&itemId="+poll_id+"&opt="+str,
                                                         async: false,
                                                        success: function(msg){


  if(msg==1)
                                                                {
                                                                        window.location = url+$('#cms_url').val()+'?p='+next+'#concurs';
                                                                }
                                                                else
                                                                {
                                                                        alert("Pentru a putea participa la concurs trebuie sa alegeti/introduceti un raspuns!");
                                                                }
                                                   }
                                                 });

                                        }
                        }
                }
                else
                {
                        if($('#curent_page').val() < $('#count_pages').val())
                                {
                                        var next = parseInt($('#curent_page').val()) + 1;
                                        $.ajax({
                                                        type: "POST",
                                                        url: "/contest_submit.php",
                                                        data: "page="+$('#curent_page').val()+"&itemId="+poll_id+"&opt="+str,
                                                         async: false,
                                                        success: function(msg){
                                                                if(msg==1)
                                                                {
                                                                        window.location = url+$('#cms_url').val()+'?p='+next+'#concurs';
                                                                }
                                                                else
                                                                {
                                                                        alert("Pentru a putea participa la concurs trebuie sa alegeti/introduceti un raspuns!");
                                                                }
                                                   }
                                         });
                                }
                }
        return false;
}



