function showLoader() {
    $.fancybox.showActivity();
}

function hideLoader() {
    $.fancybox.hideActivity();
}

function submitFormJSON(fID, fFormID) {
    fArray = $('#' + fID).serializeArray();
    if (checkForm(fID)) {
    	showLoader();

    	$.post(window.remoteURL + 'form-receive&linkid=' + fFormID, fArray, function (json) {
    		if (json.status == 'OK') {
    			$('#' + fID + 'Btn').fadeOut(100);
    			$('#' + fID).html(json.data);
    		} else {
    		}
    		hideLoader();
    	}, 'json');
    } else {
		
    }
}

function submitForm(fID) {
	fObj = $('#'+fID).serializeArray();
	if (checkForm(fID)) {
	    showLoader();
	    $.post('/php/index.php', fObj, function (data) {
	        $('#' + fID).fadeOut(300);
	        $('#' + fID + 'Btn').fadeOut(300);

	        fRedirect = $('#formRedirect').val();
	        if (fRedirect != undefined && fRedirect != '') {
	            location.href = fRedirect;
	        } else {
	            $('#contentBody').fadeOut(300, function () {
	                $('#contentBody').html(data);
	                $('#contentBody').fadeIn(300);
	            });
	        }

	        hideLoader();
	    });
	} else {
		alert('Sorry, you missed some fields.');
	}
}

function checkForm(fID) {
	fResult = true;
	$('.fieldFor'+fID).each(function() {
		fLength = parseInt($(this).attr('requiredlength'));
		fVal = $(this).val();
		if (fVal.length < fLength && fLength > 0) {
			fResult = false;
			$(this).addClass('inputWarning');
		} else {
			$(this).removeClass('inputWarning');
		}
	});

	$('.inputRequired, #'+fID+' .input-required').each(function() {
		fVal = $(this).val();
		if (fVal == '') {
			fResult = false;
			$(this).addClass('inputWarning');
		} else {
			$(this).removeClass('inputWarning');
		}
	});

    $('#' + fID + ' .input-radio.input-required').each(function () {
        fName = $(this).attr('name');
        fLen = $('.input-radio[name="' + fName + '"]:checked').length;
        if (fLen == 0) {
            fResult = false;
            $('.input-radio[name="' + fName + '"]').parent().addClass('input-warning');
        } else {
            $('.input-radio[name="' + fName + '"]').parent().removeClass('input-warning');
        }
    });

	
	return fResult;
}

function request(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	fResult = '';
	
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			fResult = ft[1];
		}
	}
	
	return fResult;
}



