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 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 convert(downUp) {
	if (downUp) {
		var from_s = document.getElementById("to_s");
		var to_s = document.getElementById("from_s");
		var from_v = document.getElementById("to_v");
		var to_v = document.getElementById("from_v");
	} else {
		var from_s = document.getElementById("from_s");
		var to_s = document.getElementById("to_s");
		var from_v = document.getElementById("from_v");
		var to_v = document.getElementById("to_v");
	}
	var suma = (from_s.value*from_v.value)/to_v.value;
	if (isNaN(parseFloat(suma))) {
		to_s.value = 0;
	} else {
		to_s.value = suma.toFixed(4);
	}
}

function recomanda(text){
	var newWin;
	newWin = window.open("/recomanda?item="+text,"recomanda","width=750,height=500,scrollbars=1,menubar=no,resizable=no,top=" + ( screen.width - 770 ) / 2 + ",left=" + ( screen.height - 570 ) / 2 + ",status=no");
	newWin.focus();
}

function crecomanda(text){
	var newWin;

	newWin = window.open("http://www.hmultiplex.ro/campaign_recomanda?item="+text,"recomanda","width=750,height=500,scrollbars=1,menubar=no,resizable=no,top=" + ( screen.width - 770 ) / 2 + ",left=" + ( screen.height - 570 ) / 2 + ",status=no");
	newWin.focus();
}

function regulament(id_item){
	var newWin;
	newWin = window.open("/regulament-"+id_item,"regulament concursuri","width=750,height=500,scrollbars=1,menubar=no,resizable=no,top=" + ( screen.width - 770 ) / 2 + ",left=" + ( screen.height - 570 ) / 2 + ",status=no");
	newWin.focus();
}


function change_banner(total_banner)
{
    if (getNextBanner == 1)
    {
		nextBanner = (currentBanner+ 1) > total_banner ? 1 : (currentBanner + 1);
		select_banner(nextBanner, total_banner);
    }
    window.clearTimeout(timeoutId);
    timeoutId = window.setTimeout('change_banner(' + total_banner + ')', time);
}

function select_banner(current_banner, total_banner)
{
    for (var i = 1; i <= total_banner; i++)
    {
	document.getElementById('banner_' + i).style.display = 'none';
    }
    document.getElementById('banner_' + current_banner).style.display = 'block';
    currentBanner = current_banner;
    if (total_banner > 1)
    {
	window.clearTimeout(timeoutId);
	timeoutId = window.setTimeout('change_banner(' + total_banner + ')', time);
    }
}

function submitSearch()
{
		var searchSiteRadio = $('#search-okidoki-check-1');
		var searchOkidokiRadio = $('#search-okidoki-check-2');
		
			searchQuery = $('#searchQuery').val();
			if (searchQuery != '')
			{
				if (searchSiteRadio.attr('checked') == true)
				{
					window.location = '/search?q=' + searchQuery;
					return false;
				}			
				else
				{
					window.location = 'http://okidoki.ro/search?query=' + searchQuery;
				}
			}
			else
			{
				alert('Introduceti termenii cautarii!');
			}
			return false;
}