var argmon= '';
var cpnID = '49b3a4a1575a724d1f44a5d20c843c09';

$(function(){

	$(document).asMask().enterToTab();

	$(".M label").live('click', function() {	//step1 - OK?
		if( $("label[for='txSexo1']").hasClass('active') ){
			$("label[for='txSexo1']").removeClass('active');
			$("label[for='txSexo2']").addClass("active");
		}
		else { 
			$("label[for='txSexo2']").removeClass('active');
			$("label[for='txSexo1']").addClass("active");
		}
		
		$("#txSexo").val($(this).attr('value'));

	});

	$(".F label").live('click', function() {	//step1 - OK?
		if( $("label[for='txSexo2']").hasClass('active') ){
			$("label[for='txSexo2']").removeClass('active');
			$("label[for='txSexo1']").addClass("active");
		}
		else { 
			$("label[for='txSexo1']").removeClass('active');
			$("label[for='txSexo2']").addClass("active");
		}
		
		$("#txSexo").val($(this).attr('value'));

	});

    
   $('#uzoForm').validate({
        submitHandler: function(form) {
            $("#btnContinuarUzo").hide();    
            $.post("uzoForm.php", $("#uzoForm").serialize(), function(data){                                       
                if (data.message == "success") {  
                    var convert = data.conversion;
                    var myReturn = convert.split("#");
                    $("#conv").html('<iframe src="http://trade.cigplatform.com/conv.php?cpnid='+cpnID+'&arg='+myReturn[0]+'&argmon='+argmon+'&idData='+myReturn[1]+'&aspid='+myReturn[2]+'" frameborder="0" width="1" height="1"></iframe>');
                    $("#uzo_form").hide();
                    $("#sucess").show();
                    track("sucesso",20);
                } else {
                    alert("Ocorreu um erro. Tente mais tarde.");
                    $("#btnContinuarUzo").show();
                    return false;
                }
            },"json");
            return false;
        },
    	showMessageOn: $('.errorContainerUzo'),
        inputHighlight: true,
        afterValidate: function(){
            if($('.error').length > 0){
                $('#uzoForm .error').each(function(){
                    if($(this).is(":text")){
                        $(this).parent().prev().attr("class","inputLeftError");
                        $(this).parent().attr("class","inputCenterError");
                        $(this).parent().next().attr("class","inputRightError");
                    }
                });
            }
            if($('.valid').length > 0){
                if((parseInt($('.error').length)-parseInt($(".errorContainer .error").length))==0){
                    $(".errorContainer").html("");
                }
                $('#uzoForm .valid').each(function(){
                    if($(this).is(":text")){
            	        $(this).parent().prev().attr("class","inputLeftOk");
            	        $(this).parent().attr("class","inputCenterOk");
            	        $(this).parent().next().attr("class","inputRightOk");
                    }
                });
            }
        }
    });
       
    
    
}); 


