var stop=1;

function contact(lang) {
	//eror
	var error='';
	// start
	// jQuery('.buton2').addClass('loading');
	// info
	var nume = jQuery('#nume').val();
	var mail = jQuery('#mail').val();
	var subject = jQuery('#subject').val();
	var mesaj = jQuery('#mesaj').val();

	if(lang=='en') {
		if(nume.length==0 || nume==' ') error += 'You have not fill in your "Name" <br />';
		if(mail.length==0 || mail==' ') error += 'You have not fill in your "Email" <br />';

		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test(mail) == false) error += 'Invalid Email Address <br />';
		if(mesaj.length==0 || mesaj==' ') error += 'You have not fill in your "Message" <br />';
	}
	else if(lang=='ro') {
		if(nume.length==0 || nume==' ') error += 'Nu ati completat campul Nume <br />';
		if(mail.length==0 || mail==' ') error += 'Nu ati completat campul Email <br />';

		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test(mail) == false) error += 'Adresa de e-mail invalida <br />';
		if(mesaj.length==0 || mesaj==' ') error += 'Nu ati completat campul Mesaj <br />';
	}

	if(error.length==0) {

		jQuery('.flerror2').slideUp('slow');
		// post
		jQuery.post('ajax.php?a=contact',
			{
				nume: nume,
				mail: mail,
				subject: subject,
				mesaj: mesaj
			},
				function(data)
			{
						// afisare ok
						jQuery('.flerror').fadeIn('fast');
						// stop
						// jQuery('.buton2').removeClass('loading');
					}
		);

	} else {
		 // jQuery('.buton2').removeClass('loading');
		jQuery('.flerror2 p').html(error);
		jQuery('.flerror2').slideDown('slow');
	}

}


function formular(lang,type) {
	//eror
	var error='';
	// start
	// jQuery('.buton2').addClass('loading');
	// info
	var nume = jQuery('#nume').val();
	var prenume = jQuery('#prenume').val();
	var company = jQuery('#company').val();
	var industry = jQuery('#industry').val();
	var job = jQuery('#job').val();
	var mail = jQuery('#mail').val();

	if(type ==1) var link='publications/in-the-press.html';
	if(type ==2) var link='publications/white-papers.html';

	if(lang=='en') {
		if(nume.length==0 || nume==' ') error += 'You have not fill in your "First Name" <br />';
		if(prenume.length==0 || prenume==' ') error += 'You have not fill in your "Last Name" <br />';
		if(company.length==0 || company==' ') error += 'You have not fill in your "Company" <br />';
		if(mail.length==0 || mail==' ') error += 'You have not fill in your "Email" <br />';
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test(mail) == false) error += 'Invalid Email Address <br />';
	}
	else if(lang=='ro') {
		if(nume.length==0 || nume==' ') error += 'Nu ati completat campul Nume <br />';
		if(prenume.length==0 || prenume==' ') error += 'Nu ati completat campul Prenume <br />';
		if(company.length==0 || company==' ') error += 'Nu ati completat campul Companie <br />';
		if(mail.length==0 || mail==' ') error += 'Nu ati completat campul Email <br />';
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test(mail) == false) error += 'Adresa de e-mail invalida <br />';
	}

	if(error.length==0) {

		jQuery('.flerror2').slideUp('slow');
		// post
		jQuery.post('ajax.php?a=formular',
			{
				nume: nume,
				prenume:prenume,
				company:company,
				industry:industry,
				job:job,
				mail: mail

			},
				function(data)
			{
						// afisare ok
						jQuery('.flerror').fadeIn('fast');
						// stop
						// jQuery('.buton2').removeClass('loading');
						window.location.href=link;
					}

		);

	} else {
		 // jQuery('.buton2').removeClass('loading');
		jQuery('.flerror2 p').html(error);
		jQuery('.flerror2').slideDown('slow');
	}

}

function scroll_news_up() {
	if(stop==1){
		var test = jQuery('#showcaseInfo ul').children().size();
		if (test % 1 == 0) {var test = test + 1;}
		stop=0;

		//alert(test);
		var top=$('#showcaseInfo ul').css('top');

		  $('#showcaseInfo ul').animate({
		    top: ((top=='0px')?'':'+=42')
		  }, 350, function() {
		  	stop=1;
		    // Animation complete.
		  });

	}

}

function scroll_news_down() {
	if(stop==1){
		var test = jQuery('#showcaseInfo ul').children().size();
		test2=((-42)*(test-3))+'px';
		stop=0;

			var top=$('#showcaseInfo ul').css('top');
	  $('#showcaseInfo ul').animate({
	    top: ((top==test2)?'-=0':'-=42')
	  }, 350, function() {
	  		stop=1;
	    // Animation complete.
	  });
	}

}

function newsletter(lang) {

	var mail = $('#newsletter').val();

	$.post('ajax.php?a=abonare',
		{
			mail: mail
		},function(data) {

			if(lang=='en'){
				if(data==1) alert('This e-mail address is already subscribed to our newsletter system.');
				else if(data==2) { $('#newsletter').val(''); alert('Your address has been registered.'); }
				else alert('Address invalid!');
			}
			else if(lang=='ro') {
				if(data==1) alert('Aceasta adresa de e-mail este deja abonata la sistemul nostru de newsletter.');
				else if(data==2) { $('#newsletter').val(''); alert('Adresa dvs. a fost inregistrata.'); }
				else alert('Adresa invalida!');
			}
			else if(lang=='sp') {
				if(data==1) alert('Esta dirección de correo electrónico ya está suscrito a nuestro sistema de boletín de noticias.');
				else if(data==2) { $('#newsletter').val(''); alert('Su dirección ha sido registrada.'); }
				else alert('Correo electrónico no válida!');
			}


		}
	);

}

