$(document).ready(function(){function comp(field){
			if($("input[name='"+field+"']").val() == ""){
				return false;
			}else{
				return true;
			}
		}
		function int(field){
			if(parseInt($("input[name='"+field+"']").val())){
				return true;
			}else{
				return false;
			}
		}
		function size(field, sz, exact, more){
			if(exact == 0){
				if(more == 0){
					if($("input[name='"+field+"']").val().length > sz){
						return false;
					}else{
						return true
					}
				}else{
					if($("input[name='"+field+"']").val().length < sz){
						return false;
					}else{
						return true
					}
				}
			}else{
				if($("input[name='"+field+"']").val().length != sz){
					return false;
				}else{
					return true
				}
			}
		}
	$("#butSubmit input[name='locForm']").click(function(){
		error = 0;
		//cnp
		if(!comp("LOCcnp")){
			$("#eroare").show().html("completeaza cnp<br />")
			$("input[name='LOCcnp']").focus()
			error = 1;
		}else
		if(!int("LOCcnp")){
			$("#eroare").show().html("cifre va rugam<br />")
			$("input[name='LOCcnp']").focus()
			error = 1;
		}else
		if(!size("LOCcnp", 13, 1, 0)){
			$("#eroare").show().html("trebuie fix 13<br />");
			$("input[name='LOCcnp']").focus()
			error = 1
		}else{
			error = 0;
		}
		//nume
		if(error == 0){
			if(!comp("LOCnumePr")){
				$("#eroare").show().html("completeaza numele<br />")
				$("input[name='LOCnumePr']").focus()
				error = 1;
			}else
			if(!size("LOCnumePr", 3, 0, 1)){
				$("#eroare").show().html("prea mic, min 3<br />");
				$("input[name='LOCnumePr']").focus()
				error = 1
			}else{
				error = 0;
			}
		}
		//strada
		if(error == 0){
			if(!comp("LOCstrada")){
				$("#eroare").show().html("completeaza strada<br />")
				$("input[name='LOCstrada']").focus()
				error = 1;
			}else
			if(!size("LOCstrada", 3, 0, 1)){
				$("#eroare").show().html("prea mic, min 3<br />");
				$("input[name='LOCstrada']").focus()
				error = 1
			}else{
				error = 0;
			}
		}
		//numar
		if(error == 0){
			if(!comp("LOCnr")){
				$("#eroare").show().html("completeaza numarul strazii<br />")
				$("input[name='LOCnr']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//telefon
		if(error == 0){
			if(!comp("LOCtelU")){
				$("#eroare").show().html("completeaza numarul de telefon<br />")
				$("input[name='LOCtelU']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//email
		if(error == 0){
			if(!comp("LOCemailU")){
				$("#eroare").show().html("completeaza adresa de email<br />")
				$("input[name='LOCemailU']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//strada loc
		if(error == 0){
			if(!comp("LOCstradaC")){
				$("#eroare").show().html("completeaza strada<br />")
				$("input[name='LOCstradaC']").focus()
				error = 1;
			}else
			if(!size("LOCstradaC", 3, 0, 1)){
				$("#eroare").show().html("prea mic, min 3<br />");
				$("input[name='LOCstradaC']").focus()
				error = 1
			}else{
				error = 0;
			}
		}
		//numar loc
		if(error == 0){
			if(!comp("LOCnrC")){
				$("#eroare").show().html("completeaza numarul strazii<br />")
				$("input[name='LOCnrC']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//caracteristici
		if(error == 0){
			if($("textarea[name='LOCcarac']").val() == ""){
				$("#eroare").show().html("completeaza caracteristicile cladirii<br />")
				$("textarea[name='LOCcarac']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//elemente
		if(error == 0){
			if($("textarea[name='LOCelem']").val() == ""){
				$("#eroare").show().html("completeaza elementele constructive<br />")
				$("textarea[name='LOCelem']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//tip constr
		if(error == 0){
			if($("#tipC").val() == ""){
				$("#eroare").show().html("alege tipul constructiei<br />")
				$("#tipC").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//suprafata
		if(error == 0){
			if(!comp("LOCsct")){
				$("#eroare").show().html("completeaza suprafata construita(mp)<br />")
				$("input[name='LOCsct']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//an constr
		if(error == 0){
			if(!comp("LOCanc")){
				$("#eroare").show().html("completeaza anul constructiei<br />")
				$("input[name='LOCanc']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//valoare
		if(error == 0){
			if(!comp("LOCval")){
				$("#eroare").show().html("completeaza valoarea cladirii<br />")
				$("input[name='LOCval']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//riscuri
		if(error == 0){
			if($("textarea[name='LOCrisc']").val() == ""){
				$("#eroare").show().html("completeaza riscurile acoperite<br />")
				$("textarea[name='LOCrisc']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		if(error == 0){
			$("#formLOC").submit();
		}
	})
	
	
	
	
	
	//MEDICALE
	$("#butSubmit input[name='medicaleForm']").click(function(){
		error = 0;
		//cnp
		if(!comp("MEDcnp")){
			$("#eroare").show().html("completeaza cnp<br />")
			$("input[name='MEDcnp']").focus()
			error = 1;
		}else
		if(!int("MEDcnp")){
			$("#eroare").show().html("cifre va rugam<br />")
			$("input[name='MEDcnp']").focus()
			error = 1;
		}else
		if(!size("MEDcnp", 13, 1, 0)){
			$("#eroare").show().html("trebuie fix 13<br />");
			$("input[name='MEDcnp']").focus()
			error = 1
		}else{
			error = 0;
		}
		//nume
		if(error == 0){
			if(!comp("MEDnumePr")){
				$("#eroare").show().html("completeaza numele<br />")
				$("input[name='MEDnumePr']").focus()
				error = 1;
			}else
			if(!size("MEDnumePr", 3, 0, 1)){
				$("#eroare").show().html("prea mic, min 3<br />");
				$("input[name='MEDnumePr']").focus()
				error = 1
			}else{
				error = 0;
			}
		}
		//strada
		if(error == 0){
			if(!comp("MEDstrada")){
				$("#eroare").show().html("completeaza strada<br />")
				$("input[name='MEDstrada']").focus()
				error = 1;
			}else
			if(!size("MEDstrada", 3, 0, 1)){
				$("#eroare").show().html("prea mic, min 3<br />");
				$("input[name='MEDstrada']").focus()
				error = 1
			}else{
				error = 0;
			}
		}
		//numar
		if(error == 0){
			if(!comp("MEDnr")){
				$("#eroare").show().html("completeaza numarul strazii<br />")
				$("input[name='MEDnr']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//telefon
		if(error == 0){
			if(!comp("MEDtelU")){
				$("#eroare").show().html("completeaza numarul de telefon<br />")
				$("input[name='MEDtelU']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//email
		if(error == 0){
			if(!comp("MEDemailU")){
				$("#eroare").show().html("completeaza adresa de email<br />")
				$("input[name='MEDemailU']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//destinatie
		if(error == 0){
			if(!comp("MEDdest")){
				$("#eroare").show().html("completeaza destinatia<br />")
				$("input[name='MEDdest']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//plecare
		if(error == 0){
			if(!comp("MEDple")){
				$("#eroare").show().html("completeaza data plecarii<br />")
				$("input[name='MEDple']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		//sosire
		if(error == 0){
			if(!comp("MEDsos")){
				$("#eroare").show().html("completeaza data sosirii<br />")
				$("input[name='MEDsos']").focus()
				error = 1;
			}else{
				error = 0;
			}
		}
		if(error == 0){
			$("#formMED").submit();
		}
	})
	$(".datePic").datepicker();
	$("#pret").click(function(){
		$("#popup").dialog({
			modal: true,
			buttons: {
				Ok: function() {
						$(this).dialog( "close" );
					}
			}
		});
	})
	$(".option").live("click", function(){
		text = $(this).html()
		$("body").append("<div id='optWind' title='Cerere'></div>")
		formular = "<form><div class='input'><span class='den'>Nume</span><input id='reqNume' type='text' name='nume' /></div><div class='input'><span class='den'>Prenume</span><input id='reqPrenume' type='text' name='prenume' /></div><div class='input'><span class='den'>Cod WIN-4-ALL</span><input id='reqWin' type='text' name='win4' /></div><div class='input'><span class='den'>Email</span><input id='reqEmail' type='text' name='email' /></div><div class='input'><span class='den'>Telefon</span><input id='reqTel' type='text' name='telefon' /></div><input type='hidden' name='text' id='text' value='"+text+"' /></form>"
		$("#optWind").html(formular)
		$("#optWind").dialog({
			modal: true,
			width: 400,
			buttons: {
				renunta: function(){
					$(this).dialog("close")
					$("#optWind").remove()
				},
				trimite: function(){
					nume = $("#reqNume").val()
					win4 = $("#reqWin").val()
					email = $("#reqEmail").val()
					tel = $("#reqTel").val()
					asig = $("#text").val()
					data = "nume="+nume+"&email="+email+"&tel="+tel+"&text="+asig+"&win4all="+win4
					$.ajax({
						url: 'includes/processes/asig.php',
						type: 'POST',
						data: data,
						success: function(){
							$("#optWind").dialog("close").remove()
							
						}
					})
				}
			}
		})
	})
})
