var vurl = window.top.location.toString();

function isEmail(str) {
	var filter= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return (filter.test(str) ? true : false);
}

function in_array(needle,haystack) {
	return new RegExp('(^|\,)'+needle+'(\,|$)','gi').test(haystack);
}

				
$(document).ready(function() {

	var s1 = new SWFObject("quote.swf", "mediaplayer", "979", "64", "8");
	s1.write("quote");

	$('a.hasPic').lightBox();
	
	$('form#comform').submit(function(){
		adComNume = jQuery.trim($('input[name=adComNume]').val());
		adComEmail = jQuery.trim($('input[name=adComEmail]').val());
		adComMesaj = jQuery.trim($('textarea[name=adComMesaj]').val());
		adComCaptcha = jQuery.trim($('input[name=captcha]').val());
		
		if(adComNume == '') alert("Va rugam introduceti numele dumneavoastra");
		else if(adComNume.length > 50) alert("Numele nu poate fi mai lung de 50 de caractere");
		else if(adComEmail == '') alert("Va rugam introduceti adresa dumneavoastra de email");
		else if(!isEmail(adComEmail)) alert("Va rugam introduceti o adresa valida de email");
		else if(adComMesaj == '') alert("Va rugam introduceti mesajul dumneavoastra");
		else if(adComMesaj.length < 10) alert("Mesajul dumneavoastra trebuie sa contina cel putin 10 caractere");
		else if(adComCaptcha.length < 4 || adComCaptcha.length > 6) alert("Completati corect codul de securitate");
		else {
			var html = $.ajax({
			type: 'POST',
			url: 'server.php',
			data: 'cod='+$('#captcha').val()+'&action=getCaptcha',
			async: false
			}).responseText;
			
			if(html == '') {
				alert("Completati corect codul de securitate");
				document.getElementById('mcptch').src = document.getElementById('mcptch').src + '?' + (new Date()).getMilliseconds();
			} else {
				return true;
			}
		}
		return false;
	});
	
	$('a[@rel=blank]').attr('target', '_blank');
	
});