var commentsCaptchaRequested = false;

function gohide(name){
  var button=document.getElementById(name); button.innerHTML = 'Trebuie sa fii logat <a target=\'_parent\' href=\'/login.html\' >Login</a>'
}

	 
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 resizeImagePopup() {
        var img = document.getElementById('popImg');
        var width = img.width;                                                                                                                                       var height = img.height;

		window.moveTo(0,0);

        if (0 == img.width || 0 == img.height) {
                var toWidth = 1130;
                var toHeight = 900;
        }
        else {
                var toWidth = 200 + img.width;
                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 enableCaptcha(id, state) {
        if (state && !commentsCaptchaRequested && !getCookie('user_name') && document.getElementById('message'+ id).value.length > 0 && 'comentariu' != document.getElementById('message'+ id).value) {
				document.getElementById("imgCaptcha"+ id).src = "/cms/images/captcha.jpg.php?" + Math.random();
                document.getElementById('divCaptcha'+ id).style.display = 'block';
                commentsCaptchaRequested = true;
        }
}
*/
function enableCaptcha(id, state) {
	var user = arguments[2] || '';
//	if (state && !commentsCaptchaRequested && !getCookie('user_name') && document.getElementById('message'+ id).value.length > 0 && 'comentariu' != document.getElementById('message'+ id).value) {
	if (state && !commentsCaptchaRequested && !getCookie(user) && (document.getElementById('commentsDetails').value.length > 0)) {
		document.getElementById("imgCaptcha"+ id).src = "/cms/images/captcha.jpg.php?" + Math.random();
		document.getElementById('divCaptcha'+ id).style.display = 'block';
		commentsCaptchaRequested = true;
	}
}
function submitComments (e) {
	if (e.anonymous_author_name.value.search('^[ \t\r\n]*$')>-1) {
		alert('Nu ati completat campul Nume !'); 
		return false;
	}
	if (e.message.value.search('^[ \t\r\n]*$')>-1 || 'comentariu' == e.message.value) {
		alert('Nu ati completat campul Comentariu !'); 
		return false;
	}

	e.submit();
}


function pollVote(box_id, poll_id) {
	xmlAsyncRequestText ('/ajax?'+box_id+'&submit=1&itemID='+poll_id+'&service_type=PollContest'
		+'&rnd='+Math.random()
		, Form_MakeQueryString('fp'+poll_id+'_'+box_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 srchSet(e){
	if ('' != e) {
		document['{/literal}{t}cautare{/t}{literal}'].action = '/'+e.replace(/[ ]+/g, '-')+'.html';
	}
	else {
		document['{/literal}{t}cautare{/t}{literal}'].action = '{/literal}{t}rezultate{/t}{literal}.html';
	}
	return true;
}
/*pt a lua din get*/
function getVar(name)
{
         get_string = document.location.search;         
         return_value = '';
         
         do { //This loop is made to catch all instances of any get variable.
            name_index = get_string.indexOf(name + '=');
            
            if(name_index != -1)
              {
              get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              
              end_of_value = get_string.indexOf('&');
              if(end_of_value != -1)                
                value = get_string.substr(0, end_of_value);                
              else                
                value = get_string;                
                
              if(return_value == '' || value == '')
                 return_value += value;
              else
                 return_value += ', ' + value;
              }
            } while(name_index != -1)
            
         //Restores all the blank spaces.
         space = return_value.indexOf('+');
         while(space != -1)
              { 
              return_value = return_value.substr(0, space) + ' ' + 
              return_value.substr(space + 1, return_value.length);
							 
              space = return_value.indexOf('+');
              }
          
         return(return_value);       
}

function showAnswer(id) {
	//var contentDiv = document.getElementById("textarticol");
	var allContainedElements = document.getElementsByTagName("div"); 
	for (var i = 0; i < allContainedElements.length; i++) { 
		var div = allContainedElements[i]; 
		if(div.className == "raspuns") div.style.display = "none"; 
	}
	document.getElementById(id).style.display = "block";
}

function submitSearch(){
			var choosed_option = $('#search_okidoki input:checked').val();
			var submit_search_url = 'http://okidoki.ro/search?query=';
			var keywords = $('input[name=q]').val();
			if(keywords != '')
			{
				keywords = keywords.replace(/ /g, "+");
				if(choosed_option == "search-csid"){
					window.location = "http://www.csid.ro/cauta.html?q=" + keywords;
				}
				if(choosed_option == "search-okidoki"){
					submit_search_url = submit_search_url + keywords;
					window.location = submit_search_url;
				}
			}
			else
			{
				alert("Cautare invalida!");
			}
			return false;
}

$(document).ready(function() {
	if ($('#commentsForm').length > 0)
	{
		$('#commentsForm').nextComments();
	}
});