$(document).ready(function(){
    $('#testMail').click(function(){
        emailSender();
    })    
    $('#testEmailTemplate').submit(function(){
        var res = emailSender();
        return false;
    })    
    var emailSender = function(){
        var emailTempID = $('#emailTempID').val();
        var testEmailId = $('#testEmailId').val();
		var brandID		= $('#brandID').val();
        if(!validate(testEmailId)) {
            jNotify(errEnterValidEmail, 'common_message','message_error');
			location.hash = "#jump-to-message";
            return false;
        }
        $('#email-sending').removeClass('hide');
        $.ajax({
            type : 'post',
            async:false,
            data : {emailTempID:emailTempID,testEmailId:testEmailId,brandID:brandID},
            url : GLOBAL_BASE_PATH+'/emailtemplate/ajaxtestmail/',
            success :function(data){
                $('#email-sending').addClass('hide');
                $('#common_message').removeAttr("style")
                if(data=='success') {
					$('#testEmailId').val('');
                    jNotify(msgTestMailSent, 'common_message','message_success');
                }
                else if(data=='failed') {
                    jNotify(errTestMailSendingFailed, 'common_message','message_error');
                }
                else if(data == 'invalid'){
                    jNotify(errInvalideRequest, 'common_message','message_error');
                }
                else{
                    jNotify(data, 'common_message','message_error');
                }
				location.hash = "#jump-to-message";
            }
        })        
    }
    
    $('#cancel').click(function(){
        parent.$.colorbox.close();
    })
    
    $(document).on("click",'.parentLevel',function(){		
        $(this).toggleClass("clps");
        $(this).next(".childLevel").slideToggle();
    })
})
function validate(email) {
    var reg = /^([A-Za-z0-9\'_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    
    if(reg.test(email) == false) {
        return false;
    }
    else{
        return true;
    }
}
	
	 
