$(document).ready(function(){
		$('a[@rel^="external"]').attr({target: '_blank'});
		$('a > img[@src$="img_rss\.jpg"]').parent().attr({target: '_blank'});
	}
);

function isValidDate(dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null) {
		return false;
	} else {
		return true;
	}
}

function clearTextBox(obj, string, autoselect) {
	if($(":input[id=" + obj + "]").val() == string) {
		$(":input[id=" + obj + "]").val("");
	} else if($(":input[id=" + obj + "]").val() == "") {
		$(":input[id=" + obj + "]").val(string);
	} else {
		if(autoselect == true) {
			$(":input[id=" + obj + "]").select();
		}
	}
}

function getUrl(url) {
	window.location.href = url;
}

function checkValidString(s) {
	if(s == "" || !isNaN(s)) {
		return false;
	} else {
		return true;
	}
}

function checkEmail(s){
  var tesresults;
  var filter=/^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i;
  if (filter.test(s)){testresults=true;}else{testresults=false;}
  return testresults;
}

function popup(url, name, width, height, options) {
	var opts = "toolbar=no,status=yes,location=no,menubar=no,resizable=yes";
	opts = "height=" + height + ",width=" + width + ",top="+(((screen.height/2)-height/2)-20)+",left=" + ((screen.width/2)-width/2) + "," + opts;
	window.open(url, name, opts);
	return false;
}

function getImageSize(prompt, i, path, maxwidth, maxheight) {
	var err = 0;
	
	if(prompt) {
		var tmp = new Image();
		tmp.src = "file:\/\/" + path;

		var imgRe = /^.+\.(jpg|jpeg)$/i;
			
		if (path.search(imgRe) == -1) {
			err++;
		}
					
		if(err > 0) {
			return false;
		} else {
			return true;
		}
	}
}

/*
// load banner concurs 
concursHtml = '<table style="width: 100%; border: 0;" cellspacing="0" cellpadding="0" id="tblContestContainer">'+
  '<tr>'+
    '<td style="width: 100%" height="30" bgcolor="#e45916" align="center"><span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; font-weight: bold; color: rgb(255, 255, 255);">Castiga o excursie de 2 persoane in Africa! &raquo;</span> <a style="font-family: Arial,Helvetica,sans-serif; font-size: 13px; font-weight: bold; color: rgb(255, 255, 255);" href="http://www.descopera.ro/concurs">Inscrie-te!</a> <span style="font-family: Arial,Helvetica,sans-serif; font-size: 16px; font-weight: bold; color: rgb(255, 255, 255);">|</span> <a style="font-family: Arial,Helvetica,sans-serif; font-size: 13px; font-weight: bold; color: rgb(255, 255, 255);" href="http://www.descopera.ro/concurs/participa">Raspunde la intrebarea zilei!</a></td>'+
  '</tr>'+
'</table>';
$(document).ready(
	function() {
		$('body > .center').prepend(concursHtml);
	}
);
*/

//functie care verifica campurile de la concurs
function check_contest_form(){
	var corect = true;
	var str = '';
	
	if($("#form_name").val() == ''){corect = false; str += 'Nu ati introdus numele si prenumele!\n';}
	if($("#form_phone").val() == ''){corect = false; str += 'Nu ati introdus numarul de telefon!\n';}
	else{
		if(phone_check($("#form_phone").val()) == false){
			corect = false;
			str += 'Numarul de telefon nu este valid!\n';
		}
	}
	if($("#form_email").val() == ''){corect = false; str += 'Nu ati introdus adresa de email!\n';}
	else{
		//validare email
		if(email_check($("#form_email").val()) == false){corect = false; str += 'Adresa de email nu este valida!\n';}
	}
	if($("#form_datacontent").val() == ''){corect = false; str += 'Nu ati introdus raspunsul!\n';}
	if($("#form_newsletter:checked").length != 1){corect = false; str += 'Pentru a participa la concurs trebuie sa va abonati la newsletter!\n';}
	/*else{
		$("#form_newsletter:checked").val('1');
	}	
	*/
	if(corect == false){
		jAlert(str, 'Avertizare');
	}
	else{
		//$("#form_trimite").val('1');
		$("#article_contest_form").submit();
	}	
}

//functie care face verificare JS pe email
function email_check(emailStr){
	var regex = /^([a-z0-9._-](\+[a-z0-9])*)+@[a-z0-9.-]+\.[a-z]{2,6}$/i;
	
	if (regex.test(emailStr)) return true;
	else return false;
}

function phone_check(phoneStr){
	var regex 		= /^([\+]*[\d]+)([-]*)([\d{2,3}])([-]*)([\.\-\s\d]+)$/;
	var regex_mobil = /^07(\d{8})$/i;
	
	if (regex.test(phoneStr) || regex_mobil.test(phoneStr)) return true;
	else return false;	
}

function send_answer(){
	var corect 	= true;
	var str 	= '';
	
	if($("#user_email").val() == ''){corect = false; str += 'Nu ati introdus adresa de email!\n';}
	else{
		//validare email
		if(email_check($("#user_email").val()) == false){corect = false; str += 'Adresa de email nu este valida!\n';}
	}
	
	if($("#user_phone_number").val() == ''){corect = false; str += 'Nu ati introdus numarul de telefon!\n';}
	else{
		if(phone_check($("#user_phone_number").val()) == false){
			corect = false;
			str += 'Numarul de telefon nu este valid!\n';
		}
	}
	
	if($("input:checked").val() == undefined || $("input:checked").val() == ''){
		corect = false;
		str += 'Trebuie sa alegi o varianta de raspuns!\n';
	}
	
	if(corect == false){
		jAlert(str, 'Avertizare');
	}
	else{
		$("#question_form").submit();
	}
}