/* window . open */
$(document).ready(function() {
	$('#close_img_contact_form').hover(
		function(){	
			$('#image_remove_contact').hide(0);
			$('#close_img_contact_form').prepend('<img src="'+TPL+'images/close_form_red.jpg" id="image_remove_contact" alt="Close" class="close_img" />');
		}, 
		function(){
			$('#image_remove_contact').hide(0);
			$('#close_img_contact_form').prepend('<img src="'+TPL+'images/close_form.jpg" id="image_remove_contact" alt="Close" class="close_img" />');
		}
	);
});
function wo(url, opt) {
	opt = opt || {};
	opt.url = url;
	// width and height
	opt.width = opt.width || 500;
	opt.height = opt.height || 300;
	// bars
	opt.status = opt.status || 'no';
	opt.toolbar = opt.toolbar || 'no';
	opt.location = opt.location || 'no';
	opt.menubar = opt.menubar || 'no';
	opt.directories = opt.directories || 'no';
	// others
	opt.resizable = opt.resizable || 'no';
	opt.scrollbars = opt.scrollbars || 'yes';
	opt.name = opt.name || '_blank';
	opt.top = opt.top || 20;
	opt.left = opt.left || 100;
	opt.channelmode = opt.channelmode || 0;
	window.open(opt.url, opt.name, 'width='+opt.width+', height='+opt.height+', status='+opt.status+', toolbar='+opt.toolbar+', location'+opt.location+', menubar='+opt.menubar+', directories='+opt.directories+', resizable='+opt.resizable+', scrollbars='+opt.scrollbars+', top='+opt.top+', left='+opt.left+', channelmode='+opt.channelmode);
	return false;
}

function tooltip() {
		xOffset = 10;
		yOffset = 20;		
	/* END CONFIG */		
	$('img').hover(function(e){											  
		this.t = this.title;
		if(this.t != '') {
			this.title = '';
			$('body').append('<p id="tooltip">'+ this.t +'</p>');
			$('#tooltip')
				.css('top',(e.pageY - xOffset) + 'px')
				.css('left',(e.pageX + yOffset) + 'px')
				.fadeIn('fast');
		}
    }, function(){
		this.title = this.t;
		if(this.title != '') $('#tooltip').remove();
    });
	$('img').mousemove(function(e){
		if($('#tooltip')) $('#tooltip')
			.css('top',(e.pageY - xOffset) + 'px')
			.css('left',(e.pageX + yOffset) + 'px');
	});			
};



function suportRight() {
	if( $('#suportshow').is(':visible') ) {
		$('#suportshow').hide();
		$('#suport').css({ width: '23px', margin:'0 0 0 464px' });
	} else {
		$('#suportshow').show();
		$('#suport').css({ width: '170px', margin:'0 0 0 317px' });
	} return false;
}


function togBut(care) {
	if($('#search_mall_'+care).val() == '1') {
		$('#butSelect'+care).removeClass();
		$('#butSelect'+care).addClass('butSelectS');
		$('#search_mall_'+care).val('0');
	} else {
		$('#butSelect'+care).removeClass();
		$('#butSelect'+care).addClass('butSelect');
		$('#search_mall_'+care).val('1');
	} return false;
}


function setTextfield(ce, care, tohide) {
	$('#'+care).val(ce);
	if(care == 'fjos_nume_magazin') $('#fjos_industrie').val('Activity domain');
	if(care == 'fjos_industrie') $('#fjos_nume_magazin').val('Shop name');
	$('#'+tohide).hide();
	return false;
}

function rfrm(id, cu) { var ifr = document.getElementById(id); ifr.src = cu; return false; }
function showtur(care) { $('.tours').hide(); $('#thehometext').hide(); $('#frameTur'+care).show(); return false; }

function show_benefits(show){
	$('#meniu_promotions').removeClass('selected');
	$('#meniu_cardavantaj').removeClass('selected');
	$('#meniu_'+show).addClass('selected');
	$('#benefits_promotions').hide();
	$('#benefits_cardavantaj').hide();
	$('#benefits_'+show).fadeIn(400);
	$('#benefits_'+show).slideDown();
}
function showtermsandcond(){
	$('#showterms').fadeIn('fast');
}
function hideterms(){
	$('#showterms').hide('fast');
}
var verifica_terms = 0;
function valideaza_checkbox(){
	if ($('#bifacheckbox:checked').val() == 1) verifica_terms = 1; else verifica_terms = 0;
	//alert(verifica_terms);
}
function show_form(){
	if(verifica_terms==1) $('#aplicaonline').show(); else alert('Trebuie sa fiti de acord cu termenii si conditiile');
}
function show_iframe(){
	$('#show_iframe').show('fast');
}
function show_iframe_magazin(care){
	switch (care){
		case 'plaza':
			$('#show_iframe_plaza').show('fast');
		break;
		case 'mall':
			$('#show_iframe_mall').show('fast');
		break;
	}
}
function hide_iframe_magazin(){
	$('.show_iframe').hide('fast');
}
function hide_iframe(){
	$('#show_iframe').hide('fast');
}
function show_mall(care){
	$('.show_iframe').hide('fast');
	$('.hidepoza').hide('fast');
	$('.hide_contact').hide('fast');
	$('.change_play').hide('fast');
	switch (care){
		case 'plaza_romania':
			//$('#show_iframe_plaza').show('fast');
			$('#poza_plaza').show('fast');
			$('#contact_plaza').show('fast');
			$('#change_play_plaza').show('fast');
		break;
		case 'bucuresti_mall':
			//$('#show_iframe_mall').show('fast');
			$('#poza_mall').show('fast');
			$('#contact_mall').show('fast');
			$('#change_play_mall').show('fast');
		break;
	}
}
function form_contact(){
	//alert('da');
	$('#form_contact').show('fast');
}
function close_form(){
	$('#form_contact').hide('fast');
}
function  IsValidEmail(email){
	var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	return filter.test(email);
}
function checkcontactform(){
	var error = ''; var nume = ''; var prenume = ''; var adresa = ''; var telefon = ''; var email = ''; var intrebare = '';

	if($('#nume').val().length>2 && $('#nume').val()!='   ') nume = $('#nume').val(); 
	if($('#prenume').val().length>2 && $('#prenume').val()!='   ') prenume = $('#prenume').val(); 
	if($('#adresa').val().length>2 && $('#adresa').val()!='   ') adresa = $('#adresa').val(); 
	if($('#telefon').val().length>2 && $('#telefon').val()!='   ') telefon = $('#telefon').val();
	if($('#email').val().length>2 && $('#email').val()!='   ') email = $('#email').val();
	if($('#intrebare').val().length>19 && $('#intrebare').val()!='   ') intrebare = $('#intrebare').val();
	var strLenTelefon = telefon.length;
	//nume
	if(nume==''){ $('#error_nume').html('*Campul Nume trebuie completat(3 caractere minim)'); error+= 'Nume';}else $('#error_nume').html('');
	//prenume
	if(prenume==''){ $('#error_prenume').html('*Campul Prenume trebuie completat(3 caractere minim)'); error+= 'Prenume';}else $('#error_prenume').html('');
	//adresa
	if(adresa==''){ $('#error_adresa').html('*Campul Adresa trebuie completat(3 caractere minim)'); error+= 'Adresa'}else $('#error_adresa').html('');
	//telefon
	if(telefon=='') {
		$('#error_telefon').html('*Campul Telefon trebuie completat(10 caractere)');
		error+= 'Telefon';
	}else{ 
		if(telefon.match('[0-9]')){
			//alert(strLenTelefon);
			if(strLenTelefon>9 && strLenTelefon<11){
				$('#error_telefon').html('');
			}else{
				$('#error_telefon').html('*Campul telefon trebuie sa contina 10 cifre');
				error+= 'Telefon';
			}
		}else{
			$('#error_telefon').html('*Campul Telefon nu este numeric');
			error+= 'Telefon';
		}

	}
	//adresa de email
	if(email==''){
		$('#error_email').html('*Campul Email trebuie completat(3 caractere minim)');
		error+= 'Email';
	}else{
		if(IsValidEmail(email)){
			$('#error_email').html('');
		}else{
			$('#error_email').html('*Campul Email nu este completat corect');
			error+= 'Email';
		}
	}
	//intrebare
	if(intrebare==''){ $('#error_intrebare').html('*Campul Intrebare trebuie completat(20 caractere minim)'); error+= 'Intrebare';}else $('#error_intrebare').html('');
	//daca nu exista erori
	if(error==''){
		$('#main_form_contact').html('Va rugam asteptati...');
		$('#submit_form_contact').remove();
		//alert(BASE+'form_contact/');
		$.post(BASE+'form_contact/', { nume:nume, prenume:prenume, adresa:adresa, telefon:telefon, email:email, intrebare:intrebare },
		function(data) {
			if(data == 'ok'){
				//alert('se pot trimite datele');
				$('#main_form_contact').html('Multumim!');
			}else{
				alert (data);
			}
		} ); return false;
	}
}

