var urlAkcija = "action.php";//lokalno
//var urlAkcija = "/action.php";//server





function quoteFormOpen () {

	$('#quote_form').toggle('slide',{ direction: 'left' });
	
}



function question1 () {

	$('#quote_form_loading').show();
	$('#quote_form_info').html('');
	var location_odgovor = 0;
	
	for (i=0; i<document.forma.location.length; i++) {
		
		if (document.forma.location[i].checked==true) {
		   location_odgovor = document.forma.location[i].value
		}
		
	}

	if (location_odgovor != 0) {
		
		$.post(urlAkcija, {strana: 'quote', tip: 'question1', location_odgovor: location_odgovor},
			function(data) {
				
				if (data) {
					questionSlide (data);
				} 
				
			}
		);
		
	} else {
		
		$('#quote_form_loading').hide();
		$('#quote_form_info').html('<p>Please choose one answer</p>');	
		
	}
	
}



function question2 () {

	$('#quote_form_loading').show();
	$('#quote_form_info').html('');
	var looking_odgovor = 0;
	
	for (i=0; i<document.forma.looking.length; i++) {
		
		if (document.forma.looking[i].checked==true) {
		   looking_odgovor = document.forma.looking[i].value
		}
		
	}
	
	if (looking_odgovor != 0) {
		
		var chk = 0;
		
		if (looking_odgovor=="Valet services for an event or party") {
			
			var size_odgovor = 0;
			for (i=0; i<document.forma.size.length; i++) {
			
				if (document.forma.size[i].checked==true) {
				   size_odgovor = document.forma.size[i].value
				}
				
			}
			
			if (size_odgovor == 0) {
				
				$('#quote_form_loading').hide();
				$('#quote_form_info').html('<p>Please choose size of event</p>');	
				chk = 1;
				
			} else {
				
				var dan = document.getElementById('element_5_1').value;
				var mesec = document.getElementById('element_5_2').value;
				var godina = document.getElementById('element_5_3').value;
				
				if (dan==0 || mesec==0 || godina==0) {
					
					$('#quote_form_loading').hide();
					$('#quote_form_info').html('<p>Please enter date of event</p>');
					chk = 1;
					
				} else {
					
					var start_time_h = document.getElementById('start_time_h').value;
					var start_time_min = document.getElementById('start_time_min').value;
					var end_time_h = document.getElementById('end_time_h').value;
					var end_time_min = document.getElementById('end_time_min').value;
					chk = 0;
					
				}
			
			}
			
		}
		
		if (chk==0) {
			
			$.post(urlAkcija, {strana: 'quote', tip: 'question2', looking_odgovor: looking_odgovor, size_odgovor: size_odgovor, dan: dan, mesec: mesec, godina: godina, start_time_h: start_time_h, start_time_min: start_time_min, end_time_h: end_time_h, end_time_min: end_time_min},
				function(data) {
					
					if (data) {
						questionSlide (data);
					} 
					
				}
			);
			
		}
		
		
		
	} else {
		
		$('#quote_form_loading').hide();
		$('#quote_form_info').html('<p>Please choose one answer</p>');	
		
	}
	
}




function question3 () {

	$('#quote_form_loading').show();
	$('#quote_form_info').html('');
	
	var name = document.getElementById('name').value;
	var e_mail = document.getElementById('e_mail').value;
	var phone = document.getElementById('phone').value;
	
	if (name==0 || phone==0) {
		
		$('#quote_form_loading').hide();
		$('#quote_form_info').html('<p>Please enter your name and phone number</p>');
		
	} else {
		
		$.post(urlAkcija, {strana: 'quote', tip: 'question3', name: name, e_mail: e_mail, phone: phone},
			function(data) {
				
				if (data) {
					questionSlide (data);
				} 
				
			}
		);
		
	}
	
}





function question4 () {

	$('#quote_form_loading').show();
	$('#quote_form_info').html('');
	
	var text = document.getElementById('text').value;
	
		
	$.post(urlAkcija, {strana: 'quote', tip: 'question4', text: text},
		function(data) {
			
			if (data) {
				questionSlide (data);
			} 
			
		}
	);
	
}





function backQuestion (pitanje) {
	
	$('#quote_form_loading').show();
	$('#quote_form_info').html('');
	
	$.post(urlAkcija, {strana: 'backQuestion', pitanje: pitanje},
		function(data) {
			
			if (data) {
				questionSlide (data);
			} 
			
		}
	);

}



function questionSlide (data) {
	
	$('#quote_form_loading').hide();
	$('#quote_form_hold').hide('slide',{ direction: 'right' });
	$('#quote_form_hold').html(data);
	$('#quote_form_hold').show('slide',{ direction: 'left' });
	
}



function quickqoute () {
	
	$('#quick_quote_form_loading').show();
	$('#quick_quote_form_info').hide();
	
	var dan = document.getElementById('element_6_1').value;
	var mesec = document.getElementById('element_6_2').value;
	var godina = document.getElementById('element_6_3').value;
	
	var iaman_odgovor = 0;
	for (i=0; i<document.quick_forma.iaman.length; i++) {
	
		if (document.quick_forma.iaman[i].checked==true) {
		   iaman_odgovor = document.quick_forma.iaman[i].value
		}
		
	}
	
	var name = document.getElementById('quick_name').value;
	var e_mail = document.getElementById('quick_e_mail').value;
	var phone = document.getElementById('quick_phone').value;
	
	var captcha = document.getElementById('captcha').value;
	var ID_slike = document.getElementById('ID_slike').value;
	
	if (dan==0 || mesec==0 || godina==0 || iaman_odgovor==0 || name==0 || e_mail==0 || phone==0 || captcha==0 || ID_slike==0) {
		
		$('#quick_quote_form_loading').hide();
		$('#quick_quote_form_info').show();
		$('#quick_quote_form_info').html('All fields are required');
		
	} else {
		
		$.post(urlAkcija, {strana: 'quickqoute', dan: dan, mesec: mesec, godina: godina, iaman_odgovor: iaman_odgovor, name: name, e_mail: e_mail, phone: phone, captcha: captcha, ID_slike: ID_slike},
			function(data) {
				
				if (data==1) {//ok
					
					$('#quick_quote_form_loading').hide();
					$('#quick_form_hold').hide();
					$('#quick_form_text').show();
					$('#quick_form_text').html('Your request has been sent <br />thank you');
					
				} 
				
				if (data==2) {//code error
				
					$('#quick_quote_form_loading').hide();
					$('#quick_quote_form_info').show();
					$('#quick_quote_form_info').html('Code you entered is invalid');
					
				}
				
				if (data==3) {//send error
				
					$('#quick_quote_form_loading').hide();
					$('#quick_quote_form_info').show();
					$('#quick_quote_form_info').html('Your request has not been sent, please try again');
					
				}
				
			}
		);
		
	}
	
}



function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
        // otherwise, update 'characters left' counter
    else
        countfield.value = maxlimit - field.value.length;
}



function codeChange () {

	$.post(urlAkcija, {strana: 'codeChange'},
		function(data) {
			
			if (data) {
				$('.codeChange').html(data);
			} 
			
		}
	);
	
}





$(document).ready(function() {
	
	//provera forme
	$("#forma").validate();
	$("#formular_login").validate();
	
	//ubacuje captcha kod
	codeChange();


});


//$('#header').html(x_poz +', '+ y_poz);
//window.alert(slikaW);
