//country objects are declared in common.plugin.js file in(common javascript folder)
$(document).ready(function () {
    $(document).on('click','#button', function () {
        $("#show").hide();
        $("#AjaxdivSuggestProcess").show();
    });
    $("#stateSelectedType").val("state");
    listState();
    $("#affiliateReqCountryID").change(function () {
        listState();
    });
    $("#affiliateReqStateID").change(function () {
        var stateID = $("#affiliateReqStateID").val();
        $("#stateSelectedID").val(stateID);
    });
    $("#reload_icon_captcha").click(function () {
        $("#affiliateRequestSecurityCode").val("");
    });
    $("#affiliateReqFirstName").bind('change keyup', function (event) {
        var message = $(this).val();
        validate(message, $(this));
    });
    $("#affiliateReqName").bind('change keyup', function (event) {
        var message = $(this).val();
        validate(message, $(this));
    });
    $("#affiliateReqComments").bind('change keyup', function (event) {
        var message = $(this).val();
        validate(message, $(this));
    });
    $("#affiliateReqLastName").bind('change keyup', function (event) {
        var message = $(this).val();
        validate(message, $(this));
    });
    $("#affiliateReqAddress1").bind('change keyup', function (event) {
        var message = $(this).val();
        validate(message, $(this));
    });
	$('#forms').bind("submit",function ()
	{	
		if($("#captchaCode").length>0 && $('.hid_err_forms_validations[value=1]').length>0)
		{
			setCapcha();
		}	
	});
});

function validate(val, item) {
    if (val.match(/([\<])([^\>]{1,})*([\>])/i)) {
        jAlert('Html tags are not allowed');
        item.val('');
    }
}

function showLoader() {
    $("#AjaxdivSuggestProcess").show();
}

function listState() {
    var dataArray = new Array();
    countryID = $("#affiliateReqCountryID").val();
    stateID = $("#stateSelectedID").val();
    if(countryID!=''){
		$.ajax({
			url: GLOBAL_BASE_PATH + "/ajax/ajaxState/",
			type: "POST",
			cache: false,
			global: false,
			data: "countryID=" + countryID + "&stateID=" + stateID,
			success: function (data) {
				var data = $.trim(data);
				if (dataArray[0] != '') {
					if (data != "") {
						$("#affiliateReqStateID").empty();
						$("#affiliateReqStateID").append('<option value="">Select</option>' + data);
						$("#spanStateProvince").hide();
						$("#spanState").show();
						$("#stateSelectedType").val("state");
						$("#stateProvince").val("");
					} else {
						$("#spanState").hide();
						$("#spanStateProvince").show();
						$("#stateSelectedType").val("province");
					}
				} else {
					$("#affiliateReqStateID").empty();
					$("#affiliateReqStateID").append('<option value="">Select</option>');
				}
			}

		});
	}
}