jQuery(document).ready(function($j) {
    if ($j('#drop-down').length) {
        activateMenu('drop-down');
    }
   	$j.datepicker.regional['ro'] = {
		clearText: 'Sterge', clearStatus: '',
		closeText: 'Inchide', closeStatus: '',
		prevText: '&laquo;&nbsp;Inapoi', prevStatus: '',
		nextText: 'Inainte&nbsp;&raquo;', nextStatus: '',
		currentText: 'Azi', currentStatus: '',
		monthNames: ['Ianuarie', 'Februarie', 'Martie', 'Aprilie', 'Mai', 'Iunie', 'Iulie', 'August', 'Septembrie', 'Octombrie', 'Noiembrie', 'Decembrie'],
		monthNamesShort: ['Ian', 'Feb', 'Mar', 'Apr', 'Mai', 'Iun', 'Iul', 'Aug', 'Sep', 'Oct', 'Noi', 'Dec'],
		monthStatus: '', yearStatus: '',
		weekHeader: 'Sm', weekStatus: '',
		dayNames: ['Duminica', 'Luni', 'Marti', 'Miercuri', 'Joi', 'Vineri', 'Sambata'],
		dayNamesShort: ['Dum', 'Lun', 'Mar', 'Mie', 'Joi', 'Vin', 'Sam'],
		dayNamesMin: ['D', 'L', 'Ma', 'Mi', 'J', 'V', 'S'],
		dayStatus: 'DD', dateStatus: 'D, M d',
		dateFormat: 'yy-mm-dd', firstDay: 1,
		yearRange: '-90:+10',
		initStatus: '', isRTL: false,
		defaultDate: new Date()
	};
	$j.datepicker.setDefaults($j.datepicker.regional['ro']);
	$j('.calendar').datepicker();
    $j('[title="Sterge!"]').click(function() {
        if (window.confirm('Sigur stergeti?')) {
            return true;
        } else {
            return false;
        }
    });
    $j('[title="Adauga!"]').click(function() {
        $j('#adauga').toggle();
        return false;
    });
	$j('h2.jact').removeClass("active");
	$j('h2.jact').addClass("marg");
	$j('h2.jact').next('div').hide().children('input:not([type="button"], :hidden, :disabled)').val('');
	$j('h2.jact').click(function(){
		$j(this).next('div').toggle();
		$j(this).toggleClass("active");
		$j(this).toggleClass("marg");
	});
	$j.extend($j.validator, {
		messages: {
			required:    "Acest camp este obligatoriu.",
//			remote:      "Please fix this field.",
			email:       "Adresa de email nu este valida.",
//			url:         "Please enter a valid URL.",
			date:        "Data aleasa nu este valida.",
			dateISO:     "Data aleasa nu este valida.",
//			dateDE:      "Bitte geben Sie ein gültiges Datum ein.",
			number:      "Introduceti un numar.",
//			numberDE:    "Bitte geben Sie eine Nummer ein.",
			digits:      "Introduceti doar cifre.",
//			creditcard:  "Please enter a valid credit card.",
			equalTo:     "Introduceti aceeasi valoare inca o data.",
//			accept:      "Please enter a value with a valid extension.",
//			maxlength:   jQuery.format("Please enter no more than {0} characters."),
//			maxLength:   jQuery.format("Please enter no more than {0} characters."),
			minlength:   jQuery.format("Introduceti o valoare lunga de cel putin {0} caractere."),
			minLength:   jQuery.format("Introduceti o valoare lunga de cel putin {0} caractere."),
//			rangelength: jQuery.format("Please enter a value between {0} and {1} characters long."),
//			rangeLength: jQuery.format("Please enter a value between {0} and {1} characters long."),
//			rangeValue:  jQuery.format("Please enter a value between {0} and {1}."),
//			range:       jQuery.format("Please enter a value between {0} and {1}."),
//			maxValue:    jQuery.format("Please enter a value less than or equal to {0}."),
//			max:         jQuery.format("Please enter a value less than or equal to {0}."),
			minValue:    jQuery.format("Introduceti o valoare mai mare sau egala cu {0}."),
			min:         jQuery.format("Introduceti o valoare mai mare sau egala cu {0}."),
			__EOF__: null
		}
	});
	$j.validator.setDefaults({
	    errorClass: "error",
	    onkeyup: false
	});
    $j.validator.addMethod("telefon", function(value, element) {
        reg_check = new RegExp('[^0-9 ;\/]')
        return !reg_check.exec(value);
    }, "Introduceti doar cifre, spatii si ; sau /");

	$j('[type="submit"]').click(function() {
	    $j('select:disabled').attr('disabled', false);
	    return true;
	});
});
function check_users_form(unde) {
	if (unde.username.value=='') {
		alert('Empty username');
		unde.username.focus();
		return false;
	}
	if (unde.email.value=='') {
		alert('Empty email');
		unde.email.focus();
		return false;
	}

	if (unde.id_user_de_salvat.value=='' && unde.password.value=='') {
		alert('Empty password');
		unde.password.focus();
		return false;
	}
	if (unde.password.value!=unde.conf_password.value) {
		alert('Passwords are not the same\nPlease confirm the password !' );
		unde.conf_password.focus();
		return false;
	}
	unde.submit();
//	return true;
}

function change_form_settings(unde, care) {
	//max lenght
	if (care!='1' && care!='2' && care!='8' && care!='9') unde.max_len.value = '255';
		else unde.max_len.value = '';
	if (care=='6') unde.max_len.value = '10';
	//max lenght end
	if (care=='4') unde.valori_default.value = '@';
}

function duplicate_field(care) {
//alert(care);
//
	var x=document.getElementById('insert_'+care);
//	var y=x.parentNode;
	var y=x
	newElem = document.createElement("input");
	newElem.name=care+'[]';
	newElem.type='text';
	newElem.className="tf bbs";

	y.appendChild(newElem);

	return false;
}

function change_select(Name,what) {
//	alert(Name);
	var formName = Name.form;
	what=what.replace(" ","-");
	what=what.toLowerCase();
//	alert(what);
	what2 = Name.name;
//	alert(what2);


	for (j=0; j<formName.length; j++) {

//alert(formName.elements[i].className.indexOf(what2));
		if (formName.elements[j].className.indexOf(what2) !=-1) {
//			alert('gasit');
			temp_x = formName.elements[j].className.split("--");
//			alert(temp_x[1]);
			id = formName.elements[j].id;
//			alert("x"+temp_x[1]+'x');
//			alert("x"+what+'x');
			if (temp_x[1])
				if (temp_x[1]==what) {
	//				alert('arata');
					document.getElementById('zona_'+id).style.display = 'block';
				}
				else {
	//				alert('ascunde');
					document.getElementById('zona_'+id).style.display = 'none';
				}
		}
	}


}

function simulate_change(fornName) {
	for (i=0; i<fornName.length; i++) {
//		alert(fornName.elements[i].type);
		if (fornName.elements[i].type=='select-one') {
//			alert(fornName.elements[i].name);
//			alert(fornName.elements[i]);
//			alert(fornName.elements[i].value);
			change_select(fornName.elements[i],fornName.elements[i].value);
//			alert(fornName.elements[i].onchange);
//			eval(fornName.elements[i].onchange);
		}
	}

}

function change_j_p(formName,what) {
if (what=='Juridical person') {	what='l_p'; what2='l_j'; }
if (what=='Physical person') { what='l_j'; what2='l_p'; }

var id;

for (i=0; i<formName.length; i++) {

		if (formName.elements[i].className.indexOf(what2) !=-1) {
			id = formName.elements[i].id;
			document.getElementById('zona_'+id).style.display = 'block';
		}


	if (formName.elements[i].className.indexOf(what) !=-1) {
			id = formName.elements[i].id;
			document.getElementById('zona_'+id).style.display = 'none';
		}
	}

}

function change_other(fieldName,what) {
	if (what=='Others') {

		var y=fieldName.parentNode;
		newElem = document.createElement("label");
		newElem.id='label_'+fieldName.name;
		y.appendChild(newElem);

		newElem = document.createElement("input");
		newElem.name=fieldName.name;
		newElem.id='input_other_'+fieldName.name;
		newElem.type='text';
		newElem.className="tf bbs";

		y.appendChild(newElem);
	}
	else {
		var x1 = document.getElementById('input_other_'+fieldName.name);
		var x3 = document.getElementById('label_'+fieldName.name);
		var x2 = document.getElementById('zona_'+fieldName.name);
		if (x1) {
			x2.removeChild(x1);
			x2.removeChild(x3);
		}
//		alert(x);
//		x.remove(x.name);


	}
}

function show_search()
{
    var contor = 1;
    while (document.getElementById('cautare_form'+contor) != undefined)
    {
        show_hide('cautare_form'+contor);
        contor = contor + 1;
    }
}

function show_hide(id)
{
	if (document.getElementById(id).style.display=="none")
		document.getElementById(id).style.display="block";
	else document.getElementById(id).style.display="none";
}

function view_window(theURL, winName) { //v2.0
	features="scrollbars=yes,resizable=no,width=1020,height=800";
	w = 1020;
	h = 800;
	sw = screen.width;
	sh = screen.height;
	l = (sw - w) / 2;
	t = (sh - h) / 2;
	window.open(theURL, winName, features);
return false;
}


function trimite_email(cale) {
	var x=prompt('Email');
	if (x) {
//		alert(cale+'&email='+x);
		document.location = cale+'&email='+x;
	}

	return false;
}

