// gives option list after country submitted
$(document).on('click','#parcelFormSubmit',function(){
$("#formSection").empty();
if ($('#packageForm').valid()) {
$(this).parent().attr('action')
$.ajax({
type: $(this).closest('form').attr('method'),
url: $(this).closest('form').attr('action'),
data: $(this).closest('form').serialize(),
beforeSend: function(){
$('html, body').animate({scrollTop:$('#formSection').position().top}, 'slow');
$('#formSection').html('
');
},
success: function(data){
$('#formSection').html(data);
$('html, body').animate({scrollTop:$('#formSection').position().top}, 'slow');
}
});
}
});
$(document).on('click','tr.option',function(){
$('tr.option').removeClass('option-active');
$(this).addClass('option-active');
$(this).find('input[type=radio]').prop('checked', true);
});
$(document).on('click','#label-business',function(){
$("#senderName").attr("placeholder", "uzņēmuma nosaukums").val("").focus().blur();
$("[for=senderName]").html("uzņēmuma nosaukums");
$("#senderSurname").attr("placeholder", "reģ. nr.").val("").focus().blur();
$("[for=senderSurname]").html("reģ. nr.");
document.getElementById("privateradio").checked = false;
document.getElementById("businessradio").checked = true;
});
$(document).on('click','#label-private',function(){
$("#senderName").attr("placeholder", "vārds").val("").focus().blur();
$("[for=senderName]").html("vārds");
$("#senderSurname").attr("placeholder", "uzvārds").val("").focus().blur();
$("[for=senderSurname]").html("uzvārds");
document.getElementById("privateradio").checked = true;
document.getElementById("businessradio").checked = false;
});
$(function() {
var max_fields = 10; // maximum input boxes allowed
var wrapper = $("#parcelStack"); // Fields wrapper
var add_button = $(".addParcel"); // Add button ID
var parcelCount = 1; // count higher
var x = 1;
$(add_button).click(function(e){
e.preventDefault();
parcelCount++;
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append(""); //add input box
}
});
$(wrapper).on("click",".removeParcel", function(e){ //user click on remove text
e.preventDefault(); $(this).closest('.row').remove(); x--;
})
});
/******************* VALIDATION ********************/
$("#packageForm").validate({
submitHandler: function(form) {
form.submit();
}
});
$(function() {
$("#packageForm").validate({
rules: {
"weight[]": { number: true, required: true },
"height[]": { number: true, required: true },
"length[]": { number: true, required: true },
"width[]": { number: true, required: true },
"receiver_index": { required: true },
"sender_index": { required: true }
},
messages: {
"weight[]": "izmērs jānorāda gramos",
"height[]": "izmērs jānorāda centimetros",
"length[]": "izmērs jānorāda centimetros",
"width[]": "izmērs jānorāda centimetros",
"receiver_index": "obligāts lauks",
"sender_index": "obligāts lauks"
},
highlight: function(element, errorClass, validClass) {
$(element).addClass(errorClass).removeClass(validClass);
$(element).siblings('span').addClass('input-addon-error');
},
unhighlight: function(element, errorClass, validClass) {
$(element).addClass(validClass).removeClass(errorClass);
$(element).siblings('span').addClass('input-addon-valid');
}
});
});
$(document).on("click","#formSubmit", function(){
$("#theForm").validate({
rules: {
"receiver_name": { required: true },
"receiver_surname": { required: true },
"receiver_phone": { number: true, required: true },
"receiver_street": { required: true },
"sender_name": { required: true },
"sender_surname": { required: true },
"sender_phone": { required: true },
"sender_email": { email: true, required: true },
"package_value": { number: true, required: true },
"package_description": { required: true }
},
messages: {
"receiver_name": "obligāts lauks",
"receiver_surname": "obligāts lauks",
"receiver_phone": "obligāts lauks",
"receiver_street": "obligāts lauks",
"sender_name": "obligāts lauks",
"sender_surname": "obligāts lauks",
"sender_phone": "obligāts lauks",
"sender_email": "obligāts lauks",
"package_value": "obligāts lauks",
"package_description": "obligāts lauks"
}
});
});
$(document).on("click","#paymentSubmit", function(){
$("#banklinkform").validate({
rules: {
"payment_method": { required: true }
},
messages: {
"payment_method": "obligāts lauks"
}
});
});
/*********** LABEL-FLOAT ************/
$(document).on("focus","input, select", function(){
if($("input, select").on("focus", function(){
$(this).parent().siblings(".label-float").animate({opacity: 1});
}));
if($("input, select").on("blur", function(){
if(!$(this).val()){
$(this).parent().siblings(".label-float").animate({opacity: 0});
}
}));
});
/************ theForm focus ***********/
$(document).on("focus",".theForm", function(){
$(this).closest(".theForm").addClass("hover");
});
$(document).on("blur",".theForm",function(){
$(this).closest(".theForm").removeClass("hover");
})
/********* payment_method *************/
$(function(){
$('#select-swedbank').click(function(){
$('#payment_method').val('swedbank');
$('.pm-select').removeClass('active');
$(this).addClass('active');
});
$('#select-paypal').click(function(){
$('#payment_method').val('paypal');
$('.pm-select').removeClass('active');
$(this).addClass('active');
});
$('#select-creditcard').click(function(){
$('#payment_method').val('creditcard');
$('.pm-select').removeClass('active');
$(this).addClass('active');
});
});
/*** change status test ***/
$(function(){
$('.changer').change(function(e){
e.preventDefault();
dataString = $(this).closest('form').serialize();
$.ajax({
type: $(this).closest('form').attr('method'),
url: $(this).closest('form').attr('action'),
data: $(this).closest('form').serialize()
})
})
});
/*** change status ***
$(function(){
$('.change_payment_status').on('change', function(e){
e.preventDefault();
dataString = $(this).parent("form").serialize();
$.ajax({
type: $(this).closest('form').attr('method'),
url: $(this).closest('form').attr('action'),
data: $(this).closest('form').serialize()
});
});
});*/
/*** extra parcel add ***/
$(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $("#parcelStack"); //Fields wrapper
var add_button = $(".addParcel"); //Add button ID
var parcelCount = 1; //count higher
var x = 1;
$(add_button).click(function(e){
e.preventDefault();
parcelCount++;
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append(""); //add input box
}
});
$(wrapper).on("click",".removeParcel", function(e){ //user click on remove text
e.preventDefault(); $(this).closest('.row').remove(); x--;
})
});
/*** package type ***/
$(function(){
$('#parcel-type-envelope').click(function(){
$("#width").parent().parent().hide();
$("#height").parent().parent().hide();
$("#length").parent().parent().hide();
$('#parcel_type').val('envelope');
$(this).siblings("button").removeClass("active-type");
$(this).addClass("active-type");
});
$('#parcel-type-box').click(function(){
$("#width").parent().parent().show();
$("#height").parent().parent().show();
$("#length").parent().parent().show();
$('#parcel_type').val('box');
$(this).siblings("button").removeClass("active-type");
$(this).addClass("active-type");
});
})
/*** spawns cities ***/
$(function() {
var userLang = "LV";
$('#receiverCountry').change(function() {
var qStringA = $(this).val();
var qStringB = userLang;
$.post('https://sutijums.lv/views/partial-city.php', { 'data': [qStringA, qStringB] }, processResponse);
});
function processResponse(data) {
$('#receiverCityDiv').html(data).show();
}
});