var commentsCaptchaRequested = false;

function resizeImagePopup() {
	var img = document.getElementById('popImg');
	var width = img.width; 
	var height = img.height; 
	
	if (0 == img.width || 0 == img.height) {
		var toWidth = 1130;
		var toHeight = 900;
	}
	else {
		var toWidth = 400 + img.width;
		var toHeight = 330 + img.height;
		if (toWidth > screen.width) {
			toWidth = screen.width;
		}
		if (toHeight > screen.height) {
			toHeight = screen.height;
		}
	}
	top.resizeTo(toWidth, toHeight);
}
function showCaptcha(id) {
	if (document.getElementById("imgCaptcha"+id).src.match("spacer")) {
		document.getElementById("imgCaptcha"+id).src = '/cms/images/captcha.jpg.php?' + Math.random();
	}
	document.getElementById("divCaptcha"+id).style.display = 'block';
}
/*
function enableCaptcha(id,state) {
        if (state && !commentsCaptchaRequested && !getCookie('user_name')) {
		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 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)
		, '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 replaceBanner()
{
	get_string = document.location.search;   
	var list1 = get_string.split("?");
	var cat = list1[1].split(";");
	if(cat[0] == '6457')
	{
	/*	alert(document.body.innerHTML);
		var body = document.body.innerHTML;
		var arrBody = body.split('bannerRectangle">');
		var arrCode = arrBody[1].split('</div>');
		var newBanner = "<!-- Mediapro Interactiv Standard Code --><script type='text/javascript'>X1_AdParams = {'pub'		:	'632203491294404','site'		:	'gandul','section'	:	'gandul_proprietatea','zone'		:	'rectangle','size'		:	'0x0'};</script><script type='text/javascript' src='http://content.ad20.net/Lib.js'></script><!-- Mediapro Interactiv Standard Code -->";
		var newBody = arrBody[0] + newBanner + arrCode[1];
		alert(newBody);
		document.body.innerHTML = newBody;
*/
		//	 document.body.innerHTML = document.body.innerHTML.replace(/rectangle/g,'sample');

			/* var scriptul= document.createElement('script');
			 scriptul.type='text/javascript';
			 scriptul.src='http://content.ad20.net/Lib.js';

			 X1_AdParams = {'pub'		:	'632203491294404','site'		:	'gandul','section'	:	'gandul_proprietatea', 'zone'		:	'rectangle', 'size'		:	'0x0' };

			 var divul = document.getElementById("bannerRectangle");//.innerHTML = "<script type='text/javascript'>X1_AdParams = {'pub'		:	'632203491294404','site'		:	'gandul','section'	:	'gandul_proprietatea', 'zone'		:	'rectangle', 'size'		:	'0x0' }; alert(53453453);</script> ";
			 divul.innerHTML = '';
			 divul.appendChild(scriptul);
			 alert(document.getElementById("bannerRectangle").innerHTML);*/
	}
	return(cat[0]);       
}
function validate_required(field,alerttxt){with (field){if (value==null||value==""){alert(alerttxt); return false;}else {return true}}}
function validate_form(thisform){
		if(document.forms["contest"]["newsletter[19]"].checked){}
		else{alert('Pentru a putea participa la acest concurs rebuie sa va abonati la newsletter-ul Gandul.'); return false;}
		//if(document.forms["contest"]["newsletter[2]"].checked){}
		//else{alert('Pentru a putea participa la acest concurs rebuie sa va abonati la newsletter-ul Descopera.'); return false;}
		if(document.forms["contest"]["newsletter[4]"].checked){}
		else{alert('Pentru a putea participa la acest concurs rebuie sa va abonati la newsletter-ul Descopera.'); return false;}
		with (thisform){
			if (validate_required(name,"Numele trebuie completat!")==false){name.focus();return false;}
			if (validate_required(telephone,"Telefonul trebuie completat!")==false){telephone.focus();return false;}
			if (validate_required(email,"Email-ul trebuie completat!")==false){email.focus();return false;}
			if (validate_required(answer,"Raspunsul trebuie completat!")==false){answer.focus();return false;}
		}
		return true;
}


function submitSearch(){
			var choosed_option = $('#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-gandul"){
					window.location = "http://www.gandul.info/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();
	}
});