/****************************************/
/*                                      */
/* General Function Library             */
/* Copyright 2007 Blue November Studios */
/* http://www.bluenovember.ro/          */
/*                                      */
/** ************************************* */

oldID = false;
// var path = 'http://www.anunturilocale.ro/';
var path = '';
/* Flash header */
function flashHeader(){
    flashVars = arguments[0];
    flashEmbed = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="780" height="279" id="flheader" align="middle" style="z-index:1">';
    flashEmbed += '<param name="allowScriptAccess" value="sameDomain" />';
    flashEmbed += '<param name="movie" value="flash/header.swf" />';
    flashEmbed += '<param name="menu" value="false" />';
    flashEmbed += '<param name="quality" value="high" />';
    flashEmbed += '<param name="bgcolor" value="#ffffff" />';
    flashEmbed += '<param name="wmode" value="transparent" />';
    flashEmbed += '<param name="FlashVars" value="' + flashVars + '" />';
    flashEmbed += '<embed src="' + path + 'flash/header.swf" FlashVars="' + flashVars + '" menu="false" quality="high" bgcolor="#ffffff" width="780" height="279" wmode="transparent" name="flheader" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    flashEmbed += '</object>';
    
    document.write(flashEmbed);
}

/* Display Details */
function showDetails(IDnum){
    if (oldID != false) {
        document.getElementById("smallSlot" + oldID).style.display = "block";
        document.getElementById("bigSlot" + oldID).style.display = "none";
        document.getElementById("rasp" + oldID).style.display = "none";
    }
    document.getElementById("smallSlot" + IDnum).style.display = "none";
    document.getElementById("bigSlot" + IDnum).style.display = "block";
    document.getElementById("rasp" + IDnum).style.display = "none";
    oldID = IDnum;
}

/* E-mail alerts */
function afInput(){
    dest = document.getElementById("aInput");
    if (dest.value == "E-mail-ul tau") {
        dest.value = "";
    }
}

function abInput(){
    dest = document.getElementById("aInput");
    if (dest.value == "") {
        dest.value = "E-mail-ul tau";
    }
}

// //////////////////////////////////////////////////

// ******************************************************************************************************************************

function GetXmlHttpObject(){
    var objXMLHttp = null
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest()
    }
    else 
        if (window.ActiveXObject) {
            objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")
        }
    return objXMLHttp
}

// ******************************************************************************************************************************
function verifyWhere(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("subdomeniu").innerHTML = xmlHttp.responseText
    }
}

/*--------------------------------------------------------------------------------------------------------------------*/
function displayA(idMic, idMare){
    document.getElementById(idMic).style.display = "none";
    document.getElementById(idMare).style.display = "inline";
}

/*--------------------------------------------------------------------------------------------------------------------*/
function verifyDom(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("subdomeniu").innerHTML = xmlHttp.responseText
        // alert(xmlHttp.responseText);
    }
}

/*--------------------------------------------------------------------------------------------------------------------*/
function showMenu(uniqueID){
    document.getElementById("side" + uniqueID).style.visibility = "visible";
}

function hideMenu(uniqueID){
    document.getElementById("side" + uniqueID).style.visibility = "hidden";
}

/*--------------------------------------------------------------------------------------------------------------------*/
function populate_dom(valoare){
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return;
    }
    var url = "alerta.php?p=1";
    url = url + "&cat=" + valoare;
    xmlHttp.onreadystatechange = verifyDom
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)
}

/*--------------------------------------------------------------------------------------------------------------------*/
function subdomenii(id_dom){
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return;
    }
    var url = "subdomenii.php";
    url = url + "?id_cat=" + id_dom;
    xmlHttp.onreadystatechange = verifyWhereDom
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)
}

// ******************************************************************************************************************************
function verifyWhereDom(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("subdom").innerHTML = xmlHttp.responseText
    }
}

/*--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------*/

function subdomeniiNews(id_dom){
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return;
    }
    var url = "subdomenii.php";
    url = url + "?id_cat=" + id_dom;
    xmlHttp.onreadystatechange = verifyWhereDomNews
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)
}

// ******************************************************************************************************************************
function verifyWhereDomNews(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("subdomNews").innerHTML = xmlHttp.responseText
    }
}

/*--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------*/
function localitati(id_jud){
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return;
    }
    var url = "localitati.php";
    url = url + "?id_jud=" + id_jud;
    xmlHttp.onreadystatechange = verifyWhereJud
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)
}

/*--------------------------------------------------------------------------------------------------------------------*/
function verifyWhereJud(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("localitati").innerHTML = xmlHttp.responseText
    }
}

/*--------------------------------------------------------------------------------------------------------------------*/
function verifyEmail(email){
    document.getElementById("errMail").style.display = "block";
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (email.value == "") {
        document.getElementById("errMail").innerHTML = "Adresa de e-mail nu a fost specificata.";
        email.focus();
        return;
    }
    else 
        if (filter.test(email.value)) {
            return true;
        }
        else {
            document.getElementById("errMail").innerHTML = "Adresa de e-mail nu este corecta";
            email.focus();
            return;
        }
}

function verifyTelephone(ph, element){
    if (ph == null) {
        return false;
    }
    var stripped = ph.replace(/[\s()+-]|ext\.?/gi, "");
    // 10 is the minimum number of numbers required
    if ((/\d{10,}/i).test(stripped)) {
        return true;
    }
    else 
        return false;
}

/*--------------------------------------------------------------------------------------------------------------------*/
function trimite_alerta(){
    if (document.alerta.domeniu.value == "") {
        alert("Selectati domeniul!")
        return;
    }
    if (document.alerta.subdomeniu.value == "") {
        alert("Selectati subdomeniul!");
        return;
    }
    if (!verifyEmail(document.alerta.mail_a)) {
        return;
    }
    document.forms.alerta.submit();
}

/*--------------------------------------------------------------------------------------------------------------------*/
function verifyUser(valoare){
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return;
    }
    var url = "verifyData.php?p=1";
    url = url + "&user=" + valoare;
    // alert(url);
    xmlHttp.onreadystatechange = verifyU
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)
}

// //////////////
function verifyU(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("responseU").innerHTML = xmlHttp.responseText
    }
}

/*--------------------------------------------------------------------------------------------------------------------*/
function verifyMail(valoare){
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return;
    }
    var url = "verifyData.php?p=2";
    url = url + "&mail=" + valoare;
    // alert(url);
    xmlHttp.onreadystatechange = verifyM
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)
}

// ////////////
function verifyM(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("responseM").innerHTML = xmlHttp.responseText
    }
}

/*--------------------------------------------------------------------------------------------------------------------*/
function forgot(){
    if (document.newPass.u_ser.value == "") {
        document.getElementById("errU").style.display = "block";
        document.getElementById("errU").innerHTML = "Introduceti userul.";
        document.newPass.u_ser.focus();
        return;
    }
    else {
        document.getElementById("errU").style.display = "none";
    }
    if (!verifyEmail(document.newPass.e_mail)) {
        document.getElementById("errMail").style.display = "block";
        return;
    }
    else {
        document.getElementById("errMail").style.display = "none";
    }
    document.forms.newPass.submit();
}

/*--------------------------------------------------------------------------------------------------------------------*/
function modificare_cont(){
    if (document.forms['updateCont'].numeM.value == "") {
        document.forms['updateCont'].numeM.focus();
        document.getElementById('errN').style.display = "block";
        document.getElementById("errN").innerHTML = "Introduceti numele";
        return;
    }
    else {
    
        document.getElementById('errN').style.display = "none";
    }
    if (document.forms['updateCont'].prenume.value == "") {
        document.forms['updateCont'].prenume.focus();
        document.getElementById('errPn').style.display = "block";
        document.getElementById("errPn").innerHTML = "Introduceti prenumele.";
        return;
    }
    else {
        document.getElementById('errPn').style.display = "none";
    }
    if (!verifyEmail(document.forms['updateCont'].mail)) {
        document.getElementById('errMail').style.display = "none";
        return;
    }
    else {
        document.getElementById('errMail').style.display = "none";
    }
    if (document.forms['updateCont'].telefon.value == "") {
        document.forms['updateCont'].telefon.focus();
        document.getElementById("errTel").style.display = "block";
        document.getElementById("errTel").innerHTML = "Introduceti numarul de telefon.";
        return;
    }
    else {
        document.getElementById("errTel").style.display = "none";
    }
    document.forms['updateCont'].submit();
}

/*--------------------------------------------------------------------------------------------------------------------*/
function modificarePass(){
    if (document.forms['updatePass'].vPass.value == "") {
        document.forms['updatePass'].vPass.focus();
        document.getElementById('errP').style.display = "block";
        document.getElementById('errP').innerHTML = "Introduceti parola veche.";
        return;
    }
    else {
        document.getElementById('errP').style.display = "block";
    }
    if (document.forms['updatePass'].pass1.value == "") {
        document.forms['updatePass'].pass1.focus();
        document.getElementById('errPas1').style.display = "block";
        document.getElementById('errPas1').innerHTML = "Introduceti parola noua.";
        return;
    }
    else {
        document.getElementById('errPas1').style.display = "none";
    }
    if (document.forms['updatePass'].pass2.value == "") {
        document.forms['updatePass'].pass2.focus();
        document.getElementById('errPas2').style.display = "block";
        document.getElementById('errPas2').innerHTML = "Reintroduceti parola noua.";
        return;
    }
    else {
        document.getElementById('errPas2').style.display = "none";
    }
    if (document.forms['updatePass'].pass1.value != document.forms['updatePass'].pass2.value) {
        document.forms['updatePass'].pass1.value = "";
        document.forms['updatePass'].pass2.value = "";
        document.forms['updatePass'].pass1.focus();
        document.getElementById('errPas3').style.display = "block";
        document.getElementById('errPas3').innerHTML = "Parolele sunt diferite.";
        return;
    }
    else {
        document.getElementById('errPas3').style.display = "none";
    }
    document.forms['updatePass'].submit();
}

/*--------------------------------------------------------------------------------------------------------------------*/
function addAnunt(){
    if (document.forms['add_a'].domeniu.value == 0) {
        alert("Domeniul de activitate a fost omis.");
        document.forms['add_a'].domeniu.focus();
        return;
    }
    if (document.forms['add_a'].subdomeniu.value == 0) {
        alert("Subdomeniul de activitate a fost omis.");
        document.forms['add_a'].subdomeniu.focus();
        return;
    }
    if (document.forms['add_a'].nume_a.value == "") {
        alert("Titlul nu a fost specificat.");
        document.forms['add_a'].nume_a.focus();
        return;
    }
    if (document.forms['add_a'].nume_a.value.length > 49) {
        alert("Titlul anun�ului are rol informativ �i nu poate dep�i 49 de caractere.");
        document.forms['add_a'].nume_a.focus();
        return;
    }
    if (document.forms['add_a'].descriere_a.value == "") {
        alert("Descrierea a fost omis�.");
        document.forms['add_a'].descriere_a.focus();
        return;
    }
    if (checkWordLength(document.forms['add_a'].descriere_a.value) == false) {
        alert("Descrierea con�ine cuvinte foarte lungi. Aceast� eroare mai apare �n cazul �n care dup� semnele de punctua�ie nu se lasa spatiu.");
        document.forms['add_a'].descriere_a.focus();
        return;
    }
    if (checkForEmail(document.forms['add_a'].descriere_a.value) == false) {
        alert("Descrierea nu poate con�ine adrese de e-mail. La detalii anunt apare deja adresa de email cu care te-ai �nregistrat.");
        document.forms['add_a'].descriere_a.focus();
        return;
    }
    if (document.forms['add_a'].descriere_a.value.length > 1500) {
        alert("Descrierea unui anun� nu poate dep�i 1500 caractere. Pentru a oferi mai multe informa�ii, cei interesa�i v� pot contacta telefonic sau prin e-mail.");
        document.forms['add_a'].descriere_a.focus();
        return;
    }
    if (document.forms['add_a'].valabilitate.value == 0) {
        alert("Valabilitatea anun�ului a fost omis�.");
        document.forms['add_a'].valabilitate.focus();
        return;
    }
    document.forms['add_a'].submit();
}

/** *********************************************************************** */
function addAnuntNe(){
    if (document.forms['add_a'].domeniu.value == 0) {
        alert("Domeniul de activitate a fost omis.");
        document.forms['add_a'].domeniu.focus();
        return;
    }
    if (document.forms['add_a'].subdomeniu.value == 0) {
        alert("Subdomeniul de activitate a fost omis.");
        document.forms['add_a'].subdomeniu.focus();
        return;
    }
    if (document.forms['add_a'].nume_a.value == "") {
        alert("Titlul nu a fost specificat.");
        document.forms['add_a'].nume_a.focus();
        return;
    }
    if (document.forms['add_a'].nume_a.value.length > 49) {
        alert("Titlul anun�ului are rol informativ �i nu poate dep�i 49 de caractere.");
        document.forms['add_a'].nume_a.focus();
        return;
    }
    if (document.forms['add_a'].descriere_a.value == "") {
        alert("Descrierea a fost omis�.");
        document.forms['add_a'].descriere_a.focus();
        return;
    }
    if (checkWordLength(document.forms['add_a'].descriere_a.value) == false) {
        alert("Descrierea con�ine cuvinte foarte lungi. Aceast� eroare mai apare �n cazul �n care dup� semnele de punctua�ie nu se lasa spatiu.");
        document.forms['add_a'].descriere_a.focus();
        return;
    }
    if (checkForEmail(document.forms['add_a'].descriere_a.value) == false) {
        alert("Descrierea nu poate con�ine adrese de e-mail. La detalii anunt apare deja adresa de email cu care te-ai �nregistrat.");
        document.forms['add_a'].descriere_a.focus();
        return;
    }
    if (document.forms['add_a'].descriere_a.value.length > 1500) {
        alert("Descrierea unui anun� nu poate depasi 1500 caractere. Pentru a oferi mai multe informa�ii, cei interesa�i v� pot contacta telefonic sau prin e-mail.");
        document.forms['add_a'].descriere_a.focus();
        return;
    }
    if (document.forms['add_a'].valabilitate.value == 0) {
        alert("Valabilitatea anun�ului a fost omis�.");
        document.forms['add_a'].valabilitate.focus();
        return;
    }
    /* ------------------ */
    
    if (!verifyEmail(document.forms['add_a'].mail)) {
        return;
    }
    if (document.forms['add_a'].user.value == "") {
        document.getElementById("errUsr").innerHTML = "Introduceti user-ul.";
        return;
    }
    if (document.forms['add_a'].password.value == "") {
        document.getElementById("errPas1").innerHTML = "Introduceti parola.";
        return;
    }
    if (document.forms['add_a'].password2.value == "") {
        document.getElementById("errPas2").innerHTML = "Reintroduceti parola.";
        return;
    }
    if ((document.forms['add_a'].password.value != document.forms['add_a'].password2.value)) {
        document.getElementById("errPas3").innerHTML = "Parolele trebuie sa coincida.";
        return;
    }
    if ((document.forms['add_a'].code.value == "")) {
        document.getElementById("errCode").innerHTML = "Introduceti codul.";
        return;
    }
    document.forms['add_a'].submit();
}

/** *********************************************************************** */
function updateAnunt(){
    if (document.update.domeniu.value == 0) {
        alert("Domeniul de activitate a fost omis.");
        document.update.domeniu.focus();
        return;
    }
    if (document.update.subdomeniu.value == 0) {
        alert("Subdomeniul de activitate a fost omis.");
        document.update.subdomeniu.focus();
        return;
    }
    if (document.update.nume_a.value == "") {
        alert("Titlul nu a fost specificat.");
        document.update.nume_a.focus();
        return;
    }
    if (document.update.nume_a.value.length > 49) {
        alert("Titlul anun�ului are rol informativ �i nu poate dep�i 49 de caractere.");
        document.update.nume_a.focus();
        return;
    }
    if (document.update.descriere_a.value == "") {
        alert("Descrierea a fost omis�.");
        document.update.descriere_a.focus();
        return;
    }
    if (checkWordLength(document.update.descriere_a.value) == false) {
        alert("Descrierea con�ine cuvinte foarte lungi. Aceast� eroare mai apare �n cazul �n care dup� semnele de punctua�ie nu se las� spa�iu.");
        document.update.descriere_a.focus();
        return;
    }
    if (checkForEmail(document.update.descriere_a.value) == false) {
        alert("Descrierea nu poate con�ine adrese de e-mail. La detalii anun� apare deja adresa de email cu care te-ai �nregistrat.");
        document.update.descriere_a.focus();
        return;
    }
    if (document.update.descriere_a.value.length > 1500) {
        alert("Descrierea unui anun� nu poate dep�i 1500 caractere. Pentru a oferi mai multe informa�ii, cei interesa�i v� pot contacta telefonic sau prin e-mail.");
        document.update.descriere_a.focus();
        return;
    }
    document.forms.update.submit();
}

/** ************************************************************************ */
function raspundeAnunt(id, num){
    url = "formular.php?id=" + id;
    divForm = "rasp" + num;
    document.getElementById(divForm).style.display = "block";
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4) 
            if (xmlhttp.status == 200) 
                verifyAnunt(xmlhttp, num, divForm);
    }
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}

/* formular contact */

function verifyAnunt(req, id, div){
    document.getElementById(div).style.display = "block";
    document.getElementById(div).innerHTML = req.responseText;
}

/** ************************************************************************ */

function raspuns(){
    if ($('#name').val() == "") {
        $("#errN").css('display', 'block');
        $("#errN").html("Introduceti numele.");
        $('#nume').focus();
        return;
    }
    else {
        $("#errN").css('display', 'none');
    }
    if ($('#subject').val() == "") {
        $("#errS").css('display', 'block');
        $("#errS").html("Introduceti subiectul.");
        $('#subject').focus();
        return;
    }
    else {
        $("#errS").css('display', 'none');
    }
    
    if (!verifyEmail(document.getElementById('email'))) {
        return;
    }
    else {
        $("#errMail").css('display', 'none');
    }
    if ($('#mesaj').val() == "") {
        $("#errMsg").css('display', 'block');
        $("errMsg").html("Introduceti mesajul.");
        return;
    }
    else {
        $("#errMsg").css('display', 'none');
    }
    $.ajax({
	        url: 'trimiteRaspuns.php',
	        type: 'post',
        data: {
            'name'		: $('#name').val(),
            'subiect'	: $('#subject').val(),
            'email'		: $('#email').val(),
            'msg'		: $('#mesaj').val(),
            'anunt'		: $('#anunt').val(),
            'dest'		: $('#destinatar').val()
        },
        
        success: function(msg){
            mailSent();
        }
    });
    
}
/** *************************************************************************** */
function verify_email(email) {
	var patern = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i
//	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!patern.test(email))
		return false
		else return true

}

/**
 * Feedback function validates the data from the feedback form and sends it via
 * ajax to the php file
 */
function feedback(){

    if ($('#uName').val() == "") {
        $('#uName').focus();
        $('#uName').css('border-color', 'red');
        return;
    } else {
    	  $('#uName').css('border-color', '#c7d2d6');
    }
    if (!verify_email($('#uEmail').val())) {
    	$('#uEmail').focus();
        $('#uEmail').css('border', '1px solid red');
        return;
    }
    else {
        $("#uEmail").css('border-color', '#c7d2d6');
    }
    if ($('#message').val() == "") {
        $("#message").css('border-color', 'red');
        return;
    }
    else {
        $("#message").css('border-color', '#c7d2d6');
    }
    
    $.ajax({
	        url		: 'send_feedback.php',
	        type	: 'post',
	       
        data: {
    		'sFeedback' : $('#sFeedback').val(),
            'uName'		: $('#uName').val(),
            'uEmail'	: $('#uEmail').val(),
            'message'	: $('#message').val()
        },
        
        success: function(msg){
            $('#feedback-form').html('<div id="success">Mesajul a fost trimis!</div>');
        }
    });   
}

/** *************************************************************************** */


function mailSent(){
    $('.smallerForm').html('<strong>Mesajul a fost trimis.</strong>')
}

/** ************************************************************************ */
function checkWordLength(propozitie){
    cuvinte = propozitie.split(" ");
    
    returnData = true;
    i = 0;
    
    while (i < cuvinte.length) {
        if (cuvinte[i].length > 26) {
            returnData = false;
        }
        i++;
    }
    return returnData;
}

function checkForEmail(propozitie){
    cuvinte = propozitie.split(" ");
    filter = /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi;
    
    returnData = true;
    i = 0;
    
    while (i < cuvinte.length) {
        if (cuvinte[i].match(filter)) {
            returnData = false;
        }
        i++;
    }
    return returnData;
}

/*--------------------------------------------------------------------------------------------------------------------*/
function inregistrare(){
    /*
	 * if(document.forms['regForm'].nume.value == ""){
	 * document.getElementById("errN").innerHTML = "Introduceti numele.";
	 * return; } if(document.forms['regForm'].prenume.value == ""){
	 * document.getElementById("errPn").innerHTML = "Introduceti prenumele.";
	 * return; }
	 */
    if (!verifyEmail(document.register.mail)) {
        return;
    }
    if ((document.forms['regForm'].telefon.value == "") || !verifyTelephone(document.forms['regForm'].telefon.value)) {
        document.getElementById("errTel").innerHTML = "Introduceti numarul de telefon. 10 cifre";
        document.getElementById("errTel").style.display = "block";
        document.forms['regForm'].telefon.focus();
        return;
    }
    if (document.forms['regForm'].user.value == "") {
        document.getElementById("errUsr").innerHTML = "Introduceti user-ul.";
        return;
    }
    if (document.forms['regForm'].password.value == "") {
        document.getElementById("errPas1").innerHTML = "Introduceti parola.";
        return;
    }
    if (document.forms['regForm'].password2.value == "") {
        document.getElementById("errPas2").innerHTML = "Reintroduceti parola.";
        return;
    }
    if ((document.forms['regForm'].password.value != document.register.password2.value)) {
        document.getElementById("errPas3").innerHTML = "Parolele trebuie sa coincida.";
        return;
    }
    document.forms['regForm'].submit();
}

/*------------------------------------------------*/
function contact(){
    if (document.contactFrm.nume.value == "") {
        document.getElementById("errN").innerHTML = "Introduceti numele!";
        // alert("Introduceti numele!");
        return;
    }
    if (document.contactFrm.mobil.value == "") {
        document.getElementById("errTel").innerHTML = "Numarul de telefon lipseste!";
        return;
    }
    if (!verifyEmail(document.contactFrm.email)) {
        return;
    }
    if (document.contactFrm.subiect.value == "") {
        document.getElementById("errS").innerHTML = "Alegeti un subiect!";
        return;
    }
    if (document.contactFrm.mesaj.value == "") {
        document.getElementById("errMsg").innerHTML = "Introduceti mesajul!";
        return;
    }
    document.forms.contactFrm.submit();
}


function sterge(ce){
    if (confirm("Doriti sa stergeti acest anunt?")) {
        document.location = "delMoFo.php?id=" + ce;
    }
}

function search(){
    document.getElementById("cautare").submit();
}

// ADMIN

function add_categ(){
    document.getElementById("cat").submit();
}

function add_subcat(){
    document.getElementById("subcat").submit();
}

function sterge_cat(id){
    if (confirm("Doriti sa stergeti aceasa categorie!")) {
        document.location = "delCat.php?id=" + id;
    }
}

function sterge_subcat(id){
    if (confirm("Doriti sa stergeti aceasa categorie!")) {
        document.location = "delSubcat.php?id=" + id;
    }
}

function sterge_anunt(id){
    if (confirm("Doriti sa stergeti acest anunt?")) {
        document.location = "delAnunt.php?id=" + id;
    }
}

function sterge_user(id){
    if (confirm("Doriti sa stergeti acest utilizator?")) {
        document.location = "delUser.php?id=" + id;
    }
}

function unblockUser(id){
    if (confirm("Doriti sa blocati acest cont!")) {
        document.location = "delUser.php?id=" + id + "&act=unblock";
    }
}

function blockUser(id){
    if (confirm("Doriti sa blocati acest cont!")) {
        document.location = "delUser.php?id=" + id + "&act=block";
    }
}

function loginAdmin(){
    if (document.getElementById("login").admin.value == "") {
        alert("Introduceti userul!");
        return;
    }
    if (document.getElementById("login").passA.value == "") {
        alert("Introduceti parola!");
        return;
    }
    document.getElementById("login").submit();
}
