<?php require_once(dirname(__FILE__).'/../../../../config.php'); ?>
<?php header("Content-type: text/javascript"); ?>
$ = jQuery;

//*** SELECT TEXT ***//
    function selectText(containerid) {
        if (document.selection) {
            var range = document.body.createTextRange();
            range.moveToElementText(document.getElementById(containerid));
            range.select();
        } else if (window.getSelection) {
            var range = document.createRange();
            range.selectNode(document.getElementById(containerid));
            window.getSelection().addRange(range);
        }
    }

//*** COLOR PICKER ***//

$('.color-picker').ColorPicker({
	onSubmit: function(hsb, hex, rgb, el) {
		$(el).val( "#"+hex );
		$(el).ColorPickerHide();
		$(el).ColorPickerSetColor(hex);

	//**UPDATE AD PREVIEW COLOR**//
	//		alert(el.id+'/'+hex);
	if ( el.id == 'title-color' ) {
		$( "#"+el.id+"-preview" ).css( "color", "#"+hex );
	}

	if ( el.id == 'link-color' ) {
		$( "#"+el.id+"-preview" ).css( "color", "#"+hex );
		$( "#button-color-preview" ).css( "background", "#"+hex );
	}

	if ( el.id == 'text-color' ) {
		$( "#"+el.id+"-preview" ).css( "color", "#"+hex );
	}

	if ( el.id == 'background-color' ) {
		$( "#ad-design-div" ).css( "background", "#"+hex );
		$( "#button-color-preview" ).css( "color", "#"+hex );
	}

	if ( el.id == 'border-color' ) {
		$( "#ad-design-div" ).css( "border", "1px solid #"+hex );
	}


	},
	onBeforeShow: function () {
		$(this).ColorPickerSetColor( this.value );
	}
})
.bind('keyup', function(){
	$(this).ColorPickerSetColor( this.value );
});
//*** END COLOR PICKER ***//

function jhzEv(emailAddress) {
    var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
    return pattern.test(emailAddress);
};

function url ( href ) {
	var url =	href;
	if(/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url)) {
	  return 'valid';
	} else {
	  return 'invalid';
	}
}


(function($) {
    $.fn.extend( {
        limiter: function(limit, elem) {
            $(this).on("keyup focus", function() {
                setCount(this, elem);
            });
            function setCount(src, elem) {
			
                var chars = src.value.length;
				
                if (chars > limit) {
                    src.value = src.value.substr(0, limit);
                    chars = limit;
                }
                elem.html( limit - chars );
            }
            setCount($(this)[0], elem);
        }
    });
})(jQuery);



jQuery(document).ready(function (e) {
	// REGISTER
	$("#ad-register").on('click', function () {
		var	t	=	0;
		var	fname		=	$("#fname").val();
		var	lname		=	$("#lname").val();
		var	email		=	$("#email").val();
		var	password	=	$("#password").val();
		var	cpassword	=	$("#cpassword").val();
		var	month		=	$("#month").val();
		var	day			=	$("#day").val();
		var	year		=	$("#year").val();
		var	location	=	$("#location").val();
		var	terms;

		if (!$("#terms").is(":checked")) {
				$("#terms-err").html('<div class="alert alert-danger"><?php echo $LANG["WBS_REGF_TERMS_AGREE_CHECK"];?></div>');
			t++;
		}else {
				$("#terms-err").html('');
		}

	if ( fname == "" ) {
		$("#fname").css("border","1px solid #b94a48");t++;
			} else { 
		$("#fname").css("border",""); }

	if ( lname == "" ) {
		$("#lname").css("border","1px solid #b94a48");t++;
			} else { 
		$("#lname").css("border",""); }

	if ( email == "" ) {
		$("#email").css("border","1px solid #b94a48");t++;
			} else { 
		$("#email").css("border",""); }

		if( !jhzEv( email ) && email != '' ){
			$("#email").css("border","1px solid #b94a48");
			t = t + 1;
		}

	if ( password == "" ) {
		$("#password").css("border","1px solid #b94a48");t++;
			} else { 
		$("#password").css("border",""); }

	if ( cpassword == "" ) {
		$("#cpassword").css("border","1px solid #b94a48");t++;
			} else { 
		$("#cpassword").css("border",""); }

	if ( cpassword != password && cpassword!="" ) {
		$("#password-err").html('<div class="alert alert-danger"><?php echo $LANG["WBS_REGF_SAME_PW"];?></div>');t++;
			} else { 
		$("#password-err").html(''); }

	if ( month == "0" ) {
		$("#month").css("border","1px solid #b94a48");t++;
			} else { 
		$("#month").css("border",""); }

	if ( day == "0" ) {
		$("#day").css("border","1px solid #b94a48");t++;
			} else { 
		$("#day").css("border",""); }

	if ( year == "0" ) {
		$("#year").css("border","1px solid #b94a48");t++;
			} else { 
		$("#year").css("border",""); }

	if ( location == "" ) {
		$("#location").css("border","1px solid #b94a48");t++;
			} else { 
		$("#location").css("border",""); }

			if ( t == 0 ) {
				$("#ad-register").attr('disabled', true);

				$("#register-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');
	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/register.php?t=new', { fname:fname, lname:lname, email:email, password:password, month:month, day:day, year:year, location:location },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			if ( mode == 1 ) {
				$("#register-loader").html('<div class="alert alert-success"><?php echo $LANG["WBS_REG_SUCCESSFULLY_CREATED"];?></div>');

						$("#fname").val("");
						$("#lname").val("");
						$("#email").val("");
						$("#password").val("");
						$("#cpassword").val("");
						$("#month").val("0");
						$("#day").val("0");
						$("#year").val("0");
						$("#location").val("");

				$("#ad-register").removeAttr('disabled');
			
			}
			if ( mode == 2 ) { 
				$("#register-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_REG_ERROR"];?></div>');
				$("#ad-register").removeAttr('disabled');
			}
			if ( mode == 3 ) { 
				$("#register-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_REG_ERROR_EMAIL"];?></div>');
				$("#ad-register").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION


			} else {
				$("#ad-register").removeAttr('disabled');
				$("#register-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_REGF_COMPLETE_ALL"];?></div>');
			}
	});


	// REGISTER
	$("#ad-login").on('click', function () {
		var	t	=	0;
		var	email		=	$("#email").val();
		var	password	=	$("#password").val();

		if ( password == "" ) {
			$("#password").css("border","1px solid #b94a48");t++;
				} else { 
			$("#password").css("border",""); }

		if ( email == "" ) {
			$("#email").css("border","1px solid #b94a48");t++;
				} else { 
			$("#email").css("border",""); }

			if( !jhzEv( email ) && email != '' ){
				$("#email").css("border","1px solid #b94a48");
				t = t + 1;
			}


if ( t == 0 ) {
				$("#ad-login").attr('disabled', true);
				$("#ad-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');


	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/login.php?t=auth', { email:email, password:password },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').html();
			var msj		= $r.filter('#message').html();
			if ( mode == 1 ) {
					//** PAGE REDIRECT **//
				window.location = '<?php echo HTTP_MASTER ?>dashboard';
			}
			if ( mode == 2 ) { 
				$("#ad-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#ad-register").removeAttr('disabled');
				$("#ad-login").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION



			} else {
				$("#ad-login").removeAttr('disabled');
				$("#ad-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_LOGIN_MANDATORY_FIELDS"];?></div>');
			}


	});


	// REQUEST NEW CODE
	$("#ad-request-code").on('click', function () {
		var	t	=	0;
		var	email		=	$("#email").val();

		if ( email == "" ) {
			$("#email").css("border","1px solid #b94a48");t++;
				} else { 
			$("#email").css("border",""); }

			if( !jhzEv( email ) && email != '' ){
				$("#email").css("border","1px solid #b94a48");
				t = t + 1;
			}

if ( t == 0 ) {
				$("#ad-request-code").attr('disabled', true);
				$("#ad-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/register.php?t=new-code', { email:email },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').html();
			var msj		= $r.filter('#message').html();
			if ( mode == 1 ) {
				$("#ad-loader").html('<div class="alert alert-success">'+msj+'</div>');
				$("#ad-request-code").removeAttr('disabled');
				$("#email").val("");
			}
			if ( mode == 2 ) { 
				$("#ad-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#ad-request-code").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION
			} else {
				$("#ad-request-code").removeAttr('disabled');
				$("#ad-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_REQ_MANDATORY_FIELDS"];?></div>');
			}

	});




	// REQUEST NEW PASSWORD
	$("#ad-request-password").on('click', function () {
		var	t	=	0;
		var	email		=	$("#email").val();

		if ( email == "" ) {
			$("#email").css("border","1px solid #b94a48");t++;
				} else { 
			$("#email").css("border",""); }

			if( !jhzEv( email ) && email != '' ){
				$("#email").css("border","1px solid #b94a48");
				t = t + 1;
			}

if ( t == 0 ) {
				$("#ad-request-code").attr('disabled', true);
				$("#ad-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/register.php?t=new-password', { email:email },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').html();
			var msj		= $r.filter('#message').html();
			if ( mode == 1 ) {
				$("#ad-loader").html('<div class="alert alert-success">'+msj+'</div>');
				$("#ad-request-code").removeAttr('disabled');
				$("#email").val("");
			}
			if ( mode == 2 ) { 
				$("#ad-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#ad-request-code").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION
			} else {
				$("#ad-request-code").removeAttr('disabled');
				$("#ad-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_REQP_MANDATORY_FIELDS"];?></div>');
			}

	});


	// LOG OUT
	$("#log-out").on('click', function () {
		$("#logged-in").html('<img class="logged-in-hd" src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/loader.gif"/>');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/login.php?t=out',
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').html();
			var msj		= $r.filter('#message').html();
			if ( mode == 1 ) { window.location = '<?php echo HTTP_MASTER ?>'; }
			if ( mode == 2 ) { 
				$("#logged-in").html('<div class="alert alert-danger">'+msj+'</div>');
			}
		});	
	//END POST FUNCTION
	});








	$("#adv-ad-type").on('change', function () {
		var	href		=	$( this ).val();
		window.location	=	href;
	});



	$("#adv-ad-campaign").on('change', function () {
		validate	=	$( this ).val();
		if ( validate == 0 ) {
			$(".disabled-form").attr("disabled", "disabled"); 
		} else {
			$(".disabled-form").removeAttr('disabled'); 
		}
	});





	$("#banner-size-value").on('change', function () {
	$("#error-img").html("");
		validate	=	$( this ).val();
		if ( validate == 0 ) {
			$(".disabled-form-banner-size").attr("disabled", "disabled"); 
		} else {
			$(".disabled-form-banner-size").removeAttr('disabled'); 
		}
	});



// var url = window.URL || window.webkitURL; // alternate use

function readImage(file) {
    var reader = new FileReader();
    var image  = new Image();


    reader.readAsDataURL(file);  
    reader.onload = function(_file) {
        image.src    = _file.target.result;              // url.createObjectURL(file);
        image.onload = function() {
            var w = this.width,
                h = this.height,
                t = file.type,                           // ext only: // file.type.split('/')[1],
                n = file.name,
                s = ~~(file.size/1024) +'KB';
            //$('#uploadPreview').append('<img src="'+ this.src +'"> '+w+'x'+h+' '+s+' '+t+' '+n+'<br>');
			
			var	getSize	=	$("#banner-size-value").val();
			if ( getSize == w+'x'+h ) {
				$("#error-img").html('');
				//alert('OK:'+ w+'-'+h );
			} else {
				//alert('err:'+ w+'-'+h );
				$("#error-img").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_BANNER_ERROR_IMG_SIZE"];?></div>');
				$("#banner-image").val("");
			}
        };
        image.onerror= function() {
				//alert('Invalid file type: '+ file.type);
				$("#error-img").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_BANNER_ERROR_IMG_INVALID"];?></div>');
				$("#banner-image").val("");
        };      
    };
    
}
$("#banner-image").change(function (e) {

    if(this.disabled) return alert('<?php echo $LANG["WBS_ADVERTISER_BANNER_ERROR_NOT_SUPORTED"];?>');
    var F = this.files;
    if(F && F[0]) for(var i=0; i<F.length; i++) readImage( F[i] );
});


$('.number').keypress(function (event) {
    if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
        event.preventDefault();
    }

    var text = $(this).val();

    if ((text.indexOf('.') != -1) && (text.substring(text.indexOf('.'), text.indexOf('.').length).length > 2)) {
        event.preventDefault();
    }
});




$("#campaign-submit").on('click', function () {
	var	t			=	0;
	var	id			=	$("#campaign-id").val();
	var	title		=	$("#campaign-title").val();
	var	budget		=	$("#campaign-daily-budget").val();
	var	description	=	$("#campaign-description").val();
	var	status		=	$("#campaign-status").val();

	if ( title == "" ) {
		$("#campaign-title").css("border","1px solid #b94a48");t++;
			} else { 
		$("#campaign-title").css("border",""); }

	if ( budget == "" ) {
		$("#campaign-daily-budget").css("border","1px solid #b94a48");t++;
			} else { 
		$("#campaign-daily-budget").css("border",""); }
/*
	if ( description == "" ) {
		$("#campaign-description").css("border","1px solid #b94a48");t++;
			} else { 
		$("#campaign-description").css("border",""); }
*/
	if ( status == "0" ) {
		$("#campaign-status").css("border","1px solid #b94a48");t++;
			} else { 
		$("#campaign-status").css("border",""); }

	if ( t == 0 ) {
		$("#campaign-submit").attr('disabled', true);
		$("#campaign-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');



	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.campaign.php?t=adm', { id:id, title:title, budget:budget, description:description, status:status },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			if ( mode == 1 ) {
				$("#campaign-loader").html('<div class="alert alert-success">'+msj+'</div>');
					$("#campaign-title").val("");
					$("#campaign-daily-budget").val("");
					$("#campaign-description").val("");
					$("#campaign-status").val("");
				$("#campaign-submit").removeAttr('disabled');
			
			}
			if ( mode == 3 ) {
				$("#campaign-loader").html('<div class="alert alert-success">'+msj+'</div>');
				$("#campaign-submit").removeAttr('disabled');
			
			}
			if ( mode == 2 ) { 
				$("#campaign-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#campaign-submit").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION




	} else {
		$("#campaign-submit").removeAttr('disabled');
		$("#campaign-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_CAMPAIGN_COMPLETE_ALL"];?></div>');
	}

});





$("#ad-submit").on('click', function () {
	var	t			=	0;
	var	id			=	$("#adv-ad-id").val();
	var	campaign	=	$("#adv-ad-campaign").val();
	var	country		=	$("#adv-ad-country").val();
	var	title		=	$("#adv-ad-title").val();
	var	summary_1	=	$("#adv-ad-summary-1").val();
	var	summary_2	=	$("#adv-ad-summary-2").val();
	var	display_url	=	$("#adv-ad-display-url").val();
	var	target_url	=	$("#adv-ad-target-url").val();

	if ( campaign == "0" ) {
		$("#adv-ad-campaign").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-ad-campaign").css("border",""); }

	if ( title == "" ) {
		$("#adv-ad-title").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-ad-title").css("border",""); }

	if ( summary_1 == "" ) {
		$("#adv-ad-summary-1").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-ad-summary-1").css("border",""); }

	if ( summary_2 == "" ) {
		$("#adv-ad-summary-2").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-ad-summary-2").css("border",""); }

	if ( display_url == "" ) {
		$("#adv-ad-display-url").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-ad-display-url").css("border",""); }

	if ( display_url != "" && url(display_url) !='valid' ) {
		$("#adv-ad-display-url").css("border","1px solid #b94a48");t++;
			}


	if ( target_url == "" ) {
		$("#adv-ad-target-url").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-ad-target-url").css("border",""); }

	if ( target_url != "" && url(target_url) !='valid' ) {
		$("#adv-ad-target-url").css("border","1px solid #b94a48");t++;
			}


	if ( t == 0 ) {
		$("#ad-submit").attr('disabled', true);
		$("#ad-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.ad.php?t=text-ad', { id:id, campaign:campaign, country:country, title:title, summary_1:summary_1, summary_2:summary_2, display_url:display_url, target_url:target_url },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			var ad_id	= $r.filter('#ad_id').text();
			if ( mode == 1 ) {
				$("#ad-loader").html('<div class="alert alert-success">'+msj+'</div>');

					$("#adv-ad-country").val("0");
					$("#adv-ad-title").val("");
					$("#adv-ad-summary-1").val("");
					$("#adv-ad-summary-2").val("");
					$("#adv-ad-display-url").val("");
					$("#adv-ad-target-url").val("");

				$("#ad-submit").removeAttr('disabled');
					//** PAGE REDIRECT **//
				window.location = '<?php echo HTTP_MASTER ?>dashboard/advertiser/keywords?id='+ad_id;
			}
			if ( mode == 3 ) {
				$("#ad-loader").html('<div class="alert alert-success">'+msj+'</div>');
				$("#ad-submit").removeAttr('disabled');
			
			}
			if ( mode == 2 ) { 
				$("#ad-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#ad-submit").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION

	} else {
		$("#ad-submit").removeAttr('disabled');
		$("#ad-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_COMPLETE_ALL"];?></div>');
	}

});


//BANNER AD



$("#ad-banner").on('click', function () {
	var	t				=	0;
	var	id				=	$("#adv-ad-id").val();
	var	campaign		=	$("#adv-ad-campaign").val();
	var	country			=	$("#adv-ad-country").val();
	var	title			=	$("#adv-ad-title").val();
	var	banner_size		=	$("#banner-size-value").val();
	var	banner_image	=	$("#banner-image").val();
	var	target_url		=	$("#adv-ad-target-url").val();
	var validate_banner	=	$("#validate-banner-image").val();


	if ( campaign == "0" ) {
		$("#adv-ad-campaign").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-ad-campaign").css("border",""); }


	if ( banner_size == "" ) {
		$("#banner-size-value").css("border","1px solid #b94a48");t++;
			} else { 
		$("#banner-size-value").css("border",""); }

	if ( banner_image == "" && validate_banner == "" ) {
		$("#banner-image").css("border","1px solid #b94a48");t++;
			} else { 
		$("#banner-image").css("border",""); }


	if ( title == "" ) {
		$("#adv-ad-title").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-ad-title").css("border",""); }

	if ( target_url == "" ) {
		$("#adv-ad-target-url").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-ad-target-url").css("border",""); }

	if ( target_url != "" && url(target_url) !='valid' ) {
		$("#adv-ad-target-url").css("border","1px solid #b94a48");t++;
			}




	if ( t == 0 ) {
		$("#ad-banner").attr('disabled', true);
		$("#ad-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');

			$( "#banner-ad-form" ).submit();

	} else {
		$("#ad-banner").removeAttr('disabled');
		$("#ad-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_COMPLETE_ALL"];?></div>');
	}



});












$("#adv-add-keyword").on('click', function () {
		$("#adv-add-keyword").attr('disabled', true);
	var	t			=	0;
	var	ad_id		=	$("#ad-ad_id").val();
	var	keyword		=	$("#ad-keyword").val();
	var	value		=	parseFloat($("#ad-value").val());
	var	maxValue	=	parseFloat($("#adv-max-value").val());


	if ( keyword == "" ) {
		$("#ad-keyword").css("border","1px solid #b94a48");t++;
			} else { 
		$("#ad-keyword").css("border",""); }

	if ( value == "" ) {
		$("#ad-value").css("border","1px solid #b94a48");t++;
			} else { 
		$("#ad-value").css("border",""); }

	if ( !$.isNumeric(value) || (value < (<?php echo COST_MIN_CLICK;?>)) ) {
		$("#ad-value").css("border", "1px solid red");t=t+1;
		$("#ad-value-error").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_KEYWORDS_MIN_ERROR"];?> <?php echo COST_MIN_CLICK;?></div>');
	} else {
		$("#ad-value-error").html('');
	}


	if ( value > maxValue ) {
		$("#ad-value").css("border", "1px solid red");t=t+1;
		$("#ad-value-error").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_KEYWORDS_MAX_ERROR"];?> ' + maxValue + '</div>');
	}



	if ( t == 0 ) {


	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.ad.php?t=keyword', { keyword:keyword, value:value, ad_id:ad_id },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			var id		= $r.filter('#keyword_id').text();
			var rval	= $r.filter('#rval').text();

			if ( mode == 1 ) {
				$('#keywords-list > tbody:last').append('<tr id="keword-' + id + '"><td class="col-md-4">' + keyword + '</td><td class="col-md-3"><div class="input-group"><span class="input-group-addon"><?php echo MONEY_SYMBOL;?></span><input id="adv-keyword-' + id + '" type="text" class="form-control number" placeholder="" value="' + value + '"></div></td><td class="col-md-2">' + rval + '</td><td class="col-md-3"><button id="keyword-update-button-' + id + '" data-id="' + id + '" type="button" class="btn btn-default btn-sm keyword-update"><span class="glyphicon glyphicon-pencil"></span> <?php echo $LANG["WBS_ADVERTISER_AD_KEYWORD_UPDATE"];?></button>&nbsp;&nbsp;<button id="keyword-remove-button-' + id + '" data-id="' + id + '" type="button" class="btn btn-default btn-sm keyword-remove"><span class="glyphicon glyphicon-trash"></span> <?php echo $LANG["WBS_ADVERTISER_AD_KEYWORD_REMOVE"];?></button></td></tr>');
				
				$("#ad-keyword").val("");
				$("#ad-value").val("");
				$("#adv-add-keyword").removeAttr('disabled');
			}
			if ( mode == 2 ) { 
				$("#ad-value-error").html('<div class="alert alert-danger">' + msj + '</div>');
				$("#adv-add-keyword").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION



	} else {
		$("#adv-add-keyword").removeAttr('disabled');
	}


});



$(".start-ad").on('click', function () {
	m	=	this.id;
	id	=	$(this).data("id");
	var	mode	=	'start';

	$("#" + m ).attr('disabled', true);

	//** REMOVE ATTR DISABLED **//
	$("#stop-" + id ).removeAttr('disabled');
	$("#pause-" + id ).removeAttr('disabled');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.ad.php?t=ad-status', { id:id,mode:mode });	
	//END POST FUNCTION

});


$(".stop-ad").on('click', function () {
	m			=	this.id;
	id			=	$(this).data("id");
	var	mode	=	'stop';
	$("#" + m ).attr('disabled', true);

	//** REMOVE ATTR DISABLED **//
	$("#start-" + id ).removeAttr('disabled');
	$("#pause-" + id ).removeAttr('disabled');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.ad.php?t=ad-status', { id:id,mode:mode });	
	//END POST FUNCTION

});


$(".pause-ad").on('click', function () {
	m	=	this.id;
	id	=	$(this).data("id");
	var	mode	=	'pause';

	$("#" + m ).attr('disabled', true);

	//** REMOVE ATTR DISABLED **//
	$("#start-" + id ).removeAttr('disabled');
	$("#stop-" + id ).removeAttr('disabled');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.ad.php?t=ad-status', { id:id,mode:mode });	
	//END POST FUNCTION

});



$(".start-campaign").on('click', function () {
	m	=	this.id;
	id	=	$(this).data("id");
	var	mode	=	'start';

	$("#" + m ).attr('disabled', true);

	//** REMOVE ATTR DISABLED **//
	$("#stop-" + id ).removeAttr('disabled');
	$("#pause-" + id ).removeAttr('disabled');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.campaign.php?t=campaign-status', { id:id,mode:mode });	
	//END POST FUNCTION
});

$(".pause-campaign").on('click', function () {
	m	=	this.id;
	id	=	$(this).data("id");
	var	mode	=	'pause';

	$("#" + m ).attr('disabled', true);

	//** REMOVE ATTR DISABLED **//
	$("#stop-" + id ).removeAttr('disabled');
	$("#start-" + id ).removeAttr('disabled');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.campaign.php?t=campaign-status', { id:id,mode:mode });	
	//END POST FUNCTION
});





$(document).on('click', ".keyword-remove", function () {

	m			=	this.id;
	id			=	$(this).data("id");
	var	ad_id	=	$("#ad-ad_id").val();


	$("#keword-"+id).hide('slow');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.ad.php?t=remove-keyword', { id:id, ad_id:ad_id },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			//extra functions
		});	
	//END POST FUNCTION

});



$(document).on('click', ".keyword-update", function () {
	var	t				=	0;
	m				=	this.id;
	id				=	$(this).data("id");
	var	ad_id		=	$("#ad-ad_id").val();
	var	value		=	$("#adv-keyword-" + id).val();
	var	maxValue	=	parseFloat($("#adv-max-value").val());

	if ( value == "" ) {
		$("#adv-keyword-").css("border","1px solid #b94a48");t++;
			} else { 
		$("#adv-keyword-" + id).css("border",""); }

	if ( !$.isNumeric(value) || (value < (<?php echo COST_MIN_CLICK;?>)) ) {
		$("#adv-keyword-" + id).css("border", "1px solid red");t=t+1;
		$("#ad-value-error").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_KEYWORDS_MIN_ERROR"];?> <?php echo COST_MIN_CLICK;?></div>');
	} else {
		$("#ad-value-error").html('');
	}

	if ( value > maxValue ) {
		$("#adv-keyword-" + id).css("border", "1px solid red");t=t+1;
		$("#ad-value-error").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_KEYWORDS_MAX_ERROR"];?> ' + maxValue + '</div>');
	}








if ( t == 0 ) {
	$("#" + m ).attr('disabled', true);
	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/advertiser.ad.php?t=update-keyword', { id:id, ad_id:ad_id , value:value},
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			//extra functions
				$("#" + m ).removeAttr('disabled');
		});	
	//END POST FUNCTION
}



});



//*** UPDATE PROFILE ***//
	$("#ad-update-profile").on('click', function () {
		var	t	=	0;
		var	fname		=	$("#fname").val();
		var	lname		=	$("#lname").val();

		var	email		=	$("#email").val();
		var	phone		=	$("#phone").val();

		var	password	=	$("#password").val();
		var	cpassword	=	$("#cpassword").val();
		var	month		=	$("#month").val();
		var	day			=	$("#day").val();
		var	year		=	$("#year").val();
		var	location	=	$("#location").val();
		var	city		=	$("#city").val();
		var	zip			=	$("#zip").val();
		var	address		=	$("#address").val();
		var	tax_id		=	$("#tax_id	").val();


	if ( fname == "" ) {
		$("#fname").css("border","1px solid #b94a48");t++;
			} else { 
		$("#fname").css("border",""); }

	if ( lname == "" ) {
		$("#lname").css("border","1px solid #b94a48");t++;
			} else { 
		$("#lname").css("border",""); }

	if ( email == "" ) {
		$("#email").css("border","1px solid #b94a48");t++;
			} else { 
		$("#email").css("border",""); }

		if( !jhzEv( email ) && email != '' ){
			$("#email").css("border","1px solid #b94a48");
			t = t + 1;
		}


	if ( month == "0" ) {
		$("#month").css("border","1px solid #b94a48");t++;
			} else { 
		$("#month").css("border",""); }

	if ( day == "0" ) {
		$("#day").css("border","1px solid #b94a48");t++;
			} else { 
		$("#day").css("border",""); }

	if ( year == "0" ) {
		$("#year").css("border","1px solid #b94a48");t++;
			} else { 
		$("#year").css("border",""); }

	if ( location == "" ) {
		$("#location").css("border","1px solid #b94a48");t++;
			} else { 
		$("#location").css("border",""); }

			if ( t == 0 ) {
				$("#ad-update-profile").attr('disabled', true);

				$("#profile-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');
	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/user.class.php?t=profile', { fname:fname, lname:lname, email:email, phone:phone, password:password, month:month, day:day, year:year, location:location, city:city, zip:zip, address:address, tax_id:tax_id },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			if ( mode == 1 ) {
				$("#profile-loader").html('<div class="alert alert-success"><?php echo $LANG["WBS_PROFILE_UPDATED"];?></div>');
				$("#ad-update-profile").removeAttr('disabled');
			
			}
			if ( mode == 2 ) { 
				$("#profile-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_PROFILE_ERROR"];?></div>');
				$("#ad-update-profile").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION


			} else {
				$("#ad-update-profile").removeAttr('disabled');
				$("#profile-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_PROFILE_COMPLETE_MANDATORY"];?></div>');
			}
	});

//*** END UPDATE PROFILE ***//





//*** ADD FUNDS ***//
	$("#add-funds").on('click', function () {
		var	t	=	0;
		var	amount		=	$("#amount").val();
		if ( amount == "" ) {
			$("#amount").css("border","1px solid #b94a48");t++;
				} else { 
			$("#amount").css("border",""); }

		if ( t == 0 ) {
			$("#add-funds").attr('disabled', true);
			$("#ad-funds-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');

				$( "#add-funds-form" ).submit();

		} else {
			$("#add-funds").removeAttr('disabled');
			$("#ad-funds-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_PAYPAL_ENTER_AMOUNT"];?></div>');
		}

	});

//*** END ADD FUNDS ***//



//*** PUBLISHER ***//

$("#channel-submit").on('click', function () {
	var	t				=	0;
	var	id				=	$("#channel-id").val();
	var	title			=	$("#channel-title").val();
	var	description		=	$("#channel-description").val();
	var	domain			=	$("#channel-domain").val();

	if ( title == "" ) {
		$("#campaign-title").css("border","1px solid #b94a48");t++;
			} else { 
		$("#campaign-title").css("border",""); }


	if ( t == 0 ) {
		$("#channel-submit").attr('disabled', true);
		$("#channel-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');



	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/publisher.channel.php?t=adm', { id:id, title:title, description:description, domain:domain },
		function(data) {


			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			if ( mode == 1 ) {
				$("#channel-loader").html('<div class="alert alert-success">'+msj+'</div>');
					$("#channel-title").val("");
					$("#channel-description").val("");
					$("#channel-domain").val("");
				$("#channel-submit").removeAttr('disabled');
			
			}
			if ( mode == 3 ) {
				$("#channel-loader").html('<div class="alert alert-success">'+msj+'</div>');
				$("#channel-submit").removeAttr('disabled');
			
			}
			if ( mode == 2 ) { 
				$("#channel-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#channel-submit").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION




	} else {
		$("#channel-submit").removeAttr('disabled');
		$("#channel-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_CAMPAIGN_COMPLETE_ALL"];?></div>');
	}

});



	$("#pub-ad-channel").on('change', function () {
		validate	=	$( this ).val();
		if ( validate == 0 ) {
			$(".disabled-form").attr("disabled", "disabled"); 
		} else {
			$(".disabled-form").removeAttr('disabled'); 
		}
	});







$("#ad-pub-submit").on('click', function () {

	var	t					=	0;
	var	id					=	$("#pub-ad-id").val();
	var	channel				=	$("#pub-ad-channel").val();
	var	ad_title			=	$("#pub-ad-title").val();
	var	ad_size				=	$("#pub-ad-size").val();
	var	ad_type				=	$("#pub-ad-type").val();
	var	title_color			=	$("#title-color").val();
	var	link_color			=	$("#link-color").val();
	var	text_color			=	$("#text-color").val();
	var	background_color	=	$("#background-color").val();
	var	border_color		=	$("#border-color").val();

	var width	=	$('option:selected', '#pub-ad-size').attr("data-width");
	var height	=	$('option:selected', '#pub-ad-size').attr("data-height");

	if ( channel == "0" ) {
		$("#pub-ad-channel").css("border","1px solid #b94a48");t++;
			} else { 
		$("#pub-ad-channel").css("border",""); }

	if ( ad_size == "0" ) {
		$("#pub-ad-size").css("border","1px solid #b94a48");t++;
			} else { 
		$("#pub-ad-size").css("border",""); }

	if ( ad_type == "0" ) {
		$("#pub-ad-type").css("border","1px solid #b94a48");t++;
			} else { 
		$("#pub-ad-type").css("border",""); }

	if ( ad_title == "" ) {
		$("#pub-ad-title").css("border","1px solid #b94a48");t++;
			} else { 
		$("#pub-ad-title").css("border",""); }

	if ( title_color == "" ) {
		$("#title-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#title-color").css("border",""); }

	if ( link_color == "" ) {
		$("#link-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#link-color").css("border",""); }

	if ( text_color == "" ) {
		$("#text-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#text-color").css("border",""); }

	if ( background_color == "" ) {
		$("#background-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#background-color").css("border",""); }

	if ( border_color == "" ) {
		$("#border-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#border-color").css("border",""); }



	if ( t == 0 ) {
		$("#ad-pub-submit").attr('disabled', true);
		$("#ad-pub-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');



	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/publisher.ad.php?t=adm', { id:id, channel:channel, ad_title:ad_title, title_color:title_color, link_color:link_color, text_color:text_color, background_color:background_color, border_color:border_color, ad_type:ad_type, ad_size:ad_size },
		function(data) {


			var $r=$(data);
			var mode		= $r.filter('#mode').text();
			var msj			= $r.filter('#message').text();
			var pub_ad_id	= $r.filter('#pub_ad_id').text();
			if ( mode == 1 ) {
				$("#pub-ad-title").val("");
				$("#ad-pub-submit").removeAttr('disabled');
				$("#ad-pub-loader").html('<div class="alert alert-success">'+msj+'</div>');


	$(".other_solution").fancybox({
		maxWidth	: 630,
		maxHeight	: 235,
		fitToView	: false,
		width		: '70%',
		height		: '70%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
    afterLoad   : function() {
        this.content = ( '<legend><?php echo $LANG["WBS_PUB_AD_CODE"];?></legend><br/><pre onclick="selectText(this.id);" id="select-me">&lt;script async src="<?php echo HTTP_SERVER_WEBSITE ?>pagead/ads.js"&gt;&lt;/script&gt;<br/>&lt;!-- ' + ad_title + ' --&gt;<br/>&lt;ins class="<?php echo ADS_CLASS_NAME;?>"<br/>     style="display:inline-block;width:' + width + 'px;height:' + height + 'px"<br/>     data-ad-client="ca-pub-<?php echo $_SESSION[USER_SESSION]['0']['user_id'];?>"<br/>     data-ad-slot="' + pub_ad_id + '"&gt;&lt;/ins&gt;<br/></pre>' );
    }
	}).trigger('click');



			}
			if ( mode == 3 ) {
				$("#ad-pub-loader").html('<div class="alert alert-success">'+msj+'</div>');
				$("#ad-pub-submit").removeAttr('disabled');

			}
			if ( mode == 2 ) { 
				$("#ad-pub-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#ad-pub-submit").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION




	} else {
		$("#ad-pub-submit").removeAttr('disabled');
		$("#ad-pub-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_COMPLETE_ALL"];?></div>');
	}





});


$("#ad-pub-get-code").on('click', function () {

	var	t					=	0;
	var	id					=	$("#pub-ad-id").val();
	var	channel				=	$("#pub-ad-channel").val();
	var	ad_title			=	$("#pub-ad-title").val();
	var	ad_size				=	$("#pub-ad-size").val();
	var	title_color			=	$("#title-color").val();
	var	link_color			=	$("#link-color").val();
	var	text_color			=	$("#text-color").val();
	var	background_color	=	$("#background-color").val();
	var	border_color		=	$("#border-color").val();

	var width	=	$('option:selected', '#pub-ad-size').attr("data-width");
	var height	=	$('option:selected', '#pub-ad-size').attr("data-height");

	if ( channel == "0" ) {
		$("#pub-ad-channel").css("border","1px solid #b94a48");t++;
			} else { 
		$("#pub-ad-channel").css("border",""); }

	if ( ad_size == "0" ) {
		$("#pub-ad-size").css("border","1px solid #b94a48");t++;
			} else { 
		$("#pub-ad-size").css("border",""); }

	if ( ad_title == "" ) {
		$("#pub-ad-title").css("border","1px solid #b94a48");t++;
			} else { 
		$("#pub-ad-title").css("border",""); }

	if ( title_color == "" ) {
		$("#title-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#title-color").css("border",""); }

	if ( link_color == "" ) {
		$("#link-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#link-color").css("border",""); }

	if ( text_color == "" ) {
		$("#text-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#text-color").css("border",""); }

	if ( background_color == "" ) {
		$("#background-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#background-color").css("border",""); }

	if ( border_color == "" ) {
		$("#border-color").css("border","1px solid #b94a48");t++;
			} else { 
		$("#border-color").css("border",""); }



	if ( t == 0 ) {
		$("#ad-pub-get-code").attr('disabled', true);
		$("#ad-pub-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');



	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/publisher.ad.php?t=adm', { id:id, channel:channel, ad_title:ad_title, title_color:title_color, link_color:link_color, text_color:text_color, background_color:background_color, border_color:border_color },
		function(data) {


			var $r=$(data);
			var mode		= $r.filter('#mode').text();
			var msj			= $r.filter('#message').text();
			var pub_ad_id	= $r.filter('#pub_ad_id').text();
			if ( mode == 1 ) {
				$("#pub-ad-title").val("");
				$("#ad-pub-get-code").removeAttr('disabled');
				$("#ad-pub-loader").html('<div class="alert alert-success">'+msj+'</div>');


	$(".other_solution").fancybox({
		maxWidth	: 630,
		maxHeight	: 235,
		fitToView	: false,
		width		: '70%',
		height		: '70%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
    afterLoad   : function() {
        this.content = ( '<legend><?php echo $LANG["WBS_PUB_AD_CODE"];?></legend><br/><pre onclick="selectText(this.id);" id="select-me">&lt;script async src="<?php echo HTTP_SERVER_WEBSITE ?>pagead/ads.js"&gt;&lt;/script&gt;<br/>&lt;!-- ' + ad_title + ' --&gt;<br/>&lt;ins class="<?php echo ADS_CLASS_NAME;?>"<br/>     style="display:inline-block;width:' + width + 'px;height:' + height + 'px"<br/>     data-ad-client="ca-pub-<?php echo $_SESSION[USER_SESSION]['0']['user_id'];?>"<br/>     data-ad-slot="' + pub_ad_id + '"&gt;&lt;/ins&gt;<br/></pre>' );
    }
	}).trigger('click');



			}
			if ( mode == 3 ) {
				$("#ad-pub-loader").html('<div class="alert alert-success">'+msj+'</div>');
				$("#ad-pub-get-code").removeAttr('disabled');


	$(".other_solution").fancybox({
		maxWidth	: 630,
		maxHeight	: 235,
		fitToView	: false,
		width		: '70%',
		height		: '70%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
    afterLoad   : function() {
        this.content = ( '<legend><?php echo $LANG["WBS_PUB_AD_CODE"];?></legend><br/><pre onclick="selectText(this.id);" id="select-me">&lt;script async src="<?php echo HTTP_SERVER_WEBSITE ?>pagead/ads.js"&gt;&lt;/script&gt;<br/>&lt;!-- ' + ad_title + ' --&gt;<br/>&lt;ins class="<?php echo ADS_CLASS_NAME;?>"<br/>     style="display:inline-block;width:' + width + 'px;height:' + height + 'px"<br/>     data-ad-client="ca-pub-<?php echo $_SESSION[USER_SESSION]['0']['user_id'];?>"<br/>     data-ad-slot="' + pub_ad_id + '"&gt;&lt;/ins&gt;<br/></pre>' );
    }
	}).trigger('click');


			}
			if ( mode == 2 ) { 

				$("#ad-pub-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#ad-pub-get-code").removeAttr('disabled');

			}
		});	
	//END POST FUNCTION




	} else {
		$("#ad-pub-get-code").removeAttr('disabled');
		$("#ad-pub-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_ADVERTISER_COMPLETE_ALL"];?></div>');
	}

});





$("#withdrawal-submit").on('click', function () {
	var	t				=	0;
	var	value			=	$("#withdrawal-value").val();
	var	maxValue		=	parseFloat($("#withdrawal-max-value").val());

	if ( value == "" ) {
		$("#withdrawal-value").css("border","1px solid #b94a48");t++;
			} else { 
		$("#withdrawal-value").css("border",""); }

	if ( value !== "" && value < <?php echo WITHDRAWAL_MINIMUM;?> ) {
		$("#withdrawal-value").css("border", "1px solid red");t=t+1;
		$("#withdrawal-loader").html('<div class="alert alert-danger">Minimum allowed withdrawal <?php echo WITHDRAWAL_MINIMUM;?></div>');
	} else {
		$("#withdrawal-loader").html('');
	}


	if ( value !== "" && maxValue < <?php echo WITHDRAWAL_MINIMUM;?> ) {
		$("#withdrawal-value").css("border", "1px solid red");t=t+1;
		$("#withdrawal-loader").html('<div class="alert alert-danger">You don\'t have enought money to withdrawal</div>');
	}


	if ( t == 0 ) {
	$("#withdrawal-submit").attr('disabled', true);
	$("#withdrawal-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');


	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/publisher.money.php?t=withdrawal', { value:value },
		function(data) {


			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			if ( mode == 1 ) {
				$("#withdrawal-loader").html('<div class="alert alert-success">'+msj+'</div>');
				$("#withdrawal-submit").removeAttr('disabled');
				$("#withdrawal-max-value").val( parseFloat( maxValue - value ).toFixed(2) );
				$("#withdrawal-max-value-text").text( parseFloat( maxValue - value ).toFixed(2) );
				$("#withdrawal-value").val( "" );
			}
			if ( mode == 2 ) { 
				$("#withdrawal-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#withdrawal-submit").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION

	}
});




$( ".cancel-withdrawal" ).on('click', function () {
	id	=	$(this).data("id");

	$( "#cancel-request-"+id ).html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');

	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/publisher.money.php?t=status', { id:id, m:'cancel' },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			if ( mode == 1 ) {
	$( "#cancel-request-"+id ).html('<div class="alert alert-success">'+msj+'</div>');
			}
			if ( mode == 2 ) { 
	$( "#cancel-request-"+id ).html('<div class="alert alert-danger">'+msj+'</div>');
			}
		});	
	//END POST FUNCTION

});






$( "#payment-paypal-profile" ).on('click', function () {

	var	t		=	0;
	var	fname	=	$("#fname").val();
	var	lname	=	$("#lname").val();
	var	email	=	$("#email").val();

	if ( fname == "" ) {
		$("#fname").css("border","1px solid #b94a48");t++;
			} else { 
		$("#fname").css("border",""); }

	if ( lname == "" ) {
		$("#lname").css("border","1px solid #b94a48");t++;
			} else { 
		$("#lname").css("border",""); }

	if ( email == "" ) {
		$("#email").css("border","1px solid #b94a48");t++;
			} else { 
		$("#email").css("border",""); }


	if ( t == 0 ) {
	$("#payment-paypal-profile").attr('disabled', true);
	$("#paypal-profile-loader").html('<img src="<?php echo HTTP_SERVER_WEBSITE ?>templates/<?php echo WEBSITE_TEMPLATE;?>/assets/images/load.gif"/>');


	//POST FUNCTION
	$.post('<?php echo HTTP_SERVER_SYSTEM;?>users/publisher.money.php?t=payment-profile', { fname:fname, lname:lname, email:email },
		function(data) {

			var $r=$(data);
			var mode	= $r.filter('#mode').text();
			var msj		= $r.filter('#message').text();
			if ( mode == 1 ) {
				$("#paypal-profile-loader").html('<div class="alert alert-success">'+msj+'</div>');
				$("#payment-paypal-profile").removeAttr('disabled');
			}
			if ( mode == 2 ) { 
				$("#paypal-profile-loader").html('<div class="alert alert-danger">'+msj+'</div>');
				$("#payment-paypal-profile").removeAttr('disabled');
			}
		});	
	//END POST FUNCTION

	} else {
		$("#paypal-profile-loader").html('<div class="alert alert-danger"><?php echo $LANG["WBS_MONEY_SETTINGS_MANDATORY_FIELDS"];?></div>');
		$("#payment-paypal-profile").removeAttr('disabled');
	}
});














});