﻿
function noError(){return true;}
window.onerror = noError;

var vurl = window.top.location.toString();

function isEmail(str) {
	var filter= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return (filter.test(str) ? true : false);
}

$(document).ready(function() {
	$('#mainimg').corner("10px");
	$('#slidedesc').corner("bl 10px br 10px");
	$('#despre').corner("10px");
	
	$('.com2').toggle(function() {
			$('#commentform').show();
		}, function() {
			$('#commentform').hide();
	});
	
	var catH = $("#slidedesc").height();
	if (catH/2 != Math.floor(catH/2)) {$("slidedesc").css({paddingBottom:1})};
	
	$.countdown.regional['ro'] = {
		labels: ['An', 'Luni', 'Saptamani', 'Zile', 'Ore', 'Minute', 'Secunde'],
		compactLabels: ['A', 'L', 'S', 'Z'], timeSeparator: ':'};
		
	$.countdown.setDefaults($.countdown.regional['ro']);

	shortly = new Date(2009, 7, 28, 13, 0, 0);
	$('#amrt').countdown({until: shortly, format: 'DHMS'});
	

	$('.banner').cycle({
		fx:     'fade',
		timeout: 5000,
		pause:	true
	});
	
	$('a.hasPic').lightBox();
	
	function newsletter(ntip) {
		if(ntip != '') {
			var vemail = $('input[name=news_email]').val();
			
			if(!isEmail(vemail)) {
				alert('Adresa de email specificata nu este valida.');
			} else {
				$.ajax({
					url: 'server.php',
					type: 'POST',
					dataType: 'html',
					data: 'email='+vemail+'&modalitate='+ntip+'&action=getNewsletter',
					success: function(html) {
						if(html != '') {
							alert(html);
						} else {
							if(ntip == 'abonare')  alert('Va multumim, ati fost adaugat cu succes in baza noastra de date');
							else alert('Va multumim, ati fost sters din baza noastra de date');
							
							$('input[name=news_email]').val('');
						}
					}
				});
			}
		}
	}

	
	$('.abonare').click(function() {
		newsletter('abonare');
		return false;
	});
	
	$('.dezabonare').click(function() {
		newsletter('dezabonare');
		return false;
	});
	
	
	$('form.contactform').submit(function(){

		adConNume = jQuery.trim($('input[name=adConNume]').val());
		adConTelefon = jQuery.trim($('input[name=adConTelefon]').val());
		adConEmail = jQuery.trim($('input[name=adConEmail]').val());
		adConSubiect = jQuery.trim($('input[name=adConSubiect]').val());
		adConMesaj = jQuery.trim($('textarea[name=adConMesaj]').val());
		adConCaptcha = jQuery.trim($('input[name=captcha]').val());
		
		if(adConNume == '') alert('Va rugam introduceti numele dumneavoastra');
		else if(adConNume.length > 100) alert('Numele nu poate fi mai lung de 100 de caractere');
		else if(adConEmail == '') alert('Va rugam introduceti adresa dumneavoastra de email');
		else if(!isEmail(adConEmail)) alert('Va rugam introduceti o adresa valida de email');
		else if(adConSubiect == '') alert('Va rugam introduceti subiectul');
		else if(adConMesaj == '') alert('Va rugam introduceti mesajul dumneavoastra');
		else if(adConMesaj.length < 10) alert('Mesajul dumneavoastra trebuie sa contina cel putin 10 caractere');
		else if(adConCaptcha.length < 4 || adConCaptcha.length > 6) alert('Completati corect codul de securitate');
		else {
			var html = $.ajax({
			type: 'POST',
			url: 'server.php',
			data: 'cod='+adConCaptcha+'&action=getCaptcha',
			async: false
			}).responseText;
			
			if(html == '') {
				alert('Completati corect codul de securitate');
				document.getElementById('mcptch').src = document.getElementById('mcptch').src + '?' + (new Date()).getMilliseconds();
			} else {
				return true;
			}
		}
		return false;
	});
	

	$('form.addComForm').submit(function(){

		adComNume = jQuery.trim($('input[name=adComNume]').val());
		//adComEmail = jQuery.trim($('input[name=adComEmail]').val());
		adComMesaj = jQuery.trim($('textarea[name=adComMesaj]').val());
		adComCaptcha = jQuery.trim($('input[name=captcha]').val());
		
		if(adComNume == '') alert('Va rugam introduceti numele dumneavoastra');
		else if(adComNume.length > 100) alert('Numele nu poate fi mai lung de 100 de caractere');
		//else if(adComEmail == '') alert('Va rugam introduceti adresa dumneavoastra de email');
		//else if(!isEmail(adComEmail)) alert('Va rugam introduceti o adresa valida de email');
		else if(adComMesaj == '') alert('Va rugam introduceti mesajul dumneavoastra');
		else if(adComMesaj.length < 10) alert('Mesajul dumneavoastra trebuie sa contina cel putin 10 caractere');
		else if(adComCaptcha.length < 4 || adComCaptcha.length > 6) alert('Completati corect codul de securitate');
		else {
			var html = $.ajax({
			type: 'POST',
			url: 'server.php',
			data: 'cod='+adComCaptcha+'&action=getCaptcha',
			async: false
			}).responseText;
			
			if(html == '') {
				alert('Completati corect codul de securitate');
				document.getElementById('mcptch').src = document.getElementById('mcptch').src + '?' + (new Date()).getMilliseconds();
			} else {
				return true;
			}
		}
		return false;
	});
	
	
	$('.videothumb').find('a').click(function() {
		vid = $(this).attr('href').split('/')[4];
		
		if(vid != '') {
			$.ajax({
				url: 'server.php',
				type: 'POST',
				dataType: 'html',
				data: 'id='+vid+'&action=getVideo',
				success: function(html) {
					if(html != '') {
						vpsp = html.split('~!~');
						var vnid = vpsp[0];
						var vnnume = vpsp[1];
						var vnautostart = vpsp[2];
						var vnimg = vpsp[3];
						
						var s1 = new SWFObject('images/mediaplayer.swf', 'mediaplayer', '398', '317', '7');
						s1.addParam('allowfullscreen', 'true');
						s1.addVariable('width', '398');
						s1.addVariable('height', '317');
						s1.addVariable('autostart', vnautostart);
						s1.addVariable('file', '../galerie/video/'+vnid+'/'+vnid+'.flv');
						s1.addVariable('image', 'images/img/img.php?src=../../galerie/video/'+vnid+'/'+vnimg);
						s1.write('videoDet');
					}
				}
			});
		}
		
		return false;
	});
	
	
	$('.submitprod').each(function() {
		$(this).click(function() {
			var vID = '#'+$(this).attr('id').replace('Sterge_', 'Input_');
			if(vID != '') {
				if(confirm('Sunteti sigur ca doriti sa stergeti?')) {
					$(vID).val(0);
					$('#cosform').submit();
				}
			}
			return false;
		});
	});

	$('#submitprodus').click(function() {
		vmarime = $('select[name=marime]').val();
		vculoare = $('select[name=culoare]').val();
		vcantitate = $('input[name=cantitate]').val();
		
		if(vmarime == undefined) {
			if(vculoare == '' || vcantitate == '') {
				alert('Completeaza toate campurile');
				return false;
			} else {
				return true;
			}
		} else {
			if(vmarime == '' || vculoare == '' || vcantitate == '') {
				alert('Completeaza toate campurile');
				return false;
			} else {
				return true;
			}
		}
	});
	
	
	$('#submitachita').click(function() {
		window.location.href=vurl.replace('cos', 'mergi-la-casa');
		return false;
	});
	
	
	
	$('form.achitaForm').submit(function(){
		vnume = jQuery.trim($('input[name=nume]').val());
		vprenume = jQuery.trim($('input[name=prenume]').val());
		vtelefon = jQuery.trim($('input[name=telefon]').val());
		vemail = jQuery.trim($('input[name=email]').val());
		vadresa = jQuery.trim($('input[name=adresa]').val());
		voras = jQuery.trim($('input[name=oras]').val());
		vjudet = jQuery.trim($('input[name=judet]').val());
		
		
		if(vnume == '' || vprenume == '' || vtelefon == '' || vemail == '' || !isEmail(vemail) || vadresa == '' || voras == '' || vjudet == '') {
			alert('Va rugam completati corect campurile marcate cu *');
			return false;
		} else return true;
	});
	
	
	$('#cautasubmit').click(function() {
		vcauta = $('input[name=cauta]').val();
		if(vcauta == '') {
			alert('Va rugam completati campul de cautare');
			return false;
		} else return true;
	});
	
	
	
	
});